use of io.dingodb.raft.util.Endpoint in project dingo by dingodb.
the class RowStoreMetaAdaptorImpl method mapping.
public Store mapping(ExecutorView executorView) {
if (executorView == null) {
return null;
}
Store store = new Store();
store.setEndpoint(new Endpoint(executorView.location().getHost(), executorView.location().getPort()));
store.setId(executorView.resourceId().toString());
store.setLabels(executorView.labels().entrySet().stream().map(e -> new StoreLabel(e.getKey(), e.getValue())).collect(Collectors.toList()));
store.setRegions(executorView.apps().stream().map(id -> scheduleMetaAdaptor.namespace().<RegionApp>getApp(id)).map(this::mapping).collect(Collectors.toList()));
return store;
}
use of io.dingodb.raft.util.Endpoint in project dingo by dingodb.
the class BoltRaftRpcFactory method createRpcServer.
@Override
public RpcServer createRpcServer(final Endpoint endpoint, final ConfigHelper<RpcServer> helper) {
final int port = Requires.requireNonNull(endpoint, "endpoint").getPort();
Requires.requireTrue(port > 0 && port < 0xFFFF, "port out of range:" + port);
final com.alipay.remoting.rpc.RpcServer boltImpl = new com.alipay.remoting.rpc.RpcServer(port, true, false);
final RpcServer rpcServer = new BoltRpcServer(boltImpl);
if (helper != null) {
helper.config(rpcServer);
}
return rpcServer;
}
use of io.dingodb.raft.util.Endpoint in project dingo by dingodb.
the class RemoteFileCopier method init.
public boolean init(String uri, final SnapshotThrottle snapshotThrottle, final SnapshotCopierOptions opts) {
this.rpcService = opts.getRaftClientService();
this.timerManager = opts.getTimerManager();
this.raftOptions = opts.getRaftOptions();
this.snapshotThrottle = snapshotThrottle;
final int prefixSize = Snapshot.REMOTE_SNAPSHOT_URI_SCHEME.length();
if (uri == null || !uri.startsWith(Snapshot.REMOTE_SNAPSHOT_URI_SCHEME)) {
LOG.error("Invalid uri {}.", uri);
return false;
}
uri = uri.substring(prefixSize);
final int slasPos = uri.indexOf('/');
final String ipAndPort = uri.substring(0, slasPos);
uri = uri.substring(slasPos + 1);
try {
this.readId = Long.parseLong(uri);
final String[] ipAndPortStrs = ipAndPort.split(":");
this.endpoint = new Endpoint(ipAndPortStrs[0], Integer.parseInt(ipAndPortStrs[1]));
} catch (final Exception e) {
LOG.error("Fail to parse readerId or endpoint.", e);
return false;
}
if (!this.rpcService.connect(this.endpoint)) {
LOG.error("Fail to init channel to {}.", this.endpoint);
return false;
}
return true;
}
use of io.dingodb.raft.util.Endpoint in project dingo by dingodb.
the class MetadataRpcClient method internalGetStoreInfo.
private void internalGetStoreInfo(final long clusterId, final Endpoint selfEndpoint, final CompletableFuture<Store> future, final int retriesLeft, final Errors lastCause) {
final RetryRunner retryRunner = retryCause -> internalGetStoreInfo(clusterId, selfEndpoint, future, retriesLeft - 1, retryCause);
final FailoverClosure<Store> closure = new FailoverClosureImpl<>(future, retriesLeft, retryRunner);
final GetStoreInfoRequest request = new GetStoreInfoRequest();
request.setClusterId(clusterId);
request.setEndpoint(selfEndpoint);
this.pdRpcService.callPdServerWithRpc(request, closure, lastCause);
}
use of io.dingodb.raft.util.Endpoint 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;
}
Aggregations