use of org.apache.accumulo.core.util.NamingThreadFactory in project accumulo by apache.
the class TabletServerResourceManager method createEs.
private ExecutorService createEs(Property max, String name, BlockingQueue<Runnable> queue) {
int maxThreads = conf.getSystemConfiguration().getCount(max);
ThreadPoolExecutor tp = new ThreadPoolExecutor(maxThreads, maxThreads, 0L, TimeUnit.MILLISECONDS, queue, new NamingThreadFactory(name));
return addEs(max, name, tp);
}
use of org.apache.accumulo.core.util.NamingThreadFactory in project accumulo by apache.
the class TableOperationsImpl method addSplits.
@Override
public void addSplits(String tableName, SortedSet<Text> partitionKeys) throws TableNotFoundException, AccumuloException, AccumuloSecurityException {
Table.ID tableId = Tables.getTableId(context.getInstance(), tableName);
List<Text> splits = new ArrayList<>(partitionKeys);
// should be sorted because we copied from a sorted set, but that makes assumptions about
// how the copy was done so resort to be sure.
Collections.sort(splits);
CountDownLatch latch = new CountDownLatch(splits.size());
AtomicReference<Throwable> exception = new AtomicReference<>(null);
ExecutorService executor = Executors.newFixedThreadPool(16, new NamingThreadFactory("addSplits"));
try {
executor.execute(new SplitTask(new SplitEnv(tableName, tableId, executor, latch, exception), splits));
while (!latch.await(100, TimeUnit.MILLISECONDS)) {
if (exception.get() != null) {
executor.shutdownNow();
Throwable excep = exception.get();
// user would only have the stack trace for the background thread.
if (excep instanceof TableNotFoundException) {
TableNotFoundException tnfe = (TableNotFoundException) excep;
throw new TableNotFoundException(tableId.canonicalID(), tableName, "Table not found by background thread", tnfe);
} else if (excep instanceof TableOfflineException) {
log.debug("TableOfflineException occurred in background thread. Throwing new exception", excep);
throw new TableOfflineException(context.getInstance(), tableId.canonicalID());
} 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 AccumuloServerException) {
throw new AccumuloServerException((AccumuloServerException) excep);
} else if (excep instanceof Error) {
throw new Error(excep);
} else {
throw new AccumuloException(excep);
}
}
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
} finally {
executor.shutdown();
}
}
use of org.apache.accumulo.core.util.NamingThreadFactory in project accumulo by apache.
the class MultiThreadedRFileTest method testMultipleReaders.
@Test
public void testMultipleReaders() throws IOException {
final List<Throwable> threadExceptions = Collections.synchronizedList(new ArrayList<Throwable>());
Map<String, MutableInt> messages = new HashMap<>();
Map<String, String> stackTrace = new HashMap<>();
final TestRFile trfBase = new TestRFile(conf);
writeData(trfBase);
trfBase.openReader();
try {
validate(trfBase);
final TestRFile trfBaseCopy = trfBase.deepCopy();
validate(trfBaseCopy);
// now start up multiple RFile deepcopies
int maxThreads = 10;
String name = "MultiThreadedRFileTestThread";
ThreadPoolExecutor pool = new ThreadPoolExecutor(maxThreads + 1, maxThreads + 1, 5 * 60, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), new NamingThreadFactory(name));
pool.allowCoreThreadTimeOut(true);
try {
Runnable runnable = new Runnable() {
@Override
public void run() {
try {
TestRFile trf = trfBase;
synchronized (trfBaseCopy) {
trf = trfBaseCopy.deepCopy();
}
validate(trf);
} catch (Throwable t) {
threadExceptions.add(t);
}
}
};
for (int i = 0; i < maxThreads; i++) {
pool.submit(runnable);
}
} finally {
pool.shutdown();
try {
pool.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
for (Throwable t : threadExceptions) {
String msg = t.getClass() + " : " + t.getMessage();
if (!messages.containsKey(msg)) {
messages.put(msg, new MutableInt(1));
} else {
messages.get(msg).increment();
}
StringWriter string = new StringWriter();
PrintWriter writer = new PrintWriter(string);
t.printStackTrace(writer);
writer.flush();
stackTrace.put(msg, string.getBuffer().toString());
}
} finally {
trfBase.closeReader();
trfBase.close();
}
for (String message : messages.keySet()) {
LOG.error(messages.get(message) + ": " + message);
LOG.error(stackTrace.get(message));
}
assertTrue(threadExceptions.isEmpty());
}
Aggregations