Permalink
Browse files

If push version of read-only store is not specified we should use max…

…Version+1 instead of currentVersion+1
  • Loading branch information...
1 parent e7888ad commit f9d9e55e810bd83053115012ba8a69e0d60251aa @rsumbaly rsumbaly committed Nov 3, 2010
@@ -37,6 +37,7 @@
import voldemort.store.StorageEngine;
import voldemort.store.readonly.FileFetcher;
import voldemort.store.readonly.ReadOnlyStorageEngine;
+import voldemort.store.readonly.ReadOnlyUtils;
import voldemort.utils.ByteArray;
import voldemort.utils.Props;
import voldemort.utils.ReflectUtils;
@@ -186,7 +187,17 @@ private void doFetch(HttpServletRequest req, HttpServletResponse resp) throws IO
long pushVersion;
if(pushVersionString == null) {
- pushVersion = store.getCurrentVersionId() + 1;
+ // Find the max version
+ long maxVersion;
+ File[] storeDirList = ReadOnlyUtils.getVersionDirs(new File(store.getStoreDirPath()));
+ if(storeDirList == null || storeDirList.length == 0) {
+ throw new ServletException("Push version required since no version folders exist");
+ } else {
+ maxVersion = ReadOnlyUtils.getVersionId(ReadOnlyUtils.findKthVersionedDir(storeDirList,
+ storeDirList.length - 1,
+ storeDirList.length - 1)[0]);
+ }
+ pushVersion = maxVersion + 1;
} else {
pushVersion = Long.parseLong(pushVersionString);
if(pushVersion <= store.getCurrentVersionId())
@@ -516,7 +516,17 @@ private void swapStore(String storeName, String directory) throws VoldemortExcep
+ ") should be greater than current version "
+ store.getCurrentVersionId());
} else {
- pushVersion = store.getCurrentVersionId() + 1;
+ // 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");
+ } 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") {

0 comments on commit f9d9e55

Please sign in to comment.