use of com.pingcap.tikv.meta.TiTimestamp in project tispark by pingcap.
the class PDClientTest method testTso.
@Test
public void testTso() throws Exception {
try (PDClient client = session.getPDClient()) {
TiTimestamp ts = client.getTimestamp(defaultBackOff());
// Test pdServer is set to generate physical == logical + 1
assertEquals(ts.getPhysical(), ts.getLogical() + 1);
}
}
use of com.pingcap.tikv.meta.TiTimestamp in project tispark by pingcap.
the class DAGIteratorTest method staleEpochTest.
@Test
public void staleEpochTest() {
Metapb.Store store = Metapb.Store.newBuilder().setAddress(LOCAL_ADDR + ":" + port).setId(1).setState(Metapb.StoreState.Up).setVersion(Version.RESOLVE_LOCK_V4).build();
TiTableInfo table = createTable();
TiDAGRequest req = new TiDAGRequest(PushDownType.NORMAL);
req.setTableInfo(table);
req.addRequiredColumn(ColumnRef.create("c1", IntegerType.INT));
req.addRequiredColumn(ColumnRef.create("c2", StringType.VARCHAR));
req.setStartTs(new TiTimestamp(0, 1));
List<KeyRange> keyRanges = ImmutableList.of(createByteStringRange(ByteString.copyFromUtf8("key1"), ByteString.copyFromUtf8("key4")));
pdServer.addGetRegionResp(GrpcUtils.makeGetRegionResponse(pdServer.getClusterId(), region.getMeta()));
pdServer.addGetStoreResp(GrpcUtils.makeGetStoreResponse(pdServer.getClusterId(), store));
server.putError("key1", KVMockServer.STALE_EPOCH);
CodecDataOutput cdo = new CodecDataOutput();
IntegerCodec.writeLongFully(cdo, 666, false);
BytesCodec.writeBytesFully(cdo, "value1".getBytes());
server.put("key1", cdo.toByteString());
List<RegionTask> tasks = ImmutableList.of(RegionTask.newInstance(region, store, keyRanges));
CoprocessorIterator<Row> iter = CoprocessorIterator.getRowIterator(req, tasks, session);
if (!iter.hasNext()) {
assertEquals("iterator has next should be true", true, false);
} else {
Row r = iter.next();
SchemaInfer infer = SchemaInfer.create(req);
assertEquals(r.get(0, infer.getType(0)), 666L);
assertEquals(r.get(1, infer.getType(1)), "value1");
}
}
use of com.pingcap.tikv.meta.TiTimestamp 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)));
}
}
use of com.pingcap.tikv.meta.TiTimestamp in project tispark by pingcap.
the class LockResolverTest method prepareAlphabetLocks.
void prepareAlphabetLocks() {
TiTimestamp startTs = session.getTimestamp();
TiTimestamp endTs = session.getTimestamp();
while (startTs == endTs) {
endTs = session.getTimestamp();
}
putKV("c", "cc", startTs.getVersion(), endTs.getVersion());
startTs = session.getTimestamp();
endTs = session.getTimestamp();
while (startTs == endTs) {
endTs = session.getTimestamp();
}
assertTrue(lockKey("c", "c", "z1", "z1", true, startTs.getVersion(), endTs.getVersion()));
startTs = session.getTimestamp();
endTs = session.getTimestamp();
while (startTs == endTs) {
endTs = session.getTimestamp();
}
assertTrue(lockKey("d", "dd", "z2", "z2", false, startTs.getVersion(), endTs.getVersion(), LARGE_LOCK_TTL));
}
Aggregations