Log failures in state machine processing
Change-Id: Ib92768cf4cf5cce5e2642265d1c1aa3e2f13b246
diff --git a/core/store/primitives/src/main/java/org/onosproject/store/primitives/resources/impl/AtomixConsistentMapState.java b/core/store/primitives/src/main/java/org/onosproject/store/primitives/resources/impl/AtomixConsistentMapState.java
index 48fd4a2..4ed3a72 100644
--- a/core/store/primitives/src/main/java/org/onosproject/store/primitives/resources/impl/AtomixConsistentMapState.java
+++ b/core/store/primitives/src/main/java/org/onosproject/store/primitives/resources/impl/AtomixConsistentMapState.java
@@ -259,36 +259,41 @@
* @return update result
*/
protected MapEntryUpdateResult<String, byte[]> updateAndGet(Commit<? extends UpdateAndGet> commit) {
- MapEntryUpdateResult.Status updateStatus = validate(commit.operation());
- String key = commit.operation().key();
- MapEntryValue oldCommitValue = mapEntries.get(commit.operation().key());
- Versioned<byte[]> oldMapValue = toVersioned(oldCommitValue);
+ try {
+ MapEntryUpdateResult.Status updateStatus = validate(commit.operation());
+ String key = commit.operation().key();
+ MapEntryValue oldCommitValue = mapEntries.get(commit.operation().key());
+ Versioned<byte[]> oldMapValue = toVersioned(oldCommitValue);
- if (updateStatus != MapEntryUpdateResult.Status.OK) {
- commit.close();
- return new MapEntryUpdateResult<>(updateStatus, "", key,
- oldMapValue, oldMapValue);
- }
+ if (updateStatus != MapEntryUpdateResult.Status.OK) {
+ commit.close();
+ return new MapEntryUpdateResult<>(updateStatus, "", key,
+ oldMapValue, oldMapValue);
+ }
- byte[] newValue = commit.operation().value();
- long newVersion = versionCounter.incrementAndGet();
- Versioned<byte[]> newMapValue = newValue == null ? null
- : new Versioned<>(newValue, newVersion);
+ byte[] newValue = commit.operation().value();
+ long newVersion = versionCounter.incrementAndGet();
+ Versioned<byte[]> newMapValue = newValue == null ? null
+ : new Versioned<>(newValue, newVersion);
- MapEvent.Type updateType = newValue == null ? REMOVE
- : oldCommitValue == null ? INSERT : UPDATE;
- if (updateType == REMOVE || updateType == UPDATE) {
- mapEntries.remove(key);
- oldCommitValue.discard();
+ MapEvent.Type updateType = newValue == null ? REMOVE
+ : oldCommitValue == null ? INSERT : UPDATE;
+ if (updateType == REMOVE || updateType == UPDATE) {
+ mapEntries.remove(key);
+ oldCommitValue.discard();
+ }
+ if (updateType == INSERT || updateType == UPDATE) {
+ mapEntries.put(key, new NonTransactionalCommit(newVersion, commit));
+ } else {
+ commit.close();
+ }
+ publish(Lists.newArrayList(new MapEvent<>("", key, newMapValue, oldMapValue)));
+ return new MapEntryUpdateResult<>(updateStatus, "", key, oldMapValue,
+ newMapValue);
+ } catch (Exception e) {
+ log.error("State machine operation failed", e);
+ throw Throwables.propagate(e);
}
- if (updateType == INSERT || updateType == UPDATE) {
- mapEntries.put(key, new NonTransactionalCommit(newVersion, commit));
- } else {
- commit.close();
- }
- publish(Lists.newArrayList(new MapEvent<>("", key, newMapValue, oldMapValue)));
- return new MapEntryUpdateResult<>(updateStatus, "", key, oldMapValue,
- newMapValue);
}
/**
diff --git a/core/store/primitives/src/main/java/org/onosproject/store/primitives/resources/impl/AtomixLeaderElectorState.java b/core/store/primitives/src/main/java/org/onosproject/store/primitives/resources/impl/AtomixLeaderElectorState.java
index 6281672..33414e7 100644
--- a/core/store/primitives/src/main/java/org/onosproject/store/primitives/resources/impl/AtomixLeaderElectorState.java
+++ b/core/store/primitives/src/main/java/org/onosproject/store/primitives/resources/impl/AtomixLeaderElectorState.java
@@ -60,6 +60,7 @@
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
+import com.google.common.base.Throwables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
@@ -172,6 +173,9 @@
notifyLeadershipChange(oldLeadership, newLeadership);
}
return newLeadership;
+ } catch (Exception e) {
+ log.error("State machine operation failed", e);
+ throw Throwables.propagate(e);
} finally {
commit.close();
}
@@ -191,6 +195,9 @@
if (!Objects.equal(oldLeadership, newLeadership)) {
notifyLeadershipChange(oldLeadership, newLeadership);
}
+ } catch (Exception e) {
+ log.error("State machine operation failed", e);
+ throw Throwables.propagate(e);
} finally {
commit.close();
}
@@ -215,6 +222,9 @@
return (electionState != null &&
electionState.leader() != null &&
commit.operation().nodeId().equals(electionState.leader().nodeId()));
+ } catch (Exception e) {
+ log.error("State machine operation failed", e);
+ throw Throwables.propagate(e);
} finally {
commit.close();
}
@@ -239,6 +249,9 @@
notifyLeadershipChange(oldLeadership, newLeadership);
}
return true;
+ } catch (Exception e) {
+ log.error("State machine operation failed", e);
+ throw Throwables.propagate(e);
} finally {
commit.close();
}
@@ -262,6 +275,9 @@
}
});
notifyLeadershipChanges(changes);
+ } catch (Exception e) {
+ log.error("State machine operation failed", e);
+ throw Throwables.propagate(e);
} finally {
commit.close();
}
@@ -276,6 +292,9 @@
String topic = commit.operation().topic();
try {
return leadership(topic);
+ } catch (Exception e) {
+ log.error("State machine operation failed", e);
+ throw Throwables.propagate(e);
} finally {
commit.close();
}
@@ -293,6 +312,9 @@
Leader leader = leadership(e.getKey()).leader();
return leader != null && leader.nodeId().equals(nodeId);
}).keySet());
+ } catch (Exception e) {
+ log.error("State machine operation failed", e);
+ throw Throwables.propagate(e);
} finally {
commit.close();
}
@@ -308,6 +330,9 @@
try {
result.putAll(Maps.transformEntries(elections, (k, v) -> leadership(k)));
return result;
+ } catch (Exception e) {
+ log.error("State machine operation failed", e);
+ throw Throwables.propagate(e);
} finally {
commit.close();
}