Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@afterdusk
Copy link
Member

@afterdusk afterdusk commented Mar 26, 2024

Current

Our current tombstoning API tombstone_value_states accepts a list of ValueState keys that tombstoning should be performed for. This means that the client flow will, more often than not, involve:

  1. looking up all ValueState objects for a given user in DB
  2. figuring out which objects should be tombstoned based on their epochs (relative to the current epoch)
  3. passing the keys of said objects to the tombstone API

Internally, the tombstone API then does another lookup of ValueState objects with the keys passed, modifies the objects to "tombstone" them, then another write to commit the now-tombstoned objects.

Proposed

We can cut out the DB lookup pre-API call by having the API take in an epoch and a username, then tombstoning all ValueState objects for the user with an epoch less than or equal to the passed epoch. Clients will not need any knowledge of what ValueState objects a user has, and just need to inform the API which epoch to stop tombstoning at.

In addition, before we write the tombstoned records, we should filter out any objects that are already tombstoned, to avoid unnecessary writes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 26, 2024
Copy link
Contributor

@slawlor slawlor left a comment

Choose a reason for hiding this comment

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

Lgtm

epoch: u64,
) -> Result<(), StorageError> {
let key_data = self.get_user_data(username).await?;
let mut new_data = vec![];
Copy link
Contributor

@dillongeorge dillongeorge Mar 26, 2024

Choose a reason for hiding this comment

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

Nit: I think you can write this a bit more cleanly (without a mutable variable) by doing something like so:

    let new_data = key_data
        .states
        .into_iter()
        .filter_map(|vs| {
            if vs.epoch <= epoch && vs.value.0 != crate::TOMBSTONE {
                DbRecord::ValueState(ValueState {
                    epoch: value_state.epoch,
                    label: value_state.label,
                    value: crate::AkdValue(crate::TOMBSTONE.to_vec()),
                    username: value_state.username,
                    version: value_state.version,
                })
            } else {
                None
            }
        })
        .collect();

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, the rest of this file uses for loops and mutable collections, I'll keep it the current way for consistency for now. Thanks for the suggestion!

@afterdusk afterdusk merged commit 0797ed2 into facebook:main Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants