use of com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore 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);
}
}
use of com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore in project sofa-jraft by sofastack.
the class Node method start.
public void start() {
this.rheaKVStore = new DefaultRheaKVStore();
this.rheaKVStore.init(this.options);
}
use of com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore in project sofa-jraft by sofastack.
the class PlacementDriverServer method init.
@Override
public synchronized boolean init(final PlacementDriverServerOptions opts) {
if (this.started) {
LOG.info("[PlacementDriverServer] already started.");
return true;
}
Requires.requireNonNull(opts, "opts");
final RheaKVStoreOptions rheaOpts = opts.getRheaKVStoreOptions();
Requires.requireNonNull(rheaOpts, "opts.rheaKVStoreOptions");
this.rheaKVStore = new DefaultRheaKVStore();
if (!this.rheaKVStore.init(rheaOpts)) {
LOG.error("Fail to init [RheaKVStore].");
return false;
}
this.placementDriverService = new DefaultPlacementDriverService(this.rheaKVStore);
if (!this.placementDriverService.init(opts)) {
LOG.error("Fail to init [PlacementDriverService].");
return false;
}
final StoreEngine storeEngine = ((DefaultRheaKVStore) this.rheaKVStore).getStoreEngine();
Requires.requireNonNull(storeEngine, "storeEngine");
final List<RegionEngine> regionEngines = storeEngine.getAllRegionEngines();
if (regionEngines.isEmpty()) {
throw new IllegalArgumentException("Non region for [PlacementDriverServer]");
}
if (regionEngines.size() > 1) {
throw new IllegalArgumentException("Only support single region for [PlacementDriverServer]");
}
this.regionEngine = regionEngines.get(0);
this.rheaKVStore.addLeaderStateListener(this.regionEngine.getRegion().getId(), ((DefaultPlacementDriverService) this.placementDriverService));
addPlacementDriverProcessor(storeEngine.getRpcServer());
LOG.info("[PlacementDriverServer] start successfully, options: {}.", opts);
return this.started = true;
}
Aggregations