Skip to content

[feature] support pin/unpin for P/D#36

Open
yapple wants to merge 1 commit intoaibrix:devfrom
yapple:pin-dev
Open

[feature] support pin/unpin for P/D#36
yapple wants to merge 1 commit intoaibrix:devfrom
yapple:pin-dev

Conversation

@yapple
Copy link

@yapple yapple commented Mar 4, 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.

client/client.c Outdated
"set KEY VALUE [ EX seconds | PX milliseconds ]\tset key:value to priskv\n"},
{"alloc_set", alloc_set_handler,
"alloc set KEY VALUE [ EX seconds | PX milliseconds ]\tset key:value to priskv\n"},
"alloc set KEY VALUE [ EX seconds | PX milliseconds ] [ --pin-on-seal ]\tzero-copy set with optional pin on seal\n"},
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's follow the redis command convention for pin flags, e.g, using "PIN" "UNPIN" instead of "--pin-on-seal" "--pin-on-acquire" and "--unpin-on-release".

Copy link
Author

Choose a reason for hiding this comment

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

changed to redis command convention, please take a look

status = priskv_publish_node(conn->kv, keynode);
/* Optional: pin-on-seal if requested */
if (status == PRISKV_RESP_STATUS_OK && (flags & PRISKV_REQ_FLAG_PIN_ON_SEAL)) {
(void)priskv_key_pin(conn->kv, keynode);
Copy link
Collaborator

Choose a reason for hiding this comment

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

what if an eviction happen in the middle of priskv_publish_node and priskv_key_pin? we need publish and pin to be atomic therefore this key is prevented from being kick off.

Copy link
Author

Choose a reason for hiding this comment

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

make it atomic in #38

old_keynode = priskv_find_key(kv, (uint8_t *)keynode->key, keynode->keylen,
PRISKV_KEY_MAX_TIMEOUT, true, NULL);
if (old_keynode) {
/* inherit pin_count from old version to keep lifecycle semantics */
Copy link
Collaborator

Choose a reason for hiding this comment

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

There appears to be a race condition in both the original priskv_publish_node function and the updated version with pin support. Consider the following scenario with thread A and thread B both calling the original priskv_publish_node on the same key (key-0):

  • Both threads execute old_keynode = priskv_find_key(kv, (uint8_t *)keynode->key, keynode->keylen, ...) nearly simultaneously
  • Since neither has inserted their keynode yet, both find no existing node and receive NULL for old_keynode
  • Consequently, both threads proceed to insert their respective keynodes into kv and LRU
  • This results in two different keynodes with identical keys coexisting in the KV store, which is invalid.

For the updated version, uint32_t old_pins = old_keynode->pin_count; and keynode->pin_count = old_pins; need to be atomic, otherwise, the value of old_keynode->pin_count could be updated before the old_keynode being deleted.

Copy link
Author

Choose a reason for hiding this comment

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

make it atomic in #38

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