25 #ifndef KUDU_CLIENT_CLIENT_H
26 #define KUDU_CLIENT_CLIENT_H
32 #include "kudu/client/resource_metrics.h"
33 #include "kudu/client/row_result.h"
34 #include "kudu/client/scan_batch.h"
35 #include "kudu/client/scan_predicate.h"
36 #include "kudu/client/schema.h"
38 #ifdef KUDU_HEADERS_NO_STUBS
39 #include <gtest/gtest_prod.h>
40 #include "kudu/gutil/macros.h"
41 #include "kudu/gutil/port.h"
43 #include "kudu/client/stubs.h"
45 #include "kudu/client/write_op.h"
46 #include "kudu/util/kudu_export.h"
47 #include "kudu/util/monotime.h"
52 class ClientStressTest_TestUniqueClientIds_Test;
53 class LinkedListTester;
54 class PartitionSchema;
58 class KuduLoggingCallback;
61 class KuduStatusCallback;
63 class KuduTableAlterer;
64 class KuduTableCreator;
66 class KuduTabletServer;
68 class KuduWriteOperation;
72 class GetTableSchemaRpc;
76 class RemoteTabletServer;
92 void KUDU_EXPORT InstallLoggingCallback(KuduLoggingCallback* cb);
100 void KUDU_EXPORT UninstallLoggingCallback();
117 void KUDU_EXPORT SetVerboseLogLevel(
int level);
128 Status KUDU_EXPORT SetInternalSignalNumber(
int signum);
132 std::string KUDU_EXPORT GetShortVersionString();
136 std::string KUDU_EXPORT GetAllVersionInfo();
198 Status Build(sp::shared_ptr<KuduClient>* client);
201 class KUDU_NO_EXPORT Data;
235 class KUDU_EXPORT
KuduClient :
public sp::enable_shared_from_this<KuduClient> {
253 Status IsCreateTableInProgress(
const std::string& table_name,
254 bool *create_in_progress);
261 Status DeleteTable(
const std::string& table_name);
279 Status IsAlterTableInProgress(
const std::string& table_name,
280 bool *alter_in_progress);
288 Status GetTableSchema(
const std::string& table_name,
297 Status ListTabletServers(std::vector<KuduTabletServer*>* tablet_servers);
306 Status ListTables(std::vector<std::string>* tables,
307 const std::string& filter =
"");
316 Status TableExists(
const std::string& table_name,
bool* exists);
331 Status OpenTable(
const std::string& table_name,
332 sp::shared_ptr<KuduTable>* table);
339 sp::shared_ptr<KuduSession> NewSession();
355 Status KUDU_NO_EXPORT GetTablet(
const std::string& tablet_id,
372 bool IsMultiMaster()
const;
375 const MonoDelta& default_admin_operation_timeout()
const;
378 const MonoDelta& default_rpc_timeout()
const;
423 uint64_t GetLatestObservedTimestamp()
const;
439 void SetLatestObservedTimestamp(uint64_t ht_timestamp);
442 class KUDU_NO_EXPORT Data;
444 friend class internal::Batcher;
445 friend class internal::GetTableSchemaRpc;
446 friend class internal::LookupRpc;
447 friend class internal::MetaCache;
448 friend class internal::RemoteTablet;
449 friend class internal::RemoteTabletServer;
450 friend class internal::WriteRpc;
451 friend class ClientTest;
460 FRIEND_TEST(kudu::ClientStressTest, TestUniqueClientIds);
461 FRIEND_TEST(ClientTest, TestGetTabletServerBlacklist);
462 FRIEND_TEST(ClientTest, TestMasterDown);
463 FRIEND_TEST(ClientTest, TestMasterLookupPermits);
464 FRIEND_TEST(ClientTest, TestMetaCacheExpiry);
465 FRIEND_TEST(ClientTest, TestNonCoveringRangePartitions);
466 FRIEND_TEST(ClientTest, TestReplicatedTabletWritesWithLeaderElection);
467 FRIEND_TEST(ClientTest, TestScanFaultTolerance);
468 FRIEND_TEST(ClientTest, TestScanTimeout);
469 FRIEND_TEST(ClientTest, TestWriteWithDeadMaster);
470 FRIEND_TEST(MasterFailoverTest, TestPauseAfterCreateTableIssued);
487 const std::string& uuid()
const;
491 const std::string& hostname()
const;
495 uint16_t port()
const;
498 class KUDU_NO_EXPORT Data;
509 DISALLOW_COPY_AND_ASSIGN(KuduTabletServer);
521 bool is_leader()
const;
530 class KUDU_NO_EXPORT Data;
537 DISALLOW_COPY_AND_ASSIGN(KuduReplica);
547 const std::string& id()
const;
554 const std::vector<const KuduReplica*>& replicas()
const;
560 class KUDU_NO_EXPORT Data;
567 DISALLOW_COPY_AND_ASSIGN(KuduTablet);
616 KuduTableCreator& add_hash_partitions(
const std::vector<std::string>& columns,
617 int32_t num_buckets);
634 KuduTableCreator& add_hash_partitions(
const std::vector<std::string>& columns,
635 int32_t num_buckets, int32_t seed);
649 KuduTableCreator& set_range_partition_columns(
const std::vector<std::string>& columns);
687 RangePartitionBound lower_bound_type = INCLUSIVE_BOUND,
688 RangePartitionBound upper_bound_type = EXCLUSIVE_BOUND);
705 KuduTableCreator& split_rows(
const std::vector<const KuduPartialRow*>& split_rows)
706 ATTRIBUTE_DEPRECATED(
"use add_range_partition_split() instead");
755 class KUDU_NO_EXPORT Data;
787 class KUDU_EXPORT
KuduTable :
public sp::enable_shared_from_this<KuduTable> {
792 const std::string& name()
const;
801 const std::string& id()
const;
807 int num_replicas()
const;
880 std::vector<KuduValue*>* values);
887 const PartitionSchema& partition_schema()
const;
890 class KUDU_NO_EXPORT Data;
894 KuduTable(
const sp::shared_ptr<KuduClient>& client,
895 const std::string& name,
896 const std::string&
id,
899 const PartitionSchema& partition_schema);
904 DISALLOW_COPY_AND_ASSIGN(KuduTable);
1060 class KUDU_NO_EXPORT Data;
1064 const std::string& name);
1069 DISALLOW_COPY_AND_ASSIGN(KuduTableAlterer);
1082 const Status& status()
const;
1106 bool was_possibly_successful()
const;
1109 class KUDU_NO_EXPORT Data;
1111 friend class internal::Batcher;
1119 DISALLOW_COPY_AND_ASSIGN(KuduError);
1181 class KUDU_EXPORT
KuduSession :
public sp::enable_shared_from_this<KuduSession> {
1227 Status SetFlushMode(FlushMode m) WARN_UNUSED_RESULT;
1273 Status SetExternalConsistencyMode(ExternalConsistencyMode m)
1293 Status SetMutationBufferSpace(
size_t size_bytes) WARN_UNUSED_RESULT;
1318 Status SetMutationBufferFlushWatermark(
double watermark_pct)
1342 Status SetMutationBufferFlushInterval(
unsigned int millis) WARN_UNUSED_RESULT;
1368 Status SetMutationBufferMaxNum(
unsigned int max_num) WARN_UNUSED_RESULT;
1375 void SetTimeoutMillis(
int millis);
1420 Status Flush() WARN_UNUSED_RESULT;
1466 Status Close() WARN_UNUSED_RESULT;
1476 bool HasPendingOperations() const;
1499 int CountBufferedOperations() const
1500 ATTRIBUTE_DEPRECATED("this method is experimental and will disappear "
1501 "in a future release");
1509 int CountPendingErrors() const;
1521 void GetPendingErrors(std::vector<
KuduError*>* errors,
bool* overflowed);
1527 class KUDU_NO_EXPORT Data;
1530 friend class internal::Batcher;
1531 friend class ClientTest;
1532 FRIEND_TEST(ClientTest, TestAutoFlushBackgroundApplyBlocks);
1533 FRIEND_TEST(ClientTest, TestAutoFlushBackgroundAndErrorCollector);
1535 explicit
KuduSession(const sp::shared_ptr<KuduClient>& client);
1604 enum { kScanTimeoutMillis = 30000 };
1611 explicit KuduScanner(KuduTable* table);
1623 Status SetProjectedColumnNames(
const std::vector<std::string>& col_names)
1635 Status SetProjectedColumnIndexes(
const std::vector<int>& col_indexes)
1643 Status SetProjectedColumns(
const std::vector<std::string>& col_names)
1645 ATTRIBUTE_DEPRECATED(
"use SetProjectedColumnNames() instead");
1655 Status AddConjunctPredicate(KuduPredicate* pred) WARN_UNUSED_RESULT;
1675 ATTRIBUTE_DEPRECATED(
"use AddLowerBound() instead");
1694 Status AddExclusiveUpperBoundRaw(
const Slice& key)
1695 ATTRIBUTE_DEPRECATED(
"use AddExclusiveUpperBound() instead");
1705 Status AddLowerBoundPartitionKeyRaw(
const Slice& partition_key);
1715 Status AddExclusiveUpperBoundPartitionKeyRaw(
const Slice& partition_key);
1723 Status SetCacheBlocks(
bool cache_blocks);
1763 bool HasMoreRows()
const;
1776 Status NextBatch(std::vector<KuduRowResult>* rows)
1777 ATTRIBUTE_DEPRECATED(
"use NextBatch(KuduScanBatch*) instead");
1787 Status NextBatch(KuduScanBatch* batch);
1797 Status GetCurrentServer(KuduTabletServer** server);
1800 const ResourceMetrics& GetResourceMetrics()
const;
1808 Status SetBatchSizeBytes(uint32_t batch_size);
1825 Status SetReadMode(ReadMode read_mode) WARN_UNUSED_RESULT;
1832 Status SetOrderMode(OrderMode order_mode) WARN_UNUSED_RESULT
1833 ATTRIBUTE_DEPRECATED(
"use SetFaultTolerant() instead");
1847 Status SetFaultTolerant() WARN_UNUSED_RESULT;
1854 Status SetSnapshotMicros(uint64_t snapshot_timestamp_micros) WARN_UNUSED_RESULT;
1868 Status SetSnapshotRaw(uint64_t snapshot_timestamp) WARN_UNUSED_RESULT;
1875 Status SetTimeoutMillis(
int millis);
1878 KuduSchema GetProjectionSchema() const;
1881 std::
string ToString() const;
1884 class KUDU_NO_EXPORT Data;
1886 friend class KuduScanToken;
1887 FRIEND_TEST(ClientTest, TestScanCloseProxy);
1888 FRIEND_TEST(ClientTest, TestScanFaultTolerance);
1889 FRIEND_TEST(ClientTest, TestScanNoBlockCaching);
1890 FRIEND_TEST(ClientTest, TestScanTimeout);
1895 DISALLOW_COPY_AND_ASSIGN(KuduScanner);
1918 class KUDU_EXPORT KuduScanToken {
1933 Status IntoKuduScanner(KuduScanner** scanner)
const WARN_UNUSED_RESULT;
1945 Status Serialize(std::string* buf)
const WARN_UNUSED_RESULT;
1958 static Status DeserializeIntoScanner(KuduClient* client,
1959 const std::string& serialized_token,
1960 KuduScanner** scanner) WARN_UNUSED_RESULT;
1963 class KUDU_NO_EXPORT Data;
1972 DISALLOW_COPY_AND_ASSIGN(KuduScanToken);
1998 Status SetProjectedColumnNames(
const std::vector<std::string>& col_names)
2002 Status SetProjectedColumnIndexes(
const std::vector<int>& col_indexes)
2022 Status SetCacheBlocks(
bool cache_blocks) WARN_UNUSED_RESULT;
2030 Status SetBatchSizeBytes(uint32_t batch_size) WARN_UNUSED_RESULT;
2046 Status SetFaultTolerant() WARN_UNUSED_RESULT;
2049 Status SetSnapshotMicros(uint64_t snapshot_timestamp_micros)
2053 Status SetSnapshotRaw(uint64_t snapshot_timestamp) WARN_UNUSED_RESULT;
2056 Status SetTimeoutMillis(
int millis) WARN_UNUSED_RESULT;
2066 Status Build(std::vector<KuduScanToken*>* tokens) WARN_UNUSED_RESULT;
2069 std::string ToString()
const;
2072 class KUDU_NO_EXPORT Data;
A single row update to be sent to the cluster.
Definition: write_op.h:178
A representation of a table's schema.
Definition: schema.h:414
A representation of an operation's outcome.
Definition: status.h:116
A constant cell value with a specific type.
Definition: value.h:33
ExternalConsistencyMode
The possible external consistency modes on which Kudu operates.
Definition: client.h:1230
Definition: client.h:1249
A single row insert to be sent to the cluster.
Definition: write_op.h:126
Builder API for specifying or altering a column within a table schema.
Definition: schema.h:227
static const uint64_t kNoTimestamp
Definition: client.h:382
ReplicaSelection
Policy with which to choose amongst multiple replicas.
Definition: client.h:361
A single row upsert to be sent to the cluster.
Definition: write_op.h:151
Builds scan tokens for a table.
Definition: client.h:1978
ComparisonOp
Supported comparison operators.
Definition: scan_predicate.h:39
Alters an existing table based on the provided steps.
Definition: client.h:918
OrderMode
Definition: client.h:1586
Definition: client.h:1592
Smart pointer typedefs for externally-faced code.
A representation of comparison predicate for Kudu queries.
Definition: scan_predicate.h:36
An exclusive bound.
Definition: client.h:653
This class represents an error which occurred in a write operation.
Definition: client.h:1077
A handle for a connection to a cluster.
Definition: client.h:235
An inclusive bound.
Definition: client.h:654
In-memory representation of a remote tablet server.
Definition: client.h:481
The interface for all status callbacks.
Definition: callbacks.h:161
A wrapper around externally allocated data.
Definition: slice.h:43
A representation of a table on a particular cluster.
Definition: client.h:787
This class is a representation of a single scan.
Definition: client.h:1548
ReadMode
The read modes for scanners.
Definition: client.h:1551
Definition: client.h:1211
Definition: client.h:1559
A "factory" for KuduClient objects.
Definition: client.h:142
A single-row write operation to be sent to a Kudu table.
Definition: write_op.h:55
Select the LEADER replica.
Definition: client.h:362
RangePartitionBound
Range partition bound type.
Definition: client.h:652
In-memory representation of a remote tablet.
Definition: client.h:541
In-memory representation of a remote tablet's replica.
Definition: client.h:513
FlushMode
Modes of flush operations.
Definition: client.h:1186
Definition: client.h:1191
A single row delete to be sent to the cluster.
Definition: write_op.h:205
A helper class to create a new table with the desired options.
Definition: client.h:571
Representation of a Kudu client session.
Definition: client.h:1181
A row which may only contain values for a subset of the columns.
Definition: partial_row.h:53
A representation of a time interval.
Definition: monotime.h:43