Search in sources :

Example 6 with TiTimestamp

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);
    }
}
Also used : TiTimestamp(com.pingcap.tikv.meta.TiTimestamp) Test(org.junit.Test)

Example 7 with TiTimestamp

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");
    }
}
Also used : TiTimestamp(com.pingcap.tikv.meta.TiTimestamp) KeyRange(org.tikv.kvproto.Coprocessor.KeyRange) TiDAGRequest(com.pingcap.tikv.meta.TiDAGRequest) RegionTask(com.pingcap.tikv.util.RangeSplitter.RegionTask) TiTableInfo(com.pingcap.tikv.meta.TiTableInfo) CodecDataOutput(com.pingcap.tikv.codec.CodecDataOutput) Row(com.pingcap.tikv.row.Row) SchemaInfer(com.pingcap.tikv.operation.SchemaInfer) Metapb(org.tikv.kvproto.Metapb) MockServerTest(com.pingcap.tikv.MockServerTest) Test(org.junit.Test)

Example 8 with TiTimestamp

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)));
    }
}
Also used : TiTimestamp(com.pingcap.tikv.meta.TiTimestamp) ByteString(com.google.protobuf.ByteString) TiRegion(com.pingcap.tikv.region.TiRegion) ArrayList(java.util.ArrayList) ConcreteBackOffer(com.pingcap.tikv.util.ConcreteBackOffer) BackOffer(com.pingcap.tikv.util.BackOffer) ByteString(com.google.protobuf.ByteString) Mutation(org.tikv.kvproto.Kvrpcpb.Mutation) RegionStoreClient(com.pingcap.tikv.region.RegionStoreClient) Test(org.junit.Test)

Example 9 with TiTimestamp

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));
}
Also used : TiTimestamp(com.pingcap.tikv.meta.TiTimestamp)

Aggregations

TiTimestamp (com.pingcap.tikv.meta.TiTimestamp)9 BackOffer (com.pingcap.tikv.util.BackOffer)5 ConcreteBackOffer (com.pingcap.tikv.util.ConcreteBackOffer)5 Test (org.junit.Test)5 ByteString (com.google.protobuf.ByteString)4 RegionStoreClient (com.pingcap.tikv.region.RegionStoreClient)4 TiRegion (com.pingcap.tikv.region.TiRegion)3 KeyException (com.pingcap.tikv.exception.KeyException)2 MockServerTest (com.pingcap.tikv.MockServerTest)1 CodecDataOutput (com.pingcap.tikv.codec.CodecDataOutput)1 GrpcException (com.pingcap.tikv.exception.GrpcException)1 TiClientInternalException (com.pingcap.tikv.exception.TiClientInternalException)1 TiKVException (com.pingcap.tikv.exception.TiKVException)1 TiDAGRequest (com.pingcap.tikv.meta.TiDAGRequest)1 TiTableInfo (com.pingcap.tikv.meta.TiTableInfo)1 PDErrorHandler (com.pingcap.tikv.operation.PDErrorHandler)1 SchemaInfer (com.pingcap.tikv.operation.SchemaInfer)1 Row (com.pingcap.tikv.row.Row)1 RegionTask (com.pingcap.tikv.util.RangeSplitter.RegionTask)1 ArrayList (java.util.ArrayList)1