Search in sources :

Example 6 with RheaKVStore

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

the class RheaKVTestCluster method shutdown.

protected void shutdown() throws IOException {
    System.out.println("RheaKVTestCluster shutdown ...");
    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));
    }
    System.out.println("RheaKVTestCluster shutdown complete");
}
Also used : DefaultRheaKVStore(com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore) RheaKVStore(com.alipay.sofa.jraft.rhea.client.RheaKVStore) File(java.io.File)

Example 7 with RheaKVStore

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

the class AbstractRheaKVStoreTest method restartAllWithLeaderTest.

@Test
public void restartAllWithLeaderTest() throws Exception {
    RheaKVStore store = getRandomLeaderStore();
    // regions: 1 -> [null, g), 2 -> [g, null)
    store.bPut("a_get_test", makeValue("a_get_test_value"));
    store.bPut("h_get_test", makeValue("h_get_test_value"));
    store.bPut("z_get_test", makeValue("z_get_test_value"));
    store.bGetSequence("a_seqTest", 10);
    store.bGetSequence("h_seqTest", 11);
    store.bGetSequence("z_seqTest", 12);
    shutdown(false);
    start(getStorageType(), false);
    store = getRandomLeaderStore();
    assertArrayEquals(makeValue("a_get_test_value"), store.bGet("a_get_test"));
    assertArrayEquals(makeValue("h_get_test_value"), store.bGet("h_get_test"));
    assertArrayEquals(makeValue("z_get_test_value"), store.bGet("z_get_test"));
    assertEquals(10, store.bGetSequence("a_seqTest", 1).getStartValue());
    assertEquals(11, store.bGetSequence("h_seqTest", 1).getStartValue());
    assertEquals(12, store.bGetSequence("z_seqTest", 1).getStartValue());
}
Also used : RheaKVStore(com.alipay.sofa.jraft.rhea.client.RheaKVStore) Test(org.junit.Test)

Example 8 with RheaKVStore

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

the class RheaKVTestCluster method start.

protected void start(final StorageType storageType, final boolean deleteFiles) throws Exception {
    if (deleteFiles) {
        deleteFiles();
    }
    for (final String c : CONF) {
        final RheaKVStoreOptions opts = readOpts(c);
        opts.getStoreEngineOptions().setStorageType(storageType);
        final RheaKVStore rheaKVStore = new DefaultRheaKVStore();
        if (rheaKVStore.init(opts)) {
            stores.add(rheaKVStore);
        } else {
            throw new RuntimeException("Fail to init rhea kv store witch conf: " + c);
        }
    }
    for (final Long id : REGION_IDS) {
        getLeaderStore(id);
    }
}
Also used : RheaKVStoreOptions(com.alipay.sofa.jraft.rhea.options.RheaKVStoreOptions) DefaultRheaKVStore(com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore) RheaKVStore(com.alipay.sofa.jraft.rhea.client.RheaKVStore) DefaultRheaKVStore(com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore)

Example 9 with RheaKVStore

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

the class AbstractChaosTest method chaosSplittingTest.

@Test
public void chaosSplittingTest() {
    final List<PeerId> peerIds = TestUtil.generatePeers(INITIAL_PEER_COUNT);
    final CliOptions opts = new CliOptions();
    opts.setTimeoutMs(30000);
    final RheaKVCliService cliService = RheaKVServiceFactory.createAndInitRheaKVCliService(opts);
    final long regionId = Constants.DEFAULT_REGION_ID;
    final long newRegionId = 2;
    final String groupId = JRaftHelper.getJRaftGroupId(ChaosTestCluster.CLUSTER_NAME, regionId);
    final Configuration conf = new Configuration(peerIds);
    ChaosTestCluster cluster = null;
    for (int l = 0; l < RETRIES; l++) {
        final ExecutorService executor = Executors.newCachedThreadPool(new NamedThreadFactory("chaos-splitting-test", true));
        final List<Future<?>> allFutures = new CopyOnWriteArrayList<>();
        try {
            cluster = new ChaosTestCluster(peerIds, getStorageType(), isAllowBatching(), isOnlyLeaderRead());
            cluster.start();
            final RheaKVStore store = cluster.getLeaderStore();
            // for least keys on split
            for (int j = 0; j < LOOP_2; j++) {
                store.bPut(j + "_split_", VALUE);
            }
            for (int i = 0; i < LOOP_1; i++) {
                final int index = i;
                final Future<?> f = executor.submit(() -> {
                    for (int j = 0; j < LOOP_2; j++) {
                        store.bPut(index + "_split_test_" + j, VALUE);
                    }
                });
                allFutures.add(f);
            }
            final Status st = cliService.rangeSplit(regionId, newRegionId, groupId, conf);
            if (!st.isOk()) {
                System.err.println("Status:" + st);
                throw new RuntimeException(st.toString());
            }
            // wait for all writes finished
            for (final Future<?> f : allFutures) {
                f.get(30, TimeUnit.SECONDS);
            }
            break;
        } catch (final Exception e) {
            System.err.println("Fail to put data, try again...");
            e.printStackTrace();
            for (final Future<?> f : allFutures) {
                f.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 {
        chaosSplittingCheckData(cluster);
    } finally {
        cluster.stopAll();
    }
}
Also used : Status(com.alipay.sofa.jraft.Status) RheaKVStore(com.alipay.sofa.jraft.rhea.client.RheaKVStore) RheaKVCliService(com.alipay.sofa.jraft.rhea.client.RheaKVCliService) Configuration(com.alipay.sofa.jraft.conf.Configuration) NamedThreadFactory(com.alipay.sofa.jraft.util.NamedThreadFactory) CliOptions(com.alipay.sofa.jraft.option.CliOptions) ExecutorService(java.util.concurrent.ExecutorService) CompletableFuture(java.util.concurrent.CompletableFuture) Future(java.util.concurrent.Future) PeerId(com.alipay.sofa.jraft.entity.PeerId) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.junit.Test)

Example 10 with RheaKVStore

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

the class RheaBenchmarkCluster method start.

protected void start() throws IOException, InterruptedException {
    SystemPropertyUtil.setProperty(Configs.NETTY_BUFFER_LOW_WATERMARK, Integer.toString(256 * 1024));
    SystemPropertyUtil.setProperty(Configs.NETTY_BUFFER_HIGH_WATERMARK, Integer.toString(512 * 1024));
    File file = new File("benchmark_rhea_db");
    if (file.exists()) {
        FileUtils.forceDelete(file);
    }
    file = new File("benchmark_rhea_db");
    if (file.mkdir()) {
        this.tempDbPath = file.getAbsolutePath();
        System.out.println("make dir: " + this.tempDbPath);
    }
    file = new File("benchmark_rhea_raft");
    if (file.exists()) {
        FileUtils.forceDelete(file);
    }
    file = new File("benchmark_rhea_raft");
    if (file.mkdir()) {
        this.tempRaftPath = file.getAbsolutePath();
        System.out.println("make dir: " + this.tempRaftPath);
    }
    for (String c : CONF) {
        ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
        final RheaKVStoreOptions opts = mapper.readValue(new File(c), RheaKVStoreOptions.class);
        RheaKVStore rheaKVStore = new DefaultRheaKVStore();
        if (rheaKVStore.init(opts)) {
            stores.add(rheaKVStore);
        } else {
            throw new RuntimeException("Fail to init rhea kv store witch conf: " + c);
        }
    }
    PlacementDriverClient pdClient = stores.get(0).getPlacementDriverClient();
    Endpoint leader1 = pdClient.getLeader(1, true, 10000);
    System.out.println("The region 1 leader is: " + leader1);
// Endpoint leader2 = pdClient.getLeader(2, true, 10000);
// System.out.println("The region 2 leader is: " + leader2);
// Endpoint leader3 = pdClient.getLeader(3, true, 10000);
// System.out.println("The region 3 leader is: " + leader3);
}
Also used : RheaKVStoreOptions(com.alipay.sofa.jraft.rhea.options.RheaKVStoreOptions) DefaultRheaKVStore(com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore) RheaKVStore(com.alipay.sofa.jraft.rhea.client.RheaKVStore) Endpoint(com.alipay.sofa.jraft.util.Endpoint) PlacementDriverClient(com.alipay.sofa.jraft.rhea.client.pd.PlacementDriverClient) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) File(java.io.File) DefaultRheaKVStore(com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

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