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