use of com.github.ambry.server.ServerErrorCode in project ambry by linkedin.
the class BlobValidator method getRecordFromNode.
/**
* Gets the {@link ServerResponse} from {@code dataNodeId} for {@code blobId}.
* @param dataNodeId the {@link DataNodeId} to query.
* @param blobId the {@link BlobId} to operate on.
* @param getOption the {@link GetOption} to use with the {@link com.github.ambry.protocol.GetRequest}.
* @param clusterMap the {@link ClusterMap} instance to use.
* @param storeKeyFactory the {@link StoreKeyFactory} to use.
* @return the {@link ServerResponse} from {@code dataNodeId} for {@code blobId}.
* @throws InterruptedException
*/
private ServerResponse getRecordFromNode(DataNodeId dataNodeId, BlobId blobId, GetOption getOption, ClusterMap clusterMap, StoreKeyFactory storeKeyFactory) throws InterruptedException {
LOGGER.debug("Getting {} from {}", blobId, dataNodeId);
ServerResponse serverResponse;
try {
Pair<ServerErrorCode, BlobAll> response = serverAdminTool.getAll(dataNodeId, blobId, getOption, clusterMap, storeKeyFactory);
ServerErrorCode errorCode = response.getFirst();
if (errorCode == ServerErrorCode.No_Error) {
BlobAll blobAll = response.getSecond();
ByteBuf buffer = blobAll.getBlobData().content();
byte[] blobBytes = new byte[buffer.readableBytes()];
buffer.readBytes(blobBytes);
buffer.release();
serverResponse = new ServerResponse(errorCode, blobAll.getStoreKey(), blobAll.getBlobInfo().getBlobProperties(), blobAll.getBlobInfo().getUserMetadata(), blobBytes, blobAll.getBlobEncryptionKey());
} else {
serverResponse = new ServerResponse(errorCode, null, null, null, null, null);
}
} catch (MessageFormatException e) {
LOGGER.error("Error while deserializing record for {} from {}", blobId, dataNodeId, e);
serverResponse = new ServerResponse(ServerErrorCode.Data_Corrupt, null, null, null, null, null);
} catch (Exception e) {
LOGGER.error("Error while getting record for {} from {}", blobId, dataNodeId, e);
serverResponse = new ServerResponse(ServerErrorCode.Unknown_Error, null, null, null, null, null);
} finally {
throttler.maybeThrottle(1);
}
LOGGER.debug("ServerError code is {} for blob {} from {}", serverResponse.serverErrorCode, blobId, dataNodeId);
return serverResponse;
}
use of com.github.ambry.server.ServerErrorCode in project ambry by linkedin.
the class BlobValidator method main.
/**
* Runs the BlobValidator
* @param args associated arguments.
* @throws Exception
*/
public static void main(String[] args) throws Exception {
VerifiableProperties verifiableProperties = ToolUtils.getVerifiableProperties(args);
BlobValidatorConfig config = new BlobValidatorConfig(verifiableProperties);
ClusterMapConfig clusterMapConfig = new ClusterMapConfig(verifiableProperties);
ClusterMap clusterMap = ((ClusterAgentsFactory) Utils.getObj(clusterMapConfig.clusterMapClusterAgentsFactory, clusterMapConfig, config.hardwareLayoutFilePath, config.partitionLayoutFilePath)).getClusterMap();
List<BlobId> blobIds = getBlobIds(config, clusterMap);
SSLFactory sslFactory = !clusterMapConfig.clusterMapSslEnabledDatacenters.isEmpty() ? SSLFactory.getNewInstance(new SSLConfig(verifiableProperties)) : null;
StoreKeyFactory storeKeyFactory = new BlobIdFactory(clusterMap);
BlobValidator validator = new BlobValidator(clusterMap, config.replicasToContactPerSec, sslFactory, verifiableProperties);
LOGGER.info("Validation starting");
switch(config.typeOfOperation) {
case ValidateBlobOnAllReplicas:
Map<BlobId, List<String>> mismatchDetailsMap = validator.validateBlobsOnAllReplicas(blobIds, config.getOption, clusterMap, storeKeyFactory);
logMismatches(mismatchDetailsMap);
break;
case ValidateBlobOnDatacenter:
if (config.datacenter.isEmpty() || !clusterMap.hasDatacenter(config.datacenter)) {
throw new IllegalArgumentException("Please provide a valid datacenter");
}
mismatchDetailsMap = validator.validateBlobsOnDatacenter(config.datacenter, blobIds, config.getOption, clusterMap, storeKeyFactory);
logMismatches(mismatchDetailsMap);
break;
case ValidateBlobOnReplica:
DataNodeId dataNodeId = clusterMap.getDataNodeId(config.hostname, config.port);
if (dataNodeId == null) {
throw new IllegalArgumentException("Could not find a data node corresponding to " + config.hostname + ":" + config.port);
}
List<ServerErrorCode> validErrorCodes = Arrays.asList(ServerErrorCode.No_Error, ServerErrorCode.Blob_Deleted, ServerErrorCode.Blob_Expired);
Map<BlobId, ServerErrorCode> blobIdToErrorCode = validator.validateBlobsOnReplica(dataNodeId, blobIds, config.getOption, clusterMap, storeKeyFactory);
for (Map.Entry<BlobId, ServerErrorCode> entry : blobIdToErrorCode.entrySet()) {
ServerErrorCode errorCode = entry.getValue();
if (!validErrorCodes.contains(errorCode)) {
LOGGER.error("[{}] received error code: {}", entry.getKey(), errorCode);
}
}
break;
default:
throw new IllegalStateException("Recognized but unsupported operation: " + config.typeOfOperation);
}
LOGGER.info("Validation complete");
validator.close();
clusterMap.close();
}
use of com.github.ambry.server.ServerErrorCode in project ambry by linkedin.
the class ServerAdminTool method getBlobProperties.
/**
* Gets {@link BlobProperties} for {@code blobId}.
* @param dataNodeId the {@link DataNodeId} to contact.
* @param blobId the {@link BlobId} to operate on.
* @param getOption the {@link GetOption} to send with the {@link GetRequest}.
* @param clusterMap the {@link ClusterMap} to use.
* @return the {@link ServerErrorCode} and {@link BlobProperties} of {@code blobId}.
* @throws Exception
*/
public Pair<ServerErrorCode, BlobProperties> getBlobProperties(DataNodeId dataNodeId, BlobId blobId, GetOption getOption, ClusterMap clusterMap) throws Exception {
Pair<ServerErrorCode, InputStream> response = getGetResponse(dataNodeId, blobId, MessageFormatFlags.BlobProperties, getOption, clusterMap);
InputStream stream = response.getSecond();
BlobProperties blobProperties = stream != null ? MessageFormatRecord.deserializeBlobProperties(stream) : null;
return new Pair<>(response.getFirst(), blobProperties);
}
use of com.github.ambry.server.ServerErrorCode in project ambry by linkedin.
the class ServerAdminTool method getUserMetadata.
/**
* Gets user metadata for {@code blobId}.
* @param dataNodeId the {@link DataNodeId} to contact.
* @param blobId the {@link BlobId} to operate on.
* @param getOption the {@link GetOption} to send with the {@link GetRequest}.
* @param clusterMap the {@link ClusterMap} to use.
* @return the {@link ServerErrorCode} and user metadata as a {@link ByteBuffer} for {@code blobId}
* @throws Exception
*/
public Pair<ServerErrorCode, ByteBuffer> getUserMetadata(DataNodeId dataNodeId, BlobId blobId, GetOption getOption, ClusterMap clusterMap) throws Exception {
Pair<ServerErrorCode, InputStream> response = getGetResponse(dataNodeId, blobId, MessageFormatFlags.BlobUserMetadata, getOption, clusterMap);
InputStream stream = response.getSecond();
ByteBuffer userMetadata = stream != null ? MessageFormatRecord.deserializeUserMetadata(stream) : null;
return new Pair<>(response.getFirst(), userMetadata);
}
use of com.github.ambry.server.ServerErrorCode in project ambry by linkedin.
the class ServerAdminTool method getAll.
/**
* Gets all data for {@code blobId}.
* @param dataNodeId the {@link DataNodeId} to contact.
* @param blobId the {@link BlobId} to operate on.
* @param getOption the {@link GetOption} to send with the {@link GetRequest}.
* @param clusterMap the {@link ClusterMap} to use.
* @param storeKeyFactory the {@link StoreKeyFactory} to use.
* @return the {@link ServerErrorCode} and {@link BlobAll} for {@code blobId}
* @throws Exception
*/
public Pair<ServerErrorCode, BlobAll> getAll(DataNodeId dataNodeId, BlobId blobId, GetOption getOption, ClusterMap clusterMap, StoreKeyFactory storeKeyFactory) throws Exception {
Pair<ServerErrorCode, InputStream> response = getGetResponse(dataNodeId, blobId, MessageFormatFlags.All, getOption, clusterMap);
InputStream stream = response.getSecond();
BlobAll blobAll = stream != null ? MessageFormatRecord.deserializeBlobAll(stream, storeKeyFactory) : null;
return new Pair<>(response.getFirst(), blobAll);
}
Aggregations