Skip to content

Commit 61d763b

Browse files
authored
CBG-4472 remove warnings for null document bodies (#7538)
1 parent 7d271db commit 61d763b

File tree

5 files changed

+60
-10
lines changed

5 files changed

+60
-10
lines changed

db/crud.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2685,7 +2685,7 @@ func (db *DatabaseCollectionWithUser) RevDiff(ctx context.Context, docid string,
26852685

26862686
doc, err := db.GetDocSyncDataNoImport(ctx, docid, DocUnmarshalHistory)
26872687
if err != nil {
2688-
if !base.IsDocNotFoundError(err) && !errors.Is(err, base.ErrXattrNotFound) {
2688+
if !base.IsDocNotFoundError(err) && !base.IsXattrNotFoundError(err) {
26892689
base.WarnfCtx(ctx, "RevDiff(%q) --> %T %v", base.UD(docid), err, err)
26902690
}
26912691
missing = revids
@@ -2747,7 +2747,7 @@ func (db *DatabaseCollectionWithUser) CheckProposedRev(ctx context.Context, doci
27472747
}
27482748
doc, err := db.GetDocSyncDataNoImport(ctx, docid, level)
27492749
if err != nil {
2750-
if !base.IsDocNotFoundError(err) && !errors.Is(err, base.ErrXattrNotFound) {
2750+
if !base.IsDocNotFoundError(err) && !base.IsXattrNotFoundError(err) {
27512751
base.WarnfCtx(ctx, "CheckProposedRev(%q) --> %T %v", base.UD(docid), err, err)
27522752
return ProposedRev_Error, ""
27532753
}

db/crud_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,3 +1807,24 @@ func TestDocUpdateCorruptSequence(t *testing.T) {
18071807
return db.DbStats.Database().CorruptSequenceCount.Value()
18081808
}, 1)
18091809
}
1810+
1811+
func TestPutResurrection(t *testing.T) {
1812+
base.SetUpTestLogging(t, base.LevelDebug, base.KeyAll)
1813+
1814+
db, ctx := setupTestDB(t)
1815+
defer db.Close(ctx)
1816+
1817+
startWarnCount := base.SyncGatewayStats.GlobalStats.ResourceUtilization.WarnCount.Value()
1818+
collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db)
1819+
1820+
const docID = "doc1"
1821+
_, _, err := collection.Put(ctx, docID, Body{"foo": "bar"})
1822+
require.NoError(t, err)
1823+
1824+
require.NoError(t, collection.Purge(ctx, docID, false))
1825+
// assert no warnings when re-pushing a resurrection
1826+
_, _, err = collection.Put(ctx, docID, Body{"resurrect": true})
1827+
require.NoError(t, err)
1828+
1829+
require.Equal(t, startWarnCount, base.SyncGatewayStats.GlobalStats.ResourceUtilization.WarnCount.Value())
1830+
}

db/document.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ func (doc *Document) Body(ctx context.Context) Body {
272272
}
273273

274274
if doc._rawBody == nil {
275-
base.WarnfCtx(ctx, "Null doc body/rawBody %s/%s from %s", base.UD(doc.ID), base.UD(doc.RevID), caller)
276275
return nil
277276
}
278277

@@ -319,17 +318,11 @@ func (doc *Document) HasBody() bool {
319318
}
320319

321320
func (doc *Document) BodyBytes(ctx context.Context) ([]byte, error) {
322-
var caller string
323-
if base.ConsoleLogLevel().Enabled(base.LevelTrace) {
324-
caller = base.GetCallersName(1, true)
325-
}
326-
327321
if doc._rawBody != nil {
328322
return doc._rawBody, nil
329323
}
330324

331325
if doc._body == nil {
332-
base.WarnfCtx(ctx, "Null doc body/rawBody %s/%s from %s", base.UD(doc.ID), base.UD(doc.RevID), caller)
333326
return nil, nil
334327
}
335328

rest/blip_api_crud_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3195,3 +3195,37 @@ func TestChangesFeedExitDisconnect(t *testing.T) {
31953195
}, time.Second*10, time.Millisecond*100)
31963196
})
31973197
}
3198+
3199+
func TestBlipPushRevOnResurrection(t *testing.T) {
3200+
for _, allowConflicts := range []bool{true, false} {
3201+
t.Run(fmt.Sprintf("allowConflicts=%t", allowConflicts), func(t *testing.T) {
3202+
btcRunner := NewBlipTesterClientRunner(t)
3203+
btcRunner.Run(func(t *testing.T, SupportedBLIPProtocols []string) {
3204+
rt := NewRestTester(t, &RestTesterConfig{
3205+
PersistentConfig: true,
3206+
})
3207+
defer rt.Close()
3208+
3209+
dbConfig := rt.NewDbConfig()
3210+
dbConfig.AllowConflicts = base.Ptr(allowConflicts)
3211+
RequireStatus(t, rt.CreateDatabase("db", dbConfig), http.StatusCreated)
3212+
startWarnCount := base.SyncGatewayStats.GlobalStats.ResourceUtilization.WarnCount.Value()
3213+
docID := "doc1"
3214+
rt.CreateTestDoc(docID)
3215+
3216+
rt.PurgeDoc(docID)
3217+
3218+
RequireStatus(t, rt.SendAdminRequest(http.MethodGet, "/{{.keyspace}}/"+docID, ""), http.StatusNotFound)
3219+
3220+
opts := &BlipTesterClientOpts{SupportedBLIPProtocols: SupportedBLIPProtocols, Username: "alice"}
3221+
btc := btcRunner.NewBlipTesterClientOptsWithRT(rt, opts)
3222+
defer btc.Close()
3223+
3224+
btcRunner.StartPush(btc.id)
3225+
docVersion := btcRunner.AddRev(btc.id, docID, EmptyDocVersion(), []byte(`{"resurrect":true}`))
3226+
rt.WaitForVersion(docID, docVersion)
3227+
require.Equal(t, startWarnCount, base.SyncGatewayStats.GlobalStats.ResourceUtilization.WarnCount.Value())
3228+
})
3229+
})
3230+
}
3231+
}

rest/blip_client_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,9 @@ func (btcc *BlipTesterCollectionClient) sendRev(ctx context.Context, change prop
10601060
btcc.sendRev(ctx, change, false)
10611061
return
10621062
}
1063-
require.NotContains(btcc.TB(), revResp.Properties, "Error-Domain", "unexpected error response from rev %v: %s", revResp)
1063+
body, err := revResp.Body()
1064+
require.NoError(btcc.TB(), err)
1065+
require.NotContains(btcc.TB(), revResp.Properties, "Error-Domain", "unexpected error response from rev %v: %s", change.version, string(body))
10641066
base.DebugfCtx(ctx, base.KeySGTest, "peer acked rev %s / %v", change.docID, change.version)
10651067
btcc.updateLastReplicatedRev(change.docID, change.version, revRequest)
10661068
}

0 commit comments

Comments
 (0)