Search in sources :

Example 6 with Replica

use of org.apache.asterix.common.replication.Replica in project asterixdb by apache.

the class ReplicationManager method checkReplicaState.

/**
     * Checks the state of a remote replica by trying to ping it.
     *
     * @param replicaId
     *            The replica to check the state for.
     * @param async
     *            a flag indicating whether to wait for the result or not.
     * @param suspendReplication
     *            a flag indicating whether to suspend replication on replica state change or not.
     */
private void checkReplicaState(String replicaId, boolean async, boolean suspendReplication) {
    Replica replica = replicas.get(replicaId);
    ReplicaStateChecker connector = new ReplicaStateChecker(replica, replicationProperties.getReplicationTimeOut(), this, replicationProperties, suspendReplication);
    Future<? extends Object> ft = asterixAppRuntimeContextProvider.getThreadExecutor().submit(connector);
    if (!async) {
        //wait until task is done
        while (!ft.isDone()) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }
    }
}
Also used : Replica(org.apache.asterix.common.replication.Replica)

Example 7 with Replica

use of org.apache.asterix.common.replication.Replica in project asterixdb by apache.

the class ReplicationManager method updateReplicaInfo.

@Override
public synchronized void updateReplicaInfo(Replica replicaNode) {
    Replica replica = replicas.get(replicaNode.getNode().getId());
    //should not update the info of an active replica
    if (replica.getState() == ReplicaState.ACTIVE) {
        return;
    }
    replica.getNode().setClusterIp(replicaNode.getNode().getClusterIp());
}
Also used : Replica(org.apache.asterix.common.replication.Replica)

Example 8 with Replica

use of org.apache.asterix.common.replication.Replica in project asterixdb by apache.

the class ReplicationManager method sendShutdownNotifiction.

/**
     * Sends a shutdown event to remote replicas notifying them
     * no more logs/files will be sent from this local replica.
     *
     * @throws IOException
     */
private void sendShutdownNotifiction() throws IOException {
    Node node = new Node();
    node.setId(nodeId);
    node.setClusterIp(NetworkingUtil.getHostAddress(hostIPAddressFirstOctet));
    Replica replica = new Replica(node);
    ReplicaEvent event = new ReplicaEvent(replica, ClusterEventType.NODE_SHUTTING_DOWN);
    ByteBuffer buffer = ReplicationProtocol.writeReplicaEventRequest(event);
    Map<String, SocketChannel> replicaSockets = getActiveRemoteReplicasSockets();
    sendRequest(replicaSockets, buffer);
    closeReplicaSockets(replicaSockets);
}
Also used : SocketChannel(java.nio.channels.SocketChannel) Node(org.apache.asterix.event.schema.cluster.Node) Replica(org.apache.asterix.common.replication.Replica) ReplicaEvent(org.apache.asterix.common.replication.ReplicaEvent) ByteBuffer(java.nio.ByteBuffer)

Example 9 with Replica

use of org.apache.asterix.common.replication.Replica in project asterixdb by apache.

the class ReplicaEventMessage method handle.

@Override
public void handle(INcApplicationContext appContext) throws HyracksDataException, InterruptedException {
    Node node = new Node();
    node.setId(nodeId);
    node.setClusterIp(nodeIPAddress);
    Replica replica = new Replica(node);
    appContext.getReplicationManager().reportReplicaEvent(new ReplicaEvent(replica, event));
}
Also used : Node(org.apache.asterix.event.schema.cluster.Node) Replica(org.apache.asterix.common.replication.Replica) ReplicaEvent(org.apache.asterix.common.replication.ReplicaEvent)

Aggregations

Replica (org.apache.asterix.common.replication.Replica)9 SocketChannel (java.nio.channels.SocketChannel)3 ReplicaEvent (org.apache.asterix.common.replication.ReplicaEvent)3 HashMap (java.util.HashMap)2 Node (org.apache.asterix.event.schema.cluster.Node)2 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Level (java.util.logging.Level)1 Logger (java.util.logging.Logger)1 Collectors (java.util.stream.Collectors)1 BindMetadataNodeTask (org.apache.asterix.app.nc.task.BindMetadataNodeTask)1 CheckpointTask (org.apache.asterix.app.nc.task.CheckpointTask)1