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

add gocb bucket feature for multi xattr subdoc operations #6779

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
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
40 changes: 40 additions & 0 deletions base/bucket_gocb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,46 @@ func TestXattrWriteCasWithXattrCasCheck(t *testing.T) {

}

func TestMultiXattrRoundtrip(t *testing.T) {
SkipXattrTestsIfNotEnabled(t)

ctx := TestCtx(t)
bucket := GetTestBucket(t)
defer bucket.Close(ctx)
dataStore := bucket.GetSingleDataStore()

const docID = "doc1"
xattrKeys := []string{"xattr1", "xattr2", "xattr3"}
inputXattrs := map[string][]byte{
xattrKeys[0]: []byte(`{"key1": "value1"}`),
xattrKeys[1]: []byte(`{"key2": "value2"}`),
xattrKeys[2]: []byte(`{"key3": "value3"}`),
}
_, err := dataStore.WriteWithXattrs(ctx, docID, 0, 0, []byte(`{"key": "value"}`), inputXattrs, nil)
if dataStore.IsSupported(sgbucket.BucketStoreFeatureMultiXattrSubdocOperations) {
require.NoError(t, err)
} else {
require.ErrorContains(t, err, "invalid xattr key combination")
inputXattrs = map[string][]byte{
xattrKeys[0]: inputXattrs[xattrKeys[0]],
}
// write a document an xattrs, because subsequent GetXattrs needs a document to produce an error without multi-xattr support
_, err := dataStore.WriteWithXattrs(ctx, docID, 0, 0, []byte(`{"key": "value"}`), inputXattrs, nil)
require.NoError(t, err)
}

xattrs, _, err := dataStore.GetXattrs(ctx, docID, xattrKeys)
if dataStore.IsSupported(sgbucket.BucketStoreFeatureMultiXattrSubdocOperations) {
require.NoError(t, err)
for _, key := range xattrKeys {
require.Contains(t, xattrs, key)
require.JSONEq(t, string(inputXattrs[key]), string(xattrs[key]))
}
} else {
require.ErrorContains(t, err, "not supported")
}
}

// TestWriteCasXATTRRaw. Validates basic write of document and xattr as raw bytes.
func TestXattrWriteCasRaw(t *testing.T) {

Expand Down
2 changes: 1 addition & 1 deletion base/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func (b *GocbV2Bucket) IsSupported(feature sgbucket.BucketStoreFeature) bool {
case sgbucket.BucketStoreFeaturePreserveExpiry, sgbucket.BucketStoreFeatureCollections:
// TODO: Change to capability check when GOCBC-1218 merged
return isMinimumVersion(b.clusterCompatMajorVersion, b.clusterCompatMinorVersion, 7, 0)
case sgbucket.BucketStoreFeatureSystemCollections:
case sgbucket.BucketStoreFeatureSystemCollections, sgbucket.BucketStoreFeatureMultiXattrSubdocOperations:
return isMinimumVersion(b.clusterCompatMajorVersion, b.clusterCompatMinorVersion, 7, 6)
case sgbucket.BucketStoreFeatureMobileXDCR:
return b.supportsHLV
Expand Down
Loading