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
Fixes issue #3558 Initialize cache after DCP start #3607
Conversation
eb5c138
to
ecd7fe7
Compare
Ready for a review pass -- builds passing |
db/change_cache.go
Outdated
@@ -169,14 +175,25 @@ func (c *changeCache) IsStopped() bool { | |||
return c.stopped | |||
} | |||
|
|||
// Forgets all cached changes for all channels. | |||
func (c *changeCache) Clear() { | |||
// Empty out all channel caches. This doesn't touch |
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.
Comment looks like it was truncated
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.
Fixed
db/change_cache.go
Outdated
// | ||
// - Manage collection of channel caches | ||
// - Receive DCP changes via callbacks | ||
// - Perform sequence buffering to handle skipped sequences |
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.
I think this comment is misleading - sequence buffering is primarily about getting documents in sequence order. Skipped sequence handling is a separate concern.
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.
Fixed
db/change_cache.go
Outdated
nextSequence uint64 // Next consecutive sequence number to add | ||
initialSequence uint64 // DB's current sequence at startup time | ||
nextSequence uint64 // Next consecutive sequence number to add. State variable for sequence buffering tracking. Should use getNextSequence() rather than accessing directly. | ||
initialSequence uint64 // DB's current sequence at startup time. Should use getInititalSequence() rather than accessing directly. |
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.
Typo in comment
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.
My editor isn't flagging anything .. nor is it jumping out at me.
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.
Fixed getInitialSequence()
db/change_cache.go
Outdated
} | ||
|
||
// Set the initial sequence. | ||
// Think of this as _SetInitialSequence() -- since it premumes that change chache is locked. It is not safe to |
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.
Typo in comment
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.
Fixed
db/change_cache.go
Outdated
if event.Synchronous { | ||
c.DocChangedSynchronous(event) | ||
} else { | ||
go c.DocChangedSynchronous(event) | ||
} | ||
} | ||
|
||
// Set's the initial sequence, assume's that the caller is already holding a lock on the changeCache | ||
func (c *changeCache) _setInitialSequence(initialSequence 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.
How does this differ from SetInitialSequence below?
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.
Removed extraneous
db/database.go
Outdated
// Find the current global doc sequence and use that for the initial sequence for the change cache | ||
lastSequence, err := context.LastSequence() | ||
if err != nil { | ||
return nil, err |
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.
Need to unlock the changeCache on error here as well?
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.
Good catch. Fixed.
db/database.go
Outdated
|
||
if err != nil { | ||
// In the case of an error, unlock the change cache despite the fact it's in an unitialized state. | ||
context.changeCache.StartupUnlock() |
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.
Looking at this again, I'm still not thrilled about trying to manage the changeCache's internal lock from an external location. Would this approach work:
- changeCache.Init() leaves the cache locked (not started)
- A subsequent call to changeCache.Start() does the following:
- retrieves and sets initial/next sequence
- unlocks the cache
This would also let us push everything from line 313 to 324 down into changeCache.Start(), which I think makes more sense (it's cache-related code).
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.
Yeah, agreed that it's awkward to have the external locking semantics. Fixed in 8ee61c5
This reverts commit bd5e502.
…LazyLoaded == false
WARNING: DATA RACE Write at 0x00c4201fa2e0 by goroutine 9: github.com/couchbase/sync_gateway/db.(*changeCache)._addToCache() /drone/godeps/src/github.com/couchbase/sync_gateway/db/change_cache.go:689 +0x4ff github.com/couchbase/sync_gateway/db.(*changeCache).processEntry() /drone/godeps/src/github.com/couchbase/sync_gateway/db/change_cache.go:650 +0x1f6 github.com/couchbase/sync_gateway/db.(*changeCache).DocChangedSynchronous() /drone/godeps/src/github.com/couchbase/sync_gateway/db/change_cache.go:549 +0x20a4 Previous read at 0x00c4201fa2e0 by goroutine 42: github.com/couchbase/sync_gateway/db.(*changeCache).waitForSequence() /drone/godeps/src/github.com/couchbase/sync_gateway/db/util_testing.go:25 +0xbd github.com/couchbase/sync_gateway/db.TestDocDeletionFromChannelCoalesced() /drone/godeps/src/github.com/couchbase/sync_gateway/db/changes_test.go:233 +0x5fe testing.tRunner() /usr/local/go/src/testing/testing.go:746 +0x16c
8ee61c5
to
0be977f
Compare
Rebased on http://uberjenkins.sc.couchbase.com/view/Build/job/sync-gateway-integration-master/725/ |
LGTM - can merge if integration tests are clean. |
* Add experimental dockerfile * Fix attempt for build err * Trying to figure out how to get source commit/branch * Revert "Trying to figure out how to get source commit/branch" This reverts commit bd5e502. * Add artificial delay after getting last seq, but before starting dcp feed * Reload c.initialSequence in DocChanged() as long as c.initialSequenceLazyLoaded == false * Notes from call w/ Adam * Add c.getInitialSequence() + _getNextSequence() * Fixes * Add comments * Notes from call w/ Adam * Sketch out changes and test * Change the changeindex iface * Fix data race WARNING: DATA RACE Write at 0x00c4201fa2e0 by goroutine 9: github.com/couchbase/sync_gateway/db.(*changeCache)._addToCache() /drone/godeps/src/github.com/couchbase/sync_gateway/db/change_cache.go:689 +0x4ff github.com/couchbase/sync_gateway/db.(*changeCache).processEntry() /drone/godeps/src/github.com/couchbase/sync_gateway/db/change_cache.go:650 +0x1f6 github.com/couchbase/sync_gateway/db.(*changeCache).DocChangedSynchronous() /drone/godeps/src/github.com/couchbase/sync_gateway/db/change_cache.go:549 +0x20a4 Previous read at 0x00c4201fa2e0 by goroutine 42: github.com/couchbase/sync_gateway/db.(*changeCache).waitForSequence() /drone/godeps/src/github.com/couchbase/sync_gateway/db/util_testing.go:25 +0xbd github.com/couchbase/sync_gateway/db.TestDocDeletionFromChannelCoalesced() /drone/godeps/src/github.com/couchbase/sync_gateway/db/changes_test.go:233 +0x5fe testing.tRunner() /usr/local/go/src/testing/testing.go:746 +0x16c * Use getNextSequence() in a few more places * Fix another race https://gist.github.com/tleyden/dccaa3cf2be85160051a793333c24467 * Remove dockerfile, moved to a separate PR * Gofmt * PR cleanup * PR cleanup * Remove check that’s leftover from first attempt * Add comments * First round of PR feedback * Address PR feedback about avoiding external locking
* Add experimental dockerfile * Fix attempt for build err * Trying to figure out how to get source commit/branch * Revert "Trying to figure out how to get source commit/branch" This reverts commit bd5e502. * Add artificial delay after getting last seq, but before starting dcp feed * Reload c.initialSequence in DocChanged() as long as c.initialSequenceLazyLoaded == false * Notes from call w/ Adam * Add c.getInitialSequence() + _getNextSequence() * Fixes * Add comments * Notes from call w/ Adam * Sketch out changes and test * Change the changeindex iface * Fix data race WARNING: DATA RACE Write at 0x00c4201fa2e0 by goroutine 9: github.com/couchbase/sync_gateway/db.(*changeCache)._addToCache() /drone/godeps/src/github.com/couchbase/sync_gateway/db/change_cache.go:689 +0x4ff github.com/couchbase/sync_gateway/db.(*changeCache).processEntry() /drone/godeps/src/github.com/couchbase/sync_gateway/db/change_cache.go:650 +0x1f6 github.com/couchbase/sync_gateway/db.(*changeCache).DocChangedSynchronous() /drone/godeps/src/github.com/couchbase/sync_gateway/db/change_cache.go:549 +0x20a4 Previous read at 0x00c4201fa2e0 by goroutine 42: github.com/couchbase/sync_gateway/db.(*changeCache).waitForSequence() /drone/godeps/src/github.com/couchbase/sync_gateway/db/util_testing.go:25 +0xbd github.com/couchbase/sync_gateway/db.TestDocDeletionFromChannelCoalesced() /drone/godeps/src/github.com/couchbase/sync_gateway/db/changes_test.go:233 +0x5fe testing.tRunner() /usr/local/go/src/testing/testing.go:746 +0x16c * Use getNextSequence() in a few more places * Fix another race https://gist.github.com/tleyden/dccaa3cf2be85160051a793333c24467 * Remove dockerfile, moved to a separate PR * Gofmt * PR cleanup * PR cleanup * Remove check that’s leftover from first attempt * Add comments * First round of PR feedback * Address PR feedback about avoiding external locking
* Add experimental dockerfile * Fix attempt for build err * Trying to figure out how to get source commit/branch * Revert "Trying to figure out how to get source commit/branch" This reverts commit bd5e502. * Add artificial delay after getting last seq, but before starting dcp feed * Reload c.initialSequence in DocChanged() as long as c.initialSequenceLazyLoaded == false * Notes from call w/ Adam * Add c.getInitialSequence() + _getNextSequence() * Fixes * Add comments * Notes from call w/ Adam * Sketch out changes and test * Change the changeindex iface * Fix data race WARNING: DATA RACE Write at 0x00c4201fa2e0 by goroutine 9: github.com/couchbase/sync_gateway/db.(*changeCache)._addToCache() /drone/godeps/src/github.com/couchbase/sync_gateway/db/change_cache.go:689 +0x4ff github.com/couchbase/sync_gateway/db.(*changeCache).processEntry() /drone/godeps/src/github.com/couchbase/sync_gateway/db/change_cache.go:650 +0x1f6 github.com/couchbase/sync_gateway/db.(*changeCache).DocChangedSynchronous() /drone/godeps/src/github.com/couchbase/sync_gateway/db/change_cache.go:549 +0x20a4 Previous read at 0x00c4201fa2e0 by goroutine 42: github.com/couchbase/sync_gateway/db.(*changeCache).waitForSequence() /drone/godeps/src/github.com/couchbase/sync_gateway/db/util_testing.go:25 +0xbd github.com/couchbase/sync_gateway/db.TestDocDeletionFromChannelCoalesced() /drone/godeps/src/github.com/couchbase/sync_gateway/db/changes_test.go:233 +0x5fe testing.tRunner() /usr/local/go/src/testing/testing.go:746 +0x16c * Use getNextSequence() in a few more places * Fix another race https://gist.github.com/tleyden/dccaa3cf2be85160051a793333c24467 * Remove dockerfile, moved to a separate PR * Gofmt * PR cleanup * PR cleanup * Remove check that’s leftover from first attempt * Add comments * First round of PR feedback * Address PR feedback about avoiding external locking
Fixes #3558
Summary of changes:
onChange
->notifyChange
Clear()
method -- this now propagates the error to callers.Integration tests
http://uberjenkins.sc.couchbase.com/view/Build/job/sync-gateway-integration-master/725/
http://uberjenkins.sc.couchbase.com/view/Build/job/sync-gateway-integration-master/726/