Search in sources :

Example 11 with RheaKVStore

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

the class BenchmarkClient method main.

public static void main(final String[] args) {
    if (args.length < 7) {
        LOG.error("Args: [initialServerList], [configPath], [threads], [writeRatio], [readRatio], [valueSize] are needed.");
        System.exit(-1);
    }
    final String initialServerList = args[1];
    final String configPath = args[2];
    final int threads = Integer.parseInt(args[3]);
    final int writeRatio = Integer.parseInt(args[4]);
    final int readRatio = Integer.parseInt(args[5]);
    final int valueSize = Integer.parseInt(args[6]);
    final RheaKVStoreOptions opts = Yaml.readConfig(configPath);
    opts.setInitialServerList(initialServerList);
    final RheaKVStore rheaKVStore = new DefaultRheaKVStore();
    if (!rheaKVStore.init(opts)) {
        LOG.error("Fail to init [RheaKVStore]");
        System.exit(-1);
    }
    final List<RegionRouteTableOptions> regionRouteTableOptionsList = opts.getPlacementDriverOptions().getRegionRouteTableOptionsList();
    rebalance(rheaKVStore, initialServerList, regionRouteTableOptionsList);
    rheaKVStore.bPut("benchmark", BytesUtil.writeUtf8("benchmark start at: " + new Date()));
    LOG.info(BytesUtil.readUtf8(rheaKVStore.bGet("benchmark")));
    // 
    ConsoleReporter.forRegistry(KVMetrics.metricRegistry()).build().start(30, TimeUnit.SECONDS);
    LOG.info("Start benchmark...");
    startBenchmark(rheaKVStore, threads, writeRatio, readRatio, valueSize, regionRouteTableOptionsList);
}
Also used : RegionRouteTableOptions(com.alipay.sofa.jraft.rhea.options.RegionRouteTableOptions) RheaKVStoreOptions(com.alipay.sofa.jraft.rhea.options.RheaKVStoreOptions) RheaKVStore(com.alipay.sofa.jraft.rhea.client.RheaKVStore) DefaultRheaKVStore(com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore) DefaultRheaKVStore(com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore) Endpoint(com.alipay.sofa.jraft.util.Endpoint) Date(java.util.Date)

Example 12 with RheaKVStore

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

the class AbstractRheaKVStoreTest method rangeSplitTest.

@Test
public void rangeSplitTest() {
    final RheaKVStore store = getRandomLeaderStore();
    final long regionId = 1;
    for (int i = 0; i < 20; i++) {
        store.bPut("a" + i, BytesUtil.writeUtf8("split"));
    }
    final CliOptions opts = new CliOptions();
    opts.setTimeoutMs(30000);
    final RheaKVCliService cliService = RheaKVServiceFactory.createAndInitRheaKVCliService(opts);
    final long newRegionId = 101;
    final String groupId = JRaftHelper.getJRaftGroupId("rhea_test", regionId);
    final Configuration conf = JRaftUtils.getConfiguration("127.0.0.1:18181,127.0.0.1:18182,127.0.0.1:18183");
    final Status st = cliService.rangeSplit(regionId, newRegionId, groupId, conf);
    System.err.println("Status:" + st);
    assertTrue(st.isOk());
    final RheaKVStore newStore = getLeaderStore(101);
    newStore.bPut("f_first_key", BytesUtil.writeUtf8("split_ok"));
    assertArrayEquals(BytesUtil.writeUtf8("split_ok"), newStore.bGet("f_first_key"));
}
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) CliOptions(com.alipay.sofa.jraft.option.CliOptions) Test(org.junit.Test)

Example 13 with RheaKVStore

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

the class AbstractRheaKVStoreTest method restartAllWithFollowerTest.

@Test
public void restartAllWithFollowerTest() throws Exception {
    RheaKVStore store = getRandomFollowerStore();
    // 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 = getRandomFollowerStore();
    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 14 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(final boolean deleteFiles) throws Exception {
    for (final RheaKVStore store : stores) {
        store.shutdown();
    }
    stores.clear();
    if (deleteFiles) {
        deleteFiles();
    }
    LOG.info("RheaKVTestCluster shutdown complete");
}
Also used : DefaultRheaKVStore(com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore) RheaKVStore(com.alipay.sofa.jraft.rhea.client.RheaKVStore)

Example 15 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() throws IOException, InterruptedException {
    System.out.println("RheaKVTestCluster init ...");
    File file = new File("rhea_pd_db");
    if (file.exists()) {
        FileUtils.forceDelete(file);
    }
    file = new File("rhea_pd_db");
    if (file.mkdir()) {
        this.tempDbPath = file.getAbsolutePath();
        System.out.println("make dir: " + this.tempDbPath);
    }
    file = new File("rhea_pd_raft");
    if (file.exists()) {
        FileUtils.forceDelete(file);
    }
    file = new File("rhea_pd_raft");
    if (file.mkdir()) {
        this.tempRaftPath = file.getAbsolutePath();
        System.out.println("make dir: " + this.tempRaftPath);
    }
    final Set<Long> regionIds = new HashSet<>();
    for (final String c : CONF) {
        final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
        final InputStream in = RheaKVTestCluster.class.getResourceAsStream(c);
        final RheaKVStoreOptions opts = mapper.readValue(in, RheaKVStoreOptions.class);
        for (final RegionEngineOptions rOpts : opts.getStoreEngineOptions().getRegionEngineOptionsList()) {
            regionIds.add(rOpts.getRegionId());
        }
        final RheaKVStore rheaKVStore = new DefaultRheaKVStore();
        if (rheaKVStore.init(opts)) {
            stores.add(rheaKVStore);
        } else {
            System.err.println("Fail to init rhea kv store witch conf: " + c);
        }
    }
    final PlacementDriverClient pdClient = stores.get(0).getPlacementDriverClient();
    for (final Long regionId : regionIds) {
        final Endpoint leader = pdClient.getLeader(regionId, true, 10000);
        System.out.println("The region " + regionId + " leader is: " + leader);
    }
}
Also used : DefaultRheaKVStore(com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore) RheaKVStore(com.alipay.sofa.jraft.rhea.client.RheaKVStore) InputStream(java.io.InputStream) PlacementDriverClient(com.alipay.sofa.jraft.rhea.client.pd.PlacementDriverClient) RegionEngineOptions(com.alipay.sofa.jraft.rhea.options.RegionEngineOptions) DefaultRheaKVStore(com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore) RheaKVStoreOptions(com.alipay.sofa.jraft.rhea.options.RheaKVStoreOptions) Endpoint(com.alipay.sofa.jraft.util.Endpoint) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HashSet(java.util.HashSet)

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