use of voldemort.store.stats.StreamingStats in project voldemort by voldemort.
the class UpdateSlopEntriesRequestHandler method handleRequest.
public StreamRequestHandlerState handleRequest(DataInputStream inputStream, DataOutputStream outputStream) throws IOException {
if (!metadataStore.getSlopStreamingEnabledUnlocked()) {
throw new SlopStreamingDisabledException("Slop streaming is disabled on node " + metadataStore.getNodeId() + " under " + metadataStore.getServerStateUnlocked() + " state.");
}
long startNs = System.nanoTime();
if (request == null) {
int size = 0;
try {
size = inputStream.readInt();
} catch (EOFException e) {
if (logger.isTraceEnabled())
logger.trace("Incomplete read for message size");
networkTimeNs += System.nanoTime() - startNs;
return StreamRequestHandlerState.INCOMPLETE_READ;
}
if (size == -1) {
if (logger.isTraceEnabled())
logger.trace("Message size -1, completed slop update");
return StreamRequestHandlerState.COMPLETE;
}
if (logger.isTraceEnabled())
logger.trace("UpdateSlopEntriesRequest message size: " + size);
byte[] input = new byte[size];
try {
ByteUtils.read(inputStream, input);
networkTimeNs += Utils.elapsedTimeNs(startNs, System.nanoTime());
} catch (EOFException e) {
if (logger.isTraceEnabled())
logger.trace("Incomplete read for message");
return StreamRequestHandlerState.INCOMPLETE_READ;
}
VAdminProto.UpdateSlopEntriesRequest.Builder builder = VAdminProto.UpdateSlopEntriesRequest.newBuilder();
builder.mergeFrom(input);
request = builder.build();
}
StorageEngine<ByteArray, byte[], byte[]> storageEngine = AdminServiceRequestHandler.getStorageEngine(storeRepository, request.getStore());
StreamingStats streamStats = null;
if (isJmxEnabled) {
streamStats = storeRepository.getStreamingStats(storageEngine.getName());
streamStats.reportNetworkTime(Operation.SLOP_UPDATE, networkTimeNs);
}
networkTimeNs = 0;
ByteArray key = ProtoUtils.decodeBytes(request.getKey());
VectorClock vectorClock = ProtoUtils.decodeClock(request.getVersion());
switch(request.getRequestType()) {
case PUT:
try {
// Retrieve the transform if its exists
byte[] transforms = null;
if (request.hasTransform()) {
transforms = ProtoUtils.decodeBytes(request.getTransform()).get();
}
// Retrieve the value
byte[] value = ProtoUtils.decodeBytes(request.getValue()).get();
startNs = System.nanoTime();
storageEngine.put(key, Versioned.value(value, vectorClock), transforms);
if (isJmxEnabled)
streamStats.reportStorageTime(Operation.SLOP_UPDATE, Utils.elapsedTimeNs(startNs, System.nanoTime()));
if (logger.isTraceEnabled())
logger.trace("updateSlopEntries (Streaming put) successful on key:" + key + " of store: " + request.getStore());
} catch (ObsoleteVersionException e) {
// log and ignore
if (logger.isDebugEnabled())
logger.debug("updateSlopEntries (Streaming put) threw ObsoleteVersionException, Ignoring.");
}
break;
case DELETE:
try {
startNs = System.nanoTime();
storageEngine.delete(key, vectorClock);
if (isJmxEnabled)
streamStats.reportStorageTime(Operation.SLOP_UPDATE, System.nanoTime() - startNs);
if (logger.isTraceEnabled())
logger.trace("updateSlopEntries (Streaming delete) successful");
} catch (ObsoleteVersionException e) {
// log and ignore
if (logger.isDebugEnabled())
logger.debug("updateSlopEntries (Streaming delete) threw ObsoleteVersionException, Ignoring.");
}
break;
default:
throw new VoldemortException("Unsupported operation ");
}
// log progress
counter++;
if (isJmxEnabled)
streamStats.reportStreamingPut(Operation.SLOP_UPDATE);
if (0 == counter % 100000) {
long totalTime = (System.currentTimeMillis() - startTime) / 1000;
if (logger.isDebugEnabled())
logger.debug("updateSlopEntries() updated " + counter + " entries in " + totalTime + " s");
}
request = null;
return StreamRequestHandlerState.READING;
}
use of voldemort.store.stats.StreamingStats in project voldemort by voldemort.
the class AdminServiceRequestHandler method handleFetchAndUpdate.
public VAdminProto.AsyncOperationStatusResponse handleFetchAndUpdate(VAdminProto.InitiateFetchAndUpdateRequest request) {
final int nodeId = request.getNodeId();
final List<Integer> partitionIds = request.getPartitionIdsList();
final VoldemortFilter filter = request.hasFilter() ? getFilterFromRequest(request.getFilter(), voldemortConfig, networkClassLoader) : new DefaultVoldemortFilter();
final String storeName = request.getStore();
final Cluster initialCluster = request.hasInitialCluster() ? new ClusterMapper().readCluster(new StringReader(request.getInitialCluster())) : null;
int requestId = asyncService.getUniqueRequestId();
VAdminProto.AsyncOperationStatusResponse.Builder response = VAdminProto.AsyncOperationStatusResponse.newBuilder().setRequestId(requestId).setComplete(false).setDescription("Fetch and update").setStatus("Started");
final StoreDefinition storeDef = metadataStore.getStoreDef(storeName);
final boolean isReadOnlyStore = storeDef.getType().compareTo(ReadOnlyStorageConfiguration.TYPE_NAME) == 0;
final StreamingStats streamingStats = voldemortConfig.isJmxEnabled() ? storeRepository.getStreamingStats(storeName) : null;
try {
asyncService.submitOperation(requestId, new AsyncOperation(requestId, "Fetch and Update") {
private final AtomicBoolean running = new AtomicBoolean(true);
@Override
public void stop() {
running.set(false);
logger.info("Stopping fetch and update for store " + storeName + " from node " + nodeId + "( " + partitionIds + " )");
}
@Override
public void operate() {
AdminClient adminClient = AdminClient.createTempAdminClient(voldemortConfig, metadataStore.getCluster(), voldemortConfig.getClientMaxConnectionsPerNode());
try {
StorageEngine<ByteArray, byte[], byte[]> storageEngine = getStorageEngine(storeRepository, storeName);
EventThrottler throttler = new EventThrottler(voldemortConfig.getStreamMaxWriteBytesPerSec());
if (isReadOnlyStore) {
ReadOnlyStorageEngine readOnlyStorageEngine = ((ReadOnlyStorageEngine) storageEngine);
String destinationDir = readOnlyStorageEngine.getCurrentDirPath();
logger.info("Fetching files for RO store '" + storeName + "' from node " + nodeId + " ( " + partitionIds + " )");
updateStatus("Fetching files for RO store '" + storeName + "' from node " + nodeId + " ( " + partitionIds + " )");
adminClient.readonlyOps.fetchPartitionFiles(nodeId, storeName, partitionIds, destinationDir, readOnlyStorageEngine.getChunkedFileSet().getChunkIdToNumChunks().keySet(), running);
} else {
logger.info("Fetching entries for RW store '" + storeName + "' from node " + nodeId + " ( " + partitionIds + " )");
updateStatus("Fetching entries for RW store '" + storeName + "' from node " + nodeId + " ( " + partitionIds + " ) ");
if (partitionIds.size() > 0) {
Iterator<Pair<ByteArray, Versioned<byte[]>>> entriesIterator = adminClient.bulkFetchOps.fetchEntries(nodeId, storeName, partitionIds, filter, false, initialCluster, 0);
long numTuples = 0;
long startTime = System.currentTimeMillis();
long startNs = System.nanoTime();
while (running.get() && entriesIterator.hasNext()) {
Pair<ByteArray, Versioned<byte[]>> entry = entriesIterator.next();
if (streamingStats != null) {
streamingStats.reportNetworkTime(Operation.UPDATE_ENTRIES, Utils.elapsedTimeNs(startNs, System.nanoTime()));
}
ByteArray key = entry.getFirst();
Versioned<byte[]> value = entry.getSecond();
startNs = System.nanoTime();
try {
/**
* TODO This also needs to be fixed to
* use the atomic multi version puts
*/
storageEngine.put(key, value, null);
} catch (ObsoleteVersionException e) {
// log and ignore
if (logger.isDebugEnabled()) {
logger.debug("Fetch and update threw Obsolete version exception. Ignoring");
}
} finally {
if (streamingStats != null) {
streamingStats.reportStreamingPut(Operation.UPDATE_ENTRIES);
streamingStats.reportStorageTime(Operation.UPDATE_ENTRIES, Utils.elapsedTimeNs(startNs, System.nanoTime()));
}
}
long totalTime = (System.currentTimeMillis() - startTime) / 1000;
throttler.maybeThrottle(key.length() + valueSize(value));
if ((numTuples % 100000) == 0 && numTuples > 0) {
logger.info(numTuples + " entries copied from node " + nodeId + " for store '" + storeName + "' in " + totalTime + " seconds");
updateStatus(numTuples + " entries copied from node " + nodeId + " for store '" + storeName + "' in " + totalTime + " seconds");
}
numTuples++;
}
long totalTime = (System.currentTimeMillis() - startTime) / 1000;
if (running.get()) {
logger.info("Completed fetching " + numTuples + " entries from node " + nodeId + " for store '" + storeName + "' in " + totalTime + " seconds");
} else {
logger.info("Fetch and update stopped after fetching " + numTuples + " entries for node " + nodeId + " for store '" + storeName + "' in " + totalTime + " seconds");
}
} else {
logger.info("No entries to fetch from node " + nodeId + " for store '" + storeName + "'");
}
}
} finally {
adminClient.close();
}
}
});
} catch (VoldemortException e) {
response.setError(ProtoUtils.encodeError(errorCodeMapper, e));
logger.error("handleFetchAndUpdate failed for request(" + request.toString() + ")", e);
}
return response.build();
}
use of voldemort.store.stats.StreamingStats in project voldemort by voldemort.
the class StoreRepository method addStorageEngine.
public void addStorageEngine(StorageEngine<ByteArray, byte[], byte[]> engine) {
StorageEngine<ByteArray, byte[], byte[]> found = this.storageEngines.putIfAbsent(engine.getName(), engine);
if (found != null)
throw new VoldemortException("Storage Engine '" + engine.getName() + "' has already been initialized.");
// register streaming stats object for the store
if (streamingStatsMap != null) {
// lazily register the aggregated mbean
if (storageEngines.size() == 1) {
JmxUtils.registerMbean(aggregatedStreamStats, JmxUtils.createObjectName(this.getClass().getCanonicalName(), "aggregated-streaming-stats"));
}
StreamingStats stat = new StreamingStats(aggregatedStreamStats);
JmxUtils.registerMbean(stat, JmxUtils.createObjectName(this.getClass().getCanonicalName(), engine.getName() + "-streaming-stats"));
streamingStatsMap.putIfAbsent(engine.getName(), stat);
}
}
Aggregations