Search in sources :

Example 6 with NamingThreadFactory

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);
}
Also used : NamingThreadFactory(org.apache.accumulo.core.util.NamingThreadFactory) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 7 with NamingThreadFactory

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();
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) RootTable(org.apache.accumulo.core.metadata.RootTable) MetadataTable(org.apache.accumulo.core.metadata.MetadataTable) TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) NamingThreadFactory(org.apache.accumulo.core.util.NamingThreadFactory) ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) ExecutorService(java.util.concurrent.ExecutorService) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException)

Example 8 with NamingThreadFactory

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());
}
Also used : HashMap(java.util.HashMap) NamingThreadFactory(org.apache.accumulo.core.util.NamingThreadFactory) StringWriter(java.io.StringWriter) MutableInt(org.apache.commons.lang.mutable.MutableInt) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

NamingThreadFactory (org.apache.accumulo.core.util.NamingThreadFactory)8 ArrayList (java.util.ArrayList)4 ExecutorService (java.util.concurrent.ExecutorService)4 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)4 LoggingRunnable (org.apache.accumulo.fate.util.LoggingRunnable)4 List (java.util.List)3 TreeMap (java.util.TreeMap)3 KeyExtent (org.apache.accumulo.core.data.impl.KeyExtent)3 TKeyExtent (org.apache.accumulo.core.data.thrift.TKeyExtent)3 Path (org.apache.hadoop.fs.Path)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2 AccumuloException (org.apache.accumulo.core.client.AccumuloException)2 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)2 TabletLocation (org.apache.accumulo.core.client.impl.TabletLocator.TabletLocation)2 TraceRunnable (org.apache.htrace.wrappers.TraceRunnable)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 HashSet (java.util.HashSet)1