Search in sources :

Example 71 with PeerId

use of io.dingodb.raft.entity.PeerId in project dingo by dingodb.

the class DefaultDingoRowStoreCliService method rangeSplit.

@Override
public Status rangeSplit(final String regionId, final String newRegionId, final String groupId, final Configuration conf) {
    final PeerId leaderId = new PeerId();
    final Status st = this.cliService.getLeader(groupId, conf, leaderId);
    if (!st.isOk()) {
        throw new IllegalStateException(st.getErrorMsg());
    }
    final RangeSplitRequest request = new RangeSplitRequest();
    request.setRegionId(regionId);
    request.setNewRegionId(newRegionId);
    try {
        final BaseResponse<?> response = (BaseResponse<?>) this.rpcClient.invokeSync(leaderId.getEndpoint(), request, this.opts.getTimeoutMs());
        if (response.isSuccess()) {
            return Status.OK();
        }
        return new Status(-1, "Fail to range split on region %d, error: %s", regionId, response);
    } catch (final Exception e) {
        LOG.error("Fail to range split on exception: {}.", StackTraceUtil.stackTrace(e));
        return new Status(-1, "fail to range split on region %d", regionId);
    }
}
Also used : Status(io.dingodb.raft.Status) BaseResponse(io.dingodb.store.row.cmd.store.BaseResponse) RangeSplitRequest(io.dingodb.store.row.cmd.store.RangeSplitRequest) PeerId(io.dingodb.raft.entity.PeerId)

Example 72 with PeerId

use of io.dingodb.raft.entity.PeerId in project dingo by dingodb.

the class CoordinatorStateMachine method getAllLocation.

private void getAllLocation(Channel channel) {
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
        List<PeerId> peerIds = context.node().listPeers();
        baos.write(PrimitiveCodec.encodeVarInt(peerIds.size()));
        for (PeerId peerId : peerIds) {
            GetLocationResponse res = (GetLocationResponse) rpcClient.invokeSync(peerId.getEndpoint(), GetLocationRequest.INSTANCE, 3000);
            baos.write(encodeHostPort(res.getHost(), res.getPort()));
        }
        baos.flush();
        channel.send(new SimpleMessage(null, baos.toByteArray()));
    } catch (IOException e) {
        log.error("Serialize leader location error", e);
        channel.send(EmptyMessage.INSTANCE);
    } catch (RemotingException e) {
        log.error("Get peer location error", e);
        channel.send(EmptyMessage.INSTANCE);
    } catch (InterruptedException e) {
        log.error("Get all location interrupt.", e);
        channel.send(EmptyMessage.INSTANCE);
    } catch (Exception e) {
        log.error("Get leader location error.", e);
        channel.send(EmptyMessage.INSTANCE);
    }
}
Also used : SimpleMessage(io.dingodb.net.SimpleMessage) RemotingException(io.dingodb.raft.error.RemotingException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) GetLocationResponse(io.dingodb.server.coordinator.handler.GetLocationHandler.GetLocationResponse) StoreCodecException(io.dingodb.store.row.errors.StoreCodecException) RemotingException(io.dingodb.raft.error.RemotingException) IOException(java.io.IOException) IllegalRowStoreOperationException(io.dingodb.store.row.errors.IllegalRowStoreOperationException) PeerId(io.dingodb.raft.entity.PeerId)

Aggregations

PeerId (io.dingodb.raft.entity.PeerId)72 Status (io.dingodb.raft.Status)27 Configuration (io.dingodb.raft.conf.Configuration)15 Message (com.google.protobuf.Message)12 ArrayList (java.util.ArrayList)12 JRaftException (io.dingodb.raft.error.JRaftException)10 LogId (io.dingodb.raft.entity.LogId)9 CliRequests (io.dingodb.raft.rpc.CliRequests)8 Node (io.dingodb.raft.Node)6 RpcRequests (io.dingodb.raft.rpc.RpcRequests)4 Endpoint (io.dingodb.raft.util.Endpoint)4 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)4 LogEntry (io.dingodb.raft.entity.LogEntry)3 NodeOptions (io.dingodb.raft.option.NodeOptions)3 ByteBuffer (java.nio.ByteBuffer)3 TimeoutException (java.util.concurrent.TimeoutException)3 RaftOutter (io.dingodb.raft.entity.RaftOutter)2 RaftException (io.dingodb.raft.error.RaftException)2 ThreadId (io.dingodb.raft.util.ThreadId)2 ExecutionException (java.util.concurrent.ExecutionException)2