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