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
Conversation
00f9e82
to
95b4228
Compare
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
internal/datastore/common/changes.go
Outdated
|
||
func (ch Changes) RevisionChanges() (changes []*datastore.RevisionChanges) { | ||
revisionsWithChanges := make([]uint64, 0, len(ch)) | ||
for k := range ch { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k
-> revTxId
?
internal/datastore/common/changes.go
Outdated
|
||
for _, rev := range revisionsWithChanges { | ||
revisionChange := &datastore.RevisionChanges{ | ||
Revision: revisionFromTransaction(rev), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revisionFromTransactionID
internal/datastore/common/changes.go
Outdated
return revisionsWithChanges[i] < revisionsWithChanges[j] | ||
}) | ||
|
||
for _, rev := range revisionsWithChanges { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revTxId
internal/datastore/common/changes.go
Outdated
// AddChange adds a specific change to the complete list of tracked changes | ||
func (ch Changes) AddChange( | ||
ctx context.Context, | ||
revision uint64, |
There was a problem hiding this comment.
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?
internal/datastore/postgres/watch.go
Outdated
@@ -116,7 +114,7 @@ func (pgd *pgDatastore) loadChanges( | |||
return | |||
} | |||
|
|||
stagedChanges := make(map[uint64]*changeRecord) | |||
stagedChanges := make(common.Changes) |
There was a problem hiding this comment.
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)
internal/datastore/postgres/watch.go
Outdated
} | ||
changes = append(changes, revisionChange) | ||
} | ||
changes = stagedChanges.RevisionChanges() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AsRevisionChanges
?
internal/services/v1/watch_test.go
Outdated
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) |
There was a problem hiding this comment.
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 | ||
} | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
Updated |
internal/datastore/common/changes.go
Outdated
} | ||
} | ||
|
||
// AsRevisionChanges returns the list of changes processes so far as a datastore watch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
processed
internal/datastore/common/changes.go
Outdated
} | ||
|
||
// AsRevisionChanges returns the list of changes processes so far as a datastore watch | ||
// compatible, ordered changelist. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ordered,
Fixes #270 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
No description provided.