Search in sources :

Example 16 with RheaKVStore

use of com.alipay.sofa.jraft.rhea.client.RheaKVStore in project sofa-jraft by sofastack.

the class ChaosTestCluster method removePeer.

public synchronized void removePeer(final PeerId peerId) {
    for (int i = this.stores.size() - 1; i >= 0; i--) {
        final RheaKVStore store = this.stores.get(i);
        if (peerId.getEndpoint().equals(getSelfEndpoint(store))) {
            final PlacementDriverClient pdClient = store.getPlacementDriverClient();
            if (!pdClient.removeReplica(Constants.DEFAULT_REGION_ID, JRaftHelper.toPeer(peerId), true)) {
                throw new RuntimeException("fail to remove peer: " + peerId);
            }
            store.shutdown();
            this.stores.remove(i);
            this.peerIds.remove(i);
            LOG.info("Shutdown and remove peer: {}", peerId);
            return;
        }
    }
    LOG.info("Could not find peer: {}", peerId);
}
Also used : RheaKVStore(com.alipay.sofa.jraft.rhea.client.RheaKVStore) DefaultRheaKVStore(com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore) PlacementDriverClient(com.alipay.sofa.jraft.rhea.client.pd.PlacementDriverClient) Endpoint(com.alipay.sofa.jraft.util.Endpoint)

Example 17 with RheaKVStore

use of com.alipay.sofa.jraft.rhea.client.RheaKVStore in project sofa-jraft by sofastack.

the class RheaBenchmarkCluster method shutdown.

protected void shutdown() throws IOException {
    for (RheaKVStore store : stores) {
        store.shutdown();
    }
    if (this.tempDbPath != null) {
        System.out.println("removing dir: " + this.tempDbPath);
        FileUtils.forceDelete(new File(this.tempDbPath));
    }
    if (this.tempRaftPath != null) {
        System.out.println("removing dir: " + this.tempRaftPath);
        FileUtils.forceDelete(new File(this.tempRaftPath));
    }
}
Also used : DefaultRheaKVStore(com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore) RheaKVStore(com.alipay.sofa.jraft.rhea.client.RheaKVStore) File(java.io.File)

Example 18 with RheaKVStore

use of com.alipay.sofa.jraft.rhea.client.RheaKVStore in project sofa-jraft by sofastack.

the class AbstractChaosTest method chaosGetTest.

@Test
public void chaosGetTest() throws Exception {
    ChaosTestCluster cluster = null;
    PeerId p1 = null;
    PeerId p2 = null;
    for (int l = 0; l < RETRIES; l++) {
        final ExecutorService executor = Executors.newCachedThreadPool(new NamedThreadFactory("chaos-test", true));
        final List<CompletableFuture<Boolean>> allFutures = new CopyOnWriteArrayList<>();
        try {
            cluster = new ChaosTestCluster(TestUtil.generatePeers(INITIAL_PEER_COUNT), getStorageType(), isAllowBatching(), isOnlyLeaderRead());
            cluster.start();
            // Before writing data, remove a node (node1) and add it back later to verify that read consistency is guaranteed.
            p1 = cluster.getRandomPeer();
            cluster.removePeer(p1);
            final RheaKVStore store = cluster.getLeaderStore();
            // warm up
            store.bGet("test_key");
            for (int i = 0; i < LOOP_1; i++) {
                final int index = i;
                executor.execute(() -> {
                    for (int j = 0; j < LOOP_2; j++) {
                        allFutures.add(store.put("test_" + index + "_" + j, VALUE));
                    }
                });
            }
            // In the process of writing data, remove one node (node2)
            p2 = cluster.getRandomPeer();
            cluster.removePeer(p2);
            // Waiting for the write to be completed
            CompletableFuture.allOf(allFutures.toArray(new CompletableFuture[0])).get(30, TimeUnit.SECONDS);
            break;
        } catch (final Exception e) {
            System.err.println("Fail to put data, try again...");
            e.printStackTrace();
            new FutureGroup<>(allFutures).cancel(true);
            if (cluster != null) {
                cluster.stopAll();
            }
            cluster = null;
        } finally {
            ExecutorServiceHelper.shutdownAndAwaitTermination(executor);
        }
    }
    if (cluster == null) {
        throw new RuntimeException("fail to put data, can not check data");
    }
    try {
        chaosGetCheckData(cluster, p2, p1);
    } finally {
        cluster.stopAll();
    }
}
Also used : RheaKVStore(com.alipay.sofa.jraft.rhea.client.RheaKVStore) CompletableFuture(java.util.concurrent.CompletableFuture) NamedThreadFactory(com.alipay.sofa.jraft.util.NamedThreadFactory) ExecutorService(java.util.concurrent.ExecutorService) PeerId(com.alipay.sofa.jraft.entity.PeerId) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) FutureGroup(com.alipay.sofa.jraft.rhea.client.FutureGroup) Test(org.junit.Test)

Aggregations

RheaKVStore (com.alipay.sofa.jraft.rhea.client.RheaKVStore)18 DefaultRheaKVStore (com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore)12 RheaKVStoreOptions (com.alipay.sofa.jraft.rhea.options.RheaKVStoreOptions)6 Endpoint (com.alipay.sofa.jraft.util.Endpoint)6 PlacementDriverClient (com.alipay.sofa.jraft.rhea.client.pd.PlacementDriverClient)5 Test (org.junit.Test)5 Configuration (com.alipay.sofa.jraft.conf.Configuration)4 File (java.io.File)4 PeerId (com.alipay.sofa.jraft.entity.PeerId)3 Status (com.alipay.sofa.jraft.Status)2 CliOptions (com.alipay.sofa.jraft.option.CliOptions)2 RheaKVCliService (com.alipay.sofa.jraft.rhea.client.RheaKVCliService)2 BatchingOptions (com.alipay.sofa.jraft.rhea.options.BatchingOptions)2 PlacementDriverOptions (com.alipay.sofa.jraft.rhea.options.PlacementDriverOptions)2 StoreEngineOptions (com.alipay.sofa.jraft.rhea.options.StoreEngineOptions)2 NamedThreadFactory (com.alipay.sofa.jraft.util.NamedThreadFactory)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2