From 848748b1aea396ec6e29d41ece36195056df5cb9 Mon Sep 17 00:00:00 2001 From: Jean-Daniel Cryans Date: Thu, 15 Sep 2011 23:51:00 +0000 Subject: [PATCH] HBASE-4395 EnableTableHandler races with itself git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1171331 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 1 + .../master/handler/EnableTableHandler.java | 51 ++++++++++--------- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index d6e612663b7..cc5f92b3bb5 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -270,6 +270,7 @@ Release 0.91.0 - Unreleased to contact the sink (JD and Lars Hofhansl) HBASE-4390 [replication] ReplicationSource's UncaughtExceptionHandler shouldn't join + HBASE-4395 EnableTableHandler races with itself IMPROVEMENTS HBASE-3290 Max Compaction Size (Nicolas Spiegelberg via Stack) diff --git a/src/main/java/org/apache/hadoop/hbase/master/handler/EnableTableHandler.java b/src/main/java/org/apache/hadoop/hbase/master/handler/EnableTableHandler.java index b6dc1c04eb9..1e5d83cfd5f 100644 --- a/src/main/java/org/apache/hadoop/hbase/master/handler/EnableTableHandler.java +++ b/src/main/java/org/apache/hadoop/hbase/master/handler/EnableTableHandler.java @@ -109,32 +109,28 @@ public class EnableTableHandler extends EventHandler { // Set table enabling flag up in zk. this.assignmentManager.getZKTable().setEnablingTable(this.tableNameStr); boolean done = false; - while (true) { - // Get the regions of this table. We're done when all listed - // tables are onlined. - List regionsInMeta = - MetaReader.getTableRegions(this.ct, tableName, true); - int countOfRegionsInTable = regionsInMeta.size(); - List regions = regionsToAssign(regionsInMeta); - if (regions.size() == 0) { + // Get the regions of this table. We're done when all listed + // tables are onlined. + List regionsInMeta = + MetaReader.getTableRegions(this.ct, tableName, true); + int countOfRegionsInTable = regionsInMeta.size(); + List regions = regionsToAssign(regionsInMeta); + int regionsCount = regions.size(); + if (regionsCount == 0) { + done = true; + } + LOG.info("Table has " + countOfRegionsInTable + " regions of which " + + regionsCount + " are offline."); + BulkEnabler bd = new BulkEnabler(this.server, regions, + countOfRegionsInTable); + try { + if (bd.bulkAssign()) { done = true; - break; - } - LOG.info("Table has " + countOfRegionsInTable + " regions of which " + - regions.size() + " are offline."); - BulkEnabler bd = new BulkEnabler(this.server, regions, - countOfRegionsInTable); - try { - if (bd.bulkAssign()) { - done = true; - break; - } - } catch (InterruptedException e) { - LOG.warn("Enable was interrupted"); - // Preserve the interrupt. - Thread.currentThread().interrupt(); - break; } + } catch (InterruptedException e) { + LOG.warn("Enable was interrupted"); + // Preserve the interrupt. + Thread.currentThread().interrupt(); } // Flip the table to enabled. if (done) this.assignmentManager.getZKTable().setEnabledTable( @@ -191,10 +187,17 @@ public class EnableTableHandler extends EventHandler { long startTime = System.currentTimeMillis(); long remaining = timeout; List regions = null; + int lastNumberOfRegions = this.countOfRegionsInTable; while (!server.isStopped() && remaining > 0) { Thread.sleep(waitingTimeForEvents); regions = assignmentManager.getRegionsOfTable(tableName); if (isDone(regions)) break; + + // Punt on the timeout as long we make progress + if (regions.size() > lastNumberOfRegions) { + lastNumberOfRegions = regions.size(); + timeout += waitingTimeForEvents; + } remaining = timeout - (System.currentTimeMillis() - startTime); } return isDone(regions);