asyncMultiGet

异步读同一HashKey下的多行数据。

  1. public static class MultiGetResult {
  2. /**
  3. * return value for multiGet
  4. * @param allFetched true if all data on the server are fetched; false if only partial data are fetched.
  5. * @param values the got values. If sortKey in the input sortKeys is not found, it won't be in values.
  6. * The output values are ordered by the sortKey.
  7. */
  8. public boolean allFetched;
  9. public List<Pair<byte[], byte[]>> values;
  10. }
  11.  
  12. public static interface MultiGetListener extends GenericFutureListener<Future<MultiGetResult>> {
  13. /**
  14. * This function will be called when listened asyncMultiGet future is done.
  15. * @param future the listened future
  16. * @throws Exception
  17. *
  18. * Notice: User shouldn't do any operations that may block or time-consuming
  19. */
  20. @Override
  21. public void operationComplete(Future<MultiGetResult> future) throws Exception;
  22. }
  23.  
  24. /**
  25. * get multiple key-values under the same hashKey, async version
  26. * @param hashKey used to decide which partition the key may exist
  27. * should not be null or empty.
  28. * @param sortKeys try to get values of sortKeys under the hashKey
  29. * if null or empty, try to get all (sortKey,value) pairs under hashKey
  30. * @param maxFetchCount max count of kv pairs to be fetched
  31. * maxFetchCount <= 0 means no limit. default value is 100
  32. * @param maxFetchSize max size of kv pairs to be fetched.
  33. * maxFetchSize <= 0 means no limit. default value is 1000000.
  34. * @param timeout how long will the operation timeout in milliseconds.
  35. * if timeout > 0, it is a timeout value for current op,
  36. * else the timeout value in the configuration file will be used.
  37. *
  38. * @return the future for current op
  39. *
  40. * Future return:
  41. * On success: An object of type MultiGetResult
  42. * On failure: a throwable, which is an instance of PException
  43. *
  44. * Thread safety:
  45. * All the listeners for the same table are guaranteed to be dispatched in the same thread, so all the
  46. * listeners for the same future are guaranteed to be executed as the same order as the listeners added.
  47. * But listeners for different tables are not guaranteed to be dispatched in the same thread.
  48. */
  49. public Future<MultiGetResult> asyncMultiGet(byte[] hashKey, List<byte[]> sortKeys, int maxFetchCount, int maxFetchSize, int timeout/*ms*/);
  50. public Future<MultiGetResult> asyncMultiGet(byte[] hashKey, List<byte[]> sortKeys, int timeout/*ms*/);

注:

  • 提供了两个版本的接口,其中第一个接口可以指定maxFetchCount和maxFetchSize。
  • 参数:需传入HashKey、SortKeys、timeout;选择性传入maxFetchCount、maxFetchSize。
    • SortKeys如果非空,则只读取指定的数据;SortKeys如果为空,则表示读取该HashKey下的所有数据。
    • timeout单位为毫秒,如果<=0,表示使用配置文件中的默认超时。
    • maxFetchCount和maxFetchSize用于限制读取的数据量,maxFetchCount表示最多读取的数据条数,maxFetchSize表示最多读取的数据字节数,两者任一达到限制就停止读取。
  • 返回值:Future
    • allFetched:如果用户指定了maxFetchCount或者maxFetchSize,单次查询可能只获取到部分结果。如果所有满足条件的数据都已经获取到,则设置为true;否则设置为false。asyncMultiGet还有另外一个版本的接口,可以支持SortKey的范围查询条件过滤,只读取满足特定条件的数据。并且从1.8.0开始在MultiGetOptions中增加了reverse参数,支持逆向扫描数据。
  1. /**
  2. * get multiple key-values under the same hashKey with sortKey range limited, async version
  3. * @param hashKey used to decide which partition the key may exist
  4. * should not be null or empty.
  5. * @param startSortKey the start sort key.
  6. * null means "".
  7. * @param stopSortKey the stop sort key.
  8. * null or "" means fetch to the last sort key.
  9. * @param options multi-get options.
  10. * @param maxFetchCount max count of kv pairs to be fetched
  11. * maxFetchCount <= 0 means no limit. default value is 100
  12. * @param maxFetchSize max size of kv pairs to be fetched.
  13. * maxFetchSize <= 0 means no limit. default value is 1000000.
  14. * @param timeout how long will the operation timeout in milliseconds.
  15. * if timeout > 0, it is a timeout value for current op,
  16. * else the timeout value in the configuration file will be used.
  17. *
  18. * @return the future for current op
  19. *
  20. * Future return:
  21. * On success: An object of type MultiGetResult
  22. * On failure: a throwable, which is an instance of PException
  23. *
  24. * Thread safety:
  25. * All the listeners for the same table are guaranteed to be dispatched in the same thread, so all the
  26. * listeners for the same future are guaranteed to be executed as the same order as the listeners added.
  27. * But listeners for different tables are not guaranteed to be dispatched in the same thread.
  28. */
  29. public Future<MultiGetResult> asyncMultiGet(byte[] hashKey, byte[] startSortKey, byte[] stopSortKey,
  30. MultiGetOptions options, int maxFetchCount, int maxFetchSize,
  31. int timeout/*ms*/);
  32. public Future<MultiGetResult> asyncMultiGet(byte[] hashKey, byte[] startSortKey, byte[] stopSortKey,
  33. MultiGetOptions options, int timeout/*ms*/);

注: