Skip to content

Commit 0b3337d

Browse files
committed
MB-45505: Move system event types to own module
Moving code to own module to remove a cyclic dependency in an upstream change. Change-Id: I4bd371b293f9144ded5423c8f45fe24ace4e1b41 Reviewed-on: http://review.couchbase.org/c/kv_engine/+/150933 Reviewed-by: James Harrison <[email protected]> Tested-by: Build Bot <[email protected]>
1 parent 1e24eea commit 0b3337d

File tree

9 files changed

+220
-170
lines changed

9 files changed

+220
-170
lines changed

engines/ep/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ SET(COLLECTIONS_SOURCE src/collections/collections_types.cc
246246
${CMAKE_CURRENT_BINARY_DIR}/src/collections/kvstore_generated.h
247247
${CMAKE_CURRENT_BINARY_DIR}/src/collections/manifest_generated.h
248248
src/collections/scan_context.cc
249+
src/collections/system_event_types.cc
249250
src/collections/vbucket_filter.cc
250251
src/collections/vbucket_manifest.cc
251252
src/collections/vbucket_manifest_entry.cc

engines/ep/src/collections/collections_types.cc

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -77,41 +77,6 @@ AccumulatedStats& AccumulatedStats::operator+=(const AccumulatedStats& other) {
7777
return *this;
7878
}
7979

80-
std::string to_string(const CreateEventData& event) {
81-
return fmt::format(
82-
fmt("CreateCollection{{uid:{:#x} scopeID:{} collectionID:{} "
83-
"name:'"
84-
"{}' maxTTLEnabled:{} maxTTL:{}}}"),
85-
event.manifestUid.load(),
86-
event.metaData.sid.to_string(),
87-
event.metaData.cid.to_string(),
88-
event.metaData.name,
89-
event.metaData.maxTtl.has_value(),
90-
event.metaData.maxTtl.has_value() ? event.metaData.maxTtl->count()
91-
: 0);
92-
}
93-
94-
std::string to_string(const DropEventData& event) {
95-
return fmt::format(
96-
fmt("DropCollection{{uid:{:#x} scopeID:{} collectionID:{}}}"),
97-
event.manifestUid.load(),
98-
event.sid.to_string(),
99-
event.cid.to_string());
100-
}
101-
102-
std::string to_string(const CreateScopeEventData& event) {
103-
return fmt::format(fmt("CreateScope{{uid:{:#x} scopeID:{} name:'{}'}}"),
104-
event.manifestUid.load(),
105-
event.metaData.sid.to_string(),
106-
event.metaData.name);
107-
}
108-
109-
std::string to_string(const DropScopeEventData& event) {
110-
return fmt::format(fmt("DropScope{{uid:{:#x} scopeID:{}}}"),
111-
event.manifestUid.load(),
112-
event.sid.to_string());
113-
}
114-
11580
namespace VB {
11681
std::string to_string(ManifestUpdateStatus status) {
11782
switch (status) {

engines/ep/src/collections/collections_types.h

Lines changed: 1 addition & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ struct CollectionMetaData {
162162
/**
163163
* The metadata of a single scope
164164
*
165-
* Default construction yields the default collection
165+
* Default construction yields the default scope
166166
*/
167167
struct ScopeMetaData {
168168
ScopeID sid{ScopeID::Default}; // The scope's ID
@@ -173,137 +173,6 @@ struct ScopeMetaData {
173173
}
174174
};
175175

176-
/**
177-
* All of the data a system event needs
178-
*/
179-
struct CreateEventData {
180-
ManifestUid manifestUid; // The Manifest which generated the event
181-
CollectionMetaData metaData; // The data of the new collection
182-
};
183-
184-
struct DropEventData {
185-
ManifestUid manifestUid; // The Manifest which generated the event
186-
ScopeID sid; // The scope that the collection belonged to
187-
CollectionID cid; // The collection the event belongs to
188-
};
189-
190-
struct CreateScopeEventData {
191-
ManifestUid manifestUid; // The Manifest which generated the event
192-
ScopeMetaData metaData; // The data of the new scope
193-
};
194-
195-
struct DropScopeEventData {
196-
ManifestUid manifestUid; // The Manifest which generated the event
197-
ScopeID sid; // The scope the event belongs to
198-
};
199-
200-
std::string to_string(const CreateEventData& event);
201-
std::string to_string(const DropEventData& event);
202-
std::string to_string(const CreateScopeEventData& event);
203-
std::string to_string(const DropScopeEventData& event);
204-
205-
/**
206-
* All of the data a DCP create event message will transmit in the value of the
207-
* message. This is the layout to be used on the wire and is in the correct
208-
* byte order
209-
*/
210-
struct CreateEventDcpData {
211-
explicit CreateEventDcpData(const CreateEventData& ev)
212-
: manifestUid(ev.manifestUid),
213-
sid(ev.metaData.sid),
214-
cid(ev.metaData.cid) {
215-
}
216-
/// The manifest uid stored in network byte order ready for sending
217-
ManifestUidNetworkOrder manifestUid;
218-
/// The scope id stored in network byte order ready for sending
219-
ScopeIDNetworkOrder sid;
220-
/// The collection id stored in network byte order ready for sending
221-
CollectionIDNetworkOrder cid;
222-
// The size is sizeof(manifestUid) + sizeof(cid) + sizeof(sid)
223-
// (msvc won't allow that expression)
224-
constexpr static size_t size{16};
225-
};
226-
227-
/**
228-
* All of the data a DCP create event message will transmit in the value of a
229-
* DCP system event message (when the collection is created with a TTL). This is
230-
* the layout to be used on the wire and is in the correct byte order
231-
*/
232-
struct CreateWithMaxTtlEventDcpData {
233-
explicit CreateWithMaxTtlEventDcpData(const CreateEventData& ev)
234-
: manifestUid(ev.manifestUid),
235-
sid(ev.metaData.sid),
236-
cid(ev.metaData.cid),
237-
maxTtl(htonl(gsl::narrow_cast<uint32_t>(
238-
ev.metaData.maxTtl.value().count()))) {
239-
}
240-
/// The manifest uid stored in network byte order ready for sending
241-
ManifestUidNetworkOrder manifestUid;
242-
/// The scope id stored in network byte order ready for sending
243-
ScopeIDNetworkOrder sid;
244-
/// The collection id stored in network byte order ready for sending
245-
CollectionIDNetworkOrder cid;
246-
/// The collection's maxTTL value (in network byte order)
247-
uint32_t maxTtl;
248-
// The size is sizeof(manifestUid) + sizeof(cid) + sizeof(sid) +
249-
// sizeof(maxTTL) (msvc won't allow that expression)
250-
constexpr static size_t size{20};
251-
};
252-
253-
/**
254-
* All of the data a DCP drop event message will transmit in the value of the
255-
* message. This is the layout to be used on the wire and is in the correct
256-
* byte order
257-
*/
258-
struct DropEventDcpData {
259-
explicit DropEventDcpData(const DropEventData& data)
260-
: manifestUid(data.manifestUid), sid(data.sid), cid(data.cid) {
261-
}
262-
263-
/// The manifest uid stored in network byte order ready for sending
264-
ManifestUidNetworkOrder manifestUid;
265-
/// The scope id stored in network byte order ready for sending
266-
ScopeIDNetworkOrder sid;
267-
/// The collection id stored in network byte order ready for sending
268-
CollectionIDNetworkOrder cid;
269-
// The size is sizeof(manifestUid) + sizeof(cid) (msvc won't allow that
270-
// expression)
271-
constexpr static size_t size{16};
272-
};
273-
274-
/**
275-
* All of the data a DCP create scope event message will transmit in the value
276-
* of the message. This is the layout to be used on the wire and is in the
277-
* correct byte order
278-
*/
279-
struct CreateScopeEventDcpData {
280-
explicit CreateScopeEventDcpData(const CreateScopeEventData& data)
281-
: manifestUid(data.manifestUid), sid(data.metaData.sid) {
282-
}
283-
/// The manifest uid stored in network byte order ready for sending
284-
ManifestUidNetworkOrder manifestUid;
285-
/// The scope id stored in network byte order ready for sending
286-
ScopeIDNetworkOrder sid;
287-
constexpr static size_t size{12};
288-
};
289-
290-
/**
291-
* All of the data a DCP drop scope event message will transmit in the value of
292-
* the message. This is the layout to be used on the wire and is in the correct
293-
* byte order
294-
*/
295-
struct DropScopeEventDcpData {
296-
explicit DropScopeEventDcpData(const DropScopeEventData& data)
297-
: manifestUid(data.manifestUid), sid(data.sid) {
298-
}
299-
300-
/// The manifest uid stored in network byte order ready for sending
301-
ManifestUidNetworkOrder manifestUid;
302-
/// The collection id stored in network byte order ready for sending
303-
ScopeIDNetworkOrder sid;
304-
constexpr static size_t size{12};
305-
};
306-
307176
/**
308177
* For creation of collection SystemEvents - The SystemEventFactory
309178
* glues the CollectionID into the event key (so create of x doesn't
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2+
/*
3+
* Copyright 2021 Couchbase, Inc
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "collections/system_event_types.h"
19+
20+
#include <spdlog/fmt/fmt.h>
21+
22+
namespace Collections {
23+
24+
std::string to_string(const CreateEventData& event) {
25+
return fmt::format(
26+
fmt("CreateCollection{{uid:{:#x} scopeID:{} collectionID:{} "
27+
"name:'"
28+
"{}' maxTTLEnabled:{} maxTTL:{}}}"),
29+
event.manifestUid.load(),
30+
event.metaData.sid.to_string(),
31+
event.metaData.cid.to_string(),
32+
event.metaData.name,
33+
event.metaData.maxTtl.has_value(),
34+
event.metaData.maxTtl.has_value() ? event.metaData.maxTtl->count()
35+
: 0);
36+
}
37+
38+
std::string to_string(const DropEventData& event) {
39+
return fmt::format(
40+
fmt("DropCollection{{uid:{:#x} scopeID:{} collectionID:{}}}"),
41+
event.manifestUid.load(),
42+
event.sid.to_string(),
43+
event.cid.to_string());
44+
}
45+
46+
std::string to_string(const CreateScopeEventData& event) {
47+
return fmt::format(fmt("CreateScope{{uid:{:#x} scopeID:{} name:'{}'}}"),
48+
event.manifestUid.load(),
49+
event.metaData.sid.to_string(),
50+
event.metaData.name);
51+
}
52+
53+
std::string to_string(const DropScopeEventData& event) {
54+
return fmt::format(fmt("DropScope{{uid:{:#x} scopeID:{}}}"),
55+
event.manifestUid.load(),
56+
event.sid.to_string());
57+
}
58+
59+
} // namespace Collections

0 commit comments

Comments
 (0)