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

feat: Implement StateManipulator with cleaner, more efficient conflict resolution #2946

Merged
merged 2 commits into from
Sep 13, 2023

Conversation

stbrody
Copy link
Contributor

@stbrody stbrody commented Sep 11, 2023

No description provided.

@stbrody stbrody self-assigned this Sep 11, 2023
@linear
Copy link

linear bot commented Sep 11, 2023

@stbrody stbrody force-pushed the state-manipulator-cdb-2725 branch from 6b425c1 to e340e38 Compare September 11, 2023 20:38
@@ -0,0 +1,129 @@
import { jest } from '@jest/globals'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this test file is not intended to be exhaustive. I just happened to write a simple test at this layer while trying to figure out how to write a test at the lower StateManipulator layer. Figured it out, but figured I'd leave this test in because why not. I expect to more fully flesh out the tests for the StreamLoader in a subsequent PR though

).rejects.toThrow(/rejected by conflict resolution/)
})

describe('pickLogToAccept', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

these tests are ported almost directly from conflict-resolution.test.ts.

Copy link
Contributor

@PaulLeCam PaulLeCam left a comment

Choose a reason for hiding this comment

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

LGTM just noticed some small things that could be changed but aren't blockers

return log1[log1.length - 1].cid.bytes < log2[log2.length - 1].cid.bytes ? log1 : log2
}

async _applyLogToState_noCacaoVerification(
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a big deal but I don't really like mixing casing conventions like this, couldn't this method be named _applyLogToStateWithoutCacaoVerification for example please?

Comment on lines +32 to +34
throwOnInvalidCommit: boolean
throwIfStale: boolean
throwOnConflict: boolean
Copy link
Contributor

Choose a reason for hiding this comment

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

Do these default to true or false when applying the logic please?
If they default to true and must be explicitly set to false, could we inverse the logic please? Ex:

allowInvalidCommit: boolean
allowStale: boolean
allowConflict: boolean

With these flags having to be set explicitly to true not to throw? I think that would make it clearer the default behavior is to be strict, unless explicitly set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

they don't actually default to anything, it is required for the caller to pass all 3 in explicitly. There isn't really a clear case for which behavior should be the "default" - they are all set differently in different contexts. E.g. throwOnInvalidCommit is true for user-initiated writes coming in via the http api, but false for writes that come in via pubsub.

@stbrody stbrody merged commit 510e811 into develop Sep 13, 2023
1 check passed
@stbrody stbrody deleted the state-manipulator-cdb-2725 branch September 13, 2023 19:36
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