Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some update for JSegcache #452

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

JunchengYTwitter
Copy link

@JunchengYTwitter JunchengYTwitter commented Jul 28, 2022

This PR contains multiple things (let me know if you want to split them)

  1. Add get_age in segments, then add a new field age in Item so that we can return age to caller.
  2. Add RichItem to return item_info and item_info_ptr, these two are used to support opportunistic concurrency control. Not sure adding a new struct is better than adding the fields to Item, but given there might be fields (like these) that we often do not need, creating a new struct might be better.
  3. add a call to expire before we evict, this avoids the problem that users may forget to call expire.
  4. add key size check when inserting to the cache.

* add support for hash table entry verification
* this is used to support opportunistic concurrency control with multiple readers and a single writer

This PR allows us to use multiple readers
each reader reads the cache without coordination,
after copying/using the value, we verify hash table entry,
if the hash table entry is updated, it means the object is evicted/updated,
we may have read corrupt or stale value, and we should roll back.
@CLAassistant
Copy link

CLAassistant commented Jul 28, 2022

CLA assistant check
All committers have signed the CLA.

@brayniac
Copy link
Contributor

@JunchengYTwitter - this looks good overall. Just needs rustfmt. I'm okay with this remaining a single PR.

@JunchengYTwitter
Copy link
Author

updated

@@ -83,6 +89,99 @@ impl std::fmt::Debug for Item {
}
}

/// Items are the base unit of data stored within the cache.
pub struct RichItem {
Copy link
Contributor

@brayniac brayniac Jul 28, 2022

Choose a reason for hiding this comment

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

Is there a reason this can't be:

pub struct RichItem {
  item: Item,
  item_info: u64,
  item_info_ptr: *const u64,
}

It seems like re-using the Item type and having the wrapper type contain the additional fields for "rich" functionality would be a better way to go here

Copy link
Author

@JunchengYTwitter JunchengYTwitter Jul 28, 2022

Choose a reason for hiding this comment

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

nope, your proposal is better, I will change it :)

.field("cas", &self.cas())
.field("raw", &self.raw)
.field("item_info", &self.item_info)
.field("item_info_ptr", &self.item_info_ptr)
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't this print the ptr address? Is that really useful?

Copy link
Author

Choose a reason for hiding this comment

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

yes, it is not useful, printing the value itself is not very useful as well. I can print all three (two value, one pointer) or we can remove the print. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like printing if it's stale or not would maybe have value here?

} else {
freq = (freq | 0x80) << FREQ_BIT_SHIFT;
}
// TODO: this needs to be atomic
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm having trouble understanding why - we hold a mutable reference to the hashtable here - so there can be no other read or write references.

// used to support multi readers and single writer
// return true, if the item is evicted/updated since being
// read from the hash table
pub fn is_not_changed(&self) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

i don't love the is_not_ here - can this just be is_current()?

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.

3 participants