Skip to content

Commit

Permalink
GOBC-1558: Add support for ErrDocumentNotLocked
Browse files Browse the repository at this point in the history
Motivation
----------
Under MB-58088 a new NOT_LOCKED error code is being added.
Gocbcore has now added support for this.

Changes
-------
Add support for ErrDocumentNotLocked mapping to the same error in
gocbcore.

Change-Id: Ie2e5836135f0ca874876ffd844d031f16d7b2fa7
Reviewed-on: https://review.couchbase.org/c/gocb/+/203437
Reviewed-by: Dimitris Christodoulou <[email protected]>
Tested-by: Charles Dixon <[email protected]>
  • Loading branch information
chvck committed Jan 9, 2024
1 parent adc0193 commit 858308b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
26 changes: 26 additions & 0 deletions collection_crud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1677,6 +1677,32 @@ func (suite *IntegrationTestSuite) TestUnlock() {
suite.AssertKVMetrics(meterNameCBOperations, "unlock", 1, false)
}

func (suite *IntegrationTestSuite) TestUnlockNotLocked() {
suite.skipIfUnsupported(KeyValueFeature)
suite.skipIfUnsupported(NotLockedFeature)

var doc testBeerDocument
err := loadJSONTestDataset("beer_sample_single", &doc)
suite.Require().NoErrorf(err, "Could not read test dataset: %v", err)

mutRes, err := globalCollection.Upsert("unlock", doc, nil)
suite.Require().NoErrorf(err, "Upsert failed, error was %v", err)

suite.Assert().NotZero(mutRes.Cas(), "Upsert CAS was 0")

err = globalCollection.Unlock("unlock", mutRes.Cas(), nil)
suite.Assert().ErrorIs(err, ErrDocumentNotLocked)

suite.Require().Contains(globalTracer.GetSpans(), nil)
nilParents := globalTracer.GetSpans()[nil]
suite.Require().Equal(len(nilParents), 2)
suite.AssertKvOpSpan(nilParents[0], "upsert", memd.CmdSet.Name(), true, DurabilityLevelNone)
suite.AssertKvOpSpan(nilParents[1], "unlock", memd.CmdUnlockKey.Name(), false, DurabilityLevelNone)

suite.AssertKVMetrics(meterNameCBOperations, "upsert", 1, false)
suite.AssertKVMetrics(meterNameCBOperations, "unlock", 1, false)
}

func (suite *IntegrationTestSuite) TestUnlockInvalidCas() {
suite.skipIfUnsupported(KeyValueFeature)

Expand Down
6 changes: 5 additions & 1 deletion error.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,13 @@ var (
// operation in the incorrect order.
ErrXattrInvalidOrder = gocbcore.ErrXattrInvalidOrder

// ErrMutationTokenOutdated occurs when snapshow requirements are specified but the requirements do not align with
// ErrMutationTokenOutdated occurs when snapshot requirements are specified but the requirements do not align with
// the server.
ErrMutationTokenOutdated = gocbcore.ErrRangeScanVbUUIDNotEqual

// ErrDocumentNotLocked occurs when unlock is called on a document that is not locked.
// # UNCOMMITTED: This API may change in the future.
ErrDocumentNotLocked = gocbcore.ErrDocumentNotLocked
)

// Query Error Definitions RFC#58@15
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/couchbase/gocb/v2

require (
github.com/couchbase/gocbcore/v10 v10.3.1-0.20231212155116-d936c9049d5c
github.com/couchbase/gocbcore/v10 v10.3.1-0.20240109090336-a703ea62e79c
github.com/couchbase/gocbcoreps v0.1.1-0.20231220162712-aa366fd7df65
github.com/couchbase/goprotostellar v1.0.1-0.20231220111120-c4d2428ed125
github.com/couchbaselabs/gocaves/client v0.0.0-20230404095311-05e3ba4f0259
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZx
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/couchbase/gocbcore/v10 v10.3.1-0.20231212155116-d936c9049d5c h1:NWhbDPAOIX2Wh6Fd56NH1x//dHaAI7Ko0N7SGzR1VwA=
github.com/couchbase/gocbcore/v10 v10.3.1-0.20231212155116-d936c9049d5c/go.mod h1:lYQIIk+tzoMcwtwU5GzPbDdqEkwkH3isI2rkSpfL0oM=
github.com/couchbase/gocbcore/v10 v10.3.1-0.20240109090336-a703ea62e79c h1:CCpx4OmDTWfEBF/TDdjzX8oIairlA6AYty6hbqu/7iE=
github.com/couchbase/gocbcore/v10 v10.3.1-0.20240109090336-a703ea62e79c/go.mod h1:lYQIIk+tzoMcwtwU5GzPbDdqEkwkH3isI2rkSpfL0oM=
github.com/couchbase/gocbcoreps v0.1.1-0.20231220162712-aa366fd7df65 h1:A0qZ82t3wszGYXGUJwpEk6jSonTd3nvkWHqm4O+oqKY=
github.com/couchbase/gocbcoreps v0.1.1-0.20231220162712-aa366fd7df65/go.mod h1:JKJQ1vutw3r7cVhoa5fSeX5GejQSmpNBYUD6CitATv4=
github.com/couchbase/goprotostellar v1.0.1-0.20231220111120-c4d2428ed125 h1:heAkmH9V4TQVBAc8wg5yba4cXjJ10Fm8iDNVT8FFuT4=
Expand Down
6 changes: 6 additions & 0 deletions testcluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var (
srvVer720 = NodeVersion{7, 2, 0, 0, 0, "", false}
protostellarVer = NodeVersion{7, 5, 0, 0, ProtostellarNodeEdition, "", false}
srvVer750 = NodeVersion{7, 5, 0, 0, 0, "", false}
srvVer760 = NodeVersion{7, 6, 0, 0, 0, "", false}
mockVer156 = NodeVersion{1, 5, 6, 0, 0, "", true}
mockVer1513 = NodeVersion{1, 5, 13, 0, 0, "", true}
mockVer1515 = NodeVersion{1, 5, 15, 0, 0, "", true}
Expand Down Expand Up @@ -101,6 +102,7 @@ var (
FlushBucketFeature = FeatureCode("flushbucket")
MemcachedBucketFeature = FeatureCode("memcachedbucket")
UnlockMissingDocFailFeature = FeatureCode("unlockmissingdocfail")
NotLockedFeature = FeatureCode("notlocked")
)

type TestFeatureFlag struct {
Expand Down Expand Up @@ -244,6 +246,8 @@ func (c *testCluster) SupportsFeature(feature FeatureCode) bool {
supported = false
case MemcachedBucketFeature:
supported = false
case NotLockedFeature:
supported = false
}
} else {
switch feature {
Expand Down Expand Up @@ -373,6 +377,8 @@ func (c *testCluster) SupportsFeature(feature FeatureCode) bool {
supported = !c.Version.Lower(srvVer700) && !c.Version.Equal(protostellarVer) && !c.Version.Equal(srvVer750)
case UnlockMissingDocFailFeature:
supported = !c.Version.Equal(srvVer750)
case NotLockedFeature:
supported = !c.Version.Lower(srvVer760)
}
}

Expand Down

0 comments on commit 858308b

Please sign in to comment.