Skip to content

Commit

Permalink
Purge xattrs based on the set of xattrs on the DCP event
Browse files Browse the repository at this point in the history
  • Loading branch information
adamcfraser committed May 14, 2024
1 parent a534350 commit a853077
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
17 changes: 6 additions & 11 deletions db/util_testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"context"
"errors"
"fmt"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -261,23 +260,19 @@ func purgeWithDCPFeed(ctx context.Context, dataStore sgbucket.DataStore, tbp *ba
key := string(event.Key)

if base.TestUseXattrs() {
_, xattrsMap, decodeErr := sgbucket.DecodeValueWithAllXattrs(event.Value)
systemXattrNames, decodeErr := sgbucket.DecodeXattrNames(event.Value, true)
if decodeErr != nil {
purgeErrors = purgeErrors.Append(decodeErr)
tbp.Logf(ctx, "Error adding key %s to force deletion. %v", key, decodeErr)
}
systemXattrs := make([]string, 0)
for xattrName, _ := range xattrsMap {
if strings.HasPrefix(xattrName, "_") {
systemXattrs = append(systemXattrs, xattrName)
}
tbp.Logf(ctx, "Error decoding DCP event xattrs for key %s. %v", key, decodeErr)
return false
}
if len(systemXattrs) > 0 {
purgeErr = dataStore.DeleteWithXattrs(ctx, key, []string{base.SyncXattrName, base.VvXattrName})
if len(systemXattrNames) > 0 {
purgeErr = dataStore.DeleteWithXattrs(ctx, key, systemXattrNames)
} else {
purgeErr = dataStore.Delete(key)
}
} else {
purgeErr = dataStore.Delete(key)
}
if base.IsDocNotFoundError(purgeErr) {
// If key no longer exists, need to add and remove to trigger removal from view
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/couchbase/gocbcore/v10 v10.4.1
github.com/couchbase/gomemcached v0.2.1
github.com/couchbase/goutils v0.1.2
github.com/couchbase/sg-bucket v0.0.0-20240514135815-5f5e7aa8625c
github.com/couchbase/sg-bucket v0.0.0-20240514223028-c60b57e39e26
github.com/couchbaselabs/go-fleecedelta v0.0.0-20220909152808-6d09efa7a338
github.com/couchbaselabs/gocbconnstr v1.0.5
github.com/couchbaselabs/rosmar v0.0.0-20240424002439-5fd321c3b01b
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ github.com/couchbase/goutils v0.1.2 h1:gWr8B6XNWPIhfalHNog3qQKfGiYyh4K4VhO3P2o9B
github.com/couchbase/goutils v0.1.2/go.mod h1:h89Ek/tiOxxqjz30nPPlwZdQbdB8BwgnuBxeoUe/ViE=
github.com/couchbase/sg-bucket v0.0.0-20240514135815-5f5e7aa8625c h1:ftZeu97TaEWxBAINW2AaGNk3Icyg+/6XHs7OHnR23qQ=
github.com/couchbase/sg-bucket v0.0.0-20240514135815-5f5e7aa8625c/go.mod h1:IQisEdcLRfS/pjSgmqG/8gerVm0Q7GrvpQtMIZ7oYt4=
github.com/couchbase/sg-bucket v0.0.0-20240514223028-c60b57e39e26 h1:+3NTyrdEKxDQPycYPlfLxife5n7fMWWqSLvHH137+44=
github.com/couchbase/sg-bucket v0.0.0-20240514223028-c60b57e39e26/go.mod h1:IQisEdcLRfS/pjSgmqG/8gerVm0Q7GrvpQtMIZ7oYt4=
github.com/couchbase/tools-common/cloud v1.0.0 h1:SQZIccXoedbrThehc/r9BJbpi/JhwJ8X00PDjZ2gEBE=
github.com/couchbase/tools-common/cloud v1.0.0/go.mod h1:6KVlRpbcnDWrvickUJ+xpqCWx1vgYYlEli/zL4xmZAg=
github.com/couchbase/tools-common/fs v1.0.0 h1:HFA4xCF/r3BtZShFJUxzVvGuXtDkqGnaPzYJP3Kp1mw=
Expand Down

0 comments on commit a853077

Please sign in to comment.