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);
}
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"));
}
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());
}
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");
}
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);
}
}
Aggregations