Details
-
Bug
-
Resolution: Fixed
-
Major
-
Morpheus, 7.6.2
-
Untriaged
-
0
-
Unknown
Description
In the mobile mode, XDCR will need to decompress data to read xattrs section and update HLV etc, if the body received is in a compressed format.
Right now, to re-compress the decompressed body before replicating, we have the following logic in mobile mode:
https://github.com/couchbase/goxdcr/blob/master/parts/xmem_nozzle.go#L1476
The body is recompressed only if:
maxEncodedLen := snappy.MaxEncodedLen(len(mc_req.Body))
|
if maxEncodedLen > 0 && maxEncodedLen < len(mc_req.Body) { |
// compress mc_req.body |
}
|
But a positive maxEncodedLen is always: (Refer https://github.com/golang/snappy/blob/v0.0.4/encode.go#L78)
32 + len(mc_req.Body) + len(mc_req.Body)/6 |
which is always greater than len(mc_req.Body)
So the decompressed body is never re-compressed.
A potential solution could be:
1. Keep note of the pre-decompressed body length
2. Decompress body, keep note of the new body length
3. Update xattrs (HLV etc), use the same doc body -> updateSystemXattrsForTarget(...)
3. If length in (1) < length in (2), compress it back [Since we don't modify the doc body and assume xattrs are compressible]
A side note: Snappy compression is only supported for *_with_meta, and this should be skipped for subdoc command.
The change should also be such that it honours the XDCR replication setting for compression - https://docs.couchbase.com/server/current/xdcr-reference/xdcr-advanced-settings.html#xdcr-compression-type-values