use of com.pingcap.tikv.util.BackOffer in project tispark by pingcap.
the class LockResolverTest method putKVandTestGet.
void putKVandTestGet(String key, String value) {
RegionStoreClient client = getRegionStoreClient(key);
TiTimestamp startTs = session.getTimestamp();
TiTimestamp endTs = session.getTimestamp();
putKV(key, value, startTs.getVersion(), endTs.getVersion());
BackOffer backOffer = ConcreteBackOffer.newGetBackOff();
ByteString v = client.get(backOffer, ByteString.copyFromUtf8(key), session.getTimestamp().getVersion());
assertEquals(v.toStringUtf8(), value);
}
use of com.pingcap.tikv.util.BackOffer in project tispark by pingcap.
the class LockResolverTest method commit.
boolean commit(List<ByteString> keys, long startTS, long commitTS) {
if (keys.size() == 0)
return true;
BackOffer backOffer = ConcreteBackOffer.newCustomBackOff(1000);
for (ByteString byteStringK : keys) {
while (true) {
try {
TiRegion tiRegion = session.getRegionManager().getRegionByKey(byteStringK);
RegionStoreClient client = builder.build(tiRegion);
client.commit(backOffer, Collections.singletonList(byteStringK), startTS, commitTS);
break;
} catch (RegionException e) {
backOffer.doBackOff(BackOffFunction.BackOffFuncType.BoRegionMiss, e);
}
}
}
return true;
}
use of com.pingcap.tikv.util.BackOffer in project tispark by pingcap.
the class LockResolverTest method prewrite.
boolean prewrite(List<Mutation> mutations, long startTS, ByteString primary, long ttl, boolean useAsyncCommit, Iterable<ByteString> secondaries) {
if (mutations.size() == 0)
return true;
BackOffer backOffer = ConcreteBackOffer.newCustomBackOff(1000);
for (Mutation m : mutations) {
while (true) {
try {
TiRegion region = session.getRegionManager().getRegionByKey(m.getKey());
RegionStoreClient client = builder.build(region);
client.prewrite(backOffer, primary, Collections.singletonList(m), startTS, ttl, false, useAsyncCommit, secondaries);
break;
} catch (RegionException e) {
backOffer.doBackOff(BackOffFunction.BackOffFuncType.BoRegionMiss, e);
}
}
}
return true;
}
use of com.pingcap.tikv.util.BackOffer in project tispark by pingcap.
the class LockResolverTest method pointGet.
String pointGet(String key) {
BackOffer backOffer2 = ConcreteBackOffer.newCustomBackOff(GET_BACKOFF);
RegionStoreClient client = getRegionStoreClient(key);
return client.get(backOffer2, ByteString.copyFromUtf8(key), session.getTimestamp().getVersion()).toStringUtf8();
}
use of com.pingcap.tikv.util.BackOffer in project tispark by pingcap.
the class LockResolverTest method versionTest.
private void versionTest(boolean hasLock, boolean blockingRead) {
for (int i = 0; i < 26; i++) {
ByteString key = ByteString.copyFromUtf8(String.valueOf((char) ('a' + i)));
TiRegion tiRegion = session.getRegionManager().getRegionByKey(key);
RegionStoreClient client = builder.build(tiRegion);
BackOffer backOffer = ConcreteBackOffer.newGetBackOff();
if (blockingRead) {
try {
ByteString v = client.get(backOffer, key, session.getTimestamp().getVersion());
if (hasLock && i == 3) {
// key "d" should be locked
fail();
} else {
assertEquals(String.valueOf((char) ('a' + i)), v.toStringUtf8());
}
} catch (GrpcException e) {
assertEquals(e.getMessage(), "retry is exhausted.");
}
} else {
ByteString v = client.get(backOffer, key, session.getTimestamp().getVersion());
assertEquals(String.valueOf((char) ('a' + i)), v.toStringUtf8());
}
}
}
Aggregations