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

CBG-3332 increase log information for documents not imported #6391

Merged
merged 2 commits into from
Sep 7, 2023
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
5 changes: 4 additions & 1 deletion db/import_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func (il *importListener) ProcessFeedEvent(event sgbucket.FeedEvent) (shouldPers

// If this is a binary document we can ignore, but update checkpoint to avoid reprocessing upon restart
if event.DataType == base.MemcachedDataTypeRaw {
base.InfofCtx(il.loggingCtx, base.KeyImport, "Ignoring binary mutation event for %s.", base.UD(event.Key))
return true
}

Expand Down Expand Up @@ -179,10 +180,12 @@ func (il *importListener) ImportFeedEvent(event sgbucket.FeedEvent) {

syncData, rawBody, rawXattr, rawUserXattr, err := UnmarshalDocumentSyncDataFromFeed(event.Value, event.DataType, collectionCtx.userXattrKey(), false)
if err != nil {
base.DebugfCtx(il.loggingCtx, base.KeyImport, "Found sync metadata, but unable to unmarshal for feed document %q. Will not be imported. Error: %v", base.UD(event.Key), err)
if err == base.ErrEmptyMetadata {
base.WarnfCtx(il.loggingCtx, "Unexpected empty metadata when processing feed event. docid: %s opcode: %v datatype:%v", base.UD(event.Key), event.Opcode, event.DataType)
} else {
base.WarnfCtx(il.loggingCtx, "Found sync metadata, but unable to unmarshal for feed document %q. Will not be imported. Error: %v", base.UD(event.Key), err)
}
il.importStats.ImportErrorCount.Add(1)
return
}

Expand Down
24 changes: 24 additions & 0 deletions db/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,5 +557,29 @@ func TestImportNonZeroStart(t *testing.T) {
doc, err := collection.GetDocument(base.TestCtx(t), doc1, DocUnmarshalAll)
require.NoError(t, err)
require.Equal(t, revID1, doc.SyncData.CurrentRev)
}

// TestImportInvalidMetadata tests triggering an import error if the metadata is unmarshalable
func TestImportInvalidMetadata(t *testing.T) {
base.SkipImportTestsIfNotEnabled(t)
bucket := base.GetTestBucket(t)
defer bucket.Close()

db, ctx := setupTestDBWithOptionsAndImport(t, bucket, DatabaseContextOptions{})
defer db.Close(ctx)

// make sure no documents are imported
require.Equal(t, int64(0), db.DbStats.SharedBucketImport().ImportCount.Value())
require.Equal(t, int64(0), db.DbStats.SharedBucketImport().ImportErrorCount.Value())

// write a document with inline sync metadata that is unmarshalable, triggering an import error
// can't write a document with invalid sync metadata as an xattr, so rely on legacy behavior
_, err := bucket.GetSingleDataStore().Add("doc1", 0, `{"foo" : "bar", "_sync" : 1 }`)
require.NoError(t, err)

_, ok := base.WaitForStat(func() int64 {
return db.DbStats.SharedBucketImport().ImportErrorCount.Value()
}, 1)
require.True(t, ok)
require.Equal(t, int64(0), db.DbStats.SharedBucketImport().ImportCount.Value())
}