Repository: accumulo Updated Branches: refs/heads/master 2ab04606d -> f09af2e8a
ACCUMULO-4619 fix split hanging on Error Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/8c0f03ac Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/8c0f03ac Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/8c0f03ac Branch: refs/heads/master Commit: 8c0f03ac2d8e06b220e2882d54914f2034625e15 Parents: 4ba5faf Author: Keith Turner <ktur...@apache.org> Authored: Fri Apr 7 18:43:55 2017 -0400 Committer: Keith Turner <ktur...@apache.org> Committed: Fri Apr 7 18:43:55 2017 -0400 ---------------------------------------------------------------------- .../core/client/impl/TableOperationsImpl.java | 39 +++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/accumulo/blob/8c0f03ac/core/src/main/java/org/apache/accumulo/core/client/impl/TableOperationsImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/client/impl/TableOperationsImpl.java b/core/src/main/java/org/apache/accumulo/core/client/impl/TableOperationsImpl.java index 1a7a38c..42afb9d 100644 --- a/core/src/main/java/org/apache/accumulo/core/client/impl/TableOperationsImpl.java +++ b/core/src/main/java/org/apache/accumulo/core/client/impl/TableOperationsImpl.java @@ -318,9 +318,9 @@ public class TableOperationsImpl extends TableOperationsHelper { private String tableId; private ExecutorService executor; private CountDownLatch latch; - private AtomicReference<Exception> exception; + private AtomicReference<Throwable> exception; - SplitEnv(String tableName, String tableId, ExecutorService executor, CountDownLatch latch, AtomicReference<Exception> exception) { + SplitEnv(String tableName, String tableId, ExecutorService executor, CountDownLatch latch, AtomicReference<Throwable> exception) { this.tableName = tableName; this.tableId = tableId; this.executor = executor; @@ -359,11 +359,11 @@ public class TableOperationsImpl extends TableOperationsHelper { addSplits(env.tableName, new TreeSet<>(splits.subList(mid, mid + 1)), env.tableId); env.latch.countDown(); - env.executor.submit(new SplitTask(env, splits.subList(0, mid))); - env.executor.submit(new SplitTask(env, splits.subList(mid + 1, splits.size()))); + env.executor.execute(new SplitTask(env, splits.subList(0, mid))); + env.executor.execute(new SplitTask(env, splits.subList(mid + 1, splits.size()))); - } catch (Exception e) { - env.exception.compareAndSet(null, e); + } catch (Throwable t) { + env.exception.compareAndSet(null, t); } } @@ -379,26 +379,29 @@ public class TableOperationsImpl extends TableOperationsHelper { Collections.sort(splits); CountDownLatch latch = new CountDownLatch(splits.size()); - AtomicReference<Exception> exception = new AtomicReference<>(null); + AtomicReference<Throwable> exception = new AtomicReference<>(null); ExecutorService executor = Executors.newFixedThreadPool(16, new NamingThreadFactory("addSplits")); try { - executor.submit(new SplitTask(new SplitEnv(tableName, tableId, executor, latch, exception), splits)); + executor.execute(new SplitTask(new SplitEnv(tableName, tableId, executor, latch, exception), splits)); while (!latch.await(100, TimeUnit.MILLISECONDS)) { if (exception.get() != null) { executor.shutdownNow(); - Exception excep = exception.get(); - if (excep instanceof TableNotFoundException) - throw (TableNotFoundException) excep; - else if (excep instanceof AccumuloException) - throw (AccumuloException) excep; - else if (excep instanceof AccumuloSecurityException) - throw (AccumuloSecurityException) excep; - else if (excep instanceof RuntimeException) - throw (RuntimeException) excep; + Throwable excep = exception.get(); + // Below all exceptions are wrapped and rethrown. This is done so that the user knows what code path got them here. If the wrapping was not done, the + // user would only have the stack trace for the background thread. + if (excep instanceof TableNotFoundException) { + TableNotFoundException tnfe = (TableNotFoundException) excep; + throw new TableNotFoundException(tableId, tableName, "Table not found by background thread", tnfe); + } else if (excep instanceof AccumuloSecurityException) { + // base == background accumulo security exception + AccumuloSecurityException base = (AccumuloSecurityException) excep; + throw new AccumuloSecurityException(base.getUser(), base.asThriftException().getCode(), base.getTableInfo(), excep); + } else if (excep instanceof Error) + throw new Error(excep); else - throw new RuntimeException(excep); + throw new AccumuloException(excep); } } } catch (InterruptedException e) {