STORM-307: fixed IOException retry logic Change-Id: Iffa4609ee9b8a0afbd437d2b2ee802cc83773a0a
Project: http://git-wip-us.apache.org/repos/asf/storm/repo Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/ccde2332 Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/ccde2332 Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/ccde2332 Branch: refs/heads/security Commit: ccde2332da9ae2c4b43e38651cc0d08ae0ebdb18 Parents: b2ecd44 Author: Wurstmeister <[email protected]> Authored: Mon Oct 6 10:17:26 2014 +0100 Committer: Wurstmeister <[email protected]> Committed: Mon Oct 6 10:17:26 2014 +0100 ---------------------------------------------------------------------- .../jvm/backtype/storm/utils/LocalState.java | 38 +++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/storm/blob/ccde2332/storm-core/src/jvm/backtype/storm/utils/LocalState.java ---------------------------------------------------------------------- diff --git a/storm-core/src/jvm/backtype/storm/utils/LocalState.java b/storm-core/src/jvm/backtype/storm/utils/LocalState.java index f58e79c..14a45da 100644 --- a/storm-core/src/jvm/backtype/storm/utils/LocalState.java +++ b/storm-core/src/jvm/backtype/storm/utils/LocalState.java @@ -42,28 +42,32 @@ public class LocalState { public synchronized Map<Object, Object> snapshot() throws IOException { int attempts = 0; - Map<Object, Object> result = new HashMap<Object, Object>(); while(true) { - String latestPath = _vs.mostRecentVersionPath(); - if(latestPath != null) { - try { - byte[] serialized = FileUtils.readFileToByteArray(new File(latestPath)); - if (serialized.length == 0) { - LOG.warn("LocalState file '{}' contained no data, resetting state", latestPath); - } else { - result = (Map<Object, Object>) Utils.deserialize(serialized); - } - } catch (IOException e) { - attempts++; - if (attempts >= 10) { - throw e; - } + try { + return deserializeLatestVersion(); + } catch (IOException e) { + attempts++; + if (attempts >= 10) { + throw e; } } - return result; } } - + + private Map<Object, Object> deserializeLatestVersion() throws IOException { + String latestPath = _vs.mostRecentVersionPath(); + Map<Object, Object> result = new HashMap<Object, Object>(); + if (latestPath != null) { + byte[] serialized = FileUtils.readFileToByteArray(new File(latestPath)); + if (serialized.length == 0) { + LOG.warn("LocalState file '{}' contained no data, resetting state", latestPath); + } else { + result = (Map<Object, Object>) Utils.deserialize(serialized); + } + } + return result; + } + public Object get(Object key) throws IOException { return snapshot().get(key); }
