Skip to content

[3.2.5 Backport] CBG-4660: remove warnings for null document bodies #7542

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

Open
wants to merge 3 commits into
base: release/3.2.5
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions db/crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -2685,7 +2685,7 @@ func (db *DatabaseCollectionWithUser) RevDiff(ctx context.Context, docid string,

doc, err := db.GetDocSyncDataNoImport(ctx, docid, DocUnmarshalHistory)
if err != nil {
if !base.IsDocNotFoundError(err) && !errors.Is(err, base.ErrXattrNotFound) {
if !base.IsDocNotFoundError(err) && !base.IsXattrNotFoundError(err) {
base.WarnfCtx(ctx, "RevDiff(%q) --> %T %v", base.UD(docid), err, err)
}
missing = revids
Expand Down Expand Up @@ -2747,7 +2747,7 @@ func (db *DatabaseCollectionWithUser) CheckProposedRev(ctx context.Context, doci
}
doc, err := db.GetDocSyncDataNoImport(ctx, docid, level)
if err != nil {
if !base.IsDocNotFoundError(err) && !errors.Is(err, base.ErrXattrNotFound) {
if !base.IsDocNotFoundError(err) && !base.IsXattrNotFoundError(err) {
base.WarnfCtx(ctx, "CheckProposedRev(%q) --> %T %v", base.UD(docid), err, err)
return ProposedRev_Error, ""
}
Expand Down
21 changes: 21 additions & 0 deletions db/crud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1806,3 +1806,24 @@ func TestDocUpdateCorruptSequence(t *testing.T) {
return db.DbStats.Database().CorruptSequenceCount.Value()
}, 1)
}

func TestPutResurrection(t *testing.T) {
base.SetUpTestLogging(t, base.LevelDebug, base.KeyAll)

db, ctx := setupTestDB(t)
defer db.Close(ctx)

startWarnCount := base.SyncGatewayStats.GlobalStats.ResourceUtilization.WarnCount.Value()
collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db)

const docID = "doc1"
_, _, err := collection.Put(ctx, docID, Body{"foo": "bar"})
require.NoError(t, err)

require.NoError(t, collection.Purge(ctx, docID, false))
// assert no warnings when re-pushing a resurrection
_, _, err = collection.Put(ctx, docID, Body{"resurrect": true})
require.NoError(t, err)

require.Equal(t, startWarnCount, base.SyncGatewayStats.GlobalStats.ResourceUtilization.WarnCount.Value())
}
7 changes: 0 additions & 7 deletions db/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ func (doc *Document) Body(ctx context.Context) Body {
}

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

Expand Down Expand Up @@ -319,17 +318,11 @@ func (doc *Document) HasBody() bool {
}

func (doc *Document) BodyBytes(ctx context.Context) ([]byte, error) {
var caller string
if base.ConsoleLogLevel().Enabled(base.LevelTrace) {
caller = base.GetCallersName(1, true)
}

if doc._rawBody != nil {
return doc._rawBody, nil
}

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

Expand Down
34 changes: 34 additions & 0 deletions rest/blip_api_crud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3243,3 +3243,37 @@ func TestChangesFeedExitDisconnect(t *testing.T) {
}, time.Second*10, time.Millisecond*100)
})
}

func TestBlipPushRevOnResurrection(t *testing.T) {
for _, allowConflicts := range []bool{true, false} {
t.Run(fmt.Sprintf("allowConflicts=%t", allowConflicts), func(t *testing.T) {
btcRunner := NewBlipTesterClientRunner(t)
btcRunner.Run(func(t *testing.T, SupportedBLIPProtocols []string) {
rt := NewRestTester(t, &RestTesterConfig{
PersistentConfig: true,
})
defer rt.Close()

dbConfig := rt.NewDbConfig()
dbConfig.AllowConflicts = base.Ptr(allowConflicts)
RequireStatus(t, rt.CreateDatabase("db", dbConfig), http.StatusCreated)
startWarnCount := base.SyncGatewayStats.GlobalStats.ResourceUtilization.WarnCount.Value()
docID := "doc1"
rt.CreateTestDoc(docID)

rt.PurgeDoc(docID)

RequireStatus(t, rt.SendAdminRequest(http.MethodGet, "/{{.keyspace}}/"+docID, ""), http.StatusNotFound)

opts := &BlipTesterClientOpts{SupportedBLIPProtocols: SupportedBLIPProtocols, Username: "alice"}
btc := btcRunner.NewBlipTesterClientOptsWithRT(rt, opts)
defer btc.Close()

docVersion, err := btcRunner.PushRev(btc.id, docID, EmptyDocVersion(), []byte(`{"resurrect":true}`))
require.NoError(t, err)
require.NoError(t, rt.WaitForVersion(docID, docVersion))
require.Equal(t, startWarnCount, base.SyncGatewayStats.GlobalStats.ResourceUtilization.WarnCount.Value())
})
})
}
}
Loading