batchGet
读取一批数据,对get函数的批量封装。该函数并发地向server发送异步请求,并等待结果。如果有任意一个请求失败,就提前终止并抛出异常。如果抛出了异常,则values中的结果是未定义的。
- /**
- * Batch get values of different keys.
- * Will terminate immediately if any error occurs.
- * @param tableName table name
- * @param keys hashKey and sortKey pair list.
- * @param values output values; should be created by caller; if succeed, the size of values will
- * be same with keys; the value of keys[i] is stored in values[i]; if the value of
- * keys[i] is not found, then values[i] will be set to null.
- * @throws PException throws exception if any error occurs.
- *
- * Notice: the method is not atomic, that means, maybe some keys succeed but some keys failed.
- */
- public void batchGet(String tableName, List<Pair<byte[], byte[]>> keys, List<byte[]> values) throws PException;
注:
- 参数:
- 传入参数:TableName、Keys。
- 传出参数:Values。该变量需由调用者创建;如果读取成功,Values[i]中存放Keys[i]对应的结果,如果value不存在则为null。
- 返回值:无。
- 异常:如果出现异常,譬如网络错误、超时错误、服务端错误等,会抛出 PException。
- 注意:该方法不是原子的,有可能出现部分成功部分失败的情况,只要任意一个失败都会抛出异常。