forked from apple/foundationdb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommitProxyInterface.h
More file actions
464 lines (388 loc) · 16.7 KB
/
CommitProxyInterface.h
File metadata and controls
464 lines (388 loc) · 16.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
/*
* CommitProxyInterface.h
*
* This source file is part of the FoundationDB open source project
*
* Copyright 2013-2026 Apple Inc. and the FoundationDB project authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef FDBCLIENT_COMMITPROXYINTERFACE_H
#define FDBCLIENT_COMMITPROXYINTERFACE_H
#pragma once
#include <utility>
#include <vector>
#include "fdbclient/CommitTransaction.h"
#include "fdbclient/FDBTypes.h"
#include "fdbclient/GlobalConfig.h"
#include "fdbclient/GrvProxyInterface.h"
#include "fdbclient/IdempotencyId.h"
#include "fdbclient/StorageServerInterface.h"
struct CommitProxyInterface {
constexpr static FileIdentifier file_identifier = 8954922;
enum { LocationAwareLoadBalance = 1 };
enum { AlwaysFresh = 1 };
Optional<Key> processId;
bool provisional;
PublicRequestStream<struct CommitTransactionRequest> commit;
// Reserved to preserve the historical adjusted-endpoint numbering for the
// commit proxy interface. Commit proxies do not serve GRV traffic; clients
// use GrvProxyInterface::getConsistentReadVersion for that path.
PublicRequestStream<struct GetReadVersionRequest> legacyGetConsistentReadVersion;
PublicRequestStream<struct GetKeyServerLocationsRequest> getKeyServersLocations;
RequestStream<struct GetStorageServerRejoinInfoRequest> getStorageServerRejoinInfo;
RequestStream<ReplyPromise<Void>> waitFailure;
RequestStream<struct TxnStateRequest> txnState;
RequestStream<struct ProxySnapRequest> proxySnapReq;
RequestStream<struct ExclusionSafetyCheckRequest> exclusionSafetyCheckReq;
RequestStream<struct GetDDMetricsRequest> getDDMetrics;
PublicRequestStream<struct ExpireIdempotencyIdRequest> expireIdempotencyId;
RequestStream<struct SetThrottledShardRequest> setThrottledShard;
UID id() const { return commit.getEndpoint().token; }
std::string toString() const { return id().shortString(); }
bool operator==(CommitProxyInterface const& r) const { return id() == r.id(); }
bool operator!=(CommitProxyInterface const& r) const { return id() != r.id(); }
NetworkAddress address() const { return commit.getEndpoint().getPrimaryAddress(); }
NetworkAddressList addresses() const { return commit.getEndpoint().addresses; }
template <class Archive>
void serialize(Archive& ar) {
serializer(ar, processId, provisional, commit);
if (Archive::isDeserializing) {
legacyGetConsistentReadVersion =
PublicRequestStream<struct GetReadVersionRequest>(commit.getEndpoint().getAdjustedEndpoint(1));
getKeyServersLocations =
PublicRequestStream<struct GetKeyServerLocationsRequest>(commit.getEndpoint().getAdjustedEndpoint(2));
getStorageServerRejoinInfo =
RequestStream<struct GetStorageServerRejoinInfoRequest>(commit.getEndpoint().getAdjustedEndpoint(3));
waitFailure = RequestStream<ReplyPromise<Void>>(commit.getEndpoint().getAdjustedEndpoint(4));
txnState = RequestStream<struct TxnStateRequest>(commit.getEndpoint().getAdjustedEndpoint(5));
proxySnapReq = RequestStream<struct ProxySnapRequest>(commit.getEndpoint().getAdjustedEndpoint(6));
exclusionSafetyCheckReq =
RequestStream<struct ExclusionSafetyCheckRequest>(commit.getEndpoint().getAdjustedEndpoint(7));
getDDMetrics = RequestStream<struct GetDDMetricsRequest>(commit.getEndpoint().getAdjustedEndpoint(8));
expireIdempotencyId =
PublicRequestStream<struct ExpireIdempotencyIdRequest>(commit.getEndpoint().getAdjustedEndpoint(9));
setThrottledShard =
RequestStream<struct SetThrottledShardRequest>(commit.getEndpoint().getAdjustedEndpoint(10));
}
}
void initEndpoints() {
std::vector<std::pair<FlowReceiver*, TaskPriority>> streams;
streams.push_back(commit.getReceiver(TaskPriority::ReadSocket));
streams.push_back(legacyGetConsistentReadVersion.getReceiver(TaskPriority::ReadSocket));
streams.push_back(getKeyServersLocations.getReceiver(
TaskPriority::ReadSocket)); // priority lowered to TaskPriority::DefaultEndpoint on the proxy
streams.push_back(getStorageServerRejoinInfo.getReceiver(TaskPriority::ProxyStorageRejoin));
streams.push_back(waitFailure.getReceiver());
streams.push_back(txnState.getReceiver());
streams.push_back(proxySnapReq.getReceiver());
streams.push_back(exclusionSafetyCheckReq.getReceiver());
streams.push_back(getDDMetrics.getReceiver());
streams.push_back(expireIdempotencyId.getReceiver());
streams.push_back(setThrottledShard.getReceiver());
FlowTransport::transport().addEndpoints(streams);
}
};
// ClientDBInfo is all the information needed by a database client to access the database
// It is returned (and kept up to date) by the OpenDatabaseRequest interface of ClusterInterface
struct ClientDBInfo {
constexpr static FileIdentifier file_identifier = 5355080;
UID id; // Changes each time anything else changes
std::vector<GrvProxyInterface> grvProxies;
std::vector<CommitProxyInterface> commitProxies;
Optional<CommitProxyInterface>
firstCommitProxy; // not serialized, used for commitOnFirstProxy when the commit proxies vector has been shrunk
Optional<Value> forward;
std::vector<VersionHistory> history;
UID clusterId;
ClusterType clusterType = ClusterType::STANDALONE;
ClientDBInfo() {}
bool operator==(ClientDBInfo const& r) const { return id == r.id; }
bool operator!=(ClientDBInfo const& r) const { return id != r.id; }
template <class Archive>
void serialize(Archive& ar) {
if constexpr (!is_fb_function<Archive>) {
ASSERT(ar.protocolVersion().isValid());
}
serializer(ar, grvProxies, commitProxies, id, forward, history, clusterId, clusterType);
}
};
// Compile ReplyPromise<CachedSerialization<ClientDBInfo>> takes long time, extern template is used to fix this. The
// corresponding instantiations are done in CommitProxyInterface.cpp
extern template class ReplyPromise<struct ClientDBInfo>;
extern template class ReplyPromise<class CachedSerialization<struct ClientDBInfo>>;
struct ExpireIdempotencyIdRequest {
constexpr static FileIdentifier file_identifier = 1900933;
Version commitVersion = invalidVersion;
uint8_t batchIndexHighByte = 0;
ExpireIdempotencyIdRequest() {}
ExpireIdempotencyIdRequest(Version commitVersion, uint8_t batchIndexHighByte)
: commitVersion(commitVersion), batchIndexHighByte(batchIndexHighByte) {}
bool verify() const { return true; }
template <class Ar>
void serialize(Ar& ar) {
serializer(ar, commitVersion, batchIndexHighByte);
}
};
struct CommitID {
constexpr static FileIdentifier file_identifier = 14254927;
Version version; // returns invalidVersion if transaction conflicts
uint16_t txnBatchId;
Optional<Value> metadataVersion;
Optional<Standalone<VectorRef<int>>> conflictingKRIndices;
template <class Ar>
void serialize(Ar& ar) {
serializer(ar, version, txnBatchId, metadataVersion, conflictingKRIndices);
}
CommitID() : version(invalidVersion), txnBatchId(0) {}
CommitID(Version version,
uint16_t txnBatchId,
const Optional<Value>& metadataVersion,
const Optional<Standalone<VectorRef<int>>>& conflictingKRIndices = Optional<Standalone<VectorRef<int>>>())
: version(version), txnBatchId(txnBatchId), metadataVersion(metadataVersion),
conflictingKRIndices(conflictingKRIndices) {}
};
struct CommitTransactionRequest : TimedRequest {
constexpr static FileIdentifier file_identifier = 93948;
enum { FLAG_IS_LOCK_AWARE = 0x1, FLAG_FIRST_IN_BATCH = 0x2, FLAG_BYPASS_STORAGE_QUOTA = 0x4 };
bool isLockAware() const { return (flags & FLAG_IS_LOCK_AWARE) != 0; }
bool firstInBatch() const { return (flags & FLAG_FIRST_IN_BATCH) != 0; }
bool bypassStorageQuota() const { return (flags & FLAG_BYPASS_STORAGE_QUOTA) != 0; }
Arena arena;
SpanContext spanContext;
CommitTransactionRef transaction;
ReplyPromise<CommitID> reply;
uint32_t flags;
Optional<UID> debugID;
Optional<ClientTrCommitCostEstimation> commitCostEstimation;
Optional<TagSet> tagSet;
IdempotencyIdRef idempotencyId;
bool verify() const { return true; }
CommitTransactionRequest() : CommitTransactionRequest(SpanContext()) {}
explicit CommitTransactionRequest(SpanContext const& context) : spanContext(context), flags(0) {}
template <class Ar>
void serialize(Ar& ar) {
serializer(
ar, transaction, reply, flags, debugID, commitCostEstimation, tagSet, spanContext, idempotencyId, arena);
}
};
static inline int getBytes(CommitTransactionRequest const& r) {
// SOMEDAY: Optimize
// return r.arena.getSize(); // NOT correct because arena can be shared!
int total = sizeof(r);
for (auto m = r.transaction.mutations.begin(); m != r.transaction.mutations.end(); ++m)
total += m->expectedSize() + CLIENT_KNOBS->PROXY_COMMIT_OVERHEAD_BYTES;
for (auto i = r.transaction.read_conflict_ranges.begin(); i != r.transaction.read_conflict_ranges.end(); ++i)
total += i->expectedSize();
for (auto i = r.transaction.write_conflict_ranges.begin(); i != r.transaction.write_conflict_ranges.end(); ++i)
total += i->expectedSize();
return total;
}
struct GetKeyServerLocationsReply {
constexpr static FileIdentifier file_identifier = 10636023;
Arena arena;
std::vector<std::pair<KeyRangeRef, std::vector<StorageServerInterface>>> results;
// if any storage servers in results have a TSS pair, that mapping is in here
std::vector<std::pair<UID, StorageServerInterface>> resultsTssMapping;
// maps storage server interfaces (captured in "results") to the tags of
// their corresponding storage servers
// @note this map allows the client to identify the latest commit versions
// of storage servers (the version vector, which captures the latest commit
// versions of storage servers, identifies storage servers by their tags).
std::vector<std::pair<UID, Tag>> resultsTagMapping;
template <class Ar>
void serialize(Ar& ar) {
serializer(ar, results, resultsTssMapping, resultsTagMapping, arena);
}
};
// Instantiated in CommitProxyInterface.cpp
extern template class ReplyPromise<GetKeyServerLocationsReply>;
extern template struct NetSAV<GetKeyServerLocationsReply>;
struct GetKeyServerLocationsRequest {
constexpr static FileIdentifier file_identifier = 9144680;
Arena arena;
SpanContext spanContext;
KeyRef begin;
Optional<KeyRef> end;
int limit;
bool reverse;
ReplyPromise<GetKeyServerLocationsReply> reply;
// TODO(gglass): see if this can be removed now that tenant is removed.
Version legacyVersion;
GetKeyServerLocationsRequest() : limit(0), reverse(false), legacyVersion(latestVersion) {}
GetKeyServerLocationsRequest(SpanContext spanContext,
KeyRef const& begin,
Optional<KeyRef> const& end,
int limit,
bool reverse,
Version version,
Arena const& arena)
: arena(arena), spanContext(spanContext), begin(begin), end(end), limit(limit), reverse(reverse),
legacyVersion(version) {}
bool verify() const { return true; }
template <class Ar>
void serialize(Ar& ar) {
serializer(ar, begin, end, limit, reverse, reply, spanContext, legacyVersion, arena);
}
};
struct SWIFT_CXX_IMPORT_OWNED GetRawCommittedVersionReply {
constexpr static FileIdentifier file_identifier = 1314732;
Optional<UID> debugID;
Version version;
bool locked;
Optional<Value> metadataVersion;
Version minKnownCommittedVersion;
VersionVector ssVersionVectorDelta;
GetRawCommittedVersionReply()
: debugID(Optional<UID>()), version(invalidVersion), locked(false), metadataVersion(Optional<Value>()),
minKnownCommittedVersion(invalidVersion) {}
template <class Ar>
void serialize(Ar& ar) {
serializer(ar, debugID, version, locked, metadataVersion, minKnownCommittedVersion, ssVersionVectorDelta);
}
};
struct SWIFT_CXX_IMPORT_OWNED GetRawCommittedVersionRequest {
constexpr static FileIdentifier file_identifier = 12954034;
SpanContext spanContext;
Optional<UID> debugID;
ReplyPromise<GetRawCommittedVersionReply> reply;
Version maxVersion; // max version in the grv proxy's version vector cache
explicit GetRawCommittedVersionRequest(SpanContext spanContext,
Optional<UID> const& debugID = Optional<UID>(),
Version maxVersion = invalidVersion)
: spanContext(spanContext), debugID(debugID), maxVersion(maxVersion) {}
explicit GetRawCommittedVersionRequest() : spanContext(), debugID(), maxVersion(invalidVersion) {}
template <class Ar>
void serialize(Ar& ar) {
serializer(ar, debugID, reply, spanContext, maxVersion);
}
};
struct SWIFT_CXX_IMPORT_OWNED GetStorageServerRejoinInfoReply {
constexpr static FileIdentifier file_identifier = 9469225;
Version version;
Tag tag;
Optional<Tag> newTag;
bool newLocality;
std::vector<std::pair<Version, Tag>> history;
EncryptionAtRestModeDeprecated encryptMode;
template <class Ar>
void serialize(Ar& ar) {
serializer(ar, version, tag, newTag, newLocality, history, encryptMode);
}
};
struct GetStorageServerRejoinInfoRequest {
constexpr static FileIdentifier file_identifier = 994279;
UID id;
Optional<Value> dcId;
ReplyPromise<GetStorageServerRejoinInfoReply> reply;
GetStorageServerRejoinInfoRequest() {}
explicit GetStorageServerRejoinInfoRequest(UID const& id, Optional<Value> const& dcId) : id(id), dcId(dcId) {}
template <class Ar>
void serialize(Ar& ar) {
serializer(ar, id, dcId, reply);
}
};
struct TxnStateRequest {
constexpr static FileIdentifier file_identifier = 15250781;
Arena arena;
VectorRef<KeyValueRef> data;
Sequence sequence;
bool last;
std::vector<Endpoint> broadcastInfo;
ReplyPromise<Void> reply;
template <class Ar>
void serialize(Ar& ar) {
serializer(ar, data, sequence, last, broadcastInfo, reply, arena);
}
};
struct GetDDMetricsReply {
constexpr static FileIdentifier file_identifier = 7277713;
Standalone<VectorRef<DDMetricsRef>> storageMetricsList;
GetDDMetricsReply() {}
template <class Ar>
void serialize(Ar& ar) {
serializer(ar, storageMetricsList);
}
};
struct GetDDMetricsRequest {
constexpr static FileIdentifier file_identifier = 14536812;
KeyRange keys;
int shardLimit;
ReplyPromise<struct GetDDMetricsReply> reply;
GetDDMetricsRequest() {}
explicit GetDDMetricsRequest(KeyRange const& keys, const int shardLimit) : keys(keys), shardLimit(shardLimit) {}
template <class Ar>
void serialize(Ar& ar) {
serializer(ar, keys, shardLimit, reply);
}
};
struct ProxySnapRequest {
constexpr static FileIdentifier file_identifier = 5427684;
Arena arena;
StringRef snapPayload; // command used to snapshot the data folder
UID snapUID;
ReplyPromise<Void> reply;
Optional<UID> debugID;
explicit ProxySnapRequest(Optional<UID> const& debugID = Optional<UID>()) : debugID(debugID) {}
explicit ProxySnapRequest(StringRef snap, UID snapUID, Optional<UID> debugID = Optional<UID>())
: snapPayload(snap), snapUID(snapUID), debugID(debugID) {}
template <class Ar>
void serialize(Ar& ar) {
serializer(ar, snapPayload, snapUID, reply, debugID, arena);
}
};
struct ExclusionSafetyCheckReply {
constexpr static FileIdentifier file_identifier = 11;
bool safe;
ExclusionSafetyCheckReply() : safe(false) {}
explicit ExclusionSafetyCheckReply(bool safe) : safe(safe) {}
template <class Ar>
void serialize(Ar& ar) {
serializer(ar, safe);
}
};
struct ExclusionSafetyCheckRequest {
constexpr static FileIdentifier file_identifier = 13852702;
std::vector<AddressExclusion> exclusions;
ReplyPromise<ExclusionSafetyCheckReply> reply;
ExclusionSafetyCheckRequest() {}
explicit ExclusionSafetyCheckRequest(std::vector<AddressExclusion> exclusions) : exclusions(exclusions) {}
template <class Ar>
void serialize(Ar& ar) {
serializer(ar, exclusions, reply);
}
};
struct SetThrottledShardReply {
constexpr static FileIdentifier file_identifier = 2828140;
SetThrottledShardReply() {}
template <class Ar>
void serialize(Ar& ar) {
serializer(ar);
}
};
struct SetThrottledShardRequest {
constexpr static FileIdentifier file_identifier = 2828141;
std::vector<KeyRange> throttledShards;
double expirationTime;
ReplyPromise<SetThrottledShardReply> reply;
SetThrottledShardRequest() {}
explicit SetThrottledShardRequest(std::vector<KeyRange> throttledShards, double expirationTime)
: throttledShards(throttledShards), expirationTime(expirationTime) {}
template <class Ar>
void serialize(Ar& ar) {
serializer(ar, throttledShards, expirationTime, reply);
}
};
Standalone<StringRef> getBackupKey(BinaryWriter& wr, uint32_t** partBuffer, int part);
StringRef getBackupValue(Key& content, int part);
#endif