asyncMultiGet
异步读同一HashKey下的多行数据。
- public static class MultiGetResult {
- /**
- * return value for multiGet
- * @param allFetched true if all data on the server are fetched; false if only partial data are fetched.
- * @param values the got values. If sortKey in the input sortKeys is not found, it won't be in values.
- * The output values are ordered by the sortKey.
- */
- public boolean allFetched;
- public List<Pair<byte[], byte[]>> values;
- }
- public static interface MultiGetListener extends GenericFutureListener<Future<MultiGetResult>> {
- /**
- * This function will be called when listened asyncMultiGet future is done.
- * @param future the listened future
- * @throws Exception
- *
- * Notice: User shouldn't do any operations that may block or time-consuming
- */
- @Override
- public void operationComplete(Future<MultiGetResult> future) throws Exception;
- }
- /**
- * get multiple key-values under the same hashKey, async version
- * @param hashKey used to decide which partition the key may exist
- * should not be null or empty.
- * @param sortKeys try to get values of sortKeys under the hashKey
- * if null or empty, try to get all (sortKey,value) pairs under hashKey
- * @param maxFetchCount max count of kv pairs to be fetched
- * maxFetchCount <= 0 means no limit. default value is 100
- * @param maxFetchSize max size of kv pairs to be fetched.
- * maxFetchSize <= 0 means no limit. default value is 1000000.
- * @param timeout how long will the operation timeout in milliseconds.
- * if timeout > 0, it is a timeout value for current op,
- * else the timeout value in the configuration file will be used.
- *
- * @return the future for current op
- *
- * Future return:
- * On success: An object of type MultiGetResult
- * On failure: a throwable, which is an instance of PException
- *
- * Thread safety:
- * All the listeners for the same table are guaranteed to be dispatched in the same thread, so all the
- * listeners for the same future are guaranteed to be executed as the same order as the listeners added.
- * But listeners for different tables are not guaranteed to be dispatched in the same thread.
- */
- public Future<MultiGetResult> asyncMultiGet(byte[] hashKey, List<byte[]> sortKeys, int maxFetchCount, int maxFetchSize, int timeout/*ms*/);
- 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参数,支持逆向扫描数据。
- /**
- * get multiple key-values under the same hashKey with sortKey range limited, async version
- * @param hashKey used to decide which partition the key may exist
- * should not be null or empty.
- * @param startSortKey the start sort key.
- * null means "".
- * @param stopSortKey the stop sort key.
- * null or "" means fetch to the last sort key.
- * @param options multi-get options.
- * @param maxFetchCount max count of kv pairs to be fetched
- * maxFetchCount <= 0 means no limit. default value is 100
- * @param maxFetchSize max size of kv pairs to be fetched.
- * maxFetchSize <= 0 means no limit. default value is 1000000.
- * @param timeout how long will the operation timeout in milliseconds.
- * if timeout > 0, it is a timeout value for current op,
- * else the timeout value in the configuration file will be used.
- *
- * @return the future for current op
- *
- * Future return:
- * On success: An object of type MultiGetResult
- * On failure: a throwable, which is an instance of PException
- *
- * Thread safety:
- * All the listeners for the same table are guaranteed to be dispatched in the same thread, so all the
- * listeners for the same future are guaranteed to be executed as the same order as the listeners added.
- * But listeners for different tables are not guaranteed to be dispatched in the same thread.
- */
- public Future<MultiGetResult> asyncMultiGet(byte[] hashKey, byte[] startSortKey, byte[] stopSortKey,
- MultiGetOptions options, int maxFetchCount, int maxFetchSize,
- int timeout/*ms*/);
- public Future<MultiGetResult> asyncMultiGet(byte[] hashKey, byte[] startSortKey, byte[] stopSortKey,
- MultiGetOptions options, int timeout/*ms*/);
注:
- 参数使用同multiGet