fix rawBatchPut

Signed-off-by: iosmanthus <myosmanthustree@gmail.com>
This commit is contained in:
iosmanthus 2022-07-28 16:51:20 +08:00
parent 5fca510ae3
commit af6ab50233
No known key found for this signature in database
GPG Key ID: DEE5BAABFE092169
2 changed files with 18 additions and 22 deletions

View File

@ -749,17 +749,17 @@ public class RawKVClient implements RawKVClientBase {
while (!taskQueue.isEmpty()) {
List<Batch> task = taskQueue.poll();
for (Batch batch : task) {
completionService.submit(
() -> doSendBatchPutInBatchesWithRetry(batch.getBackOffer(), batch, ttl));
futureList.add(completionService.submit(
() -> doSendBatchPutInBatchesWithRetry(batch.getBackOffer(), batch, ttl)));
}
try {
getTasks(completionService, taskQueue, task, deadline - System.currentTimeMillis());
} catch (Exception e) {
for (Future<List<Batch>> future : futureList) {
future.cancel(true);
}
throw e;
try {
getTasks(completionService, taskQueue, task, deadline - System.currentTimeMillis());
} catch (Exception e) {
for (Future<List<Batch>> future : futureList) {
future.cancel(true);
}
throw e;
}
}
}

View File

@ -20,6 +20,7 @@ package org.tikv.raw;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.tikv.raw.RawKVClientBase.MAX_RAW_BATCH_LIMIT;
import com.google.common.collect.ImmutableList;
import com.google.protobuf.ByteString;
@ -1086,18 +1087,13 @@ public class RawKVClientTest extends BaseRawKVTest {
}
@Test
public void testBatchPut() throws Exception {
TiConfiguration conf = session.getConf();
conf.setRawKVBatchWriteTimeoutInMS(100000);
conf.setTimeout(100000);
try(TiSession newSession = TiSession.create(conf)){
try(RawKVClient client=newSession.createRawClient()) {
HashMap<ByteString, ByteString> kvs = new HashMap<>();
for (int i = 0; i < 2048; i++) {
kvs.put(ByteString.copyFromUtf8("key@" + i), rawValue("value@" + i));
}
client.batchPut(kvs);
}
};
public void testBatchPutForIssue634() {
ByteString prefix = ByteString.copyFromUtf8("testBatchPutForIssue634");
client.deletePrefix(prefix);
HashMap<ByteString, ByteString> kvs = new HashMap<>();
for (int i = 0; i < MAX_RAW_BATCH_LIMIT * 4; i++) {
kvs.put(prefix.concat(ByteString.copyFromUtf8("key@" + i)), rawValue("value@" + i));
}
client.batchPut(kvs);
}
}