DRILL-924: Update trim so that it synchronized within the arena to avoid 
inconsistent state.


Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/cca3cec1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/cca3cec1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/cca3cec1

Branch: refs/heads/master
Commit: cca3cec18914f7b25481f57ad2fe422a8ec3d475
Parents: e830f7f
Author: Jacques Nadeau <[email protected]>
Authored: Fri Jun 6 10:52:01 2014 -0700
Committer: Jacques Nadeau <[email protected]>
Committed: Fri Jun 6 17:11:41 2014 -0700

----------------------------------------------------------------------
 .../java/io/netty/buffer/PoolChunkListL.java    | 49 ++++++++++----------
 1 file changed, 25 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/cca3cec1/exec/bufferl/src/main/java/io/netty/buffer/PoolChunkListL.java
----------------------------------------------------------------------
diff --git a/exec/bufferl/src/main/java/io/netty/buffer/PoolChunkListL.java 
b/exec/bufferl/src/main/java/io/netty/buffer/PoolChunkListL.java
index 16f11fa..7e25557 100644
--- a/exec/bufferl/src/main/java/io/netty/buffer/PoolChunkListL.java
+++ b/exec/bufferl/src/main/java/io/netty/buffer/PoolChunkListL.java
@@ -61,7 +61,7 @@ final class PoolChunkListL<T> {
      * @return
      */
     boolean allocate(PooledByteBufL<T> buf, int minRequested, int 
maxRequested) {
-       
+
        // If list is empty, then allocation fails
         if (head == null) {
             return false;
@@ -69,7 +69,7 @@ final class PoolChunkListL<T> {
 
         // Do for each chunk in the list
         for (PoolChunkL<T> cur = head;;) {
-               
+
                // If we successfully allocated from the chunk ...
             long handle = cur.allocate(minRequested, maxRequested);
             if (handle < 0) {
@@ -77,11 +77,11 @@ final class PoolChunkListL<T> {
                 if (cur == null) {
                     return false;
                 }
-                
+
             // ... then add the memory to the buffer container
             } else {
                 cur.initBuf(buf, handle, minRequested, maxRequested);
-                
+
                 // If usage changed, then move to next list
                 if (cur.usage() >= maxUsage) {
                     remove(cur);
@@ -92,17 +92,17 @@ final class PoolChunkListL<T> {
         }
     }
 
-    
+
     /**
      * Release a buffer back to the original chunk.
      * @param chunk
      * @param handle
      */
     void free(PoolChunkL<T> chunk, long handle) {
-       
+
        // Release buffer back to the original chunk
         chunk.free(handle);
-        
+
         // If usage changed, then move to different list
         if (chunk.usage() < minUsage) {
             remove(chunk);
@@ -114,7 +114,7 @@ final class PoolChunkListL<T> {
             }
         }
     }
-    
+
     /**
      * Shrink the buffer down to the specified size, freeing up unused memory.
      * @param chunk - chunk the buffer resides in
@@ -123,29 +123,30 @@ final class PoolChunkListL<T> {
      * @return a new handle to the smaller buffer
      */
     long trim(PoolChunkL<T> chunk, long handle, int size) {
-       
-       // Trim the buffer, possibly getting a new handle.
-       handle = chunk.trim(handle,  size);
-       if (handle == -1) return handle;
-       
-       // Move the chunk to a different list if usage changed significantly
-       if (chunk.usage() < minUsage) {
-               assert chunk.usage() > 0 && prevList != null;
-               remove(chunk);
-               prevList.add(chunk);
+       synchronized(arena){
+        // Trim the buffer, possibly getting a new handle.
+        handle = chunk.trim(handle,  size);
+        if (handle == -1) return handle;
+
+        // Move the chunk to a different list if usage changed significantly
+        if (chunk.usage() < minUsage) {
+          assert chunk.usage() > 0 && prevList != null;
+          remove(chunk);
+          prevList.add(chunk);
+        }
+
+        // return new handle for the smaller buffer
+        return handle;
        }
-       
-       // return new handle for the smaller buffer
-       return handle;
     }
 
-    
+
     /**
      * Add a chunk to the current chunklist
      * @param chunk
      */
     void add(PoolChunkL<T> chunk) {
-       
+
        // If usage has change, then add to the neighboring list instead
        int usage = chunk.usage();
         if (usage >= maxUsage) {
@@ -170,7 +171,7 @@ final class PoolChunkListL<T> {
         }
     }
 
-    
+
     /**
      * Remove a chunk from the current linked list of chunks
      * @param cur

Reply via email to