Search in sources :

Example 1 with TiTimestamp

use of com.pingcap.tikv.meta.TiTimestamp in project tispark by pingcap.

the class LockResolverSITest method SITestNonBlocking.

@Test
public void SITestNonBlocking() {
    if (!init) {
        skipTestInit();
        return;
    }
    if (!isLockResolverClientV4()) {
        skipTestTiDBV4();
        return;
    }
    TiTimestamp startTs = session.getTimestamp();
    TiTimestamp endTs = session.getTimestamp();
    // Put <a, a> into kv
    putKV("a", "a", startTs.getVersion(), endTs.getVersion());
    startTs = session.getTimestamp();
    endTs = session.getTimestamp();
    // Prewrite <a, aa> as primary without committing it
    assertTrue(lockKey("a", "aa", "a", "aa", false, startTs.getVersion(), endTs.getVersion(), LARGE_LOCK_TTL));
    TiRegion tiRegion = session.getRegionManager().getRegionByKey(ByteString.copyFromUtf8("a"));
    RegionStoreClient client = builder.build(tiRegion);
    {
        BackOffer backOffer = ConcreteBackOffer.newGetBackOff();
        Long callerTS = session.getTimestamp().getVersion();
        System.out.println("callerTS1= " + callerTS);
        ByteString v = client.get(backOffer, ByteString.copyFromUtf8("a"), callerTS);
        assertEquals(v.toStringUtf8(), String.valueOf('a'));
    }
    try {
        // Trying to continue the commitString phase of <a, aa> will fail because CommitTS <
        // MinCommitTS
        commitString(Collections.singletonList("a"), startTs.getVersion(), endTs.getVersion());
        fail();
    } catch (KeyException e) {
        assertTrue(e.getMessage().startsWith("Key exception occurred and the reason is commit_ts_expired"));
    }
    // Trying to continue the commitString phase of <a, aa> will success because CommitTS >
    // MinCommitTS
    endTs = session.getTimestamp();
    assertTrue(commitString(Collections.singletonList("a"), startTs.getVersion(), endTs.getVersion()));
}
Also used : TiTimestamp(com.pingcap.tikv.meta.TiTimestamp) ByteString(com.google.protobuf.ByteString) TiRegion(com.pingcap.tikv.region.TiRegion) ConcreteBackOffer(com.pingcap.tikv.util.ConcreteBackOffer) BackOffer(com.pingcap.tikv.util.BackOffer) RegionStoreClient(com.pingcap.tikv.region.RegionStoreClient) KeyException(com.pingcap.tikv.exception.KeyException) Test(org.junit.Test)

Example 2 with TiTimestamp

use of com.pingcap.tikv.meta.TiTimestamp in project tispark by pingcap.

the class LockResolverSITest method SITestBlocking.

@Test
public void SITestBlocking() {
    if (!init) {
        skipTestInit();
        return;
    }
    if (isLockResolverClientV4()) {
        logger.warn("Test skipped due to version of TiDB/TiKV should be 2.x or 3.x.");
        return;
    }
    TiTimestamp startTs = session.getTimestamp();
    TiTimestamp endTs = session.getTimestamp();
    // Put <a, a> into kv
    putKV("a", "a", startTs.getVersion(), endTs.getVersion());
    startTs = session.getTimestamp();
    endTs = session.getTimestamp();
    // Prewrite <a, aa> as primary without committing it
    assertTrue(lockKey("a", "aa", "a", "aa", false, startTs.getVersion(), endTs.getVersion()));
    TiRegion tiRegion = session.getRegionManager().getRegionByKey(ByteString.copyFromUtf8("a"));
    RegionStoreClient client = builder.build(tiRegion);
    {
        BackOffer backOffer = ConcreteBackOffer.newGetBackOff();
        // With TTL set to 10, after 10 milliseconds <a, aa> is resolved.
        // We should be able to read <a, a> instead.
        ByteString v = client.get(backOffer, ByteString.copyFromUtf8("a"), session.getTimestamp().getVersion());
        assertEquals(v.toStringUtf8(), String.valueOf('a'));
    }
    try {
        // Trying to continue the commitString phase of <a, aa> will fail because TxnLockNotFound
        commitString(Collections.singletonList("a"), startTs.getVersion(), endTs.getVersion());
        fail();
    } catch (KeyException e) {
        assertFalse(e.getKeyError().getRetryable().isEmpty());
    }
}
Also used : TiTimestamp(com.pingcap.tikv.meta.TiTimestamp) ByteString(com.google.protobuf.ByteString) TiRegion(com.pingcap.tikv.region.TiRegion) ConcreteBackOffer(com.pingcap.tikv.util.ConcreteBackOffer) BackOffer(com.pingcap.tikv.util.BackOffer) RegionStoreClient(com.pingcap.tikv.region.RegionStoreClient) KeyException(com.pingcap.tikv.exception.KeyException) Test(org.junit.Test)

Example 3 with TiTimestamp

use of com.pingcap.tikv.meta.TiTimestamp 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);
}
Also used : TiTimestamp(com.pingcap.tikv.meta.TiTimestamp) ByteString(com.google.protobuf.ByteString) ConcreteBackOffer(com.pingcap.tikv.util.ConcreteBackOffer) BackOffer(com.pingcap.tikv.util.BackOffer) RegionStoreClient(com.pingcap.tikv.region.RegionStoreClient)

Example 4 with TiTimestamp

use of com.pingcap.tikv.meta.TiTimestamp in project tispark by pingcap.

the class PDClient method getTimestamp.

@Override
public TiTimestamp getTimestamp(BackOffer backOffer) {
    Supplier<TsoRequest> request = () -> tsoReq;
    PDErrorHandler<TsoResponse> handler = new PDErrorHandler<>(r -> r.getHeader().hasError() ? buildFromPdpbError(r.getHeader().getError()) : null, this);
    TsoResponse resp = callWithRetry(backOffer, PDGrpc.getTsoMethod(), request, handler);
    Timestamp timestamp = resp.getTimestamp();
    return new TiTimestamp(timestamp.getPhysical(), timestamp.getLogical());
}
Also used : TiTimestamp(com.pingcap.tikv.meta.TiTimestamp) PDErrorHandler(com.pingcap.tikv.operation.PDErrorHandler) TsoResponse(org.tikv.kvproto.Pdpb.TsoResponse) Timestamp(org.tikv.kvproto.Pdpb.Timestamp) TiTimestamp(com.pingcap.tikv.meta.TiTimestamp) TsoRequest(org.tikv.kvproto.Pdpb.TsoRequest)

Example 5 with TiTimestamp

use of com.pingcap.tikv.meta.TiTimestamp in project tispark by pingcap.

the class TxnKVClient method getTimestamp.

public TiTimestamp getTimestamp() {
    BackOffer bo = ConcreteBackOffer.newTsoBackOff();
    TiTimestamp timestamp = new TiTimestamp(0, 0);
    try {
        while (true) {
            try {
                timestamp = pdClient.getTimestamp(bo);
                break;
            } catch (final TiKVException | TiClientInternalException e) {
                // retry is exhausted
                bo.doBackOff(BackOffFunction.BackOffFuncType.BoPDRPC, e);
            }
        }
    } catch (GrpcException e1) {
        LOG.error("Get tso from pd failed,", e1);
    }
    return timestamp;
}
Also used : TiTimestamp(com.pingcap.tikv.meta.TiTimestamp) TiClientInternalException(com.pingcap.tikv.exception.TiClientInternalException) TiKVException(com.pingcap.tikv.exception.TiKVException) GrpcException(com.pingcap.tikv.exception.GrpcException) ConcreteBackOffer(com.pingcap.tikv.util.ConcreteBackOffer) BackOffer(com.pingcap.tikv.util.BackOffer)

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