runzhiwang edited a comment on pull request #1028:
URL: https://github.com/apache/hadoop-ozone/pull/1028#issuecomment-647830265


   @elek Thanks for review. You are right, if the write code like following, 
maybe after  `currentInfo.setState(newState)` and before 
`currentInfo.setOwner(owner)`, we read the currentInfo, so we read a half write 
ContainerInfo. 
   ```
   lock.writeLock().lock();
   final ContainerInfo currentInfo = containerMap.get(containerID);
   currentInfo.setState(newState);
   currentInfo.setOwner(owner);
   lock.writeLock().unlock();
   ```
   
   I think we can avoid this by the following code. Though write become more 
complicated because it needs to new an object, but read is pretty more than 
write, so it's worth. What do you think ?
   ```
   lock.writeLock().lock();
   final ContainerInfo currentInfo = containerMap.get(containerID);
   ContainerInfo newInfo = new ContainerInfo(currentInfo);
   newInfo.setState(newState);
   newInfo.setOwner(owner);
   containerMap.put(containerID, newInfo);
   lock.writeLock().unlock();
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: ozone-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: ozone-issues-h...@hadoop.apache.org

Reply via email to