Conversation
There was a problem hiding this comment.
Pull request overview
This PR enhances the change listener to skip processing documents without xattrs, improving performance by avoiding unnecessary unmarshalling operations. The change cache previously attempted to process documents lacking _sync xattrs (e.g., un-imported documents or those rejected by import filters), which was only necessary in pre-xattr mode.
Changes:
- Add early return when documents lack xattrs, preventing unnecessary processing
- Reorder validation checks to filter out documents without xattrs before attempting unmarshalling
- Remove obsolete error logging for binary documents that are now filtered earlier
| // If this is a binary document, we can ignore. | ||
| if event.DataType == base.MemcachedDataTypeRaw { |
There was a problem hiding this comment.
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.
| // 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 { |
CBG-5170 change listener: don't process docs without xattr
This avoids unmarshalling documents without _sync xattr, which was necessarily in pre-xattr mode. The change cache could see documents without _sync xattrs if they were not yet imported, or they got rejected by the import filter.
If this were to get backported to 3.3, you would add a check for db.UseXattrs() around this section.
Pre-review checklist
fmt.Print,log.Print, ...)base.UD(docID),base.MD(dbName))docs/apiIntegration Tests
GSI=true,xattrs=truehttps://jenkins.sgwdev.com/job/SyncGatewayIntegration/273/