-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
storage: support basic watch #3507
Conversation
@@ -38,6 +42,17 @@ type KV interface { | |||
TxnPut(txnID int64, key, value []byte) (rev int64, err error) | |||
TxnDeleteRange(txnID int64, key, end []byte) (n, rev int64, err error) | |||
|
|||
// Watcher watches the events happening or happened in etcd. The whole |
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.
How about having another interface called WatchableKV that embeds KV?
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.
That sounds to abstract it better. It may cause KV to expose some new API to facilitate watch in the future or even this PR in my design. Will try.
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.
This can replace the old KV api. And we only expose WatchableKV to outside world.
2d7d0e7
to
db2783d
Compare
Have updated the architecture based on discussion. Head to implement the left part: 1. startRev 2. endRev |
tdelete map[string]bool | ||
} | ||
|
||
func newWatchableStore(path string) *watchableStore { |
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.
Let's return the interface
@yichengq The basic idea looks good to me. |
b98420d
to
4ab6140
Compare
Support full Watcher feature now. The test only covers the most basic one, and it works fine. Will add more tests to follow up. This is the initial code for watch. It mostly focuses on the API and structures. PTAL |
@@ -118,6 +120,35 @@ func (ti *treeIndex) Tombstone(key []byte, rev revision) error { | |||
return ki.tombstone(rev.main, rev.sub) | |||
} | |||
|
|||
func (ti *treeIndex) RangeEvents(key, end []byte, rev int64) []revision { |
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 add a comment for this function? It is not quite obvious.
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
// filtering without allocating | ||
// https://github.com/golang/go/wiki/SliceTricks#filtering-without-allocating | ||
b := s.check[:0] | ||
for _, w := range s.check { |
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.
let us make this code block another func
LGTM in general. But we probably need one or two more rounds on this one. |
Addressed all comments. Ready for the next round review. |
@@ -132,6 +132,41 @@ func (ki *keyIndex) get(atRev int64) (modified, created revision, ver int64, err | |||
return revision{}, revision{}, 0, ErrRevisionNotFound | |||
} | |||
|
|||
// since returns recorded valid revisions since the given 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.
since returns revisions since the give rev.
Only the revision with the largest sub revision will be returned if multiple revisions have the same main revision.
@yichengq The code looks good to me. However, we still need to improve the comments. Basically, when we use a adj we need to be careful. The adj. has to be clear and understandable. Or we need to explain it in detail. |
f50c5cf
to
77bab36
Compare
I would say the first step is to not use random adj.. |
6dacc2b
to
be2485a
Compare
Let's merge this as it is. |
@xiang90 I will squash all commits into one. |
WatchableKV is an interface upon KV, and supports watch feature.
Each watch acclamis
446 B/op 6 allocs/op
. Watch uses fixed length-10 channel, and if httpHandler wants to cache more, it could cache events at its side.