2017-05-26 04:48:44 +08:00
|
|
|
/*
|
|
|
|
* IClientApi.h
|
|
|
|
*
|
|
|
|
* This source file is part of the FoundationDB open source project
|
|
|
|
*
|
2022-03-22 04:36:23 +08:00
|
|
|
* Copyright 2013-2022 Apple Inc. and the FoundationDB project authors
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* 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
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* 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_ICLIENTAPI_H
|
|
|
|
#define FDBCLIENT_ICLIENTAPI_H
|
2022-03-31 01:28:06 +08:00
|
|
|
#include "flow/ProtocolVersion.h"
|
2017-05-26 04:48:44 +08:00
|
|
|
#pragma once
|
|
|
|
|
2018-10-20 01:30:13 +08:00
|
|
|
#include "fdbclient/FDBOptions.g.h"
|
|
|
|
#include "fdbclient/FDBTypes.h"
|
2022-02-23 23:56:01 +08:00
|
|
|
#include "fdbclient/Tenant.h"
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2022-05-03 03:56:51 +08:00
|
|
|
#include "flow/Tracing.h"
|
2017-05-26 04:48:44 +08:00
|
|
|
#include "flow/ThreadHelper.actor.h"
|
|
|
|
|
2022-02-04 07:44:34 +08:00
|
|
|
struct VersionVector;
|
2021-09-16 03:20:43 +08:00
|
|
|
|
2021-04-15 03:50:30 +08:00
|
|
|
// An interface that represents a transaction created by a client
|
2017-05-26 04:48:44 +08:00
|
|
|
class ITransaction {
|
|
|
|
public:
|
|
|
|
virtual ~ITransaction() {}
|
|
|
|
|
|
|
|
virtual void cancel() = 0;
|
|
|
|
virtual void setVersion(Version v) = 0;
|
|
|
|
virtual ThreadFuture<Version> getReadVersion() = 0;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// These functions that read data return Standalone<...> objects, but these objects are not required to manage their
|
|
|
|
// own memory. It is guaranteed, however, that the ThreadFuture will hold a reference to the memory. It will persist
|
|
|
|
// until the ThreadFuture's ThreadSingleAssignmentVar has its memory released or it is destroyed.
|
|
|
|
virtual ThreadFuture<Optional<Value>> get(const KeyRef& key, bool snapshot = false) = 0;
|
|
|
|
virtual ThreadFuture<Key> getKey(const KeySelectorRef& key, bool snapshot = false) = 0;
|
2021-05-04 04:14:16 +08:00
|
|
|
virtual ThreadFuture<RangeResult> getRange(const KeySelectorRef& begin,
|
|
|
|
const KeySelectorRef& end,
|
|
|
|
int limit,
|
|
|
|
bool snapshot = false,
|
|
|
|
bool reverse = false) = 0;
|
|
|
|
virtual ThreadFuture<RangeResult> getRange(const KeySelectorRef& begin,
|
|
|
|
const KeySelectorRef& end,
|
|
|
|
GetRangeLimits limits,
|
|
|
|
bool snapshot = false,
|
|
|
|
bool reverse = false) = 0;
|
|
|
|
virtual ThreadFuture<RangeResult> getRange(const KeyRangeRef& keys,
|
|
|
|
int limit,
|
|
|
|
bool snapshot = false,
|
|
|
|
bool reverse = false) = 0;
|
|
|
|
virtual ThreadFuture<RangeResult> getRange(const KeyRangeRef& keys,
|
|
|
|
GetRangeLimits limits,
|
|
|
|
bool snapshot = false,
|
|
|
|
bool reverse = false) = 0;
|
2022-03-11 02:05:44 +08:00
|
|
|
virtual ThreadFuture<MappedRangeResult> getMappedRange(const KeySelectorRef& begin,
|
|
|
|
const KeySelectorRef& end,
|
|
|
|
const StringRef& mapper,
|
|
|
|
GetRangeLimits limits,
|
2022-05-14 01:10:43 +08:00
|
|
|
int matchIndex = MATCH_INDEX_ALL,
|
2022-03-11 02:05:44 +08:00
|
|
|
bool snapshot = false,
|
|
|
|
bool reverse = false) = 0;
|
2017-05-26 04:48:44 +08:00
|
|
|
virtual ThreadFuture<Standalone<VectorRef<const char*>>> getAddressesForKey(const KeyRef& key) = 0;
|
|
|
|
virtual ThreadFuture<Standalone<StringRef>> getVersionstamp() = 0;
|
|
|
|
|
|
|
|
virtual void addReadConflictRange(const KeyRangeRef& keys) = 0;
|
2020-01-17 09:39:23 +08:00
|
|
|
virtual ThreadFuture<int64_t> getEstimatedRangeSizeBytes(const KeyRangeRef& keys) = 0;
|
2020-06-19 00:41:50 +08:00
|
|
|
virtual ThreadFuture<Standalone<VectorRef<KeyRef>>> getRangeSplitPoints(const KeyRangeRef& range,
|
|
|
|
int64_t chunkSize) = 0;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-11-09 02:24:45 +08:00
|
|
|
virtual ThreadFuture<Standalone<VectorRef<KeyRangeRef>>> getBlobGranuleRanges(const KeyRangeRef& keyRange) = 0;
|
|
|
|
|
2021-12-02 04:43:23 +08:00
|
|
|
virtual ThreadResult<RangeResult> readBlobGranules(const KeyRangeRef& keyRange,
|
2021-11-09 02:24:45 +08:00
|
|
|
Version beginVersion,
|
|
|
|
Optional<Version> readVersion,
|
|
|
|
ReadBlobGranuleContext granuleContext) = 0;
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
virtual void atomicOp(const KeyRef& key, const ValueRef& value, uint32_t operationType) = 0;
|
|
|
|
virtual void set(const KeyRef& key, const ValueRef& value) = 0;
|
|
|
|
virtual void clear(const KeyRef& begin, const KeyRef& end) = 0;
|
|
|
|
virtual void clear(const KeyRangeRef& range) = 0;
|
|
|
|
virtual void clear(const KeyRef& key) = 0;
|
|
|
|
|
|
|
|
virtual ThreadFuture<Void> watch(const KeyRef& key) = 0;
|
|
|
|
|
|
|
|
virtual void addWriteConflictRange(const KeyRangeRef& keys) = 0;
|
|
|
|
|
|
|
|
virtual ThreadFuture<Void> commit() = 0;
|
|
|
|
virtual Version getCommittedVersion() = 0;
|
2022-05-03 03:56:51 +08:00
|
|
|
// @todo This API and the "getSpanContext()" API may help with debugging simulation
|
2021-09-16 06:20:30 +08:00
|
|
|
// test failures. (These APIs are not currently invoked anywhere.) Remove them
|
|
|
|
// later if they are not really needed.
|
2021-09-16 03:20:43 +08:00
|
|
|
virtual VersionVector getVersionVector() = 0;
|
2022-05-03 03:56:51 +08:00
|
|
|
virtual SpanContext getSpanContext() = 0;
|
2019-06-29 01:15:37 +08:00
|
|
|
virtual ThreadFuture<int64_t> getApproximateSize() = 0;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
virtual void setOption(FDBTransactionOptions::Option option, Optional<StringRef> value = Optional<StringRef>()) = 0;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
virtual ThreadFuture<Void> onError(Error const& e) = 0;
|
|
|
|
virtual void reset() = 0;
|
|
|
|
|
|
|
|
virtual void addref() = 0;
|
|
|
|
virtual void delref() = 0;
|
2021-08-11 09:07:36 +08:00
|
|
|
|
2021-08-12 09:39:47 +08:00
|
|
|
// used in template functions as returned Future type
|
2021-08-28 08:07:47 +08:00
|
|
|
template <class Type>
|
|
|
|
using FutureT = ThreadFuture<Type>;
|
2021-09-09 01:05:13 +08:00
|
|
|
// internal use only, return true by default
|
|
|
|
// Only if it's a MultiVersionTransaction and the underlying transaction handler is null,
|
|
|
|
// it will return false
|
|
|
|
virtual bool isValid() { return true; }
|
2022-02-23 23:56:01 +08:00
|
|
|
|
|
|
|
virtual Optional<TenantName> getTenant() = 0;
|
2017-05-26 04:48:44 +08:00
|
|
|
};
|
|
|
|
|
2022-02-20 07:09:55 +08:00
|
|
|
class ITenant {
|
|
|
|
public:
|
|
|
|
virtual ~ITenant() {}
|
|
|
|
|
|
|
|
virtual Reference<ITransaction> createTransaction() = 0;
|
|
|
|
|
|
|
|
virtual void addref() = 0;
|
|
|
|
virtual void delref() = 0;
|
2017-05-26 04:48:44 +08:00
|
|
|
};
|
|
|
|
|
2021-04-15 03:50:30 +08:00
|
|
|
// An interface that represents a connection to a cluster made by a client
|
2017-05-26 04:48:44 +08:00
|
|
|
class IDatabase {
|
|
|
|
public:
|
|
|
|
virtual ~IDatabase() {}
|
|
|
|
|
2022-02-23 23:56:01 +08:00
|
|
|
virtual Reference<ITenant> openTenant(TenantNameRef tenantName) = 0;
|
2018-09-22 06:58:14 +08:00
|
|
|
virtual Reference<ITransaction> createTransaction() = 0;
|
|
|
|
virtual void setOption(FDBDatabaseOptions::Option option, Optional<StringRef> value = Optional<StringRef>()) = 0;
|
2021-03-16 07:23:56 +08:00
|
|
|
virtual double getMainThreadBusyness() = 0;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-04-16 02:45:14 +08:00
|
|
|
// Returns the protocol version reported by the coordinator this client is connected to
|
2021-04-15 03:50:30 +08:00
|
|
|
// If an expected version is given, the future won't return until the protocol version is different than expected
|
2021-04-27 05:39:27 +08:00
|
|
|
// Note: this will never return if the server is running a protocol from FDB 5.0 or older
|
2021-04-15 03:50:30 +08:00
|
|
|
virtual ThreadFuture<ProtocolVersion> getServerProtocol(
|
|
|
|
Optional<ProtocolVersion> expectedVersion = Optional<ProtocolVersion>()) = 0;
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
virtual void addref() = 0;
|
|
|
|
virtual void delref() = 0;
|
2020-08-22 05:30:52 +08:00
|
|
|
|
2022-05-19 00:56:03 +08:00
|
|
|
// Management API, attempt to kill or suspend a process, return 1 for request being sent out, 0 for failure
|
|
|
|
// The address string can be extended to a comma-delimited string like <addr1>,<addr2>...,<addrN> to send reboot
|
|
|
|
// requests to multiple processes simultaneously
|
|
|
|
// If multiple addresses are provided, it returns 1 for requests being sent out to all provided addresses.
|
|
|
|
// On the contrary, if the client cannot connect to any of the given address, no requests will be sent out
|
2021-01-04 14:45:09 +08:00
|
|
|
virtual ThreadFuture<int64_t> rebootWorker(const StringRef& address, bool check, int duration) = 0;
|
2021-03-11 02:06:03 +08:00
|
|
|
// Management API, force the database to recover into DCID, causing the database to lose the most recently committed
|
|
|
|
// mutations
|
2021-01-21 17:11:40 +08:00
|
|
|
virtual ThreadFuture<Void> forceRecoveryWithDataLoss(const StringRef& dcid) = 0;
|
2021-01-27 03:53:35 +08:00
|
|
|
// Management API, create snapshot
|
2021-02-09 10:47:49 +08:00
|
|
|
virtual ThreadFuture<Void> createSnapshot(const StringRef& uid, const StringRef& snapshot_command) = 0;
|
2021-08-11 09:07:36 +08:00
|
|
|
|
2022-04-09 05:15:25 +08:00
|
|
|
// purge blob granules api. purgeBlobGranules is asynchronus, calling waitPurgeGranulesComplete after guarantees
|
|
|
|
// completion.
|
|
|
|
virtual ThreadFuture<Key> purgeBlobGranules(const KeyRangeRef& keyRange, Version purgeVersion, bool force) = 0;
|
|
|
|
virtual ThreadFuture<Void> waitPurgeGranulesComplete(const KeyRef& purgeKey) = 0;
|
|
|
|
|
2022-03-16 02:01:05 +08:00
|
|
|
// Interface to manage shared state across multiple connections to the same Database
|
2022-03-31 03:28:55 +08:00
|
|
|
virtual ThreadFuture<DatabaseSharedState*> createSharedState() = 0;
|
|
|
|
virtual void setSharedState(DatabaseSharedState* p) = 0;
|
2022-03-16 02:01:05 +08:00
|
|
|
|
2021-08-12 14:19:39 +08:00
|
|
|
// used in template functions as the Transaction type that can be created through createTransaction()
|
2021-08-11 09:07:36 +08:00
|
|
|
using TransactionT = ITransaction;
|
2017-05-26 04:48:44 +08:00
|
|
|
};
|
|
|
|
|
2021-04-15 03:50:30 +08:00
|
|
|
// An interface that presents the top-level FDB client API as exposed through the C bindings
|
|
|
|
//
|
|
|
|
// This interface and its associated objects are intended to live outside the network thread, so its asynchronous
|
|
|
|
// operations use ThreadFutures and implementations should be thread safe.
|
2017-05-26 04:48:44 +08:00
|
|
|
class IClientApi {
|
|
|
|
public:
|
|
|
|
virtual ~IClientApi() {}
|
|
|
|
|
|
|
|
virtual void selectApiVersion(int apiVersion) = 0;
|
|
|
|
virtual const char* getClientVersion() = 0;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
virtual void setNetworkOption(FDBNetworkOptions::Option option,
|
|
|
|
Optional<StringRef> value = Optional<StringRef>()) = 0;
|
2017-05-26 04:48:44 +08:00
|
|
|
virtual void setupNetwork() = 0;
|
|
|
|
virtual void runNetwork() = 0;
|
|
|
|
virtual void stopNetwork() = 0;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
virtual Reference<IDatabase> createDatabase(const char* clusterFilePath) = 0;
|
2018-05-09 07:33:43 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
virtual void addNetworkThreadCompletionHook(void (*hook)(void*), void* hookParameter) = 0;
|
2017-05-26 04:48:44 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|