00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00024
00025 #ifndef KUDU_CLIENT_CLIENT_H
00026 #define KUDU_CLIENT_CLIENT_H
00027
00028 #include <stdint.h>
00029 #include <string>
00030 #include <vector>
00031
00032 #include "kudu/client/resource_metrics.h"
00033 #include "kudu/client/row_result.h"
00034 #include "kudu/client/scan_batch.h"
00035 #include "kudu/client/scan_predicate.h"
00036 #include "kudu/client/schema.h"
00037 #include "kudu/client/shared_ptr.h"
00038 #ifdef KUDU_HEADERS_NO_STUBS
00039 #include <gtest/gtest_prod.h>
00040 #include "kudu/gutil/macros.h"
00041 #include "kudu/gutil/port.h"
00042 #else
00043 #include "kudu/client/stubs.h"
00044 #endif
00045 #include "kudu/client/write_op.h"
00046 #include "kudu/util/kudu_export.h"
00047 #include "kudu/util/monotime.h"
00048 #include "kudu/util/status.h"
00049
00050 #if _GLIBCXX_USE_CXX11_ABI
00051 #error \
00052 "Kudu will not function properly if built with gcc 5's new ABI. " \
00053 "Please modify your application to set -D_GLIBCXX_USE_CXX11_ABI=0. " \
00054 "For more information about the new ABI, see " \
00055 "https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html."
00056 #endif
00057
00058 namespace kudu {
00059
00060 class ClientStressTest_TestUniqueClientIds_Test;
00061 class LinkedListTester;
00062 class PartitionSchema;
00063
00064 namespace client {
00065
00066 class KuduLoggingCallback;
00067 class KuduScanToken;
00068 class KuduSession;
00069 class KuduStatusCallback;
00070 class KuduTable;
00071 class KuduTableAlterer;
00072 class KuduTableCreator;
00073 class KuduTablet;
00074 class KuduTabletServer;
00075 class KuduValue;
00076 class KuduWriteOperation;
00077
00078 namespace internal {
00079 class Batcher;
00080 class GetTableSchemaRpc;
00081 class LookupRpc;
00082 class MetaCache;
00083 class RemoteTablet;
00084 class RemoteTabletServer;
00085 class WriteRpc;
00086 }
00087
00100 void KUDU_EXPORT InstallLoggingCallback(KuduLoggingCallback* cb);
00101
00108 void KUDU_EXPORT UninstallLoggingCallback();
00109
00125 void KUDU_EXPORT SetVerboseLogLevel(int level);
00126
00136 Status KUDU_EXPORT SetInternalSignalNumber(int signum);
00137
00140 std::string KUDU_EXPORT GetShortVersionString();
00141
00144 std::string KUDU_EXPORT GetAllVersionInfo();
00145
00150 class KUDU_EXPORT KuduClientBuilder {
00151 public:
00152 KuduClientBuilder();
00153 ~KuduClientBuilder();
00154
00158 KuduClientBuilder& clear_master_server_addrs();
00159
00165 KuduClientBuilder& master_server_addrs(const std::vector<std::string>& addrs);
00166
00174 KuduClientBuilder& add_master_server_addr(const std::string& addr);
00175
00185 KuduClientBuilder& default_admin_operation_timeout(const MonoDelta& timeout);
00186
00194 KuduClientBuilder& default_rpc_timeout(const MonoDelta& timeout);
00195
00206 Status Build(sp::shared_ptr<KuduClient>* client);
00207
00208 private:
00209 class KUDU_NO_EXPORT Data;
00210
00211
00212 Data* data_;
00213
00214 DISALLOW_COPY_AND_ASSIGN(KuduClientBuilder);
00215 };
00216
00243 class KUDU_EXPORT KuduClient : public sp::enable_shared_from_this<KuduClient> {
00244 public:
00245 ~KuduClient();
00246
00251 KuduTableCreator* NewTableCreator();
00252
00261 Status IsCreateTableInProgress(const std::string& table_name,
00262 bool *create_in_progress);
00263
00269 Status DeleteTable(const std::string& table_name);
00270
00277 KuduTableAlterer* NewTableAlterer(const std::string& table_name);
00278
00287 Status IsAlterTableInProgress(const std::string& table_name,
00288 bool *alter_in_progress);
00296 Status GetTableSchema(const std::string& table_name,
00297 KuduSchema* schema);
00298
00305 Status ListTabletServers(std::vector<KuduTabletServer*>* tablet_servers);
00306
00314 Status ListTables(std::vector<std::string>* tables,
00315 const std::string& filter = "");
00316
00324 Status TableExists(const std::string& table_name, bool* exists);
00325
00339 Status OpenTable(const std::string& table_name,
00340 sp::shared_ptr<KuduTable>* table);
00341
00347 sp::shared_ptr<KuduSession> NewSession();
00348
00350
00363 Status KUDU_NO_EXPORT GetTablet(const std::string& tablet_id,
00364 KuduTablet** tablet);
00365
00367
00369 enum ReplicaSelection {
00370 LEADER_ONLY,
00371
00372 CLOSEST_REPLICA,
00373
00374
00375 FIRST_REPLICA
00376 };
00377
00380 bool IsMultiMaster() const;
00381
00383 const MonoDelta& default_admin_operation_timeout() const;
00384
00386 const MonoDelta& default_rpc_timeout() const;
00387
00390 static const uint64_t kNoTimestamp;
00391
00431 uint64_t GetLatestObservedTimestamp() const;
00432
00447 void SetLatestObservedTimestamp(uint64_t ht_timestamp);
00448
00449 private:
00450 class KUDU_NO_EXPORT Data;
00451
00452 friend class internal::Batcher;
00453 friend class internal::GetTableSchemaRpc;
00454 friend class internal::LookupRpc;
00455 friend class internal::MetaCache;
00456 friend class internal::RemoteTablet;
00457 friend class internal::RemoteTabletServer;
00458 friend class internal::WriteRpc;
00459 friend class ClientTest;
00460 friend class KuduClientBuilder;
00461 friend class KuduScanner;
00462 friend class KuduScanTokenBuilder;
00463 friend class KuduSession;
00464 friend class KuduTable;
00465 friend class KuduTableAlterer;
00466 friend class KuduTableCreator;
00467
00468 FRIEND_TEST(kudu::ClientStressTest, TestUniqueClientIds);
00469 FRIEND_TEST(ClientTest, TestGetTabletServerBlacklist);
00470 FRIEND_TEST(ClientTest, TestMasterDown);
00471 FRIEND_TEST(ClientTest, TestMasterLookupPermits);
00472 FRIEND_TEST(ClientTest, TestMetaCacheExpiry);
00473 FRIEND_TEST(ClientTest, TestNonCoveringRangePartitions);
00474 FRIEND_TEST(ClientTest, TestReplicatedTabletWritesWithLeaderElection);
00475 FRIEND_TEST(ClientTest, TestScanFaultTolerance);
00476 FRIEND_TEST(ClientTest, TestScanTimeout);
00477 FRIEND_TEST(ClientTest, TestWriteWithDeadMaster);
00478 FRIEND_TEST(MasterFailoverTest, TestPauseAfterCreateTableIssued);
00479
00480 KuduClient();
00481
00482
00483 Data* data_;
00484
00485 DISALLOW_COPY_AND_ASSIGN(KuduClient);
00486 };
00487
00489 class KUDU_EXPORT KuduTabletServer {
00490 public:
00491 ~KuduTabletServer();
00492
00495 const std::string& uuid() const;
00496
00499 const std::string& hostname() const;
00500
00503 uint16_t port() const;
00504
00505 private:
00506 class KUDU_NO_EXPORT Data;
00507
00508 friend class KuduClient;
00509 friend class KuduScanner;
00510 friend class KuduScanTokenBuilder;
00511
00512 KuduTabletServer();
00513
00514
00515 Data* data_;
00516
00517 DISALLOW_COPY_AND_ASSIGN(KuduTabletServer);
00518 };
00519
00521 class KUDU_EXPORT KuduReplica {
00522 public:
00523 ~KuduReplica();
00524
00529 bool is_leader() const;
00530
00532 const KuduTabletServer& ts() const;
00533
00534 private:
00535 friend class KuduClient;
00536 friend class KuduScanTokenBuilder;
00537
00538 class KUDU_NO_EXPORT Data;
00539
00540 KuduReplica();
00541
00542
00543 Data* data_;
00544
00545 DISALLOW_COPY_AND_ASSIGN(KuduReplica);
00546 };
00547
00549 class KUDU_EXPORT KuduTablet {
00550 public:
00551 ~KuduTablet();
00552
00555 const std::string& id() const;
00556
00562 const std::vector<const KuduReplica*>& replicas() const;
00563
00564 private:
00565 friend class KuduClient;
00566 friend class KuduScanTokenBuilder;
00567
00568 class KUDU_NO_EXPORT Data;
00569
00570 KuduTablet();
00571
00572
00573 Data* data_;
00574
00575 DISALLOW_COPY_AND_ASSIGN(KuduTablet);
00576 };
00577
00579 class KUDU_EXPORT KuduTableCreator {
00580 public:
00581 ~KuduTableCreator();
00582
00594 KuduTableCreator& table_name(const std::string& name);
00595
00606 KuduTableCreator& schema(const KuduSchema* schema);
00607
00624 KuduTableCreator& add_hash_partitions(const std::vector<std::string>& columns,
00625 int32_t num_buckets);
00626
00642 KuduTableCreator& add_hash_partitions(const std::vector<std::string>& columns,
00643 int32_t num_buckets, int32_t seed);
00644
00657 KuduTableCreator& set_range_partition_columns(const std::vector<std::string>& columns);
00658
00660 enum RangePartitionBound {
00661 EXCLUSIVE_BOUND,
00662 INCLUSIVE_BOUND,
00663 };
00664
00693 KuduTableCreator& add_range_partition(KuduPartialRow* lower_bound,
00694 KuduPartialRow* upper_bound,
00695 RangePartitionBound lower_bound_type = INCLUSIVE_BOUND,
00696 RangePartitionBound upper_bound_type = EXCLUSIVE_BOUND);
00697
00706 KuduTableCreator& add_range_partition_split(KuduPartialRow* split_row);
00707
00713 KuduTableCreator& split_rows(const std::vector<const KuduPartialRow*>& split_rows);
00714
00724 KuduTableCreator& num_replicas(int n_replicas);
00725
00735 KuduTableCreator& timeout(const MonoDelta& timeout);
00736
00744 KuduTableCreator& wait(bool wait);
00745
00759 Status Create();
00760
00761 private:
00762 class KUDU_NO_EXPORT Data;
00763
00764 friend class KuduClient;
00765
00766 explicit KuduTableCreator(KuduClient* client);
00767
00768
00769 Data* data_;
00770
00771 DISALLOW_COPY_AND_ASSIGN(KuduTableCreator);
00772 };
00773
00794 class KUDU_EXPORT KuduTable : public sp::enable_shared_from_this<KuduTable> {
00795 public:
00796 ~KuduTable();
00797
00799 const std::string& name() const;
00800
00808 const std::string& id() const;
00809
00811 const KuduSchema& schema() const;
00812
00814 int num_replicas() const;
00815
00819 KuduInsert* NewInsert();
00820
00824 KuduUpsert* NewUpsert();
00825
00829 KuduUpdate* NewUpdate();
00830
00834 KuduDelete* NewDelete();
00835
00859 KuduPredicate* NewComparisonPredicate(const Slice& col_name,
00860 KuduPredicate::ComparisonOp op,
00861 KuduValue* value);
00862
00865 KuduClient* client() const;
00866
00868 const PartitionSchema& partition_schema() const;
00869
00870 private:
00871 class KUDU_NO_EXPORT Data;
00872
00873 friend class KuduClient;
00874
00875 KuduTable(const sp::shared_ptr<KuduClient>& client,
00876 const std::string& name,
00877 const std::string& id,
00878 int num_replicas,
00879 const KuduSchema& schema,
00880 const PartitionSchema& partition_schema);
00881
00882
00883 Data* data_;
00884
00885 DISALLOW_COPY_AND_ASSIGN(KuduTable);
00886 };
00887
00899 class KUDU_EXPORT KuduTableAlterer {
00900 public:
00901 ~KuduTableAlterer();
00902
00908 KuduTableAlterer* RenameTo(const std::string& new_name);
00909
00919 KuduColumnSpec* AddColumn(const std::string& name);
00920
00929 KuduColumnSpec* AlterColumn(const std::string& name);
00930
00938 KuduTableAlterer* DropColumn(const std::string& name);
00939
00971 KuduTableAlterer* AddRangePartition(
00972 KuduPartialRow* lower_bound,
00973 KuduPartialRow* upper_bound,
00974 KuduTableCreator::RangePartitionBound lower_bound_type = KuduTableCreator::INCLUSIVE_BOUND,
00975 KuduTableCreator::RangePartitionBound upper_bound_type = KuduTableCreator::EXCLUSIVE_BOUND);
00976
01004 KuduTableAlterer* DropRangePartition(
01005 KuduPartialRow* lower_bound,
01006 KuduPartialRow* upper_bound,
01007 KuduTableCreator::RangePartitionBound lower_bound_type = KuduTableCreator::INCLUSIVE_BOUND,
01008 KuduTableCreator::RangePartitionBound upper_bound_type = KuduTableCreator::EXCLUSIVE_BOUND);
01009
01019 KuduTableAlterer* timeout(const MonoDelta& timeout);
01020
01032 KuduTableAlterer* wait(bool wait);
01033
01038 Status Alter();
01039
01040 private:
01041 class KUDU_NO_EXPORT Data;
01042 friend class KuduClient;
01043
01044 KuduTableAlterer(KuduClient* client,
01045 const std::string& name);
01046
01047
01048 Data* data_;
01049
01050 DISALLOW_COPY_AND_ASSIGN(KuduTableAlterer);
01051 };
01052
01058 class KUDU_EXPORT KuduError {
01059 public:
01060 ~KuduError();
01061
01063 const Status& status() const;
01064
01066 const KuduWriteOperation& failed_op() const;
01067
01075 KuduWriteOperation* release_failed_op();
01076
01087 bool was_possibly_successful() const;
01088
01089 private:
01090 class KUDU_NO_EXPORT Data;
01091
01092 friend class internal::Batcher;
01093 friend class KuduSession;
01094
01095 KuduError(KuduWriteOperation* failed_op, const Status& error);
01096
01097
01098 Data* data_;
01099
01100 DISALLOW_COPY_AND_ASSIGN(KuduError);
01101 };
01102
01103
01162 class KUDU_EXPORT KuduSession : public sp::enable_shared_from_this<KuduSession> {
01163 public:
01164 ~KuduSession();
01165
01167 enum FlushMode {
01172 AUTO_FLUSH_SYNC,
01173
01192 AUTO_FLUSH_BACKGROUND,
01193
01197 MANUAL_FLUSH
01198 };
01199
01208 Status SetFlushMode(FlushMode m) WARN_UNUSED_RESULT;
01209
01211 enum ExternalConsistencyMode {
01230 CLIENT_PROPAGATED,
01231
01246 COMMIT_WAIT
01247 };
01248
01254 Status SetExternalConsistencyMode(ExternalConsistencyMode m)
01255 WARN_UNUSED_RESULT;
01256
01274 Status SetMutationBufferSpace(size_t size_bytes) WARN_UNUSED_RESULT;
01275
01299 Status SetMutationBufferFlushWatermark(double watermark_pct)
01300 WARN_UNUSED_RESULT;
01301
01323 Status SetMutationBufferFlushInterval(unsigned int millis) WARN_UNUSED_RESULT;
01324
01349 Status SetMutationBufferMaxNum(unsigned int max_num) WARN_UNUSED_RESULT;
01350
01356 void SetTimeoutMillis(int millis);
01357
01361
01385 Status Apply(KuduWriteOperation* write_op) WARN_UNUSED_RESULT;
01386
01401 Status Flush() WARN_UNUSED_RESULT;
01402
01443 void FlushAsync(KuduStatusCallback* cb);
01444
01447 Status Close() WARN_UNUSED_RESULT;
01448
01457 bool HasPendingOperations() const;
01458
01470 int CountBufferedOperations() const;
01471
01478 int CountPendingErrors() const;
01479
01490 void GetPendingErrors(std::vector<KuduError*>* errors, bool* overflowed);
01491
01493 KuduClient* client() const;
01494
01495 private:
01496 class KUDU_NO_EXPORT Data;
01497
01498 friend class KuduClient;
01499 friend class internal::Batcher;
01500 friend class ClientTest;
01501 FRIEND_TEST(ClientTest, TestAutoFlushBackgroundApplyBlocks);
01502
01503 explicit KuduSession(const sp::shared_ptr<KuduClient>& client);
01504
01505
01506 Data* data_;
01507
01508 DISALLOW_COPY_AND_ASSIGN(KuduSession);
01509 };
01510
01511
01516 class KUDU_EXPORT KuduScanner {
01517 public:
01519 enum ReadMode {
01527 READ_LATEST,
01528
01548 READ_AT_SNAPSHOT
01549 };
01550
01554 enum OrderMode {
01560 UNORDERED,
01561
01566 ORDERED
01567 };
01568
01572 enum { kScanTimeoutMillis = 30000 };
01573
01579 explicit KuduScanner(KuduTable* table);
01580 ~KuduScanner();
01581
01591 Status SetProjectedColumnNames(const std::vector<std::string>& col_names)
01592 WARN_UNUSED_RESULT;
01593
01603 Status SetProjectedColumnIndexes(const std::vector<int>& col_indexes)
01604 WARN_UNUSED_RESULT;
01605
01611 Status SetProjectedColumns(const std::vector<std::string>& col_names)
01612 WARN_UNUSED_RESULT;
01613
01622 Status AddConjunctPredicate(KuduPredicate* pred) WARN_UNUSED_RESULT;
01623
01632 Status AddLowerBound(const KuduPartialRow& key);
01633
01641 Status AddLowerBoundRaw(const Slice& key);
01642
01651 Status AddExclusiveUpperBound(const KuduPartialRow& key);
01652
01660 Status AddExclusiveUpperBoundRaw(const Slice& key);
01661
01670 Status AddLowerBoundPartitionKeyRaw(const Slice& partition_key);
01671
01680 Status AddExclusiveUpperBoundPartitionKeyRaw(const Slice& partition_key);
01681
01688 Status SetCacheBlocks(bool cache_blocks);
01689
01691 Status Open();
01692
01708 Status KeepAlive();
01709
01718 void Close();
01719
01728 bool HasMoreRows() const;
01729
01741 Status NextBatch(std::vector<KuduRowResult>* rows);
01742
01751 Status NextBatch(KuduScanBatch* batch);
01752
01761 Status GetCurrentServer(KuduTabletServer** server);
01762
01764 const ResourceMetrics& GetResourceMetrics() const;
01765
01772 Status SetBatchSizeBytes(uint32_t batch_size);
01773
01781 Status SetSelection(KuduClient::ReplicaSelection selection)
01782 WARN_UNUSED_RESULT;
01783
01789 Status SetReadMode(ReadMode read_mode) WARN_UNUSED_RESULT;
01790
01796 Status SetOrderMode(OrderMode order_mode) WARN_UNUSED_RESULT;
01797
01810 Status SetFaultTolerant() WARN_UNUSED_RESULT;
01811
01817 Status SetSnapshotMicros(uint64_t snapshot_timestamp_micros) WARN_UNUSED_RESULT;
01818
01831 Status SetSnapshotRaw(uint64_t snapshot_timestamp) WARN_UNUSED_RESULT;
01832
01838 Status SetTimeoutMillis(int millis);
01839
01841 KuduSchema GetProjectionSchema() const;
01842
01844 std::string ToString() const;
01845
01846 private:
01847 class KUDU_NO_EXPORT Data;
01848
01849 friend class KuduScanToken;
01850 FRIEND_TEST(ClientTest, TestScanCloseProxy);
01851 FRIEND_TEST(ClientTest, TestScanFaultTolerance);
01852 FRIEND_TEST(ClientTest, TestScanNoBlockCaching);
01853 FRIEND_TEST(ClientTest, TestScanTimeout);
01854
01855
01856 Data* data_;
01857
01858 DISALLOW_COPY_AND_ASSIGN(KuduScanner);
01859 };
01860
01881 class KUDU_EXPORT KuduScanToken {
01882 public:
01883
01884 ~KuduScanToken();
01885
01896 Status IntoKuduScanner(KuduScanner** scanner) const WARN_UNUSED_RESULT;
01897
01899 const KuduTablet& tablet() const;
01900
01908 Status Serialize(std::string* buf) const WARN_UNUSED_RESULT;
01909
01921 static Status DeserializeIntoScanner(KuduClient* client,
01922 const std::string& serialized_token,
01923 KuduScanner** scanner) WARN_UNUSED_RESULT;
01924
01925 private:
01926 class KUDU_NO_EXPORT Data;
01927
01928 friend class KuduScanTokenBuilder;
01929
01930 KuduScanToken();
01931
01932
01933 Data* data_;
01934
01935 DISALLOW_COPY_AND_ASSIGN(KuduScanToken);
01936 };
01937
01941 class KUDU_EXPORT KuduScanTokenBuilder {
01942 public:
01943
01949 explicit KuduScanTokenBuilder(KuduTable* table);
01950 ~KuduScanTokenBuilder();
01951
01961 Status SetProjectedColumnNames(const std::vector<std::string>& col_names)
01962 WARN_UNUSED_RESULT;
01963
01965 Status SetProjectedColumnIndexes(const std::vector<int>& col_indexes)
01966 WARN_UNUSED_RESULT;
01967
01969 Status AddConjunctPredicate(KuduPredicate* pred) WARN_UNUSED_RESULT;
01970
01972 Status AddLowerBound(const KuduPartialRow& key) WARN_UNUSED_RESULT;
01973
01982 Status AddUpperBound(const KuduPartialRow& key) WARN_UNUSED_RESULT;
01983
01985 Status SetCacheBlocks(bool cache_blocks) WARN_UNUSED_RESULT;
01986
01993 Status SetBatchSizeBytes(uint32_t batch_size) WARN_UNUSED_RESULT;
01994
02002 Status SetSelection(KuduClient::ReplicaSelection selection)
02003 WARN_UNUSED_RESULT;
02004
02006 Status SetReadMode(KuduScanner::ReadMode read_mode) WARN_UNUSED_RESULT;
02007
02009 Status SetFaultTolerant() WARN_UNUSED_RESULT;
02010
02012 Status SetSnapshotMicros(uint64_t snapshot_timestamp_micros)
02013 WARN_UNUSED_RESULT;
02014
02016 Status SetSnapshotRaw(uint64_t snapshot_timestamp) WARN_UNUSED_RESULT;
02017
02019 Status SetTimeoutMillis(int millis) WARN_UNUSED_RESULT;
02020
02029 Status Build(std::vector<KuduScanToken*>* tokens) WARN_UNUSED_RESULT;
02030
02032 std::string ToString() const;
02033
02034 private:
02035 class KUDU_NO_EXPORT Data;
02036
02037
02038 Data* data_;
02039
02040 DISALLOW_COPY_AND_ASSIGN(KuduScanTokenBuilder);
02041 };
02042
02043 }
02044 }
02045 #endif