You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@zookeeper.apache.org by GitBox <gi...@apache.org> on 2019/03/27 00:21:27 UTC

[GitHub] [zookeeper] enixon commented on a change in pull request #870: ZOOKEEPER-3335: Prefer ArrayList over LinkedList

enixon commented on a change in pull request #870: ZOOKEEPER-3335: Prefer ArrayList over LinkedList
URL: https://github.com/apache/zookeeper/pull/870#discussion_r269365587
 
 

 ##########
 File path: zookeeper-server/src/main/java/org/apache/zookeeper/server/ZKDatabase.java
 ##########
 @@ -187,18 +190,21 @@ public ReentrantReadWriteLock getLogLock() {
     }
 
 
-    public synchronized List<Proposal> getCommittedLog() {
+    public synchronized Collection<Proposal> getCommittedLog() {
+        final Collection<Proposal> result;
         ReadLock rl = logLock.readLock();
-        // only make a copy if this thread isn't already holding a lock
-        if(logLock.getReadHoldCount() <=0) {
+        // make a copy if this thread is not already holding a lock
+        if (logLock.getReadHoldCount() > 0) {
+          result = this.committedLog;
+        } else {
+            rl.lock();
             try {
-                rl.lock();
-                return new LinkedList<Proposal>(this.committedLog);
+                result = new ArrayList<>(this.committedLog);
             } finally {
                 rl.unlock();
             }
         }
-        return this.committedLog;
+        return Collections.unmodifiableCollection(result);
 
 Review comment:
   For other reviewers - the changes here are the most interesting (imo).

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services