diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestTableLockManager.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestTableLockManager.java index 5152b3e..3a6b721 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestTableLockManager.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestTableLockManager.java @@ -41,6 +41,7 @@ import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HTableDescriptor; +import org.apache.hadoop.hbase.InterProcessLock; import org.apache.hadoop.hbase.NotServingRegionException; import org.apache.hadoop.hbase.ScheduledChore; import org.apache.hadoop.hbase.ServerName; @@ -233,6 +234,55 @@ public class TestTableLockManager { } + public class TableLockCallable implements Callable { + CountDownLatch writeLocksObtained; + CountDownLatch writeLocksAttempted; + String table; + TableLockManager lockManager; + int index; + + public TableLockCallable(CountDownLatch writeLocksObtained, + CountDownLatch writeLocksAttempted, + String table, + TableLockManager lockManager, + int index) { + this.writeLocksAttempted = writeLocksAttempted; + this.writeLocksObtained = writeLocksObtained; + this.table = table; + this.lockManager = lockManager; + this.index = index; + } + + @Override + public Void call() throws Exception { + writeLocksAttempted.countDown(); + if (index == 10) { + Thread.sleep(3000); + } + lockManager.writeLock(TableName.valueOf(table), + "testReapAllTableLocks").acquire(); + writeLocksObtained.countDown(); + return null; + } + } + + public class TableLockCounter implements InterProcessLock.MetadataHandler { + + private int lockCount = 0; + + @Override + public void handleMetadata(byte[] metadata) { + lockCount++; + } + + public void reset() { + lockCount = 0; + } + + public int getLockCount() { + return lockCount; + } + } @Test(timeout = 600000) public void testReapAllTableLocks() throws Exception { @@ -249,28 +299,29 @@ public class TestTableLockManager { //TODO: read lock tables //6 threads will be stuck waiting for the table lock + int count = 0; for (int i = 0; i < tables.length; i++) { final String table = tables[i]; for (int j = 0; j < i+1; j++) { //i+1 write locks attempted for table[i] - executor.submit(new Callable() { - @Override - public Void call() throws Exception { - writeLocksAttempted.countDown(); - lockManager.writeLock(TableName.valueOf(table), - "testReapAllTableLocks").acquire(); - writeLocksObtained.countDown(); - return null; - } - }); + executor.submit(new TableLockCallable(writeLocksObtained, writeLocksAttempted, table, lockManager, ++count)); } } writeLocksObtained.await(); writeLocksAttempted.await(); +// TableLockCounter counter = new TableLockCounter(); +// do { +// counter.reset(); +// lockManager.visitAllLocks(counter); +// Thread.sleep(10); +// } while (counter.getLockCount() != 10); + //now reap all table locks lockManager.reapWriteLocks(); + Thread.sleep(4000); + TEST_UTIL.getConfiguration().setInt(TableLockManager.TABLE_WRITE_LOCK_TIMEOUT_MS, 0); TableLockManager zeroTimeoutLockManager = TableLockManager.createTableLockManager( TEST_UTIL.getConfiguration(), TEST_UTIL.getZooKeeperWatcher(), serverName);