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

storage: support basic watch #3507

Merged
merged 1 commit into from
Sep 15, 2015
Merged

storage: support basic watch #3507

merged 1 commit into from
Sep 15, 2015

Conversation

yichengq
Copy link
Contributor

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.

@@ -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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@yichengq
Copy link
Contributor Author

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 {
Copy link
Contributor

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

@xiang90
Copy link
Contributor

xiang90 commented Sep 13, 2015

@yichengq The basic idea looks good to me.

@yichengq yichengq changed the title WIP storage: support basic watch storage: support basic watch Sep 14, 2015
@yichengq
Copy link
Contributor Author

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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 {
Copy link
Contributor

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

@xiang90
Copy link
Contributor

xiang90 commented Sep 14, 2015

LGTM in general. But we probably need one or two more rounds on this one.

@yichengq
Copy link
Contributor Author

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.
Copy link
Contributor

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.

@xiang90
Copy link
Contributor

xiang90 commented Sep 15, 2015

@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.

@yichengq
Copy link
Contributor Author

I would say the first step is to not use random adj..

@xiang90
Copy link
Contributor

xiang90 commented Sep 15, 2015

Let's merge this as it is.

@yichengq
Copy link
Contributor Author

@xiang90 I will squash all commits into one.

WatchableKV is an interface upon KV, and supports watch feature.
yichengq added a commit that referenced this pull request Sep 15, 2015
storage: support basic watch
@yichengq yichengq merged commit c082488 into etcd-io:master Sep 15, 2015
@yichengq yichengq deleted the watch branch September 15, 2015 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants