Skip to content

Fix race in pin/unpin#38

Open
yapple wants to merge 1 commit intoaibrix:devfrom
yapple:fix-race
Open

Fix race in pin/unpin#38
yapple wants to merge 1 commit intoaibrix:devfrom
yapple:fix-race

Conversation

@yapple
Copy link

@yapple yapple commented Mar 11, 2026

Pull Request Description

[Please provide a clear and concise description of your changes here]

Related Issues

Resolves: #[Insert issue number(s)]

Important: Before submitting, please complete the description above and review the checklist below.


Contribution Guidelines (Expand for Details)

We appreciate your contribution to PrisKV! To ensure a smooth review process and maintain high code quality, please adhere to the following guidelines:

Pull Request Title Format

Your PR title should start with one of these prefixes to indicate the nature of the change:

  • [Bug]: Corrections to existing functionality
  • [CI]: Changes to build process or CI pipeline
  • [Docs]: Updates or additions to documentation
  • [API]: Modifications to PrisKV's API or interface
  • [CLI]: Changes or additions to the Command Line Interface
  • [Misc]: For changes not covered above (use sparingly)

Note: For changes spanning multiple categories, use multiple prefixes in order of importance.

Submission Checklist

  • PR title includes appropriate prefix(es)
  • Changes are clearly explained in the PR description
  • New and existing tests pass successfully
  • Code adheres to project style and best practices
  • Documentation updated to reflect changes (if applicable)
  • Thorough testing completed, no regressions introduced

By submitting this PR, you confirm that you've read these guidelines and your changes align with the project's contribution standards.

@yapple yapple force-pushed the fix-race branch 3 times, most recently from cb3e88b to c98fcb5 Compare March 12, 2026 08:09
}
/* Optional: unpin on release if requested; unpin always targets latest version */
/* Enforce RELEASE+UNPIN all-or-nothing semantics when requested:
* - If UNPIN_ON_RELEASE is set and unpin fails (e.g., NO_SUCH_KEY / UNPIN_NOT_CLOSED),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why retry on NO_SUCH_KEY / UNPIN_NOT_CLOSED?

  • NO_SUCH_KEY: retrying until the same key is stored & pinned is not feasible, no one knows how long it will take
  • UNPIN_NOT_CLOSED: pin count already mismatched, retrying may make the mismatch even worse, it'd better to fail earlier

Copy link
Author

@yapple yapple Mar 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is true that there should not be retrying after a pin operation fails;

* - Then perform unpin on latest version to maintain multi-version semantics.
*/
resp = priskv_key_unpin_latest(conn->kv, keynode);
if (resp != PRISKV_RESP_STATUS_OK) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to cleanup if retrying does not make sense

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure , i will cleanup token in here

  • Add priskv_publish_node_with_pin(kv, keynode, pin_on_publish) and make priskv_publish_node delegate to it. Publishing now runs under the hash-bucket lock, inherits pin_count from the old version, removes the old visible node, inserts the new one, and cleans up the old outside the lock—ensuring a single visible version.
  • Replace deprecated priskv_key_pin with priskv_key_pin_latest; update semantics so both pin and unpin operate on the latest visible version under the bucket lock, with inline expiry cleanup on miss/expired.
  • Transport SEAL now calls priskv_publish_node_with_pin to remove the publish→pin race; ACQUIRE uses priskv_key_pin_latest; RELEASE uses priskv_key_unpin_latest.
  • Add concurrency tests (two-thread and stress) to verify single-version visibility and pin_count inheritance; extend negative/permission and failure-path coverage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants