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

Deferred Value Checks #104

Merged
merged 3 commits into from
May 13, 2020
Merged

Deferred Value Checks #104

merged 3 commits into from
May 13, 2020

Conversation

KrzysFR
Copy link
Member

@KrzysFR KrzysFR commented May 11, 2020

Prototype implementation of deferred value checks (as described in #103).

Add a set of APIs on transaction operation context, to hold a set of pending Task that will read the value of a key. Before "commit", all tasks are resolved, and their result is checked against the expected value (as provided by the application).

Each "check" is linked to a tag, so that multiple layers can all contribute to the same transaction, without interference.

If at least on check fails, a not_commited error is simulated, and the transaction will retry. Before it retries, an internal map is updated with all the tags of checks that passed/failed in the previous attempt.

Implementing metadata caching in a layer can use this API to protect against external change in the database.

The API is considered "expert level" and is not exposed directly on the transaction instance. Since metadata caching is a hard problem anyway, we don't expect this API to be called by top-level application code, but instead by layer implementors who need to have better performance.

Added APIs

public class FdbOperationContext
{
    //...

    public void AddValueCheck(string tag, Slice key, Slice expectedValue);
    public void AddValueChecks(string tag, IEnumerable<KeyValuePair<Slice, Slice>> items);
    public void AddValueChecks(string tag, KeyValuePair<Slice, Slice>[] items);
    public void AddValueChecks(string tag, ReadOnlySpan<KeyValuePair<Slice, Slice>> items);

    public bool HasAtLeastOneFailedValueCheck { get; }
    public bool? ValueCheckFailedInPreviousAttempt(string tag);
}

KrzysFR added 3 commits May 11, 2020 14:05
- Value checks is a list of deferred key reads that must complete before commit, and will check that the value of a key in the database is equal to some expected value.
- Can be leveraged to implement caching in layers with offsetting the cost of one or more reads.
- Returns null if no check was performed with this tag
- Returns true if at least one check with this tag failed
- Returns false if all checks with this tag passed
@KrzysFR KrzysFR merged commit 9abaeae into master May 13, 2020
@KrzysFR KrzysFR deleted the feature_value_checks branch April 17, 2022 21:41
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.

1 participant