-
Notifications
You must be signed in to change notification settings - Fork 140
CBG-2838: Rely on index 'IF NOT EXISTS' and idempotent deferred index builds fo… #7161
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
Conversation
…r simpler and lower-overhead index creation
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.
As discussed offline, some improvements to this PR should be made:
- look for
IsIndexerRetryIndexError
usage as that is where we are taking action on a retryable error. Potentially withCREATE INDEX .. IF NOT EXISTS
this error type will not be returned. - test this on CBS <7.1 which does not have
IF NOT EXISTS
…ation, handle not found error case in deferred build, swallow `ErrIndexBackgroundRetry` where we can fall back to collection-scoped wait
@@ -123,7 +123,7 @@ func (im *indexManager) GetAllIndexes() ([]gocb.QueryIndex, error) { | |||
return im.cluster.GetAllIndexes(im.bucketName, opts) | |||
} | |||
|
|||
// CreateIndex issues a CREATE INDEX query in the current bucket, using the form: |
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.
Do you want to change example also? This might be pedantic since this will be bucket.scope.collection
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.
It's still a valid example if using the default collection and it doesn't seem necessary to change.
@@ -149,23 +149,23 @@ func CreateIndexIfNotExists(ctx context.Context, store N1QLStore, indexName stri | |||
|
|||
// createIndex is a common function for CreateIndex and CreateIndexIfNotExists | |||
func createIndex(ctx context.Context, store N1QLStore, indexName string, expression string, filterExpression string, ifNotExists bool, options *N1qlIndexOptions) error { | |||
createClause := "CREATE INDEX" | |||
|
|||
var ifNotExistsStr string | |||
// Server 7.1+ - we can still safely _not_ use this when it's not available, because we have equivalent error handling inside this function to swallow `ErrAlreadyExists`. |
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 now needs to be 7.6+
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.
Nope, still 7.1+
CBG-2838
Rely on index
IF NOT EXISTS
and idempotent deferred index builds for simpler and lower-overhead index creation.According to the query docs, this is perfectly fine to do, and eliminates a lot of our manual
system:indexes
queries and retry/error handling logic?Now the only
system:indexes
call we have to make is the final one for each collection, to make sure all of the indexes are finished building and are online.Integration Tests
GSI=true,xattrs=true
https://jenkins.sgwdev.com/job/SyncGateway-Integration/2756/CBS 7.0.5
https://jenkins.sgwdev.com/job/SyncGateway-Integration/2754/