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();
}
}
}
}
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);
}
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;
}
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;
}
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;
}
Aggregations