Details
-
Bug
-
Resolution: Fixed
-
Major
-
7.0.0
-
None
-
Untriaged
-
0
-
Yes
Description
As part of refactoring to support concurrent couchstore compaction (https://review.couchbase.org/c/couchstore/+/125688), the --dropdeletes flag of couch_compact was inadvertently broken; due to the semantics of the COUCHSTORE_COMPACT_FLAG_DROP_DELETES compact_flag - quoting from couch_db.h:
/**
|
* A compactor hook will be given each DocInfo, and can either keep or drop
|
* the item based on its contents.
|
...
|
* If a compactor hook is set, COUCHSTORE_COMPACT_FLAG_DROP_DELETES will
|
* *not* drop deletes, but will bump the purge counter. The hook is
|
* responsible for dropping deletes. |
As part of that refactor, we changed to use std::function with a lambda wrapping the C-style filter API API, this in effect meant that a compactor hook was always set - the new implementation of the C-style couchstore_compact_db_ex() function:
couchstore_error_t couchstore_compact_db_ex(Db* source,
|
const char* target_filename, |
couchstore_compact_flags flags,
|
couchstore_compact_hook hook,
|
couchstore_docinfo_hook dhook,
|
void* hook_ctx, |
FileOpsInterface* ops,
|
PrecommitHook precommitHook) {
|
return cb::couchstore::compact( |
*source,
|
target_filename,
|
flags,
|
[hook, hook_ctx](Db& db, DocInfo* info, sized_buf body) -> int { |
if (hook == nullptr) { |
return COUCHSTORE_COMPACT_KEEP_ITEM; |
}
|
return hook(&db, info, body, hook_ctx); |
},
|
...
|
i.e. note the 4th argument to compact() is always non-empty, even if hook is null. Looking at the later checking of the flag, note simply checks that ctx->filterCallback - the std::function - is non-empty:
compact_seq_fetchcb() |
if ((bpWithDeleted & BP_DELETED_FLAG) && (!ctx->filterCallback) && |
(ctx->flags & COUCHSTORE_COMPACT_FLAG_DROP_DELETES)) {
|
return COUCHSTORE_SUCCESS; |
}
|
As such, this if() statement is never taken after the aforementioned refactor.
Note that this has limited product impact - couch_compact is not directly used in normal operation, compaction is driven internally from ep-engine (via the C++ APIs), and moreover the COUCHSTORE_COMPACT_FLAG_DROP_DELETES flag is only used by couch_compact. As such, this just means that support / development-initiated compaction via the command-line tools would not respect the --dropdeletes flag.