Search in sources :

Example 1 with SimpleMessage

use of io.dingodb.net.SimpleMessage 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

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