From 53e7f73ab9197cfb3f9939b5c2b60c1b4402291b Mon Sep 17 00:00:00 2001 From: Zhihong Yu Date: Mon, 29 Aug 2011 16:00:47 +0000 Subject: [PATCH] HBASE-4278 Race condition in Slab.java that occurs due to spinlock unlocking early (Li Pi) git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1162886 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 2 ++ .../java/org/apache/hadoop/hbase/io/hfile/slab/Slab.java | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index f21c717abbe..211654e30c3 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -220,6 +220,8 @@ Release 0.91.0 - Unreleased HBASE-3229 HBASE-3229 Table creation, though using "async" call to master, can actually run for a while and cause RPC timeout (Ming Ma) HBASE-4252 TestLogRolling's low-probability failure (Jieshan Bean) + HBASE-4278 Race condition in Slab.java that occurs due to spinlock unlocking + early (Li Pi) IMPROVEMENTS HBASE-3290 Max Compaction Size (Nicolas Spiegelberg via Stack) diff --git a/src/main/java/org/apache/hadoop/hbase/io/hfile/slab/Slab.java b/src/main/java/org/apache/hadoop/hbase/io/hfile/slab/Slab.java index 69d2662a52d..70781256ba0 100644 --- a/src/main/java/org/apache/hadoop/hbase/io/hfile/slab/Slab.java +++ b/src/main/java/org/apache/hadoop/hbase/io/hfile/slab/Slab.java @@ -113,8 +113,11 @@ class Slab implements org.apache.hadoop.hbase.io.HeapSize { */ ByteBuffer alloc(int bufferSize) { int newCapacity = Preconditions.checkPositionIndex(bufferSize, blockSize); - while (buffers.isEmpty()); // Spinlock - ByteBuffer returnedBuffer = buffers.remove(); + + ByteBuffer returnedBuffer = buffers.poll(); + while(returnedBuffer == null){ + returnedBuffer = buffers.poll(); + } returnedBuffer.clear().limit(newCapacity); return returnedBuffer; }