From a851521980ee4ba558f3327e4d672025fd35c2bf Mon Sep 17 00:00:00 2001 From: Tor Colvin Date: Wed, 15 May 2024 15:41:38 -0400 Subject: [PATCH 1/2] CBG-3921 use IsDocNotFoundError everywhere - switch IsKeyNotFoundError and IsError(sgbucket.KeyNotFoundError) --- base/bucket.go | 12 +-- base/bucket_gocb_test.go | 2 +- base/bucket_test.go | 4 +- base/collection.go | 12 --- base/collection_gocb.go | 4 - base/constants_syncdocs.go | 2 +- base/dcp_client_metadata.go | 4 +- base/dcp_common.go | 2 +- base/error.go | 17 ++-- base/error_test.go | 86 ++++++++++++++----- base/heartbeat.go | 6 +- base/leaky_bucket.go | 4 - base/leaky_datastore.go | 4 - base/sg_cluster_cfg.go | 4 +- db/active_replicator_checkpointer.go | 2 +- db/active_replicator_common.go | 2 +- db/blip_handler.go | 2 +- db/crud_test.go | 4 +- db/design_doc.go | 2 +- db/revision.go | 2 +- db/util_testing.go | 2 +- go.mod | 4 +- go.sum | 4 + rest/replicatortest/replicator_test_helper.go | 6 +- xdcr/rosmar_xdcr.go | 2 +- xdcr/xdcr_test.go | 2 +- 26 files changed, 105 insertions(+), 92 deletions(-) diff --git a/base/bucket.go b/base/bucket.go index d49acb513d..41d3b090ca 100644 --- a/base/bucket.go +++ b/base/bucket.go @@ -320,22 +320,12 @@ func GetBucket(ctx context.Context, spec BucketSpec) (bucket Bucket, err error) // If the given key is not found in the bucket, this function returns a result of zero. func GetCounter(datastore DataStore, k string) (result uint64, err error) { _, err = datastore.Get(k, &result) - if datastore.IsError(err, sgbucket.KeyNotFoundError) { + if IsDocNotFoundError(err) { return 0, nil } return result, err } -func IsKeyNotFoundError(datastore DataStore, err error) bool { - - if err == nil { - return false - } - - unwrappedErr := pkgerrors.Cause(err) - return datastore.IsError(unwrappedErr, sgbucket.KeyNotFoundError) -} - func IsCasMismatch(err error) bool { if err == nil { return false diff --git a/base/bucket_gocb_test.go b/base/bucket_gocb_test.go index affe7cc328..9e799faf60 100644 --- a/base/bucket_gocb_test.go +++ b/base/bucket_gocb_test.go @@ -2275,7 +2275,7 @@ func TestGetExpiry(t *testing.T) { // ensure expiry retrieval on non-existent doc returns key not found _, nonExistentExpiryErr := dataStore.GetExpiry(ctx, "nonExistentKey") assert.Error(t, nonExistentExpiryErr) - assert.True(t, IsKeyNotFoundError(dataStore, nonExistentExpiryErr)) + RequireDocNotFoundError(t, nonExistentExpiryErr) } func TestGetStatsVbSeqNo(t *testing.T) { diff --git a/base/bucket_test.go b/base/bucket_test.go index 220e4f2017..e3a6f0d78a 100644 --- a/base/bucket_test.go +++ b/base/bucket_test.go @@ -532,8 +532,8 @@ func TestKeyNotFound(t *testing.T) { ds := bucket.GetSingleDataStore() var body []byte _, getErr := ds.Get("nonexistentKey", &body) - require.True(t, IsKeyNotFoundError(ds, getErr)) + RequireDocNotFoundError(t, getErr) _, _, getRawErr := ds.GetRaw("nonexistentKey") - require.True(t, IsKeyNotFoundError(ds, getRawErr)) + RequireDocNotFoundError(t, getRawErr) } diff --git a/base/collection.go b/base/collection.go index 17c8d45c45..366b22c8dd 100644 --- a/base/collection.go +++ b/base/collection.go @@ -363,18 +363,6 @@ func (b *GocbV2Bucket) getConfigSnapshot() (*gocbcore.ConfigSnapshot, error) { return config, nil } -func (b *GocbV2Bucket) IsError(err error, errorType sgbucket.DataStoreErrorType) bool { - if err == nil { - return false - } - switch errorType { - case sgbucket.KeyNotFoundError: - return errors.Is(err, gocb.ErrDocumentNotFound) - default: - return false - } -} - func (b *GocbV2Bucket) GetSpec() BucketSpec { return b.Spec } diff --git a/base/collection_gocb.go b/base/collection_gocb.go index 4fa194ea1d..d97c1f9da4 100644 --- a/base/collection_gocb.go +++ b/base/collection_gocb.go @@ -459,10 +459,6 @@ func (c *Collection) Exists(k string) (exists bool, err error) { return res.Exists(), nil } -func (c *Collection) IsError(err error, errorType sgbucket.DataStoreErrorType) bool { - return c.Bucket.IsError(err, errorType) -} - // SGJsonTranscoder reads and writes JSON, with relaxed datatype restrictions on decode, and // embedded support for writing raw JSON on encode type SGJSONTranscoder struct { diff --git a/base/constants_syncdocs.go b/base/constants_syncdocs.go index c5e086d902..5b1eaeccd9 100644 --- a/base/constants_syncdocs.go +++ b/base/constants_syncdocs.go @@ -374,7 +374,7 @@ func InitSyncInfo(ds DataStore, metadataID string) (requiresResync bool, err err var syncInfo SyncInfo _, fetchErr := ds.Get(SGSyncInfo, &syncInfo) - if IsKeyNotFoundError(ds, fetchErr) { + if IsDocNotFoundError(fetchErr) { if metadataID == "" { return false, nil } diff --git a/base/dcp_client_metadata.go b/base/dcp_client_metadata.go index f78099aab3..2f85360c1b 100644 --- a/base/dcp_client_metadata.go +++ b/base/dcp_client_metadata.go @@ -245,7 +245,7 @@ func (m *DCPMetadataCS) load(ctx context.Context, workerID int) { var meta WorkerMetadata _, err := m.dataStore.Get(m.getMetadataKey(workerID), &meta) if err != nil { - if IsKeyNotFoundError(m.dataStore, err) { + if IsDocNotFoundError(err) { return } InfofCtx(ctx, KeyDCP, "Error loading persisted metadata - metadata will be reset for worker %d: %s", workerID, err) @@ -260,7 +260,7 @@ func (m *DCPMetadataCS) load(ctx context.Context, workerID int) { func (m *DCPMetadataCS) Purge(ctx context.Context, numWorkers int) { for i := 0; i < numWorkers; i++ { err := m.dataStore.Delete(m.getMetadataKey(i)) - if err != nil && !IsKeyNotFoundError(m.dataStore, err) { + if err != nil && !IsDocNotFoundError(err) { InfofCtx(ctx, KeyDCP, "Unable to remove DCP checkpoint for key %s: %v", m.getMetadataKey(i), err) } } diff --git a/base/dcp_common.go b/base/dcp_common.go index c8eccfa7fd..3c54c041e0 100644 --- a/base/dcp_common.go +++ b/base/dcp_common.go @@ -189,7 +189,7 @@ func (c *DCPCommon) loadCheckpoint(vbNo uint16) (vbMetadata []byte, snapshotStar rawValue, _, err := c.metaStore.GetRaw(fmt.Sprintf("%s%d", c.checkpointPrefix, vbNo)) if err != nil { // On a key not found error, metadata hasn't been persisted for this vbucket - if IsKeyNotFoundError(c.metaStore, err) { + if IsDocNotFoundError(err) { return []byte{}, 0, 0, nil } else { return []byte{}, 0, 0, err diff --git a/base/error.go b/base/error.go index 8b41558f49..7224df07b7 100644 --- a/base/error.go +++ b/base/error.go @@ -205,15 +205,12 @@ func CouchHTTPErrorName(status int) string { return fmt.Sprintf("%d", status) } -// Returns true if an error is a doc-not-found error +// IsDocNotFoundError returns true if an error is a doc-not-found error func IsDocNotFoundError(err error) bool { - - unwrappedErr := pkgerrors.Cause(err) - if unwrappedErr == nil { + if err == nil { return false } - - if unwrappedErr == ErrNotFound { + if errors.Is(err, ErrNotFound) { return true } @@ -221,11 +218,15 @@ func IsDocNotFoundError(err error) bool { return true } + var missingError sgbucket.MissingError + if errors.As(err, &missingError) { + return true + } + unwrappedErr := pkgerrors.Cause(err) + switch unwrappedErr := unwrappedErr.(type) { case *gomemcached.MCResponse: return unwrappedErr.Status == gomemcached.KEY_ENOENT || unwrappedErr.Status == gomemcached.NOT_STORED - case sgbucket.MissingError: - return true case *HTTPError: return unwrappedErr.Status == http.StatusNotFound default: diff --git a/base/error_test.go b/base/error_test.go index c8d25e1097..90a3cfcbb0 100644 --- a/base/error_test.go +++ b/base/error_test.go @@ -154,27 +154,71 @@ func TestCouchHTTPErrorName(t *testing.T) { } func TestIsDocNotFoundError(t *testing.T) { - - fakeMCResponse := &gomemcached.MCResponse{Status: gomemcached.KEY_ENOENT} - assert.True(t, IsDocNotFoundError(fakeMCResponse)) - - fakeMCResponse = &gomemcached.MCResponse{Status: gomemcached.NOT_STORED} - assert.True(t, IsDocNotFoundError(fakeMCResponse)) - - fakeMCResponse = &gomemcached.MCResponse{Status: gomemcached.ROLLBACK} - assert.False(t, IsDocNotFoundError(fakeMCResponse)) - - fakeMissingError := sgbucket.MissingError{} - assert.True(t, IsDocNotFoundError(fakeMissingError)) - - fakeHTTPError := &HTTPError{Status: http.StatusNotFound} - assert.True(t, IsDocNotFoundError(fakeHTTPError)) - - fakeHTTPError = &HTTPError{Status: http.StatusForbidden} - assert.False(t, IsDocNotFoundError(fakeHTTPError)) - - fakeSyntaxError := &json.SyntaxError{} - assert.False(t, IsDocNotFoundError(fakeSyntaxError)) + testCases := []struct { + name string + err error + isDocNotFound bool + }{ + { + name: "gomemcached.MCResponse KEY_ENOENT", + err: &gomemcached.MCResponse{Status: gomemcached.KEY_ENOENT}, + isDocNotFound: true, + }, + { + name: "gomemcached.MCResponse NOT_STORED", + err: &gomemcached.MCResponse{Status: gomemcached.NOT_STORED}, + isDocNotFound: true, + }, + { + name: "gomemcached.MCResponse ROLLBACK", + err: &gomemcached.MCResponse{Status: gomemcached.ROLLBACK}, + isDocNotFound: false, + }, + { + name: "sgbucket.MissingError", + err: sgbucket.MissingError{}, + isDocNotFound: true, + }, + { + name: "HTTPError StatusNotFound", + err: &HTTPError{Status: http.StatusNotFound}, + isDocNotFound: true, + }, + { + name: "HTTPError StatusForbidden", + err: &HTTPError{Status: http.StatusForbidden}, + isDocNotFound: false, + }, + { + name: "json.SyntaxError", + err: &json.SyntaxError{}, + isDocNotFound: false, + }, + { + name: "nil", + err: nil, + isDocNotFound: false, + }, + { + name: "other error", + err: fmt.Errorf("some error"), + isDocNotFound: false, + }, + { + name: "sgbucket.MissingError with values", + err: sgbucket.MissingError{Key: "key"}, + isDocNotFound: true, + }, + } + for _, test := range testCases { + t.Run(test.name, func(t *testing.T) { + if test.isDocNotFound { + assert.True(t, IsDocNotFoundError(test.err)) + } else { + assert.False(t, IsDocNotFoundError(test.err)) + } + }) + } } func TestMultiError(t *testing.T) { diff --git a/base/heartbeat.go b/base/heartbeat.go index e1b5cb7186..2e3d57b39f 100644 --- a/base/heartbeat.go +++ b/base/heartbeat.go @@ -284,7 +284,7 @@ func (h *couchbaseHeartBeater) checkStaleHeartbeats(ctx context.Context) error { _, _, err := h.datastore.GetRaw(timeoutDocID) SyncGatewayStats.GlobalStats.ResourceUtilizationStats().NumIdleKvOps.Add(1) if err != nil { - if !IsKeyNotFoundError(h.datastore, err) { + if !IsDocNotFoundError(err) { // unexpected error return err } @@ -316,7 +316,7 @@ func (h *couchbaseHeartBeater) sendHeartbeat() error { } // On KeyNotFound, recreate heartbeat timeout doc - if IsKeyNotFoundError(h.datastore, touchErr) { + if IsDocNotFoundError(touchErr) { heartbeatDocBody := []byte(h.nodeUUID) setErr := h.datastore.SetRaw(docID, h.heartbeatExpirySeconds, nil, heartbeatDocBody) SyncGatewayStats.GlobalStats.ResourceUtilizationStats().NumIdleKvOps.Add(1) @@ -473,7 +473,7 @@ func (dh *documentBackedListener) loadNodeIDs() error { if err != nil { dh.cas = 0 dh.nodeIDs = []string{} - if !IsKeyNotFoundError(dh.datastore, err) { + if !IsDocNotFoundError(err) { return err } } diff --git a/base/leaky_bucket.go b/base/leaky_bucket.go index f34eda63a8..ade1d07a1b 100644 --- a/base/leaky_bucket.go +++ b/base/leaky_bucket.go @@ -71,10 +71,6 @@ func (b *LeakyBucket) GetMaxVbno() (uint16, error) { return b.bucket.GetMaxVbno() } -func (b *LeakyBucket) IsError(err error, errorType sgbucket.DataStoreErrorType) bool { - return b.bucket.IsError(err, errorType) -} - func (b *LeakyBucket) DefaultDataStore() sgbucket.DataStore { return NewLeakyDataStore(b, b.bucket.DefaultDataStore(), b.config) } diff --git a/base/leaky_datastore.go b/base/leaky_datastore.go index b252d7cedf..738189740c 100644 --- a/base/leaky_datastore.go +++ b/base/leaky_datastore.go @@ -326,10 +326,6 @@ func (lds *LeakyDataStore) SetUpdateCallback(callback func(key string)) { lds.config.UpdateCallback = callback } -func (lds *LeakyDataStore) IsError(err error, errorType sgbucket.DataStoreErrorType) bool { - return lds.dataStore.IsError(err, errorType) -} - func (lds *LeakyDataStore) IsSupported(feature sgbucket.BucketStoreFeature) bool { return lds.dataStore.IsSupported(feature) } diff --git a/base/sg_cluster_cfg.go b/base/sg_cluster_cfg.go index dcd8a20dd3..7ff1fba2d3 100644 --- a/base/sg_cluster_cfg.go +++ b/base/sg_cluster_cfg.go @@ -75,7 +75,7 @@ func (c *CfgSG) Get(cfgKey string, cas uint64) ( bucketKey := c.sgCfgBucketKey(cfgKey) var value []byte casOut, err := c.datastore.Get(bucketKey, &value) - if err != nil && !IsKeyNotFoundError(c.datastore, err) { + if err != nil && !IsDocNotFoundError(err) { InfofCtx(c.loggingCtx, KeyCluster, "cfg_sg: Get, key: %s, cas: %d, err: %v", cfgKey, cas, err) return nil, 0, err } @@ -116,7 +116,7 @@ func (c *CfgSG) Del(cfgKey string, cas uint64) error { _, err := c.datastore.Remove(bucketKey, cas) if IsCasMismatch(err) { return ErrCfgCasError - } else if err != nil && !IsKeyNotFoundError(c.datastore, err) { + } else if err != nil && !IsDocNotFoundError(err) { return err } diff --git a/db/active_replicator_checkpointer.go b/db/active_replicator_checkpointer.go index df1a86346b..7b88e9372c 100644 --- a/db/active_replicator_checkpointer.go +++ b/db/active_replicator_checkpointer.go @@ -516,7 +516,7 @@ func (c *Checkpointer) getLocalCheckpoint() (checkpoint *replicationCheckpoint, checkpointBytes, err := getSpecialBytes(c.collectionDataStore, DocTypeLocal, CheckpointDocIDPrefix+c.clientID, c.localDocExpirySecs) if err != nil { - if !base.IsKeyNotFoundError(c.collectionDataStore, err) { + if !base.IsDocNotFoundError(err) { return &replicationCheckpoint{}, err } base.DebugfCtx(c.ctx, base.KeyReplicate, "couldn't find existing local checkpoint for client %q", c.clientID) diff --git a/db/active_replicator_common.go b/db/active_replicator_common.go index 1ab55fade8..387b901264 100644 --- a/db/active_replicator_common.go +++ b/db/active_replicator_common.go @@ -389,7 +389,7 @@ func (arc *activeReplicatorCommon) startStatusReporter() error { func getLocalStatusDoc(ctx context.Context, metadataStore base.DataStore, statusKey string) (*ReplicationStatusDoc, error) { statusDocBytes, err := getWithTouch(metadataStore, statusKey, 0) if err != nil { - if !base.IsKeyNotFoundError(metadataStore, err) { + if !base.IsDocNotFoundError(err) { return nil, err } base.DebugfCtx(ctx, base.KeyReplicate, "couldn't find existing local checkpoint for ID %q", statusKey) diff --git a/db/blip_handler.go b/db/blip_handler.go index 980887447f..b56653bec3 100644 --- a/db/blip_handler.go +++ b/db/blip_handler.go @@ -1266,7 +1266,7 @@ func (bh *blipHandler) handleProveAttachment(rq *blip.Message) error { if bh.clientType == BLIPClientTypeSGR2 { return ErrAttachmentNotFound } - if base.IsKeyNotFoundError(bh.collection.dataStore, err) { + if base.IsDocNotFoundError(err) { return ErrAttachmentNotFound } return base.HTTPErrorf(http.StatusInternalServerError, fmt.Sprintf("Error getting client attachment: %v", err)) diff --git a/db/crud_test.go b/db/crud_test.go index 93d2df6744..2abe4cb1e4 100644 --- a/db/crud_test.go +++ b/db/crud_test.go @@ -410,7 +410,7 @@ func TestRevisionStorageConflictAndTombstones(t *testing.T) { // Ensure previous revision body backup has been removed _, _, err = db.MetadataStore.GetRaw(base.RevBodyPrefix + "4GctXhLVg13d59D0PUTPRD0i58Hbe1d0djgo1qOEpfI=") - assert.True(t, base.IsKeyNotFoundError(collection.dataStore, err), "Revision should be not found") + base.RequireDocNotFoundError(t, err) // Validate the tombstone is stored inline (due to small size) revTree, err = getRevTreeList(ctx, collection.dataStore, "doc1", db.UseXattrs()) @@ -644,7 +644,7 @@ func TestRevisionStoragePruneTombstone(t *testing.T) { // Ensure previous tombstone body backup has been removed log.Printf("Verify revision body doc has been removed from bucket") _, _, err = collection.dataStore.GetRaw(base.SyncDocPrefix + "rb:ULDLuEgDoKFJeET2hojeFANXM8SrHdVfAGONki+kPxM=") - assert.True(t, base.IsKeyNotFoundError(collection.dataStore, err), "Revision should be not found") + base.RequireDocNotFoundError(t, err) } diff --git a/db/design_doc.go b/db/design_doc.go index dc7b868f93..9383c4aa67 100644 --- a/db/design_doc.go +++ b/db/design_doc.go @@ -750,7 +750,7 @@ func removeObsoleteDesignDocs(ctx context.Context, viewStore sgbucket.ViewStore, return removedDesignDocs, nil } -// Similar to IsKeyNotFoundError(), but for the specific error returned by GetDDoc/DeleteDDoc +// Similar to IsDocNotFoundError(), but for the specific error returned by GetDDoc/DeleteDDoc func IsMissingDDocError(err error) bool { if err == nil { return false diff --git a/db/revision.go b/db/revision.go index 90c783f305..1317d2529b 100644 --- a/db/revision.go +++ b/db/revision.go @@ -316,7 +316,7 @@ func (db *DatabaseCollectionWithUser) setOldRevisionJSON(ctx context.Context, do func (db *DatabaseCollectionWithUser) refreshPreviousRevisionBackup(ctx context.Context, docid string, revid string, body []byte, expiry uint32) error { _, err := db.dataStore.Touch(oldRevisionKey(docid, revid), expiry) - if base.IsKeyNotFoundError(db.dataStore, err) && len(body) > 0 { + if base.IsDocNotFoundError(err) && len(body) > 0 { return db.setOldRevisionJSON(ctx, docid, revid, body, expiry) } return err diff --git a/db/util_testing.go b/db/util_testing.go index 7cedbd2166..60127a1ef0 100644 --- a/db/util_testing.go +++ b/db/util_testing.go @@ -344,7 +344,7 @@ FROM ` + base.KeyspaceQueryToken + ` AS ks USE INDEX (sg_allDocs_x1)` } else { purgeErr = dataStore.Delete(row.Id) } - if base.IsKeyNotFoundError(dataStore, purgeErr) { + if base.IsDocNotFoundError(purgeErr) { // If key no longer exists, need to add and remove to trigger removal from view _, addErr := dataStore.Add(row.Id, 0, purgeBody) if addErr != nil { diff --git a/go.mod b/go.mod index 64be859568..4586b6db81 100644 --- a/go.mod +++ b/go.mod @@ -12,10 +12,10 @@ 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-20240515192422-65113dc10339 github.com/couchbaselabs/go-fleecedelta v0.0.0-20220909152808-6d09efa7a338 github.com/couchbaselabs/gocbconnstr v1.0.5 - github.com/couchbaselabs/rosmar v0.0.0-20240417141520-4127f7d4c389 + github.com/couchbaselabs/rosmar v0.0.0-20240515192921-54683dca426b github.com/elastic/gosigar v0.14.3 github.com/felixge/fgprof v0.9.4 github.com/google/uuid v1.6.0 diff --git a/go.sum b/go.sum index e56ec666cb..bc50c480a5 100644 --- a/go.sum +++ b/go.sum @@ -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-20240515192422-65113dc10339 h1:19edcUy6ESglvcYHO6CpDgHLTH8xYbXN62HB7hT1edQ= +github.com/couchbase/sg-bucket v0.0.0-20240515192422-65113dc10339/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= @@ -76,6 +78,8 @@ github.com/couchbaselabs/gocbconnstr/v2 v2.0.0-20230515165046-68b522a21131 h1:2E github.com/couchbaselabs/gocbconnstr/v2 v2.0.0-20230515165046-68b522a21131/go.mod h1:o7T431UOfFVHDNvMBUmUxpHnhivwv7BziUao/nMl81E= github.com/couchbaselabs/rosmar v0.0.0-20240417141520-4127f7d4c389 h1:feX52yzl6wrIXt6gqmcOKzpHOdigwnzJ5TP15M9i3Ow= github.com/couchbaselabs/rosmar v0.0.0-20240417141520-4127f7d4c389/go.mod h1:SM0w4YHwXFMIyfqUbkpXZNWwAQKLwsUH91fsKUooMqw= +github.com/couchbaselabs/rosmar v0.0.0-20240515192921-54683dca426b h1:NchKMFWgHE8BYybNJ3pAQ+Zt0oenVaXF6ESHCBlhvEE= +github.com/couchbaselabs/rosmar v0.0.0-20240515192921-54683dca426b/go.mod h1:2LVm2GopDeIhVuI723AGo4MhxZmvRXUj+9yTlavYsug= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/rest/replicatortest/replicator_test_helper.go b/rest/replicatortest/replicator_test_helper.go index e95ddb347c..6f35c28c21 100644 --- a/rest/replicatortest/replicator_test_helper.go +++ b/rest/replicatortest/replicator_test_helper.go @@ -83,10 +83,8 @@ func requireVersion(rt *rest.RestTester, docID string, version rest.DocVersion) } func requireErrorKeyNotFound(t *testing.T, rt *rest.RestTester, docID string) { - var body []byte - _, err := rt.Bucket().DefaultDataStore().Get(docID, &body) - require.Error(t, err) - require.True(t, base.IsKeyNotFoundError(rt.Bucket().DefaultDataStore(), err)) + _, err := rt.Bucket().DefaultDataStore().Get(docID, nil) + base.RequireDocNotFoundError(t, err) } // waitForTombstone waits until the specified tombstone revision is available diff --git a/xdcr/rosmar_xdcr.go b/xdcr/rosmar_xdcr.go index 610be23b0c..6daa60d158 100644 --- a/xdcr/rosmar_xdcr.go +++ b/xdcr/rosmar_xdcr.go @@ -72,7 +72,7 @@ func (r *rosmarManager) processEvent(ctx context.Context, event sgbucket.FeedEve } toCas, err := col.Get(docID, nil) - if err != nil && !col.IsError(err, sgbucket.KeyNotFoundError) { + if err != nil && !base.IsDocNotFoundError(err) { base.WarnfCtx(ctx, "Skipping replicating doc %s, could not perform a kv op get doc in toBucket: %s", event.Key, err) r.errorCount.Add(1) return false diff --git a/xdcr/xdcr_test.go b/xdcr/xdcr_test.go index fffc676671..b861937340 100644 --- a/xdcr/xdcr_test.go +++ b/xdcr/xdcr_test.go @@ -85,7 +85,7 @@ func TestMobileXDCRNoSyncDataCopied(t *testing.T) { var value any _, err = toDs.Get(syncDoc, &value) - require.True(t, base.IsKeyNotFoundError(toDs, err)) + base.RequireDocNotFoundError(t, err) // stats are not updated in real time, so we need to wait a bit require.EventuallyWithT(t, func(c *assert.CollectT) { From b099eb67de0bdefcd42616ee57f35f85c8c3fff0 Mon Sep 17 00:00:00 2001 From: Tor Colvin Date: Thu, 16 May 2024 10:57:52 -0400 Subject: [PATCH 2/2] Pick up upstream PRs from rosmar/sg-bucket --- go.mod | 4 ++-- go.sum | 12 ++++-------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 4586b6db81..b282afef93 100644 --- a/go.mod +++ b/go.mod @@ -12,10 +12,10 @@ 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-20240515192422-65113dc10339 + github.com/couchbase/sg-bucket v0.0.0-20240516142514-d65d1f2192a1 github.com/couchbaselabs/go-fleecedelta v0.0.0-20220909152808-6d09efa7a338 github.com/couchbaselabs/gocbconnstr v1.0.5 - github.com/couchbaselabs/rosmar v0.0.0-20240515192921-54683dca426b + github.com/couchbaselabs/rosmar v0.0.0-20240516145123-749ae63effda github.com/elastic/gosigar v0.14.3 github.com/felixge/fgprof v0.9.4 github.com/google/uuid v1.6.0 diff --git a/go.sum b/go.sum index bc50c480a5..42e8b77737 100644 --- a/go.sum +++ b/go.sum @@ -54,10 +54,8 @@ github.com/couchbase/goprotostellar v1.0.2 h1:yoPbAL9sCtcyZ5e/DcU5PRMOEFaJrF9awX github.com/couchbase/goprotostellar v1.0.2/go.mod h1:5/yqVnZlW2/NSbAWu1hPJCFBEwjxgpe0PFFOlRixnp4= github.com/couchbase/goutils v0.1.2 h1:gWr8B6XNWPIhfalHNog3qQKfGiYyh4K4VhO3P2o9BCs= 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-20240515192422-65113dc10339 h1:19edcUy6ESglvcYHO6CpDgHLTH8xYbXN62HB7hT1edQ= -github.com/couchbase/sg-bucket v0.0.0-20240515192422-65113dc10339/go.mod h1:IQisEdcLRfS/pjSgmqG/8gerVm0Q7GrvpQtMIZ7oYt4= +github.com/couchbase/sg-bucket v0.0.0-20240516142514-d65d1f2192a1 h1:saVwgFjPGNvDf8rM88C/RFsgyg370P1DJOVCy2+lqUA= +github.com/couchbase/sg-bucket v0.0.0-20240516142514-d65d1f2192a1/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= @@ -76,10 +74,8 @@ github.com/couchbaselabs/gocbconnstr v1.0.5 h1:e0JokB5qbcz7rfnxEhNRTKz8q1svoRvDo github.com/couchbaselabs/gocbconnstr v1.0.5/go.mod h1:KV3fnIKMi8/AzX0O9zOrO9rofEqrRF1d2rG7qqjxC7o= github.com/couchbaselabs/gocbconnstr/v2 v2.0.0-20230515165046-68b522a21131 h1:2EAfFswAfgYn3a05DVcegiw6DgMgn1Mv5eGz6IHt1Cw= github.com/couchbaselabs/gocbconnstr/v2 v2.0.0-20230515165046-68b522a21131/go.mod h1:o7T431UOfFVHDNvMBUmUxpHnhivwv7BziUao/nMl81E= -github.com/couchbaselabs/rosmar v0.0.0-20240417141520-4127f7d4c389 h1:feX52yzl6wrIXt6gqmcOKzpHOdigwnzJ5TP15M9i3Ow= -github.com/couchbaselabs/rosmar v0.0.0-20240417141520-4127f7d4c389/go.mod h1:SM0w4YHwXFMIyfqUbkpXZNWwAQKLwsUH91fsKUooMqw= -github.com/couchbaselabs/rosmar v0.0.0-20240515192921-54683dca426b h1:NchKMFWgHE8BYybNJ3pAQ+Zt0oenVaXF6ESHCBlhvEE= -github.com/couchbaselabs/rosmar v0.0.0-20240515192921-54683dca426b/go.mod h1:2LVm2GopDeIhVuI723AGo4MhxZmvRXUj+9yTlavYsug= +github.com/couchbaselabs/rosmar v0.0.0-20240516145123-749ae63effda h1:mt5WbjJa54UWtuvuxEnqGpO6Zo7WE2gdzt4gt6AOqlo= +github.com/couchbaselabs/rosmar v0.0.0-20240516145123-749ae63effda/go.mod h1:R/FMQ/bYhulyKzNxZ+LIR0h0KdNLB25WtrrD/Ar2q5o= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=