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

fix: bit operation #16381

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions server/etcdserver/api/v2store/event_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ type eventQueue struct {
Size int
Front int
Back int
Capacity int
Capacity int // capacity must be 2^n
}

func (eq *eventQueue) insert(e *Event) {
eq.Events[eq.Back] = e
eq.Back = (eq.Back + 1) % eq.Capacity
eq.Back = (eq.Back + 1) & (eq.Capacity - 1)

if eq.Size == eq.Capacity { //dequeue
eq.Front = (eq.Front + 1) % eq.Capacity
eq.Front = (eq.Front + 1) & (eq.Capacity - 1)
} else {
eq.Size++
}
Expand Down
11 changes: 5 additions & 6 deletions server/etcdserver/api/v2store/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
// previous 100 events have been swapped out.
func TestEventQueue(t *testing.T) {

eh := newEventHistory(100)
eh := newEventHistory(128)

// Add
for i := 0; i < 200; i++ {
Expand All @@ -48,7 +48,7 @@ func TestEventQueue(t *testing.T) {
}

func TestScanHistory(t *testing.T) {
eh := newEventHistory(100)
eh := newEventHistory(128)

// Add
eh.addEvent(newEvent(Create, "/foo", 1, 1))
Expand Down Expand Up @@ -91,17 +91,16 @@ func TestScanHistory(t *testing.T) {
}

func TestEventIndexHistoryCleared(t *testing.T) {
eh := newEventHistory(5)
eh := newEventHistory(4)

// Add
eh.addEvent(newEvent(Create, "/foo", 1, 1))
eh.addEvent(newEvent(Create, "/foo/bar", 2, 2))
eh.addEvent(newEvent(Create, "/foo/foo", 3, 3))
eh.addEvent(newEvent(Create, "/foo/bar/bar", 4, 4))
eh.addEvent(newEvent(Create, "/foo/foo/foo", 5, 5))

// Add a new event which will replace/de-queue the first entry
eh.addEvent(newEvent(Create, "/foo/bar/bar/bar", 6, 6))
eh.addEvent(newEvent(Create, "/foo/foo/foo", 5, 5))

// test for the event which has been replaced.
_, err := eh.scan("/foo", false, 1)
Expand All @@ -115,7 +114,7 @@ func TestEventIndexHistoryCleared(t *testing.T) {
// works still for previous events.
func TestFullEventQueue(t *testing.T) {

eh := newEventHistory(10)
eh := newEventHistory(8)

// Add
for i := 0; i < 1000; i++ {
Expand Down
2 changes: 1 addition & 1 deletion server/etcdserver/api/v2store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func newStore(namespaces ...string) *store {
s.Root.Add(newDir(s, namespace, s.CurrentIndex, s.Root, Permanent))
}
s.Stats = newStats()
s.WatcherHub = newWatchHub(1000)
s.WatcherHub = newWatchHub(1024)
s.ttlKeyHeap = newTtlKeyHeap()
s.readonlySet = types.NewUnsafeSet(append(namespaces, "/")...)
return s
Expand Down