if(!metadataStore.getReadOnlyFetchEnabledUnlocked()) {
throw new VoldemortException("Read-only fetcher is disabled in "
+ metadataStore.getServerStateUnlocked()
+ " state on node " + metadataStore.getNodeId());
}
final ReadOnlyStorageEngine store = getReadOnlyStorageEngine(metadataStore,
storeRepository,
storeName);
final long pushVersion;
if(request.hasPushVersion()) {
pushVersion = request.getPushVersion();
if(pushVersion <= store.getCurrentVersionId())
throw new VoldemortException("Version of push specified (" + pushVersion
+ ") should be greater than current version "
+ store.getCurrentVersionId() + " for store "
+ storeName + " on node "
+ metadataStore.getNodeId());
} else {
// Find the max version
long maxVersion;
File[] storeDirList = ReadOnlyUtils.getVersionDirs(new File(store.getStoreDirPath()));
if(storeDirList == null || storeDirList.length == 0) {
throw new VoldemortException("Push version required since no version folders exist for store "
+ storeName
+ " on node "
+ metadataStore.getNodeId());
} else {
maxVersion = ReadOnlyUtils.getVersionId(ReadOnlyUtils.findKthVersionedDir(storeDirList,
storeDirList.length - 1,
storeDirList.length - 1)[0]);
}
pushVersion = maxVersion + 1;
}
asyncService.submitOperation(requestId, new AsyncOperation(requestId, "Fetch store") {
private String fetchDirPath = null;
@Override
public void markComplete() {
if(fetchDirPath != null)
status.setStatus(fetchDirPath);
status.setComplete(true);
}
@Override
public void operate() {
File fetchDir = null;
if(fileFetcher == null) {
logger.warn("File fetcher class has not instantiated correctly. Assuming local file");
if(!Utils.isReadableDir(fetchUrl)) {
throw new VoldemortException("Fetch url " + fetchUrl
+ " is not readable");
}
fetchDir = new File(store.getStoreDirPath(), "version-"
+ Long.toString(pushVersion));
if(fetchDir.exists())
throw new VoldemortException("Version directory "
+ fetchDir.getAbsolutePath()
+ " already exists");
Utils.move(new File(fetchUrl), fetchDir);
} else {
logger.info("Started executing fetch of " + fetchUrl + " for RO store '"
+ storeName + "'");
updateStatus("0 MB copied at 0 MB/sec - 0 % complete");
try {
fileFetcher.setAsyncOperationStatus(status);
fetchDir = fileFetcher.fetch(fetchUrl, store.getStoreDirPath()
+ File.separator + "version-"
+ Long.toString(pushVersion));
if(fetchDir == null) {
String errorMessage = "File fetcher failed for "
+ fetchUrl