Permalink
Browse files

have localstate try again if exception while trying to read from disk

  • Loading branch information...
1 parent f6804ad commit da2480487b53ab49238e2ba31e01a35efd1e8a57 @nathanmarz nathanmarz committed Mar 7, 2013
Showing with 14 additions and 3 deletions.
  1. +14 −3 src/jvm/backtype/storm/utils/LocalState.java
@@ -1,6 +1,7 @@
package backtype.storm.utils;
import org.apache.commons.io.FileUtils;
+
import java.io.File;
import java.util.Map;
import java.util.HashMap;
@@ -19,9 +20,19 @@ public LocalState(String backingDir) throws IOException {
}
public synchronized Map<Object, Object> snapshot() throws IOException {
- String latestPath = _vs.mostRecentVersionPath();
- if(latestPath==null) return new HashMap<Object, Object>();
- return (Map<Object, Object>) Utils.deserialize(FileUtils.readFileToByteArray(new File(latestPath)));
+ int attempts = 0;
+ while(true) {
+ String latestPath = _vs.mostRecentVersionPath();
+ if(latestPath==null) return new HashMap<Object, Object>();
+ try {
+ return (Map<Object, Object>) Utils.deserialize(FileUtils.readFileToByteArray(new File(latestPath)));
+ } catch(IOException e) {
+ attempts++;
+ if(attempts >= 10) {
+ throw e;
+ }
+ }
+ }
}
public Object get(Object key) throws IOException {

0 comments on commit da24804

Please sign in to comment.