batchGet

读取一批数据,对get函数的批量封装。该函数并发地向server发送异步请求,并等待结果。如果有任意一个请求失败,就提前终止并抛出异常。如果抛出了异常,则values中的结果是未定义的。

  1. /**
  2. * Batch get values of different keys.
  3. * Will terminate immediately if any error occurs.
  4. * @param tableName table name
  5. * @param keys hashKey and sortKey pair list.
  6. * @param values output values; should be created by caller; if succeed, the size of values will
  7. * be same with keys; the value of keys[i] is stored in values[i]; if the value of
  8. * keys[i] is not found, then values[i] will be set to null.
  9. * @throws PException throws exception if any error occurs.
  10. *
  11. * Notice: the method is not atomic, that means, maybe some keys succeed but some keys failed.
  12. */
  13. 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。
  • 注意:该方法不是原子的,有可能出现部分成功部分失败的情况,只要任意一个失败都会抛出异常。