Skip to content

Commit c743157

Browse files
committed
compatible new client to old server
1 parent 15be3fd commit c743157

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

src/main/java/com/alipay/oceanbase/hbase/OHTable.java

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -464,16 +464,17 @@ public boolean exists(Get get) throws IOException {
464464

465465
@Override
466466
public boolean[] existsAll(List<Get> gets) throws IOException {
467-
if (gets.isEmpty()) {
468-
return new boolean[] {};
469-
}
470-
if (gets.size() == 1) {
471-
return new boolean[] { exists(gets.get(0)) };
472-
}
473-
Result[] r = get(gets);
474-
boolean[] ret = new boolean[r.length];
475-
for (int i = 0; i < gets.size(); ++i) {
476-
ret[i] = exists(gets.get(i));
467+
boolean[] ret = new boolean[gets.size()];
468+
if (CompatibilityUtil.isBatchSupport()) {
469+
Result[] results = new Result[gets.size()];
470+
batch(gets, results);
471+
for (int i = 0; i < gets.size(); ++i) {
472+
ret[i] = !results[i].isEmpty();
473+
}
474+
} else {
475+
for (int i = 0; i < gets.size(); ++i) {
476+
ret[i] = exists(gets.get(i));
477+
}
477478
}
478479
return ret;
479480
}
@@ -933,17 +934,21 @@ public Result call() throws IOException {
933934
@Override
934935
public Result[] get(List<Get> gets) throws IOException {
935936
Result[] results = new Result[gets.size()];
936-
List<Future<Result>> futures = new LinkedList<>();
937-
for (int i = 0; i < gets.size(); i++) {
938-
int index = i;
939-
Future<Result> future = executePool.submit(() -> get(gets.get(index)));
940-
futures.add(future);
941-
}
942-
for (int i = 0; i < gets.size(); i++) {
943-
try {
944-
results[i] = futures.get(i).get();
945-
} catch (Exception e) {
946-
throw new RuntimeException("gets occur error. index:{" + i + "}", e);
937+
if (CompatibilityUtil.isBatchSupport()) { // get only supported in BatchSupport version
938+
batch(gets, results);
939+
} else {
940+
List<Future<Result>> futures = new LinkedList<>();
941+
for (int i = 0; i < gets.size(); i++) {
942+
int index = i;
943+
Future<Result> future = executePool.submit(() -> get(gets.get(index)));
944+
futures.add(future);
945+
}
946+
for (int i = 0; i < gets.size(); i++) {
947+
try {
948+
results[i] = futures.get(i).get();
949+
} catch (Exception e) {
950+
throw new RuntimeException("gets occur error. index:{" + i + "}", e);
951+
}
947952
}
948953
}
949954
return results;

0 commit comments

Comments
 (0)