use of com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore in project sofa-jraft by sofastack.
the class ChaosTestCluster method addPeer.
public synchronized void addPeer(final PeerId peerId) {
if (this.peerIds.contains(peerId)) {
throw new RuntimeException("peerId is exist: " + peerId);
}
this.peerIds.add(peerId);
final Configuration conf = new Configuration(this.peerIds);
final String initialServerList = conf.toString();
final PlacementDriverOptions pdOpts = // use a fake pd
PlacementDriverOptionsConfigured.newConfigured().withFake(true).config();
final StoreEngineOptions storeOpts = //
StoreEngineOptionsConfigured.newConfigured().withStorageType(//
this.storageType).withRocksDBOptions(//
RocksDBOptionsConfigured.newConfigured().withDbPath(DB_PATH).config()).withRaftDataPath(//
RAFT_DATA_PATH).withServerAddress(//
peerId.getEndpoint()).config();
final RheaKVStoreOptions opts = //
RheaKVStoreOptionsConfigured.newConfigured().withClusterName(//
"chaos_test").withInitialServerList(initialServerList).withStoreEngineOptions(//
storeOpts).withPlacementDriverOptions(//
pdOpts).config();
BatchingOptions batchingOptions = opts.getBatchingOptions();
if (batchingOptions == null) {
batchingOptions = new BatchingOptions();
}
batchingOptions.setAllowBatching(this.allowBatching);
opts.setBatchingOptions(batchingOptions);
final RheaKVStore store = new DefaultRheaKVStore();
if (!store.init(opts)) {
throw new IllegalStateException("fail to init store with options: " + opts);
}
final RheaKVStore leader = getLeaderStore();
final PlacementDriverClient pdClient = leader.getPlacementDriverClient();
if (!pdClient.addReplica(Constants.DEFAULT_REGION_ID, JRaftHelper.toPeer(peerId), true)) {
throw new RuntimeException("fail to add peer: " + peerId);
}
this.stores.add(store);
awaitLeader();
}
use of com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore in project sofa-jraft by sofastack.
the class ChaosTestCluster method start.
public synchronized void start() {
deleteFiles();
final Configuration conf = new Configuration(this.peerIds);
final String initialServerList = conf.toString();
for (final PeerId p : conf.listPeers()) {
final PlacementDriverOptions pdOpts = // use a fake pd
PlacementDriverOptionsConfigured.newConfigured().withFake(true).config();
final StoreEngineOptions storeOpts = //
StoreEngineOptionsConfigured.newConfigured().withStorageType(//
this.storageType).withRocksDBOptions(//
RocksDBOptionsConfigured.newConfigured().withDbPath(DB_PATH).config()).withRaftDataPath(//
RAFT_DATA_PATH).withServerAddress(//
p.getEndpoint()).withLeastKeysOnSplit(//
10).config();
final RheaKVStoreOptions opts = //
RheaKVStoreOptionsConfigured.newConfigured().withClusterName(//
CLUSTER_NAME).withInitialServerList(initialServerList).withOnlyLeaderRead(//
this.onlyLeaderRead).withStoreEngineOptions(//
storeOpts).withPlacementDriverOptions(//
pdOpts).withFailoverRetries(//
30).withFutureTimeoutMillis(//
TimeUnit.SECONDS.toMillis(60)).config();
BatchingOptions batchingOptions = opts.getBatchingOptions();
if (batchingOptions == null) {
batchingOptions = new BatchingOptions();
}
batchingOptions.setAllowBatching(this.allowBatching);
opts.setBatchingOptions(batchingOptions);
final RheaKVStore store = new DefaultRheaKVStore();
if (!store.init(opts)) {
throw new IllegalStateException("fail to init store with options: " + opts);
}
this.stores.add(store);
}
awaitLeader();
}
use of com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore 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.DefaultRheaKVStore 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);
}
use of com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore 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);
}
Aggregations