Skip to content
Open
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
20 changes: 10 additions & 10 deletions db/change_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,25 +364,25 @@ func (c *changeCache) DocChanged(event sgbucket.FeedEvent, docType DocumentType)

ctx = collection.AddCollectionContext(ctx)

// If this is a delete and there are no xattrs (no existing SG revision), we can ignore
if event.Opcode == sgbucket.FeedOpDeletion && len(docJSON) == 0 {
base.DebugfCtx(ctx, base.KeyCache, "Ignoring delete mutation for %s - no existing Sync Gateway metadata.", base.UD(docID))
// If the document has no xattrs, it can not have a _sync xattr
if event.DataType&base.MemcachedDataTypeXattr == 0 {
return
}

// If this is a binary document, we can ignore.
if event.DataType == base.MemcachedDataTypeRaw {
return
}

// If this is a binary document (and not one of the above types), we can ignore. Currently only performing this check when xattrs
// are enabled, because walrus doesn't support DataType on feed.
if collection.UseXattrs() && event.DataType == base.MemcachedDataTypeRaw {
// If this is a delete and there are no xattrs (no existing SG revision), we can ignore
if event.Opcode == sgbucket.FeedOpDeletion && len(docJSON) == 0 {
base.DebugfCtx(ctx, base.KeyCache, "Ignoring delete mutation for %s - no existing Sync Gateway metadata.", base.UD(docID))
return
}

// First unmarshal the doc (just its metadata, to save time/memory):
doc, syncData, err := UnmarshalDocumentSyncDataFromFeed(docJSON, event.DataType, collection.UserXattrKey(), false)
if err != nil {
// Avoid log noise related to failed unmarshaling of binary documents.
if event.DataType != base.MemcachedDataTypeRaw {
base.DebugfCtx(ctx, base.KeyCache, "Unable to unmarshal sync metadata for feed document %q. Will not be included in channel cache. Error: %v", base.UD(docID), err)
}
if errors.Is(err, sgbucket.ErrEmptyMetadata) {
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the new early return for documents without xattrs (line 368-370), this warning about empty metadata may no longer be reachable or relevant. Consider adding a comment explaining when this condition could still occur, or verify if this error handling is still necessary given the earlier xattr check.

Suggested change
if errors.Is(err, sgbucket.ErrEmptyMetadata) {
if errors.Is(err, sgbucket.ErrEmptyMetadata) {
// At this point we know the document has *some* xattrs (see early return above),
// but Sync Gateway metadata may still be missing or empty. This can happen if the
// document only has non-SG xattrs, or if the SG metadata xattr is present but
// logically empty/corrupt. Log a warning so these unexpected cases are visible.

Copilot uses AI. Check for mistakes.
base.WarnfCtx(ctx, "Unexpected empty metadata when processing feed event. docid: %s opcode: %v datatype:%v", base.UD(event.Key), event.Opcode, event.DataType)
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removed error logging provided useful debugging information when unmarshalling failed. Now that binary documents and documents without xattrs are filtered earlier, any unmarshalling errors that do occur are unexpected and warrant logging. Consider adding back a debug log for the general error case to aid troubleshooting, since these errors would now indicate genuinely unexpected conditions.

Suggested change
base.WarnfCtx(ctx, "Unexpected empty metadata when processing feed event. docid: %s opcode: %v datatype:%v", base.UD(event.Key), event.Opcode, event.DataType)
base.WarnfCtx(ctx, "Unexpected empty metadata when processing feed event. docid: %s opcode: %v datatype:%v", base.UD(event.Key), event.Opcode, event.DataType)
} else {
base.DebugfCtx(ctx, base.KeyCache, "Error unmarshalling sync data from feed for %s (opcode:%v datatype:%v): %v", base.UD(event.Key), event.Opcode, event.DataType, err)

Copilot uses AI. Check for mistakes.
}
Expand Down
Loading