Search in sources :

Example 1 with Mutation

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;
}
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 2 with Mutation

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);
}
Also used : Mutation(org.tikv.kvproto.Kvrpcpb.Mutation)

Example 3 with Mutation

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

Aggregations

Mutation (org.tikv.kvproto.Kvrpcpb.Mutation)3 RegionStoreClient (com.pingcap.tikv.region.RegionStoreClient)2 TiRegion (com.pingcap.tikv.region.TiRegion)2 BackOffer (com.pingcap.tikv.util.BackOffer)2 ConcreteBackOffer (com.pingcap.tikv.util.ConcreteBackOffer)2 ByteString (com.google.protobuf.ByteString)1 RegionException (com.pingcap.tikv.exception.RegionException)1 TiTimestamp (com.pingcap.tikv.meta.TiTimestamp)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1