Skip to content

Conversation

bbrks
Copy link
Member

@bbrks bbrks commented Oct 17, 2024

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

Copy link
Collaborator

@torcolvin torcolvin left a 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 with CREATE INDEX .. IF NOT EXISTS this error type will not be returned.
  • test this on CBS <7.1 which does not have IF NOT EXISTS

bbrks added 3 commits October 18, 2024 16:46
…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:
Copy link
Collaborator

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

Copy link
Member Author

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`.
Copy link
Collaborator

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+

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, still 7.1+

@bbrks bbrks assigned torcolvin and unassigned bbrks Oct 21, 2024
@bbrks bbrks requested a review from torcolvin October 21, 2024 17:38
@torcolvin torcolvin merged commit e1581d7 into main Oct 22, 2024
38 checks passed
@torcolvin torcolvin deleted the CBG-2838 branch October 22, 2024 02:26
bbrks added a commit that referenced this pull request Oct 22, 2024
torcolvin pushed a commit that referenced this pull request Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants