[grid] Add lock while finding a node in GridModel. Fix a log typo.
@@ -305,6 +305,9 @@ private void reserve(NodeStatus status, Slot slot) {
public void setSession(SlotId slotId, Session session) {
Require.nonNull("Slot ID", slotId);
+ Lock writeLock = lock.writeLock();
+ writeLock.lock();
+ try {
AvailabilityAndNode node = findNode(slotId.getOwningNodeId());
if (node == null) {
LOG.warning("Grid model and reality have diverged. Unable to find node " + slotId.getOwningNodeId());
@@ -329,7 +332,7 @@ public void setSession(SlotId slotId, Session session) {
Session current = maybeSession.get();
if (!RESERVED.equals(current.getId())) {
- LOG.warning("Gid model and reality have diverged. Slot has session and is not reserved. " + slotId);
+ LOG.warning("Grid model and reality have diverged. Slot has session and is not reserved. " + slotId);
return;
}
@@ -340,6 +343,9 @@ public void setSession(SlotId slotId, Session session) {
Optional.ofNullable(session));
amend(node.availability, node.status, updated);
+ } finally {
+ writeLock.unlock();
+ }
}
private void amend(Availability availability, NodeStatus status, Slot slot) {
