use of voldemort.VoldemortException in project voldemort by voldemort.
the class AdminServiceRequestHandler method handleAsyncStatus.
public VAdminProto.AsyncOperationStatusResponse handleAsyncStatus(VAdminProto.AsyncOperationStatusRequest request) {
VAdminProto.AsyncOperationStatusResponse.Builder response = VAdminProto.AsyncOperationStatusResponse.newBuilder();
try {
int requestId = request.getRequestId();
AsyncOperationStatus operationStatus = asyncService.getOperationStatus(requestId);
boolean requestComplete = asyncService.isComplete(requestId);
response.setDescription(operationStatus.getDescription());
response.setComplete(requestComplete);
response.setStatus(operationStatus.getStatus());
response.setRequestId(requestId);
if (operationStatus.hasException()) {
String erroMessage = "HandleAsyncStatus received Exception: " + operationStatus.getException().getMessage();
Exception exception = operationStatus.getException();
if (exception instanceof VoldemortException) {
throw (VoldemortException) exception;
} else {
throw new VoldemortException(erroMessage, exception);
}
}
} catch (VoldemortException e) {
response.setError(ProtoUtils.encodeError(errorCodeMapper, e));
logger.error("handleAsyncStatus failed for request(" + request.toString().trim() + ")", e);
}
return response.build();
}
use of voldemort.VoldemortException in project voldemort by voldemort.
the class AdminServiceRequestHandler method handleGetROMaxVersionDir.
public VAdminProto.GetROMaxVersionDirResponse handleGetROMaxVersionDir(VAdminProto.GetROMaxVersionDirRequest request) {
final List<String> storeNames = request.getStoreNameList();
VAdminProto.GetROMaxVersionDirResponse.Builder response = VAdminProto.GetROMaxVersionDirResponse.newBuilder();
try {
for (String storeName : storeNames) {
ReadOnlyStorageEngine store = getReadOnlyStorageEngine(metadataStore, storeRepository, storeName);
File storeDirPath = new File(store.getStoreDirPath());
if (!storeDirPath.exists())
throw new VoldemortException("Unable to locate the directory of the read-only store " + storeName);
File[] versionDirs = ReadOnlyUtils.getVersionDirs(storeDirPath);
File[] kthDir = ReadOnlyUtils.findKthVersionedDir(versionDirs, versionDirs.length - 1, versionDirs.length - 1);
VAdminProto.ROStoreVersionDirMap storeResponse = VAdminProto.ROStoreVersionDirMap.newBuilder().setStoreName(storeName).setStoreDir(kthDir[0].getAbsolutePath()).build();
response.addRoStoreVersions(storeResponse);
}
} catch (VoldemortException e) {
response.setError(ProtoUtils.encodeError(errorCodeMapper, e));
logger.error("handleGetROMaxVersion failed for request(" + request.toString() + ")", e);
}
return response.build();
}
use of voldemort.VoldemortException in project voldemort by voldemort.
the class SocketServerSession method run.
public void run() {
try {
activeSessions.put(sessionId, this);
DataInputStream inputStream = new DataInputStream(new BufferedInputStream(socket.getInputStream(), 64000));
DataOutputStream outputStream = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream(), 64000));
RequestFormatType protocol = negotiateProtocol(inputStream, outputStream);
RequestHandler handler = handlerFactory.getRequestHandler(protocol);
logger.info("Client " + socket.getRemoteSocketAddress() + " connected successfully with protocol " + protocol.getCode());
while (!isInterrupted() && !socket.isClosed() && !isClosed) {
StreamRequestHandler srh = handler.handleRequest(inputStream, outputStream);
if (srh != null) {
if (logger.isTraceEnabled())
logger.trace("Request is streaming");
StreamRequestHandlerState srhs = null;
try {
do {
if (logger.isTraceEnabled())
logger.trace("About to enter streaming request handler");
srhs = srh.handleRequest(inputStream, outputStream);
if (logger.isTraceEnabled())
logger.trace("Finished invocation of streaming request handler, result is " + srhs);
} while (srhs != StreamRequestHandlerState.COMPLETE);
} catch (VoldemortException e) {
srh.handleError(outputStream, e);
outputStream.flush();
break;
} finally {
srh.close(outputStream);
}
}
outputStream.flush();
}
if (isInterrupted())
logger.info(Thread.currentThread().getName() + " has been interrupted, closing session.");
} catch (EOFException e) {
logger.info("Client " + socket.getRemoteSocketAddress() + " disconnected.");
} catch (IOException e) {
// if this is an unexpected
if (!isClosed)
logger.error(e);
} finally {
try {
if (!socket.isClosed())
socket.close();
} catch (Exception e) {
logger.error("Error while closing socket", e);
}
// now remove ourselves from the set of active sessions
this.activeSessions.remove(sessionId);
}
}
use of voldemort.VoldemortException in project voldemort by voldemort.
the class AdminServiceRequestHandler method handleGetMetadata.
public VAdminProto.GetMetadataResponse handleGetMetadata(VAdminProto.GetMetadataRequest request) {
VAdminProto.GetMetadataResponse.Builder response = VAdminProto.GetMetadataResponse.newBuilder();
try {
ByteArray key = ProtoUtils.decodeBytes(request.getKey());
String keyString = ByteUtils.getString(key.get(), "UTF-8");
if (keyString.isEmpty()) {
// a new instance, with an empty key field.
throw new VoldemortException("Received admin operation which got interpreted as a " + "GetMetadataRequest with an empty metadata key. This " + "typically means that the requested admin operation is not " + "supported on this version of the Voldemort server.");
}
List<Versioned<byte[]>> versionedList = metadataStore.get(key, null);
if (versionedList.size() > 0) {
Versioned<byte[]> versioned = versionedList.get(0);
response.setVersion(ProtoUtils.encodeVersioned(versioned));
}
} catch (VoldemortException e) {
response.setError(ProtoUtils.encodeError(errorCodeMapper, e));
String errorMessage = "handleGetMetadata failed for request(" + request.toString() + ")";
if (e instanceof StoreNotFoundException) {
logger.info(errorMessage + " with " + StoreNotFoundException.class.getSimpleName());
} else {
logger.error(errorMessage, e);
}
}
return response.build();
}
use of voldemort.VoldemortException in project voldemort by voldemort.
the class AdminServiceRequestHandler method handleUpdateMetadataPair.
public VAdminProto.UpdateMetadataPairResponse handleUpdateMetadataPair(VAdminProto.UpdateMetadataPairRequest request) {
VAdminProto.UpdateMetadataPairResponse.Builder response = VAdminProto.UpdateMetadataPairResponse.newBuilder();
try {
ByteArray clusterKey = ProtoUtils.decodeBytes(request.getClusterKey());
ByteArray storesKey = ProtoUtils.decodeBytes(request.getStoresKey());
String clusterKeyString = ByteUtils.getString(clusterKey.get(), "UTF-8");
String storesKeyString = ByteUtils.getString(storesKey.get(), "UTF-8");
if (MetadataStore.METADATA_KEYS.contains(clusterKeyString) && MetadataStore.METADATA_KEYS.contains(storesKeyString)) {
Versioned<byte[]> clusterVersionedValue = ProtoUtils.decodeVersioned(request.getClusterValue());
Versioned<byte[]> storesVersionedValue = ProtoUtils.decodeVersioned(request.getStoresValue());
metadataStore.writeLock.lock();
try {
logger.info("Updating metadata for keys '" + clusterKeyString + "'" + " and '" + storesKeyString + "'");
metadataStore.put(clusterKey, clusterVersionedValue, null);
// replace this with put
metadataStore.put(storesKey, storesVersionedValue, null);
// metadataStore.updateStoreDefinitions(storesVersionedValue);
logger.info("Successfully updated metadata for keys '" + clusterKeyString + "'" + " and '" + storesKeyString + "'");
} finally {
metadataStore.writeLock.unlock();
}
}
} catch (VoldemortException e) {
response.setError(ProtoUtils.encodeError(errorCodeMapper, e));
logger.error("handleUpdateMetadataPair failed for request(" + request.toString() + ")", e);
}
return response.build();
}
Aggregations