Search in sources :

Example 6 with BackOffer

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);
}
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 7 with BackOffer

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;
}
Also used : ByteString(com.google.protobuf.ByteString) TiRegion(com.pingcap.tikv.region.TiRegion) ConcreteBackOffer(com.pingcap.tikv.util.ConcreteBackOffer) BackOffer(com.pingcap.tikv.util.BackOffer) RegionException(com.pingcap.tikv.exception.RegionException) RegionStoreClient(com.pingcap.tikv.region.RegionStoreClient)

Example 8 with BackOffer

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;
}
Also used : TiRegion(com.pingcap.tikv.region.TiRegion) ConcreteBackOffer(com.pingcap.tikv.util.ConcreteBackOffer) BackOffer(com.pingcap.tikv.util.BackOffer) Mutation(org.tikv.kvproto.Kvrpcpb.Mutation) RegionException(com.pingcap.tikv.exception.RegionException) RegionStoreClient(com.pingcap.tikv.region.RegionStoreClient)

Example 9 with BackOffer

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();
}
Also used : ConcreteBackOffer(com.pingcap.tikv.util.ConcreteBackOffer) BackOffer(com.pingcap.tikv.util.BackOffer) RegionStoreClient(com.pingcap.tikv.region.RegionStoreClient)

Example 10 with BackOffer

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());
        }
    }
}
Also used : ByteString(com.google.protobuf.ByteString) TiRegion(com.pingcap.tikv.region.TiRegion) GrpcException(com.pingcap.tikv.exception.GrpcException) ConcreteBackOffer(com.pingcap.tikv.util.ConcreteBackOffer) BackOffer(com.pingcap.tikv.util.BackOffer) RegionStoreClient(com.pingcap.tikv.region.RegionStoreClient)

Aggregations

BackOffer (com.pingcap.tikv.util.BackOffer)19 ConcreteBackOffer (com.pingcap.tikv.util.ConcreteBackOffer)19 RegionStoreClient (com.pingcap.tikv.region.RegionStoreClient)13 TiRegion (com.pingcap.tikv.region.TiRegion)10 ByteString (com.google.protobuf.ByteString)9 TiTimestamp (com.pingcap.tikv.meta.TiTimestamp)6 ArrayList (java.util.ArrayList)6 GrpcException (com.pingcap.tikv.exception.GrpcException)5 TiKVException (com.pingcap.tikv.exception.TiKVException)4 Metapb (org.tikv.kvproto.Metapb)4 KeyException (com.pingcap.tikv.exception.KeyException)3 TiBatchWriteException (com.pingcap.tikv.exception.TiBatchWriteException)3 Test (org.junit.Test)3 Chunk (com.pingcap.tidb.tipb.Chunk)2 SelectResponse (com.pingcap.tidb.tipb.SelectResponse)2 RegionException (com.pingcap.tikv.exception.RegionException)2 ArrayDeque (java.util.ArrayDeque)2 List (java.util.List)2 ExecutionException (java.util.concurrent.ExecutionException)2 ExecutorCompletionService (java.util.concurrent.ExecutorCompletionService)2