use of com.alipay.sofa.jraft.rhea.options.RheaKVStoreOptions in project sofa-jraft by sofastack.
the class Server1 method main.
public static void main(final String[] args) {
final PlacementDriverOptions pdOpts = PlacementDriverOptionsConfigured.newConfigured().withFake(// use a fake pd
true).config();
final StoreEngineOptions storeOpts = //
StoreEngineOptionsConfigured.newConfigured().withStorageType(StorageType.RocksDB).withRocksDBOptions(RocksDBOptionsConfigured.newConfigured().withDbPath(Configs.DB_PATH).config()).withRaftDataPath(Configs.RAFT_DATA_PATH).withServerAddress(new Endpoint("127.0.0.1", 8181)).config();
final RheaKVStoreOptions opts = //
RheaKVStoreOptionsConfigured.newConfigured().withClusterName(//
Configs.CLUSTER_NAME).withUseParallelCompress(//
true).withInitialServerList(Configs.ALL_NODE_ADDRESSES).withStoreEngineOptions(//
storeOpts).withPlacementDriverOptions(//
pdOpts).config();
System.out.println(opts);
final Node node = new Node(opts);
node.start();
Runtime.getRuntime().addShutdownHook(new Thread(node::stop));
System.out.println("server1 start OK");
}
use of com.alipay.sofa.jraft.rhea.options.RheaKVStoreOptions in project sofa-jraft by sofastack.
the class Yaml method readConfig.
public static RheaKVStoreOptions readConfig(final String name) {
final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
final RheaKVStoreOptions opts;
try {
opts = mapper.readValue(new File(name), RheaKVStoreOptions.class);
System.out.println(opts);
} catch (IOException e) {
throw new RuntimeException(e);
}
return opts;
}
use of com.alipay.sofa.jraft.rhea.options.RheaKVStoreOptions in project sofa-jraft by sofastack.
the class Client method init.
public void init() {
final List<RegionRouteTableOptions> regionRouteTableOptionsList = MultiRegionRouteTableOptionsConfigured.newConfigured().withInitialServerList(-1L, /* default id */
Configs.ALL_NODE_ADDRESSES).config();
final PlacementDriverOptions pdOpts = //
PlacementDriverOptionsConfigured.newConfigured().withFake(//
true).withRegionRouteTableOptionsList(//
regionRouteTableOptionsList).config();
final RheaKVStoreOptions opts = //
RheaKVStoreOptionsConfigured.newConfigured().withClusterName(//
Configs.CLUSTER_NAME).withPlacementDriverOptions(//
pdOpts).config();
System.out.println(opts);
rheaKVStore.init(opts);
}
use of com.alipay.sofa.jraft.rhea.options.RheaKVStoreOptions in project sofa-jraft by sofastack.
the class YamlTest method parseStoreEngineOptionsTest.
@Test
public void parseStoreEngineOptionsTest() throws IOException {
final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
final InputStream in = YamlTest.class.getResourceAsStream("/conf/rhea_test_cluster_1.yaml");
final RheaKVStoreOptions opts = mapper.readValue(in, RheaKVStoreOptions.class);
System.out.println(opts);
}
use of com.alipay.sofa.jraft.rhea.options.RheaKVStoreOptions 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