use of org.tikv.kvproto.Kvrpcpb.Mutation 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 org.tikv.kvproto.Kvrpcpb.Mutation in project tispark by pingcap.
the class LockResolverTest method putKV.
void putKV(String key, String value, long startTS, long commitTS) {
Mutation m = Mutation.newBuilder().setKey(ByteString.copyFromUtf8(key)).setOp(Op.Put).setValue(ByteString.copyFromUtf8(value)).build();
boolean res = prewriteString(Collections.singletonList(m), startTS, key, DEFAULT_TTL);
assertTrue(res);
res = commitString(Collections.singletonList(key), startTS, commitTS);
assertTrue(res);
}
use of org.tikv.kvproto.Kvrpcpb.Mutation in project tispark by pingcap.
the class LockResolverSITest method cleanLockTest.
@Test
public void cleanLockTest() {
if (!init) {
skipTestInit();
return;
}
for (int i = 0; i < 26; i++) {
String k = String.valueOf((char) ('a' + i));
TiTimestamp startTs = session.getTimestamp();
TiTimestamp endTs = session.getTimestamp();
assertTrue(lockKey(k, k, k, k, false, startTs.getVersion(), endTs.getVersion()));
}
List<Mutation> mutations = new ArrayList<>();
List<String> keys = new ArrayList<>();
for (int i = 0; i < 26; i++) {
String k = String.valueOf((char) ('a' + i));
String v = String.valueOf((char) ('a' + i + 1));
Mutation m = Mutation.newBuilder().setKey(ByteString.copyFromUtf8(k)).setOp(Op.Put).setValue(ByteString.copyFromUtf8(v)).build();
mutations.add(m);
keys.add(k);
}
TiTimestamp startTs = session.getTimestamp();
TiTimestamp endTs = session.getTimestamp();
boolean res = prewriteString(mutations, startTs.getVersion(), mutations.get(0).getKey().toStringUtf8(), DEFAULT_TTL);
assertTrue(res);
res = commitString(keys, startTs.getVersion(), endTs.getVersion());
assertTrue(res);
for (int i = 0; i < 26; i++) {
TiRegion tiRegion = session.getRegionManager().getRegionByKey(ByteString.copyFromUtf8(String.valueOf((char) ('a' + i))));
RegionStoreClient client = builder.build(tiRegion);
BackOffer backOffer = ConcreteBackOffer.newGetBackOff();
ByteString v = client.get(backOffer, ByteString.copyFromUtf8(String.valueOf((char) ('a' + i))), session.getTimestamp().getVersion());
assertEquals(v.toStringUtf8(), String.valueOf((char) ('a' + i + 1)));
}
}
Aggregations