Search in sources :

Example 1 with ReplicaId

use of com.github.ambry.clustermap.ReplicaId in project ambry by linkedin.

the class ReplicaThread method replicate.

/**
 * Replicas from the given replicas
 * @param replicasToReplicate list of {@link RemoteReplicaInfo} by data node
 */
void replicate(List<List<RemoteReplicaInfo>> replicasToReplicate) {
    // shuffle the nodes
    Collections.shuffle(replicasToReplicate);
    for (List<RemoteReplicaInfo> replicasToReplicatePerNode : replicasToReplicate) {
        if (!running) {
            break;
        }
        DataNodeId remoteNode = replicasToReplicatePerNode.get(0).getReplicaId().getDataNodeId();
        logger.trace("Remote node: {} Thread name: {} Remote replicas: {}", remoteNode, threadName, replicasToReplicatePerNode);
        Timer.Context context = null;
        Timer.Context portTypeBasedContext = null;
        if (replicatingFromRemoteColo) {
            context = replicationMetrics.interColoReplicationLatency.get(remoteNode.getDatacenterName()).time();
            if (replicatingOverSsl) {
                portTypeBasedContext = replicationMetrics.sslInterColoReplicationLatency.get(remoteNode.getDatacenterName()).time();
            } else {
                portTypeBasedContext = replicationMetrics.plainTextInterColoReplicationLatency.get(remoteNode.getDatacenterName()).time();
            }
        } else {
            context = replicationMetrics.intraColoReplicationLatency.time();
            if (replicatingOverSsl) {
                portTypeBasedContext = replicationMetrics.sslIntraColoReplicationLatency.time();
            } else {
                portTypeBasedContext = replicationMetrics.plainTextIntraColoReplicationLatency.time();
            }
        }
        ConnectedChannel connectedChannel = null;
        long checkoutConnectionTimeInMs = -1;
        long exchangeMetadataTimeInMs = -1;
        long fixMissingStoreKeysTimeInMs = -1;
        long replicationStartTimeInMs = SystemTime.getInstance().milliseconds();
        long startTimeInMs = replicationStartTimeInMs;
        List<RemoteReplicaInfo> activeReplicasPerNode = new ArrayList<RemoteReplicaInfo>();
        for (RemoteReplicaInfo remoteReplicaInfo : replicasToReplicatePerNode) {
            ReplicaId replicaId = remoteReplicaInfo.getReplicaId();
            if (!replicationDisabledPartitions.contains(replicaId.getPartitionId()) && !replicaId.isDown()) {
                activeReplicasPerNode.add(remoteReplicaInfo);
            }
        }
        if (activeReplicasPerNode.size() > 0) {
            try {
                connectedChannel = connectionPool.checkOutConnection(remoteNode.getHostname(), activeReplicasPerNode.get(0).getPort(), replicationConfig.replicationConnectionPoolCheckoutTimeoutMs);
                checkoutConnectionTimeInMs = SystemTime.getInstance().milliseconds() - startTimeInMs;
                startTimeInMs = SystemTime.getInstance().milliseconds();
                List<ExchangeMetadataResponse> exchangeMetadataResponseList = exchangeMetadata(connectedChannel, activeReplicasPerNode);
                exchangeMetadataTimeInMs = SystemTime.getInstance().milliseconds() - startTimeInMs;
                startTimeInMs = SystemTime.getInstance().milliseconds();
                fixMissingStoreKeys(connectedChannel, activeReplicasPerNode, exchangeMetadataResponseList);
                fixMissingStoreKeysTimeInMs = SystemTime.getInstance().milliseconds() - startTimeInMs;
            } catch (Throwable e) {
                if (checkoutConnectionTimeInMs == -1) {
                    // throwable happened in checkout connection phase
                    checkoutConnectionTimeInMs = SystemTime.getInstance().milliseconds() - startTimeInMs;
                    responseHandler.onEvent(activeReplicasPerNode.get(0).getReplicaId(), e);
                } else if (exchangeMetadataTimeInMs == -1) {
                    // throwable happened in exchange metadata phase
                    exchangeMetadataTimeInMs = SystemTime.getInstance().milliseconds() - startTimeInMs;
                } else if (fixMissingStoreKeysTimeInMs == -1) {
                    // throwable happened in fix missing store phase
                    fixMissingStoreKeysTimeInMs = SystemTime.getInstance().milliseconds() - startTimeInMs;
                }
                logger.error("Error while talking to peer: Remote node: {}, Thread name: {}, Remote replicas: {}, Active " + "remote replicas: {}, Checkout connection time: {}, Exchange metadata time: {}, Fix missing store key " + "time {}", remoteNode, threadName, replicasToReplicatePerNode, activeReplicasPerNode, checkoutConnectionTimeInMs, exchangeMetadataTimeInMs, fixMissingStoreKeysTimeInMs, e);
                replicationMetrics.incrementReplicationErrors(replicatingOverSsl);
                if (connectedChannel != null) {
                    connectionPool.destroyConnection(connectedChannel);
                    connectedChannel = null;
                }
            } finally {
                long totalReplicationTime = SystemTime.getInstance().milliseconds() - replicationStartTimeInMs;
                replicationMetrics.updateTotalReplicationTime(totalReplicationTime, replicatingFromRemoteColo, replicatingOverSsl, datacenterName);
                if (connectedChannel != null) {
                    connectionPool.checkInConnection(connectedChannel);
                }
                context.stop();
                portTypeBasedContext.stop();
            }
        }
    }
}
Also used : Timer(com.codahale.metrics.Timer) ArrayList(java.util.ArrayList) ConnectedChannel(com.github.ambry.network.ConnectedChannel) DataNodeId(com.github.ambry.clustermap.DataNodeId) ReplicaId(com.github.ambry.clustermap.ReplicaId)

Example 2 with ReplicaId

use of com.github.ambry.clustermap.ReplicaId in project ambry by linkedin.

the class ReplicationMetrics method addRemoteReplicaToLagMetrics.

public void addRemoteReplicaToLagMetrics(final RemoteReplicaInfo remoteReplicaInfo) {
    ReplicaId replicaId = remoteReplicaInfo.getReplicaId();
    DataNodeId dataNodeId = replicaId.getDataNodeId();
    final String metricName = dataNodeId.getHostname() + "-" + dataNodeId.getPort() + "-" + replicaId.getPartitionId() + "-replicaLagInBytes";
    Gauge<Long> replicaLag = new Gauge<Long>() {

        @Override
        public Long getValue() {
            return remoteReplicaInfo.getRemoteLagFromLocalInBytes();
        }
    };
    registry.register(MetricRegistry.name(ReplicationMetrics.class, metricName), replicaLag);
    replicaLagInBytes.add(replicaLag);
}
Also used : DataNodeId(com.github.ambry.clustermap.DataNodeId) ReplicaId(com.github.ambry.clustermap.ReplicaId) Gauge(com.codahale.metrics.Gauge)

Example 3 with ReplicaId

use of com.github.ambry.clustermap.ReplicaId in project ambry by linkedin.

the class DeleteManager method extractDeleteResponseAndNotifyResponseHandler.

/**
 * Extract the {@link DeleteResponse} from the given {@link ResponseInfo}
 * @param responseInfo the {@link ResponseInfo} from which the {@link DeleteResponse} is to be extracted.
 * @return the extracted {@link DeleteResponse} if there is one; null otherwise.
 */
private DeleteResponse extractDeleteResponseAndNotifyResponseHandler(ResponseInfo responseInfo) {
    DeleteResponse deleteResponse = null;
    ReplicaId replicaId = ((RouterRequestInfo) responseInfo.getRequestInfo()).getReplicaId();
    NetworkClientErrorCode networkClientErrorCode = responseInfo.getError();
    if (networkClientErrorCode == null) {
        try {
            deleteResponse = DeleteResponse.readFrom(new DataInputStream(new ByteBufferInputStream(responseInfo.getResponse())));
            responseHandler.onEvent(replicaId, deleteResponse.getError());
        } catch (Exception e) {
            // Ignore. There is no value in notifying the response handler.
            logger.error("Response deserialization received unexpected error", e);
            routerMetrics.responseDeserializationErrorCount.inc();
        }
    } else {
        responseHandler.onEvent(replicaId, networkClientErrorCode);
    }
    return deleteResponse;
}
Also used : DeleteResponse(com.github.ambry.protocol.DeleteResponse) NetworkClientErrorCode(com.github.ambry.network.NetworkClientErrorCode) ByteBufferInputStream(com.github.ambry.utils.ByteBufferInputStream) DataInputStream(java.io.DataInputStream) ReplicaId(com.github.ambry.clustermap.ReplicaId)

Example 4 with ReplicaId

use of com.github.ambry.clustermap.ReplicaId in project ambry by linkedin.

the class GetBlobResultInternal method extractGetResponseAndNotifyResponseHandler.

/**
 * Extract the {@link GetResponse} from the given {@link ResponseInfo}
 * @param responseInfo the {@link ResponseInfo} from which the {@link GetResponse} is to be extracted.
 * @return the extracted {@link GetResponse} if there is one; null otherwise.
 */
private GetResponse extractGetResponseAndNotifyResponseHandler(ResponseInfo responseInfo) {
    GetResponse getResponse = null;
    ReplicaId replicaId = ((RouterRequestInfo) responseInfo.getRequestInfo()).getReplicaId();
    NetworkClientErrorCode networkClientErrorCode = responseInfo.getError();
    if (networkClientErrorCode == null) {
        try {
            getResponse = GetResponse.readFrom(new DataInputStream(new ByteBufferInputStream(responseInfo.getResponse())), clusterMap);
            ServerErrorCode serverError = getResponse.getError();
            if (serverError == ServerErrorCode.No_Error) {
                serverError = getResponse.getPartitionResponseInfoList().get(0).getErrorCode();
            }
            responseHandler.onEvent(replicaId, serverError);
        } catch (Exception e) {
            // Ignore. There is no value in notifying the response handler.
            logger.error("Response deserialization received unexpected error", e);
            routerMetrics.responseDeserializationErrorCount.inc();
        }
    } else {
        responseHandler.onEvent(replicaId, networkClientErrorCode);
    }
    return getResponse;
}
Also used : NetworkClientErrorCode(com.github.ambry.network.NetworkClientErrorCode) ByteBufferInputStream(com.github.ambry.utils.ByteBufferInputStream) DataInputStream(java.io.DataInputStream) GetResponse(com.github.ambry.protocol.GetResponse) ReplicaId(com.github.ambry.clustermap.ReplicaId) ServerErrorCode(com.github.ambry.commons.ServerErrorCode)

Example 5 with ReplicaId

use of com.github.ambry.clustermap.ReplicaId in project ambry by linkedin.

the class PutManager method extractPutResponseAndNotifyResponseHandler.

/**
 * Extract the {@link PutResponse} from the given {@link ResponseInfo}
 * @param responseInfo the {@link ResponseInfo} from which the {@link PutResponse} is to be extracted.
 * @return the extracted {@link PutResponse} if there is one; null otherwise.
 */
private PutResponse extractPutResponseAndNotifyResponseHandler(ResponseInfo responseInfo) {
    PutResponse putResponse = null;
    ReplicaId replicaId = ((RouterRequestInfo) responseInfo.getRequestInfo()).getReplicaId();
    NetworkClientErrorCode networkClientErrorCode = responseInfo.getError();
    if (networkClientErrorCode == null) {
        try {
            putResponse = PutResponse.readFrom(new DataInputStream(new ByteBufferInputStream(responseInfo.getResponse())));
            responseHandler.onEvent(replicaId, putResponse.getError());
        } catch (Exception e) {
            // Ignore. There is no value in notifying the response handler.
            logger.error("Response deserialization received unexpected error", e);
            routerMetrics.responseDeserializationErrorCount.inc();
        }
    } else {
        responseHandler.onEvent(replicaId, networkClientErrorCode);
    }
    return putResponse;
}
Also used : NetworkClientErrorCode(com.github.ambry.network.NetworkClientErrorCode) ByteBufferInputStream(com.github.ambry.utils.ByteBufferInputStream) PutResponse(com.github.ambry.protocol.PutResponse) DataInputStream(java.io.DataInputStream) ReplicaId(com.github.ambry.clustermap.ReplicaId)

Aggregations

ReplicaId (com.github.ambry.clustermap.ReplicaId)147 Test (org.junit.Test)83 PartitionId (com.github.ambry.clustermap.PartitionId)68 MockPartitionId (com.github.ambry.clustermap.MockPartitionId)60 MockReplicaId (com.github.ambry.clustermap.MockReplicaId)57 ArrayList (java.util.ArrayList)55 MockDataNodeId (com.github.ambry.clustermap.MockDataNodeId)43 DataNodeId (com.github.ambry.clustermap.DataNodeId)32 MockClusterMap (com.github.ambry.clustermap.MockClusterMap)31 MetricRegistry (com.codahale.metrics.MetricRegistry)29 HashMap (java.util.HashMap)28 HashSet (java.util.HashSet)25 ClusterMapConfig (com.github.ambry.config.ClusterMapConfig)24 VerifiableProperties (com.github.ambry.config.VerifiableProperties)24 BlobStoreTest (com.github.ambry.store.BlobStoreTest)24 File (java.io.File)24 List (java.util.List)21 Map (java.util.Map)21 Port (com.github.ambry.network.Port)20 Properties (java.util.Properties)20