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
16 changes: 6 additions & 10 deletions db/change_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,27 +364,23 @@ 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 (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 binary document, we can ignore.
if event.DataType == base.MemcachedDataTypeRaw {
Comment on lines +372 to +373
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

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

The binary document check will not correctly filter out binary documents that have xattrs. Since the xattr check at line 368 returns early for documents without xattrs, only documents WITH xattrs reach this check. For a binary document with xattrs, the DataType would be MemcachedDataTypeXattr (4), not MemcachedDataTypeRaw (0), so this equality check will fail and binary documents with xattrs will continue to be processed. The correct check should verify that the JSON flag is not set using a bitwise operation: event.DataType&base.MemcachedDataTypeJSON == 0.

Suggested change
// If this is a binary document, we can ignore.
if event.DataType == base.MemcachedDataTypeRaw {
// If this is not a JSON document (e.g. binary, with or without xattrs), we can ignore.
if event.DataType&base.MemcachedDataTypeJSON == 0 {

Copilot uses AI. Check for mistakes.
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) {
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, "Unable to unmarshal sync metadata for feed document %q. Will not be included in channel cache. Error: %v", base.UD(docID), err)
}
return
}
Expand Down
Loading