use of io.dingodb.store.row.options.StoreEngineOptions in project dingo by dingodb.
the class RemotePlacementDriverClient method getStoreMetadata.
@Override
public Store getStoreMetadata(final StoreEngineOptions opts) {
final Endpoint selfEndpoint = opts.getServerAddress();
/**
* for debugger.
*/
for (RegionEngineOptions opt : opts.getRegionEngineOptionsList()) {
LOG.info("RegionEngineOptions-before: update from local conf. opt:{}", opt.toString());
}
// remote conf is the preferred
final Store remoteStore = this.metadataRpcClient.getStoreInfo(this.clusterId, selfEndpoint);
if (!remoteStore.isEmpty()) {
final List<Region> regions = remoteStore.getRegions();
Long metricsReportPeriodMs = opts.getMetricsReportPeriod();
if (opts.getRegionEngineOptionsList() != null && opts.getRegionEngineOptionsList().size() > 0) {
metricsReportPeriodMs = opts.getRegionEngineOptionsList().get(0).getMetricsReportPeriod();
}
opts.getRegionEngineOptionsList().clear();
for (final Region region : regions) {
super.regionRouteTable.addOrUpdateRegion(region);
RegionEngineOptions engineOptions = new RegionEngineOptions();
engineOptions.setRegionId(region.getId());
engineOptions.setStartKey(BytesUtil.readUtf8(region.getStartKey()));
engineOptions.setStartKeyBytes(region.getStartKey());
engineOptions.setEndKey(BytesUtil.readUtf8(region.getEndKey()));
engineOptions.setEndKeyBytes(region.getEndKey());
engineOptions.setNodeOptions(new NodeOptions());
engineOptions.setRaftGroupId(JRaftHelper.getJRaftGroupId(this.clusterName, region.getId()));
String raftDataPath = JRaftHelper.getRaftDataPath(opts.getRaftStoreOptions().getDataPath(), region.getId(), opts.getServerAddress().getPort());
engineOptions.setRaftDataPath(raftDataPath);
engineOptions.setServerAddress(opts.getServerAddress());
String initServerList = region.getPeers().stream().map(x -> x.getEndpoint().toString()).collect(Collectors.joining(","));
engineOptions.setInitialServerList(initServerList);
engineOptions.setMetricsReportPeriod(metricsReportPeriodMs);
opts.getRegionEngineOptionsList().add(engineOptions);
}
/**
* for debugger.
*/
for (RegionEngineOptions opt : opts.getRegionEngineOptionsList()) {
LOG.info("RegionEngineOptions-After: update from remote PD. opt:{}", opt.toString());
}
return remoteStore;
}
// local conf
final Store localStore = new Store();
final List<RegionEngineOptions> rOptsList = opts.getRegionEngineOptionsList();
final List<Region> regionList = Lists.newArrayListWithCapacity(rOptsList.size());
localStore.setId(remoteStore.getId());
localStore.setEndpoint(selfEndpoint);
for (final RegionEngineOptions rOpts : rOptsList) {
regionList.add(getLocalRegionMetadata(rOpts));
}
localStore.setRegions(regionList);
refreshStore(localStore);
return localStore;
}
use of io.dingodb.store.row.options.StoreEngineOptions in project dingo by dingodb.
the class DefaultDingoRowStore method init.
@Override
public synchronized boolean init(final DingoRowStoreOptions opts) {
if (this.started) {
LOG.info("[DefaultDingoRowStore] already started.");
return true;
}
DescriberManager.getInstance().addDescriber(RouteTable.getInstance());
this.opts = opts;
// init placement driver
final PlacementDriverOptions pdOpts = opts.getPlacementDriverOptions();
final String clusterName = opts.getClusterName();
Requires.requireNonNull(pdOpts, "opts.placementDriverOptions");
Requires.requireNonNull(clusterName, "opts.clusterName");
if (Strings.isBlank(pdOpts.getInitialServerList())) {
// if blank, extends parent's value
pdOpts.setInitialServerList(opts.getInitialServerList());
}
if (pdOpts.isFake()) {
this.pdClient = new FakePlacementDriverClient(opts.getClusterId(), clusterName);
} else {
this.pdClient = new RemotePlacementDriverClient(opts.getClusterId(), clusterName);
}
if (!this.pdClient.init(pdOpts)) {
LOG.error("Fail to init [PlacementDriverClient].");
return false;
}
// init compress strategies
ZipStrategyManager.init(opts);
// init store engine
final StoreEngineOptions stOpts = opts.getStoreEngineOptions();
if (stOpts != null) {
stOpts.setInitialServerList(opts.getInitialServerList());
this.storeEngine = new StoreEngine(this.pdClient, this.stateListenerContainer);
if (!this.storeEngine.init(stOpts)) {
LOG.error("Fail to init [StoreEngine].");
return false;
}
}
final Endpoint selfEndpoint = this.storeEngine == null ? null : this.storeEngine.getSelfEndpoint();
final RpcOptions rpcOpts = opts.getRpcOptions();
Requires.requireNonNull(rpcOpts, "opts.rpcOptions");
this.dingoRowStoreRpcService = new DefaultDingoRowStoreRpcService(this.pdClient, selfEndpoint) {
@Override
public Endpoint getLeader(final String regionId, final boolean forceRefresh, final long timeoutMillis) {
final Endpoint leader = getLeaderByRegionEngine(regionId);
if (leader != null) {
return leader;
}
return super.getLeader(regionId, forceRefresh, timeoutMillis);
}
};
if (!this.dingoRowStoreRpcService.init(rpcOpts)) {
LOG.error("Fail to init [DingoRowStoreRpcService].");
return false;
}
this.failoverRetries = opts.getFailoverRetries();
this.futureTimeoutMillis = opts.getFutureTimeoutMillis();
this.onlyLeaderRead = opts.isOnlyLeaderRead();
if (opts.isUseParallelKVExecutor()) {
final int numWorkers = Utils.cpus();
final int bufSize = numWorkers << 4;
final String name = "parallel-kv-executor";
final ThreadFactory threadFactory = Constants.THREAD_AFFINITY_ENABLED ? new AffinityNamedThreadFactory(name, true) : new NamedThreadFactory(name, true);
this.kvDispatcher = new TaskDispatcher(bufSize, numWorkers, WaitStrategyType.LITE_BLOCKING_WAIT, threadFactory);
}
this.batchingOpts = opts.getBatchingOptions();
if (this.batchingOpts.isAllowBatching()) {
this.getBatching = new GetBatching(KeyEvent::new, "get_batching", new GetBatchingHandler("get", false));
this.getBatchingOnlySafe = new GetBatching(KeyEvent::new, "get_batching_only_safe", new GetBatchingHandler("get_only_safe", true));
this.putBatching = new PutBatching(KVEvent::new, "put_batching", new PutBatchingHandler("put"));
}
LOG.info("[DefaultDingoRowStore] start successfully, options: {}.", opts);
return this.started = true;
}
Aggregations