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

CBG-3940 use atomics for counting docs #6841

Merged
merged 1 commit into from
May 23, 2024
Merged
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
15 changes: 8 additions & 7 deletions db/util_testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"context"
"errors"
"fmt"
"sync/atomic"
"testing"
"time"

Expand Down Expand Up @@ -220,10 +221,10 @@ func EmptyPrimaryIndex(ctx context.Context, dataStore sgbucket.DataStore) error

// purgeWithDCPFeed purges all documents seen on a DCP feed with system xattrs, including tombstones which aren't found when emptying the primary index.
func purgeWithDCPFeed(ctx context.Context, dataStore sgbucket.DataStore, tbp *base.TestBucketPool) (numCompacted int, err error) {
purgedDocCount := 0
purgeTimeout := 60 * time.Second
purgeBody := Body{"_purged": true}
processedDocCount := 0
var processedDocCount atomic.Int64
var purgedDocCount atomic.Int64

var purgeErrors *base.MultiError
collection, err := base.AsCollection(dataStore)
Expand All @@ -246,7 +247,7 @@ func purgeWithDCPFeed(ctx context.Context, dataStore sgbucket.DataStore, tbp *ba
purgeCallback := func(event sgbucket.FeedEvent) bool {
var purgeErr error

processedDocCount++
processedDocCount.Add(1)
// We only need to purge mutations/deletions
if event.Opcode != sgbucket.FeedOpMutation && event.Opcode != sgbucket.FeedOpDeletion {
return false
Expand Down Expand Up @@ -277,7 +278,7 @@ func purgeWithDCPFeed(ctx context.Context, dataStore sgbucket.DataStore, tbp *ba
purgeErrors = purgeErrors.Append(delErr)
tbp.Logf(ctx, "Error deleting key %s. %v", key, delErr)
}
purgedDocCount++
purgedDocCount.Add(1)
} else if purgeErr != nil {
purgeErrors = purgeErrors.Append(purgeErr)
tbp.Logf(ctx, "Error removing key %s (purge). %v", key, purgeErr)
Expand Down Expand Up @@ -308,9 +309,9 @@ func purgeWithDCPFeed(ctx context.Context, dataStore sgbucket.DataStore, tbp *ba
tbp.Logf(ctx, "error closing purge DCP feed: %v", closeErr)
}

tbp.Logf(ctx, "Finished purge DCP feed ... Total docs purged: %d", purgedDocCount)
tbp.Logf(ctx, "Finished purge DCP feed ... Total docs processed: %d", processedDocCount)
return purgedDocCount, purgeErrors.ErrorOrNil()
tbp.Logf(ctx, "Finished purge DCP feed ... Total docs purged: %d", purgedDocCount.Load())
tbp.Logf(ctx, "Finished purge DCP feed ... Total docs processed: %d", processedDocCount.Load())
return int(purgedDocCount.Load()), purgeErrors.ErrorOrNil()
}

// emptyAllDocsIndex ensures the AllDocs index for the given bucket is empty, including tombstones which aren't found when emptying the primary index.
Expand Down
Loading