Skip to content

Commit 6b73781

Browse files
jimwwalkerdaverigby
authored andcommitted
MB-41321: Fix a regression of collection persisted high-seqno
The high-persisted seqno should only change for committed items, part 1 of MB-41321 regressed that yet was undetected. Update Flush to skip prepares in stat updates and add checks in sync-write collection tests. Change-Id: I4fc91ecbf5b93358686fcf553f01f5d9f896826b Reviewed-on: http://review.couchbase.org/c/kv_engine/+/137967 Reviewed-by: Dave Rigby <[email protected]> Tested-by: Build Bot <[email protected]>
1 parent fe97b16 commit 6b73781

File tree

3 files changed

+33
-32
lines changed

3 files changed

+33
-32
lines changed

engines/ep/src/collections/flush.cc

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -58,36 +58,25 @@ void Flush::StatisticsUpdate::updateDiskSize(ssize_t delta) {
5858
}
5959

6060
void Flush::StatisticsUpdate::insert(bool isSystem,
61-
bool isCommitted,
6261
bool isDelete,
6362
ssize_t diskSizeDelta) {
64-
if (!isSystem && !isDelete && isCommitted) {
63+
if (!isSystem && !isDelete) {
6564
incrementItemCount();
66-
} // else inserting a tombstone or it's a prepare
65+
} // else inserting a tombstone - no item increment
6766

68-
if (isSystem || isCommitted) {
69-
updateDiskSize(diskSizeDelta);
70-
}
67+
updateDiskSize(diskSizeDelta);
7168
}
7269

73-
void Flush::StatisticsUpdate::update(bool isSystem,
74-
bool isCommitted,
75-
ssize_t diskSizeDelta) {
76-
if (isSystem || isCommitted) {
77-
updateDiskSize(diskSizeDelta);
78-
}
70+
void Flush::StatisticsUpdate::update(ssize_t diskSizeDelta) {
71+
updateDiskSize(diskSizeDelta);
7972
}
8073

8174
void Flush::StatisticsUpdate::remove(bool isSystem,
82-
bool isCommitted,
8375
ssize_t diskSizeDelta) {
84-
if (isCommitted) {
76+
if (!isSystem) {
8577
decrementItemCount();
86-
} // else inserting a tombstone or it's a prepare
87-
88-
if (isSystem || isCommitted) {
89-
updateDiskSize(diskSizeDelta);
9078
}
79+
updateDiskSize(diskSizeDelta);
9180
}
9281

9382
// Called from KVStore during the flush process and before we consider the
@@ -195,6 +184,10 @@ void Flush::updateStats(const DocKey& key,
195184
bool isCommitted,
196185
bool isDelete,
197186
size_t size) {
187+
// Prepares don't change the stats
188+
if (!isCommitted) {
189+
return;
190+
}
198191
auto [isSystemEvent, cid] = getCollectionID(key);
199192

200193
if (!cid || isLogicallyDeleted(cid.value(), seqno)) {
@@ -209,7 +202,7 @@ void Flush::updateStats(const DocKey& key,
209202
}
210203

211204
getStatsAndMaybeSetPersistedHighSeqno(cid.value(), seqno)
212-
.insert(isSystemEvent, isCommitted, isDelete, size);
205+
.insert(isSystemEvent, isDelete, size);
213206
}
214207

215208
void Flush::updateStats(const DocKey& key,
@@ -220,6 +213,10 @@ void Flush::updateStats(const DocKey& key,
220213
uint64_t oldSeqno,
221214
bool oldIsDelete,
222215
size_t oldSize) {
216+
// Prepares don't change the stats
217+
if (!isCommitted) {
218+
return;
219+
}
223220
// Same logic and comment as updateStats above.
224221
auto [isSystemEvent, cid] = getCollectionID(key);
225222
if (!cid || isLogicallyDeleted(cid.value(), seqno)) {
@@ -239,11 +236,11 @@ void Flush::updateStats(const DocKey& key,
239236
auto& stats = getStatsAndMaybeSetPersistedHighSeqno(cid.value(), seqno);
240237

241238
if (oldIsDelete) {
242-
stats.insert(isSystemEvent, isCommitted, isDelete, size);
239+
stats.insert(isSystemEvent, isDelete, size);
243240
} else if (!oldIsDelete && isDelete) {
244-
stats.remove(isSystemEvent, isCommitted, size - oldSize);
241+
stats.remove(isSystemEvent, size - oldSize);
245242
} else {
246-
stats.update(isSystemEvent, isCommitted, size - oldSize);
243+
stats.update(size - oldSize);
247244
}
248245
}
249246

engines/ep/src/collections/flush.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -257,40 +257,32 @@ class Flush {
257257
/**
258258
* Process an insert into the collection
259259
* @param isSystem true if a system event is inserted
260-
* @param isCommitted true if a committed item is inserted, false for
261-
** prepare/abort
262260
* @param isDelete true if a deleted item is inserted (tombstone
263261
* creation)
264262
* @param diskSize size in bytes 'inserted' into disk. Should be
265263
* representative of the bytes used by each document, but does
266264
* not need to be exact.
267265
*/
268266
void insert(bool isSystem,
269-
bool isCommitted,
270267
bool isDelete,
271268
ssize_t diskSize);
272269

273270
/**
274271
* Process an update into the collection
275-
* @param isSystem true if a system event is updated
276-
* @param isCommitted true if a committed item is updated, false for
277-
** prepare/abort
278272
* @param diskSizeDelta size in bytes difference. Should be
279273
* representative of the difference between existing and new
280274
* documents, but does not need to be exact.
281275
*/
282-
void update(bool isSystem, bool isCommitted, ssize_t diskSizeDelta);
276+
void update(ssize_t diskSizeDelta);
283277

284278
/**
285279
* Process a remove from the collection (store of a delete)
286280
* @param isSystem true if a system event is removed
287-
* @param isCommitted true if a committed item is removed, false for
288-
** prepare/abort
289281
* @param diskSizeDelta size in bytes difference. Should be
290282
* representative of the difference between existing and new
291283
* documents, but does not need to be exact.
292284
*/
293-
void remove(bool isSystem, bool isCommitted, ssize_t diskSizeDelta);
285+
void remove(bool isSystem, ssize_t diskSizeDelta);
294286

295287
/// @returns the highest persisted seqno recorded by the Flush object
296288
uint64_t getPersistedHighSeqno() const {

engines/ep/tests/module_tests/collections/evp_store_collections_eraser_test.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,10 +952,16 @@ class CollectionsEraserSyncWriteTest : public CollectionsEraserTest {
952952
}
953953

954954
void createPendingWrite(bool deleted = false) {
955+
auto persistedHighSeqno = vb->lockCollections().getPersistedHighSeqno(
956+
key.getCollectionID());
957+
955958
if (deleted) {
956959
auto item = makeCommittedItem(key, "value");
957960
EXPECT_EQ(ENGINE_SUCCESS, store->set(*item, cookie));
958961
flushVBucketToDiskIfPersistent(vbid, 1);
962+
// Delete changed the stats
963+
persistedHighSeqno = vb->lockCollections().getPersistedHighSeqno(
964+
key.getCollectionID());
959965

960966
mutation_descr_t delInfo;
961967
uint64_t cas = item->getCas();
@@ -973,6 +979,12 @@ class CollectionsEraserSyncWriteTest : public CollectionsEraserTest {
973979
EXPECT_EQ(ENGINE_SYNC_WRITE_PENDING, store->set(*item, cookie));
974980
}
975981
flushVBucketToDiskIfPersistent(vbid, 1);
982+
983+
// Validate the collection high-persisted-seqno didn't change for the
984+
// pending item
985+
EXPECT_EQ(persistedHighSeqno,
986+
vb->lockCollections().getPersistedHighSeqno(
987+
key.getCollectionID()));
976988
}
977989

978990
void commit() {

0 commit comments

Comments
 (0)