Skip to content

Commit a43ff3f

Browse files
committed
Fix DocKey::to_string() parsing of queued_item's keys
Currently we don't parse the key of a empty, checkpoint_start, set_vbucket_sate and checkpoint_end keys correctly. For example the below checkpoint dump shows that we crop the first few chars and interpret them as leb128 values: {2803,empty,cid:0x1:0x65:0x6d:pty,118,[m]} {2803,checkpoint_start,cid:0x1:0x63:0x68:eckpoint_start,129,[m]} {2803,system_event[d],cid:0x1:0x0:0x385:_collection,176,} {2804,set_vbucket_state,cid:0x1:0x73:0x65:t_vbucket_state,241,[m]} {2804,checkpoint_end,cid:0x1:0x63:0x68:eckpoint_end,127,[m]} With this patch: {2803,empty,cid:0x1:empty,118,[m]} {2803,checkpoint_start,cid:0x1:checkpoint_start,129,[m]} {2803,system_event[d],cid:0x1:0x0:0x385:_collection,176,} {2804,set_vbucket_state,cid:0x1:set_vbucket_state,241,[m]} {2804,checkpoint_end,cid:0x1:checkpoint_end,127,[m]} To also ensure we parse system events correctly, this patch moves enum Class SystemEvent to include/memcached/systemevent.h so that it can be accessed by dockey.cc. This patch also clang-tidys some lines in checkpoint_test.cc and also adds test to ensure correct parsing of all types of items. Change-Id: I31db2826316f60b068f7e9370e488f0df0ae4324 Reviewed-on: http://review.couchbase.org/c/kv_engine/+/141044 Reviewed-by: Dave Rigby <[email protected]> Tested-by: Build Bot <[email protected]>
1 parent 2db176f commit a43ff3f

File tree

13 files changed

+119
-65
lines changed

13 files changed

+119
-65
lines changed

engines/ep/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ ADD_LIBRARY(ep_objs OBJECT
357357
src/stored-value.cc
358358
src/stored_value_factories.cc
359359
src/stored_value_factories.h
360-
src/systemevent.cc
360+
src/systemevent_factory.cc
361361
src/tasks.cc
362362
src/taskqueue.cc
363363
src/vb_commit.cc

engines/ep/src/collections/collections_types.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
#include "collections/collections_types.h"
19-
#include "systemevent.h"
19+
#include "systemevent_factory.h"
2020

2121
#include <mcbp/protocol/unsigned_leb128.h>
2222
#include <nlohmann/json.hpp>

engines/ep/src/collections/eraser_context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
#include "collections/scan_context.h"
19-
#include "systemevent.h"
19+
#include "systemevent_factory.h"
2020

2121
#pragma once
2222

engines/ep/src/collections/vbucket_manifest.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "collections/manifest.h"
2626
#include "ep_time.h"
2727
#include "item.h"
28-
#include "systemevent.h"
28+
#include "systemevent_factory.h"
2929
#include "vbucket.h"
3030

3131
#include <statistics/cbstat_collector.h>

engines/ep/src/dcp/response.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "ep_types.h"
2222
#include "ext_meta_parser.h"
2323
#include "item.h"
24-
#include "systemevent.h"
24+
#include "systemevent_factory.h"
2525

2626
#include <mcbp/protocol/dcp_stream_end_status.h>
2727
#include <memcached/dcp_stream_id.h>

engines/ep/src/stored-value.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "item.h"
2222
#include "objectregistry.h"
2323
#include "stats.h"
24-
#include "systemevent.h"
24+
#include "systemevent_factory.h"
2525

2626
#include <platform/cb_malloc.h>
2727
#include <platform/compress.h>

engines/ep/src/systemevent.cc renamed to engines/ep/src/systemevent_factory.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
#include "systemevent.h"
18+
#include "systemevent_factory.h"
1919

2020
#include "collections/collections_types.h"
2121
#include "collections/vbucket_manifest.h"

engines/ep/src/systemevent.h renamed to engines/ep/src/systemevent_factory.h

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "ep_types.h"
2323
#include "storeddockey_fwd.h"
2424

25+
#include <memcached/systemevent.h>
26+
2527
#include <string>
2628

2729
class Item;
@@ -32,46 +34,6 @@ namespace Collections::VB {
3234
class Manifest;
3335
} // namespace Collections::VB
3436

35-
/// underlying size of uint32_t as this is to be stored in the Item flags field.
36-
enum class SystemEvent : uint32_t {
37-
/**
38-
* The Collection system event represents the beginning or end of a
39-
* collection. Each Collection system event has a key which contains the
40-
* collection ID. When the event is queued in a checkpoint or stored on
41-
* disk the seqno of that item states that this is the point when that
42-
* collection became accessible unless that queued/stored item is deleted,
43-
* then it represent when that collection became inaccesible (logically
44-
* deleted).
45-
*
46-
* A Collection system event when queued into a checkpoint carries with it
47-
* a value, the value is used to maintain a per vbucket JSON collection's
48-
* manifest (for persisted buckets).
49-
*/
50-
Collection,
51-
52-
/**
53-
* The Scope system event represents the beginning or end of a
54-
* scope. Each Scope system event has a key which contains the
55-
* Scope ID. When the event is queued in a checkpoint or stored on
56-
* disk the seqno of that item states that this is the point when that
57-
* scope became accessible unless that queued/stored item is deleted,
58-
* then it represent when that scope became inaccessible
59-
*
60-
*/
61-
Scope
62-
};
63-
64-
static inline std::string to_string(const SystemEvent se) {
65-
switch (se) {
66-
case SystemEvent::Collection:
67-
return "Collection";
68-
case SystemEvent::Scope:
69-
return "Scope";
70-
}
71-
throw std::invalid_argument("to_string(SystemEvent) unknown " +
72-
std::to_string(int(se)));
73-
}
74-
7537
class SystemEventFactory {
7638
public:
7739
/**

engines/ep/tests/module_tests/checkpoint_test.cc

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@
3333
#include "../mock/mock_checkpoint_manager.h"
3434
#include "../mock/mock_dcp_consumer.h"
3535
#include "../mock/mock_stream.h"
36-
#include "../mock/mock_synchronous_ep_engine.h"
3736

38-
#include <folly/portability/GMock.h>
3937
#include <folly/portability/GTest.h>
4038
#include <valgrind/valgrind.h>
4139

@@ -47,7 +45,6 @@
4745
#define NUM_SET_THREADS_VG 2
4846

4947
#define NUM_ITEMS 500
50-
#define NUM_ITEMS_VG 10
5148

5249
#define DCP_CURSOR_PREFIX "dcp-client-"
5350

@@ -1024,7 +1021,7 @@ TEST_P(CheckpointTest, SeqnoAndHLCOrdering) {
10241021
std::vector<std::vector<std::pair<uint64_t, uint64_t> > > threadData(n_threads);
10251022
for (int ii = 0; ii < n_threads; ii++) {
10261023
auto& threadsData = threadData[ii];
1027-
threads.push_back(std::thread([this, ii, n_items, &threadsData](){
1024+
threads.emplace_back([this, ii, n_items, &threadsData]() {
10281025
std::string key = "key" + std::to_string(ii);
10291026
for (int item = 0; item < n_items; item++) {
10301027
queued_item qi(
@@ -1041,9 +1038,9 @@ TEST_P(CheckpointTest, SeqnoAndHLCOrdering) {
10411038
/*preLinkDocCtx*/ nullptr));
10421039

10431040
// Save seqno/cas
1044-
threadsData.push_back(std::make_pair(qi->getBySeqno(), qi->getCas()));
1041+
threadsData.emplace_back(qi->getBySeqno(), qi->getCas());
10451042
}
1046-
}));
1043+
});
10471044
}
10481045

10491046
// Wait for all threads
@@ -2984,6 +2981,36 @@ TEST_P(CheckpointTest, MB_41283_TestNoCrashForDuplicateKeysInDiskCheckpoint) {
29842981
EXPECT_FALSE(queueReplicatedItem("k1001", 1002));
29852982
}
29862983

2984+
TEST_P(CheckpointTest, CheckpointItemToString) {
2985+
auto item = this->manager->public_createCheckpointItem(
2986+
0, Vbid(0), queue_op::empty);
2987+
EXPECT_EQ("cid:0x1:empty", item->getKey().to_string());
2988+
2989+
item = this->manager->public_createCheckpointItem(
2990+
0, Vbid(0), queue_op::checkpoint_start);
2991+
EXPECT_EQ("cid:0x1:checkpoint_start", item->getKey().to_string());
2992+
2993+
item = this->manager->public_createCheckpointItem(
2994+
0, Vbid(0), queue_op::set_vbucket_state);
2995+
EXPECT_EQ("cid:0x1:set_vbucket_state", item->getKey().to_string());
2996+
2997+
item = this->manager->public_createCheckpointItem(
2998+
0, Vbid(0), queue_op::checkpoint_end);
2999+
EXPECT_EQ("cid:0x1:checkpoint_end", item->getKey().to_string());
3000+
3001+
auto disk = makeDiskDocKey("test_key");
3002+
EXPECT_EQ("cid:0x0:test_key", disk.to_string());
3003+
3004+
disk = makeDiskDocKey("test_key", true, CollectionID(99));
3005+
EXPECT_EQ("pre:cid:0x63:test_key", disk.to_string());
3006+
3007+
auto event =
3008+
SystemEventFactory::makeCollectionEvent(CollectionID(99), {}, {});
3009+
EXPECT_EQ("cid:0x1:0x0:0x63:_collection", event->getKey().to_string());
3010+
event = SystemEventFactory::makeScopeEvent(ScopeID(99), {}, {});
3011+
EXPECT_EQ("cid:0x1:0x1:0x63:_scope", event->getKey().to_string());
3012+
}
3013+
29873014
INSTANTIATE_TEST_SUITE_P(
29883015
AllVBTypesAllEvictionModes,
29893016
CheckpointTest,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "failover-table.h"
2626
#include "item.h"
2727
#include "stats.h"
28-
#include "systemevent.h"
28+
#include "systemevent_factory.h"
2929
#include "tests/module_tests/collections/collections_test_helpers.h"
3030
#include "tests/module_tests/test_helpers.h"
3131
#include <utilities/test_manifest.h>

0 commit comments

Comments
 (0)