获取Cpp客户端

首先需要编译Pegasus,编译完成后运行以下命令可以打包生产Cpp客户端库:

  1. ./run.sh pack_client

运行成功后,会在本地文件夹下生产pegasus-client-{version}-{platform}-{buildType}的文件夹以及tar.gz文件。在文件夹里面有个sample/文件夹,进去后可以运行make编译示例程序。

配置文件

Cpp客户端由于使用了rdsn框架,所以配置文件较为复杂,如下:

  1. [apps..default]
  2. run = true
  3. count = 1
  4. ;network.client.RPC_CHANNEL_TCP = dsn::tools::sim_network_provider, 65536
  5. ;network.client.RPC_CHANNEL_UDP = dsn::tools::sim_network_provider, 65536
  6. ;network.server.0.RPC_CHANNEL_TCP = dsn::tools::sim_network_provider, 65536
  7. [apps.mimic]
  8. type = dsn.app.mimic
  9. arguments =
  10. pools = THREAD_POOL_DEFAULT
  11. run = true
  12. count = 1
  13. [core]
  14. ;tool = simulator
  15. ;tool = fastrun
  16. tool = nativerun
  17. ;toollets = tracer
  18. ;toollets = tracer, profiler, fault_injector
  19. pause_on_start = false
  20. cli_local = false
  21. cli_remote = false
  22. start_nfs = false
  23. logging_start_level = LOG_LEVEL_DEBUG
  24. logging_factory_name = dsn::tools::simple_logger
  25. logging_flush_on_exit = true
  26. enable_default_app_mimic = true
  27. data_dir = ./data
  28. [tools.simple_logger]
  29. short_header = true
  30. fast_flush = true
  31. max_number_of_log_files_on_disk = 10
  32. stderr_start_level = LOG_LEVEL_ERROR
  33. [tools.hpc_logger]
  34. per_thread_buffer_bytes = 8192
  35. max_number_of_log_files_on_disk = 10
  36. [tools.simulator]
  37. random_seed = 0
  38. [network]
  39. ; how many network threads for network library(used by asio)
  40. io_service_worker_count = 4
  41. ; specification for each thread pool
  42. [threadpool..default]
  43. worker_count = 4
  44. [threadpool.THREAD_POOL_DEFAULT]
  45. name = default
  46. partitioned = false
  47. max_input_queue_length = 1024
  48. worker_priority = THREAD_xPRIORITY_NORMAL
  49. worker_count = 4
  50. [task..default]
  51. is_trace = false
  52. is_profile = false
  53. allow_inline = false
  54. fast_execution_in_network_thread = false
  55. rpc_call_header_format = NET_HDR_DSN
  56. rpc_call_channel = RPC_CHANNEL_TCP
  57. rpc_timeout_milliseconds = 5000
  58. [pegasus.clusters]
  59. onebox = @LOCAL_IP@:34601,@LOCAL_IP@:34602,@LOCAL_IP@:34603
  60. another_cluster = @SOME_IP@:34601,@SOME_IP@:34601,@SOME_IP@:34601

配置文件的具体解释,请移步配置说明

接口定义

创建Client实例

客户端工厂类

  1. namespace pegasus {
  2. class pegasus_client_factory
  3. {
  4. public:
  5. ///
  6. /// \brief initialize
  7. /// initialize pegasus client lib. must call this function before anything else.
  8. /// \param config_file
  9. /// the configuration file of client lib
  10. /// \return
  11. /// true indicate the initailize is success.
  12. ///
  13. static bool initialize(const char *config_file);
  14. ///
  15. /// \brief get_client
  16. /// get an instance for a given cluster and a given app name.
  17. /// \param cluster_name
  18. /// the pegasus cluster name.
  19. /// a cluster can have multiple apps.
  20. /// \param app_name
  21. /// an app is a logical isolated k-v store.
  22. /// a cluster can have multiple apps.
  23. /// \return
  24. /// the client instance. DO NOT delete this client even after usage.
  25. static pegasus_client *get_client(const char *cluster_name, const char *app_name);
  26. };
  27. } //end namespace

客户端的初始化,实际上是对rdsn框架初始化

  1. if (!pegasus::pegasus_client_factory::initialize("config.ini")) {
  2. fprintf(stderr, "ERROR: init pegasus failed\n");
  3. return -1;
  4. }
  5. /**succeed, continue**/

注:

  • 参数:config_file 见 配置文件 的介绍
  • 返回值:bool值,true代表初始化成功,false初始化失败
  • 该函数只需在一个进程生命周期内调用一次即可,并且非线程安全的 获取客户端
  1. pegasus::pegasus_client* pg_client = pegasus::pegasus_client_factory::get_client("cluster_name", "table_name");
  2. if (pg_client == nullptr) {
  3. fprintf(stderr, "ERROR: get pegasus client failed\n");
  4. return -1;
  5. }
  6. /*** do what you want with pg_client ****/

注意: get_client返回值不能明确的调用delete,也不能用智能指针封装,框架在停止的时候自动释放(底层使用单例来保存)

pegasus_client接口

Cpp客户端提供两种接口,异步API 和 同步API,同步API是基于异步API实现的,具体如下:

set

写单行数据

  1. ///
  2. /// \brief set
  3. /// store the k-v to the cluster.
  4. /// key is composed of hashkey and sortkey.
  5. /// \param hashkey
  6. /// used to decide which partition to put this k-v
  7. /// \param sortkey
  8. /// all the k-v under hashkey will be sorted by sortkey.
  9. /// \param value
  10. /// the value we want to store.
  11. /// \param timeout_milliseconds
  12. /// if wait longer than this value, will return time out error
  13. /// \param ttl_seconds
  14. /// time to live of this value, if expired, will return not found; 0 means no ttl
  15. /// \return
  16. /// int, the error indicates whether or not the operation is succeeded.
  17. /// this error can be converted to a string using get_error_string()
  18. ///
  19. virtual int set(const std::string &hashkey,
  20. const std::string &sortkey,
  21. const std::string &value,
  22. int timeout_milliseconds = 5000,
  23. int ttl_seconds = 0,
  24. internal_info *info = NULL) = 0;

注:

  • internal_info 结构如下,主要是记录在写入成功之后,该条数据的一些信息,在使用之前需要判断info是否为空
  1. struct internal_info
  2. {
  3. int32_t app_id;
  4. int32_t partition_index;
  5. int64_t decree;
  6. std::string server;
  7. internal_info() : app_id(-1), partition_index(-1), decree(-1) {}
  8. }
  • 返回值:int值来表示是否成功,通过get_error_string() 函数来判断返回值的意义(下面的所有同步接口的返回值,都可以通过该函数判断返回值意义)
  1. ///
  2. /// \brief get_error_string
  3. /// get error string
  4. /// all the function above return an int value that indicates an error can be converted into a
  5. /// string for human reading.
  6. /// \param error_code
  7. /// all the error code are defined in "error_def.h"
  8. /// \return
  9. ///
  10. virtual const char *get_error_string(int error_code) const = 0;

async_set

异步写单行数据

  1. ///
  2. /// \brief asynchronous set
  3. /// store the k-v to the cluster.
  4. /// will not be blocked, return immediately.
  5. /// key is composed of hashkey and sortkey.
  6. /// \param hashkey
  7. /// used to decide which partition to put this k-v
  8. /// \param sortkey
  9. /// all the k-v under hashkey will be stored by sortkey.
  10. /// \param value
  11. /// the value we want to store.
  12. /// \param callback
  13. /// the callback function will be invoked after operation finished or error occurred.
  14. /// \param timeout_milliseconds
  15. /// if wait longer than this value, will return time out error.
  16. /// \param ttl_seconds
  17. /// time to live of this value, if expired, will return not found; 0 means no ttl.
  18. /// \return
  19. /// void.
  20. ///
  21. virtual void async_set(const std::string &hashkey,
  22. const std::string &sortkey,
  23. const std::string &value,
  24. async_set_callback_t &&callback = nullptr,
  25. int timeout_milliseconds = 5000,
  26. int ttl_seconds = 0) = 0;

multi_set

写多条数据(同一hashkey下面)

  1. ///
  2. /// \brief multi_set (guarantee atomicity)
  3. /// store multiple k-v of the same hashkey to the cluster.
  4. /// \param hashkey
  5. /// used to decide which partition to put this k-v
  6. /// \param kvs
  7. /// all <sortkey,value> pairs to be set. should not be empty
  8. /// \param timeout_milliseconds
  9. /// if wait longer than this value, will return time out error
  10. /// \param ttl_seconds
  11. /// time to live of this value, if expired, will return not found; 0 means no ttl
  12. /// \return
  13. /// int, the error indicates whether or not the operation is succeeded.
  14. /// this error can be converted to a string using get_error_string().
  15. /// return PERR_INVALID_ARGUMENT if param kvs is empty.
  16. ///
  17. virtual int multi_set(const std::string &hashkey,
  18. const std::map<std::string, std::string> &kvs,
  19. int timeout_milliseconds = 5000,
  20. int ttl_seconds = 0,
  21. internal_info *info = NULL) = 0;

async_multi_set

异步写多条数据

  1. ///
  2. /// \brief asynchronous multi_set (guarantee atomicity)
  3. /// store multiple k-v of the same hashkey to the cluster.
  4. /// will not be blocked, return immediately.
  5. /// \param hashkey
  6. /// used to decide which partition to put this k-v
  7. /// \param kvs
  8. /// all <sortkey,value> pairs to be set. should not be empty
  9. /// \param callback
  10. /// the callback function will be invoked after operation finished or error occurred.
  11. /// \param timeout_milliseconds
  12. /// if wait longer than this value, will return time out error
  13. /// \param ttl_seconds
  14. /// time to live of this value, if expired, will return not found; 0 means no ttl
  15. /// \return
  16. /// void.
  17. ///
  18. virtual void async_multi_set(const std::string &hashkey,
  19. const std::map<std::string, std::string> &kvs,
  20. async_multi_set_callback_t &&callback = nullptr,
  21. int timeout_milliseconds = 5000,
  22. int ttl_seconds = 0) = 0;

get

读取一条数据

  1. ///
  2. /// \brief get
  3. /// get value by key from the cluster.
  4. /// \param hashkey
  5. /// used to decide which partition to get this k-v
  6. /// \param sortkey
  7. /// all the k-v under hashkey will be sorted by sortkey.
  8. /// \param value
  9. /// the returned value will be put into it.
  10. /// \param timeout_milliseconds
  11. /// if wait longer than this value, will return time out error
  12. /// \return
  13. /// int, the error indicates whether or not the operation is succeeded.
  14. /// this error can be converted to a string using get_error_string().
  15. /// returns PERR_NOT_FOUND if no value is found under the <hashkey,sortkey>.
  16. ///
  17. virtual int get(const std::string &hashkey,
  18. const std::string &sortkey,
  19. std::string &value,
  20. int timeout_milliseconds = 5000,
  21. internal_info *info = NULL) = 0;

async_get

异步读取一条数据

  1. ///
  2. /// \brief asynchronous get
  3. /// get value by key from the cluster.
  4. /// will not be blocked, return immediately.
  5. /// \param hashkey
  6. /// used to decide which partition to get this k-v
  7. /// \param sortkey
  8. /// all the k-v under hashkey will be sorted by sortkey.
  9. /// \param callback
  10. /// the callback function will be invoked after operation finished or error occurred.
  11. /// \param timeout_milliseconds
  12. /// if wait longer than this value, will return time out error
  13. /// \return
  14. /// void.
  15. ///
  16. virtual void async_get(const std::string &hashkey,
  17. const std::string &sortkey,
  18. async_get_callback_t &&callback = nullptr,
  19. int timeout_milliseconds = 5000) = 0;

multi_get

读取多条数据

  1. ///
  2. /// \brief multi_get
  3. /// get multiple value by key from the cluster.
  4. /// \param hashkey
  5. /// used to decide which partition to get this k-v
  6. /// \param sortkeys
  7. /// all the k-v under hashkey will be sorted by sortkey.
  8. /// if empty, means fetch all sortkeys under the hashkey.
  9. /// \param values
  10. /// the returned <sortkey,value> pairs will be put into it.
  11. /// if data is not found for some <hashkey,sortkey>, then it will not appear in the map.
  12. /// \param max_fetch_count
  13. /// max count of k-v pairs to be fetched. max_fetch_count <= 0 means no limit.
  14. /// \param max_fetch_size
  15. /// max size of k-v pairs to be fetched. max_fetch_size <= 0 means no limit.
  16. /// \param timeout_milliseconds
  17. /// if wait longer than this value, will return time out error
  18. /// \return
  19. /// int, the error indicates whether or not the operation is succeeded.
  20. /// this error can be converted to a string using get_error_string().
  21. /// returns PERR_OK if fetch done, even no data is returned.
  22. /// returns PERR_INCOMPLETE is only partial data is fetched.
  23. ///
  24. virtual int multi_get(const std::string &hashkey,
  25. const std::set<std::string> &sortkeys,
  26. std::map<std::string, std::string> &values,
  27. int max_fetch_count = 100,
  28. int max_fetch_size = 1000000,
  29. int timeout_milliseconds = 5000,
  30. internal_info *info = NULL) = 0;

注:max_fetch_count 和 max_fetch_size 分别从kv-pair的条数 和 总的大小来限制multi_get的返回值

async_multi_get

异步读取多条数据

  1. ///
  2. /// \brief asynchronous multi_get
  3. /// get multiple value by key from the cluster.
  4. /// will not be blocked, return immediately.
  5. /// \param hashkey
  6. /// used to decide which partition to get this k-v
  7. /// \param sortkeys
  8. /// all the k-v under hashkey will be sorted by sortkey.
  9. /// if empty, means fetch all sortkeys under the hashkey.
  10. /// \param callback
  11. /// the callback function will be invoked after operation finished or error occurred.
  12. /// \param max_fetch_count
  13. /// max count of k-v pairs to be fetched. max_fetch_count <= 0 means no limit.
  14. /// \param max_fetch_size
  15. /// max size of k-v pairs to be fetched. max_fetch_size <= 0 means no limit.
  16. /// \param timeout_milliseconds
  17. /// if wait longer than this value, will return time out error
  18. /// \return
  19. /// void.
  20. ///
  21. virtual void async_multi_get(const std::string &hashkey,
  22. const std::set<std::string> &sortkeys,
  23. async_multi_get_callback_t &&callback = nullptr,
  24. int max_fetch_count = 100,
  25. int max_fetch_size = 1000000,
  26. int timeout_milliseconds = 5000) = 0;

multi_get_sortkeys

获取hashkey下面的多个sortkey,不返回value

  1. ///
  2. /// \brief multi_get_sortkeys
  3. /// get multiple sort keys by hash key from the cluster.
  4. /// only fetch sort keys, but not fetch values.
  5. /// \param hashkey
  6. /// used to decide which partition to get this k-v
  7. /// \param sortkeys
  8. /// the returned sort keys will be put into it.
  9. /// \param max_fetch_count
  10. /// max count of sort keys to be fetched. max_fetch_count <= 0 means no limit.
  11. /// \param max_fetch_size
  12. /// max size of sort keys to be fetched. max_fetch_size <= 0 means no limit.
  13. /// \param timeout_milliseconds
  14. /// if wait longer than this value, will return time out error
  15. /// \return
  16. /// int, the error indicates whether or not the operation is succeeded.
  17. /// this error can be converted to a string using get_error_string().
  18. /// returns PERR_OK if fetch done, even no data is returned.
  19. /// returns PERR_INCOMPLETE is only partial data is fetched.
  20. ///
  21. virtual int multi_get_sortkeys(const std::string &hashkey,
  22. std::set<std::string> &sortkeys,
  23. int max_fetch_count = 100,
  24. int max_fetch_size = 1000000,
  25. int timeout_milliseconds = 5000,
  26. internal_info *info = NULL) = 0;

注:max_fetch_count 和 max_fetch_size 分别限制返回的sortkey的个数与总大小(计算大小的时候,为每条sortkey都计算一次hashkey的大小)

async_multi_get_sortkeys

异步获取hashkey下面的多个sortkey(不包含value)

  1. ///
  2. /// \brief asynchronous multi_get_sortkeys
  3. /// get multiple sort keys by hash key from the cluster.
  4. /// only fetch sort keys, but not fetch values.
  5. /// will not be blocked, return immediately.
  6. /// \param hashkey
  7. /// used to decide which partition to get this k-v
  8. /// \param callback
  9. /// the callback function will be invoked after operation finished or error occurred.
  10. /// \param max_fetch_count
  11. /// max count of sort keys to be fetched. max_fetch_count <= 0 means no limit.
  12. /// \param max_fetch_size
  13. /// max size of sort keys to be fetched. max_fetch_size <= 0 means no limit.
  14. /// \param timeout_milliseconds
  15. /// if wait longer than this value, will return time out error
  16. /// \return
  17. /// void.
  18. ///
  19. virtual void async_multi_get_sortkeys(const std::string &hashkey,
  20. async_multi_get_sortkeys_callback_t &&callback = nullptr,
  21. int max_fetch_count = 100,
  22. int max_fetch_size = 1000000,
  23. int timeout_milliseconds = 5000) = 0;

exist

判断单条数据是否存在

  1. ///
  2. /// \brief exist
  3. /// check value exist by key from the cluster.
  4. /// \param hashkey
  5. /// used to decide which partition to get this k-v
  6. /// \param sortkey
  7. /// all the k-v under hashkey will be sorted by sortkey.
  8. /// \param timeout_milliseconds
  9. /// if wait longer than this value, will return time out error
  10. /// \return
  11. /// int, the error indicates whether or not the operation is succeeded.
  12. /// this error can be converted to a string using get_error_string().
  13. /// returns PERR_OK if exist.
  14. /// returns PERR_NOT_FOUND if not exist.
  15. ///
  16. virtual int exist(const std::string &hashkey,
  17. const std::string &sortkey,
  18. int timeout_milliseconds = 5000,
  19. internal_info *info = NULL) = 0;

sortkey_count

统计hashkey下面的sortkey个数

  1. ///
  2. /// \brief sortkey_count
  3. /// get sortkey count by hashkey from the cluster.
  4. /// \param hashkey
  5. /// used to decide which partition to get this k-v
  6. /// \param count
  7. /// the returned sortkey count
  8. /// \param timeout_milliseconds
  9. /// if wait longer than this value, will return time out error
  10. /// \return
  11. /// int, the error indicates whether or not the operation is succeeded.
  12. /// this error can be converted to a string using get_error_string().
  13. ///
  14. virtual int sortkey_count(const std::string &hashkey,
  15. int64_t &count,
  16. int timeout_milliseconds = 5000,
  17. internal_info *info = NULL) = 0;

del

删除单条数据

  1. ///
  2. /// \brief del
  3. /// del stored k-v by key from cluster
  4. /// key is composed of hashkey and sortkey. must provide both to get the value.
  5. /// \param hashkey
  6. /// used to decide from which partition to del this k-v
  7. /// \param sortkey
  8. /// all the k-v under hashkey will be sorted by sortkey.
  9. /// \param timeout_milliseconds
  10. /// if wait longer than this value, will return time out error
  11. /// \return
  12. /// int, the error indicates whether or not the operation is succeeded.
  13. /// this error can be converted to a string using get_error_string()
  14. ///
  15. virtual int del(const std::string &hashkey,
  16. const std::string &sortkey,
  17. int timeout_milliseconds = 5000,
  18. internal_info *info = NULL) = 0;

async_del

异步删除单条数据

  1. ///
  2. /// \brief asynchronous del
  3. /// del stored k-v by key from cluster
  4. /// key is composed of hashkey and sortkey. must provide both to get the value.
  5. /// will not be blocked, return immediately.
  6. /// \param hashkey
  7. /// used to decide from which partition to del this k-v
  8. /// \param sortkey
  9. /// all the k-v under hashkey will be sorted by sortkey.
  10. /// \param callback
  11. /// the callback function will be invoked after operation finished or error occurred.
  12. /// \param timeout_milliseconds
  13. /// if wait longer than this value, will return time out error
  14. /// \return
  15. /// void.
  16. ///
  17. virtual void async_del(const std::string &hashkey,
  18. const std::string &sortkey,
  19. async_del_callback_t &&callback = nullptr,
  20. int timeout_milliseconds = 5000) = 0;

multi_del

删除多条数据

  1. ///
  2. /// \brief multi_del
  3. /// delete multiple value by key from the cluster.
  4. /// \param hashkey
  5. /// used to decide which partition to get this k-v
  6. /// \param sortkeys
  7. /// all the k-v under hashkey will be sorted by sortkey. should not be empty.
  8. /// \param deleted_count
  9. /// return count of deleted k-v pairs.
  10. /// \param timeout_milliseconds
  11. /// if wait longer than this value, will return time out error
  12. /// \return
  13. /// int, the error indicates whether or not the operation is succeeded.
  14. /// this error can be converted to a string using get_error_string().
  15. ///
  16. virtual int multi_del(const std::string &hashkey,
  17. const std::set<std::string> &sortkeys,
  18. int64_t &deleted_count,
  19. int timeout_milliseconds = 5000,
  20. internal_info *info = NULL) = 0;

async_multi_del

异步的删除多条数据

  1. ///
  2. /// \brief asynchronous multi_del
  3. /// delete multiple value by key from the cluster.
  4. /// will not be blocked, return immediately.
  5. /// \param hashkey
  6. /// used to decide which partition to get this k-v
  7. /// \param sortkeys
  8. /// all the k-v under hashkey will be sorted by sortkey. should not be empty.
  9. /// \param callback
  10. /// the callback function will be invoked after operation finished or error occurred.
  11. /// \param timeout_milliseconds
  12. /// if wait longer than this value, will return time out error
  13. /// \return
  14. /// void.
  15. ///
  16. virtual void async_multi_del(const std::string &hashkey,
  17. const std::set<std::string> &sortkeys,
  18. async_multi_del_callback_t &&callback = nullptr,
  19. int timeout_milliseconds = 5000) = 0;

ttl

获取单行数据的TTL时间。TTL表示Time To Live,表示该数据还能存活多久。如果超过存活时间,数据就读不到了

  1. ///
  2. /// \brief ttl (time to live)
  3. /// get ttl in seconds of this k-v.
  4. /// key is composed of hashkey and sortkey. must provide both to get the value.
  5. /// \param hashkey
  6. /// used to decide which partition to get this k-v
  7. /// \param sortkey
  8. /// all the k-v under hashkey will be sorted by sortkey.
  9. /// \param ttl_seconds
  10. /// the returned ttl value in seconds.
  11. /// \param timeout_milliseconds
  12. /// if wait longer than this value, will return time out error
  13. /// \return
  14. /// int, the error indicates whether or not the operation is succeeded.
  15. /// this error can be converted to a string using get_error_string()
  16. ///
  17. virtual int ttl(const std::string &hashkey,
  18. const std::string &sortkey,
  19. int &ttl_seconds,
  20. int timeout_milliseconds = 5000,
  21. internal_info *info = NULL) = 0;

get_scanner

获取针对某个hashkey下的sortkey区间 [sortkeyA ~ sortkeyB)的一个scanner

  1. ///
  2. /// \brief get hash scanner
  3. /// get scanner for [start_sortkey, stop_sortkey) of hashkey
  4. /// \param hashkey
  5. /// cannot be empty
  6. /// \param start_sortkey
  7. /// sortkey to start with
  8. /// \param stop_sortkey
  9. /// sortkey to stop. ""(empty string) represents the max key
  10. /// \param options
  11. /// which used to indicate scan options, like which bound is inclusive
  12. /// \param scanner
  13. /// out param, used to get k-v
  14. /// this pointer should be deleted when scan complete
  15. /// \return
  16. /// int, the error indicates whether or not the operation is succeeded.
  17. /// this error can be converted to a string using get_error_string()
  18. ///
  19. virtual int get_scanner(const std::string &hashkey,
  20. const std::string &start_sortkey, // start from beginning if this set ""
  21. const std::string &stop_sortkey, // to the last item if this set ""
  22. const scan_options &options,
  23. pegasus_scanner *&scanner) = 0;

async_get_scanner

异步获取针对某个hashkey下的sortkey区间 [sortkeyA ~ sortkeyB)的一个scanner

  1. ///
  2. /// \brief async get hash scanner
  3. /// get scanner for [start_sortkey, stop_sortkey) of hashkey
  4. /// will not be blocked, return immediately.
  5. /// \param hashkey
  6. /// cannot be empty
  7. /// \param start_sortkey
  8. /// sortkey to start with
  9. /// \param stop_sortkey
  10. /// sortkey to stop. ""(empty string) represents the max key
  11. /// \param options
  12. /// which used to indicate scan options, like which bound is inclusive
  13. /// \param callback
  14. /// return status and scanner in callback, and the latter should be deleted when scan complete
  15. ///
  16. virtual void
  17. async_get_scanner(const std::string &hashkey,
  18. const std::string &start_sortkey, // start from beginning if this set ""
  19. const std::string &stop_sortkey, // to the last item if this set ""
  20. const scan_options &options,
  21. async_get_scanner_callback_t &&callback) = 0;

get_unordered_scanners

获取一个遍历所有数据的scanner

  1. ///
  2. /// \brief get a bundle of scanners to iterate all k-v in table
  3. /// scanners should be deleted when scan complete
  4. /// \param max_split_count
  5. /// the number of scanners returned will always <= max_split_count
  6. /// \param options
  7. /// which used to indicate scan options, like timeout_milliseconds
  8. /// \param scanners
  9. /// out param, used to get k-v
  10. /// these pointers should be deleted
  11. /// \return
  12. /// int, the error indicates whether or not the operation is succeeded.
  13. /// this error can be converted to a string using get_error_string()
  14. ///
  15. virtual int get_unordered_scanners(int max_split_count,
  16. const scan_options &options,
  17. std::vector<pegasus_scanner *> &scanners) = 0;

async_get_unordered_scanners

异步获取一个遍历所有数据的scanner

  1. ///
  2. /// \brief async get a bundle of scanners to iterate all k-v in table
  3. /// scannners return by callback should be deleted when all scan complete
  4. /// \param max_split_count
  5. /// the number of scanners returned will always <= max_split_count
  6. /// \param options
  7. /// which used to indicate scan options, like timeout_milliseconds
  8. /// \param callback; return status and scanner in this callback
  9. ///
  10. virtual void
  11. async_get_unordered_scanners(int max_split_count,
  12. const scan_options &options,
  13. async_get_unordered_scanners_callback_t &&callback) = 0;