Search in sources :

Example 1 with GetLocationResponse

use of io.dingodb.server.coordinator.handler.GetLocationHandler.GetLocationResponse in project dingo by dingodb.

the class CoordinatorStateMachine method getLeaderLocation.

private void getLeaderLocation(Channel channel) {
    try {
        GetLocationResponse res = (GetLocationResponse) rpcClient.invokeSync(context.node().getLeaderId().getEndpoint(), GetLocationRequest.INSTANCE, 3000);
        channel.send(SimpleMessage.builder().content(encodeHostPort(res.getHost(), res.getPort())).build());
    } catch (IOException e) {
        log.error("Serialize location error", e);
        channel.send(EmptyMessage.INSTANCE);
    } catch (RemotingException e) {
        log.error("Get leader peer location error", e);
        channel.send(EmptyMessage.INSTANCE);
    } catch (InterruptedException e) {
        log.error("Get leader location interrupt.", e);
        channel.send(EmptyMessage.INSTANCE);
    } catch (Exception e) {
        log.error("Get leader location error.", e);
        channel.send(EmptyMessage.INSTANCE);
    }
}
Also used : RemotingException(io.dingodb.raft.error.RemotingException) 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)

Example 2 with GetLocationResponse

use of io.dingodb.server.coordinator.handler.GetLocationHandler.GetLocationResponse 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

RemotingException (io.dingodb.raft.error.RemotingException)2 GetLocationResponse (io.dingodb.server.coordinator.handler.GetLocationHandler.GetLocationResponse)2 IllegalRowStoreOperationException (io.dingodb.store.row.errors.IllegalRowStoreOperationException)2 StoreCodecException (io.dingodb.store.row.errors.StoreCodecException)2 IOException (java.io.IOException)2 SimpleMessage (io.dingodb.net.SimpleMessage)1 PeerId (io.dingodb.raft.entity.PeerId)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1