HBASE-7657 Make ModifyTableHandler synchronous (Himanshu Vashishtha)

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1438298 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
mbertozzi 2013-01-25 02:38:31 +00:00
parent 6d25ad02d8
commit dab6872457
3 changed files with 5 additions and 59 deletions

View File

@ -1772,9 +1772,8 @@ Server {
if (cpHost != null) {
cpHost.preModifyTable(tableName, descriptor);
}
TableEventHandler tblHandle = new ModifyTableHandler(tableName, descriptor, this, this);
this.executorService.submit(tblHandle);
tblHandle.waitForPersist();
new ModifyTableHandler(tableName, descriptor, this, this).process();
if (cpHost != null) {
cpHost.postModifyTable(tableName, descriptor);
}

View File

@ -61,7 +61,6 @@ public abstract class TableEventHandler extends EventHandler {
protected final MasterServices masterServices;
protected final byte [] tableName;
protected final String tableNameStr;
protected boolean persistedToZk = false;
public TableEventHandler(EventType eventType, byte [] tableName, Server server,
MasterServices masterServices)
@ -111,10 +110,7 @@ public abstract class TableEventHandler extends EventHandler {
LOG.error("Error manipulating table " + Bytes.toString(tableName), e);
} catch (KeeperException e) {
LOG.error("Error manipulating table " + Bytes.toString(tableName), e);
} finally {
// notify the waiting thread that we're done persisting the request
setPersist();
}
}
}
public boolean reOpenAllRegions(List<HRegionInfo> regions) throws IOException {
@ -165,29 +161,6 @@ public abstract class TableEventHandler extends EventHandler {
return done;
}
/**
* Table modifications are processed asynchronously, but provide an API for
* you to query their status.
*
* @throws IOException
*/
public synchronized void waitForPersist() throws IOException {
if (!persistedToZk) {
try {
wait();
} catch (InterruptedException ie) {
throw (IOException) new InterruptedIOException().initCause(ie);
}
assert persistedToZk;
}
}
private synchronized void setPersist() {
if (!persistedToZk) {
persistedToZk = true;
notify();
}
}
/**
* @return Table descriptor for this table

View File

@ -385,7 +385,7 @@ public class TestAdmin {
copy.setValue(key, key);
boolean expectedException = false;
try {
modifyTable(tableName, copy);
admin.modifyTable(tableName, copy);
} catch (TableNotDisabledException re) {
expectedException = true;
}
@ -474,7 +474,7 @@ public class TestAdmin {
copy.setValue(key, key);
boolean expectedException = false;
try {
modifyTable(tableName, copy);
admin.modifyTable(tableName, copy);
} catch (TableNotDisabledException re) {
expectedException = true;
}
@ -485,32 +485,6 @@ public class TestAdmin {
"hbase.online.schema.update.enable", true);
}
/**
* Modify table is async so wait on completion of the table operation in master.
* @param tableName
* @param htd
* @throws IOException
*/
private void modifyTable(final byte [] tableName, final HTableDescriptor htd)
throws IOException {
MasterServices services = TEST_UTIL.getMiniHBaseCluster().getMaster();
ExecutorService executor = services.getExecutorService();
AtomicBoolean done = new AtomicBoolean(false);
executor.registerListener(EventType.C_M_MODIFY_TABLE, new DoneListener(done));
this.admin.modifyTable(tableName, htd);
while (!done.get()) {
//noinspection SynchronizationOnLocalVariableOrMethodParameter
synchronized (done) {
try {
done.wait(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
executor.unregisterListener(EventType.C_M_MODIFY_TABLE);
}
/**
* Listens for when an event is done in Master.
*/