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

Memdb datastore MVCC improvements #319

Merged
merged 5 commits into from Dec 6, 2021
Merged

Memdb datastore MVCC improvements #319

merged 5 commits into from Dec 6, 2021

Conversation

jakedt
Copy link
Member

@jakedt jakedt commented Dec 3, 2021

No description provided.

@github-actions github-actions bot added area/api v1 Affects the v1 API area/datastore Affects the storage system area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) labels Dec 3, 2021
@jakedt jakedt force-pushed the memdb-mvcc branch 2 times, most recently from 00f9e82 to 95b4228 Compare December 3, 2021 22:14
switch op {
case v0.RelationTupleUpdate_TOUCH:
// If there was a delete for the same tuple at the same revision, drop it
delete(revisionChanges.tupleDeletes, tplKey)
Copy link
Member

Choose a reason for hiding this comment

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

Why the difference between if I have a delete and then touch, we're left with just the touch, but if I have touch and then delete, both will be emitted?

Copy link
Member Author

Choose a reason for hiding this comment

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

The won't, the test cases confirm this.


func (ch Changes) RevisionChanges() (changes []*datastore.RevisionChanges) {
revisionsWithChanges := make([]uint64, 0, len(ch))
for k := range ch {
Copy link
Member

Choose a reason for hiding this comment

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

k -> revTxId?


for _, rev := range revisionsWithChanges {
revisionChange := &datastore.RevisionChanges{
Revision: revisionFromTransaction(rev),
Copy link
Member

Choose a reason for hiding this comment

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

revisionFromTransactionID

return revisionsWithChanges[i] < revisionsWithChanges[j]
})

for _, rev := range revisionsWithChanges {
Copy link
Member

Choose a reason for hiding this comment

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

revTxId

// AddChange adds a specific change to the complete list of tracked changes
func (ch Changes) AddChange(
ctx context.Context,
revision uint64,
Copy link
Member

Choose a reason for hiding this comment

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

revision -> revTxId or have it take in the actual revision type?

@@ -116,7 +114,7 @@ func (pgd *pgDatastore) loadChanges(
return
}

stagedChanges := make(map[uint64]*changeRecord)
stagedChanges := make(common.Changes)
Copy link
Member

Choose a reason for hiding this comment

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

Since this is non-obvious, maybe a common.NewChanges() that does the make? (especially since if we do decide to change the type to a struct down the road, the make wouldn't work)

}
changes = append(changes, revisionChange)
}
changes = stagedChanges.RevisionChanges()
Copy link
Member

Choose a reason for hiding this comment

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

AsRevisionChanges?

Comment on lines 170 to 167
return
}

require.Equal(len(tc.expectedUpdates), len(receivedUpdates))

for len(receivedUpdates) < len(tc.expectedUpdates) {
select {
case updates := <-updatesChan:
receivedUpdates = append(receivedUpdates, updates...)
fmt.Printf("expected: %v\n", tc.expectedUpdates)
Copy link
Member

Choose a reason for hiding this comment

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

remove fmt

require.FailNow("timed out waiting for updates")
return
}
}
Copy link
Member

Choose a reason for hiding this comment

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

We should check the updates received match, content wise, those expected

Copy link
Member Author

Choose a reason for hiding this comment

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

There is no canonical ordering for the v1.RelationshipUpdates, so testing this becomes a major effort.

Copy link
Member

Choose a reason for hiding this comment

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

Can we sort and see that we've at least seen the expected ones?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes of course it's possible, but it raises the question: why was the test accepted in the first place only checking len?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member

Choose a reason for hiding this comment

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

Probably an oversight in my review

}

type tupleEntry struct {
type relationship struct {
Copy link
Member

Choose a reason for hiding this comment

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

Since this is being renamed to relationship, thoughts on renaming the members to resource/subject?

@jakedt
Copy link
Member Author

jakedt commented Dec 6, 2021

Updated

}
}

// AsRevisionChanges returns the list of changes processes so far as a datastore watch
Copy link
Member

Choose a reason for hiding this comment

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

processed

}

// AsRevisionChanges returns the list of changes processes so far as a datastore watch
// compatible, ordered changelist.
Copy link
Member

Choose a reason for hiding this comment

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

ordered,

@jakedt
Copy link
Member Author

jakedt commented Dec 6, 2021

Fixes #270

Copy link
Member

@josephschorr josephschorr left a comment

Choose a reason for hiding this comment

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

LGTM

@jakedt jakedt merged commit 44523b6 into main Dec 6, 2021
@jakedt jakedt deleted the memdb-mvcc branch December 6, 2021 20:50
@github-actions github-actions bot locked and limited conversation to collaborators Dec 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/api v1 Affects the v1 API area/datastore Affects the storage system area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants