Search in sources :

Example 71 with AtomicBoolean

use of java.util.concurrent.atomic.AtomicBoolean in project hbase by apache.

the class TestVisibilityLabelsWithDefaultVisLabelService method testAddVisibilityLabelsOnRSRestart.

@Test(timeout = 60 * 1000)
public void testAddVisibilityLabelsOnRSRestart() throws Exception {
    List<RegionServerThread> regionServerThreads = TEST_UTIL.getHBaseCluster().getRegionServerThreads();
    for (RegionServerThread rsThread : regionServerThreads) {
        rsThread.getRegionServer().abort("Aborting ");
    }
    // Start one new RS
    RegionServerThread rs = TEST_UTIL.getHBaseCluster().startRegionServer();
    waitForLabelsRegionAvailability(rs.getRegionServer());
    final AtomicBoolean vcInitialized = new AtomicBoolean(true);
    do {
        PrivilegedExceptionAction<VisibilityLabelsResponse> action = new PrivilegedExceptionAction<VisibilityLabelsResponse>() {

            public VisibilityLabelsResponse run() throws Exception {
                String[] labels = { SECRET, CONFIDENTIAL, PRIVATE, "ABC", "XYZ" };
                try (Connection conn = ConnectionFactory.createConnection(conf)) {
                    VisibilityLabelsResponse resp = VisibilityClient.addLabels(conn, labels);
                    List<RegionActionResult> results = resp.getResultList();
                    if (results.get(0).hasException()) {
                        NameBytesPair pair = results.get(0).getException();
                        Throwable t = ProtobufUtil.toException(pair);
                        LOG.debug("Got exception writing labels", t);
                        if (t instanceof VisibilityControllerNotReadyException) {
                            vcInitialized.set(false);
                            LOG.warn("VisibilityController was not yet initialized");
                            Threads.sleep(10);
                        } else {
                            vcInitialized.set(true);
                        }
                    } else
                        LOG.debug("new labels added: " + resp);
                } catch (Throwable t) {
                    throw new IOException(t);
                }
                return null;
            }
        };
        SUPERUSER.runAs(action);
    } while (!vcInitialized.get());
    // Scan the visibility label
    Scan s = new Scan();
    s.setAuthorizations(new Authorizations(VisibilityUtils.SYSTEM_LABEL));
    int i = 0;
    try (Table ht = TEST_UTIL.getConnection().getTable(LABELS_TABLE_NAME);
        ResultScanner scanner = ht.getScanner(s)) {
        while (true) {
            Result next = scanner.next();
            if (next == null) {
                break;
            }
            i++;
        }
    }
    // One label is the "system" label.
    Assert.assertEquals("The count should be 13", 13, i);
}
Also used : Table(org.apache.hadoop.hbase.client.Table) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) Connection(org.apache.hadoop.hbase.client.Connection) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) ByteString(com.google.protobuf.ByteString) RegionActionResult(org.apache.hadoop.hbase.protobuf.generated.ClientProtos.RegionActionResult) IOException(java.io.IOException) RegionActionResult(org.apache.hadoop.hbase.protobuf.generated.ClientProtos.RegionActionResult) Result(org.apache.hadoop.hbase.client.Result) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) NameBytesPair(org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.NameBytesPair) Scan(org.apache.hadoop.hbase.client.Scan) RegionServerThread(org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread) VisibilityLabelsResponse(org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.VisibilityLabelsResponse) Test(org.junit.Test)

Example 72 with AtomicBoolean

use of java.util.concurrent.atomic.AtomicBoolean in project hive by apache.

the class HiveMetaStore method main.

/**
   * @param args
   */
public static void main(String[] args) throws Throwable {
    HiveConf.setLoadMetastoreConfig(true);
    final HiveConf conf = new HiveConf(HMSHandler.class);
    HiveMetastoreCli cli = new HiveMetastoreCli(conf);
    cli.parse(args);
    final boolean isCliVerbose = cli.isVerbose();
    // NOTE: It is critical to do this prior to initializing log4j, otherwise
    // any log specific settings via hiveconf will be ignored
    Properties hiveconf = cli.addHiveconfToSystemProperties();
    // use Hive's default log4j configuration
    if (System.getProperty("log4j.configurationFile") == null) {
        // before any of the other core hive classes are loaded
        try {
            LogUtils.initHiveLog4j();
        } catch (LogInitializationException e) {
            HMSHandler.LOG.warn(e.getMessage());
        }
    }
    HiveStringUtils.startupShutdownMessage(HiveMetaStore.class, args, LOG);
    try {
        String msg = "Starting hive metastore on port " + cli.port;
        HMSHandler.LOG.info(msg);
        if (cli.isVerbose()) {
            System.err.println(msg);
        }
        // set all properties specified on the command line
        for (Map.Entry<Object, Object> item : hiveconf.entrySet()) {
            conf.set((String) item.getKey(), (String) item.getValue());
        }
        // Add shutdown hook.
        ShutdownHookManager.addShutdownHook(new Runnable() {

            @Override
            public void run() {
                String shutdownMsg = "Shutting down hive metastore.";
                HMSHandler.LOG.info(shutdownMsg);
                if (isCliVerbose) {
                    System.err.println(shutdownMsg);
                }
                if (conf.getBoolVar(ConfVars.METASTORE_METRICS)) {
                    try {
                        MetricsFactory.close();
                    } catch (Exception e) {
                        LOG.error("error in Metrics deinit: " + e.getClass().getName() + " " + e.getMessage(), e);
                    }
                }
            }
        });
        //Start Metrics for Standalone (Remote) Mode
        if (conf.getBoolVar(ConfVars.METASTORE_METRICS)) {
            try {
                MetricsFactory.init(conf);
            } catch (Exception e) {
                // log exception, but ignore inability to start
                LOG.error("error in Metrics init: " + e.getClass().getName() + " " + e.getMessage(), e);
            }
        }
        Lock startLock = new ReentrantLock();
        Condition startCondition = startLock.newCondition();
        AtomicBoolean startedServing = new AtomicBoolean();
        startMetaStoreThreads(conf, startLock, startCondition, startedServing);
        startMetaStore(cli.getPort(), ShimLoader.getHadoopThriftAuthBridge(), conf, startLock, startCondition, startedServing);
    } catch (Throwable t) {
        // Catch the exception, log it and rethrow it.
        HMSHandler.LOG.error("Metastore Thrift Server threw an exception...", t);
        throw t;
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) Condition(java.util.concurrent.locks.Condition) Properties(java.util.Properties) JDOException(javax.jdo.JDOException) LogInitializationException(org.apache.hadoop.hive.common.LogUtils.LogInitializationException) TException(org.apache.thrift.TException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) SerDeException(org.apache.hadoop.hive.serde2.SerDeException) Lock(java.util.concurrent.locks.Lock) ReentrantLock(java.util.concurrent.locks.ReentrantLock) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LogInitializationException(org.apache.hadoop.hive.common.LogUtils.LogInitializationException) HiveConf(org.apache.hadoop.hive.conf.HiveConf) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap)

Example 73 with AtomicBoolean

use of java.util.concurrent.atomic.AtomicBoolean in project hbase by apache.

the class TestExecutorService method testExecutorService.

@Test
public void testExecutorService() throws Exception {
    int maxThreads = 5;
    int maxTries = 10;
    int sleepInterval = 10;
    Server mockedServer = mock(Server.class);
    when(mockedServer.getConfiguration()).thenReturn(HBaseConfiguration.create());
    // Start an executor service pool with max 5 threads
    ExecutorService executorService = new ExecutorService("unit_test");
    executorService.startExecutorService(ExecutorType.MASTER_SERVER_OPERATIONS, maxThreads);
    Executor executor = executorService.getExecutor(ExecutorType.MASTER_SERVER_OPERATIONS);
    ThreadPoolExecutor pool = executor.threadPoolExecutor;
    // Assert no threads yet
    assertEquals(0, pool.getPoolSize());
    AtomicBoolean lock = new AtomicBoolean(true);
    AtomicInteger counter = new AtomicInteger(0);
    // Submit maxThreads executors.
    for (int i = 0; i < maxThreads; i++) {
        executorService.submit(new TestEventHandler(mockedServer, EventType.M_SERVER_SHUTDOWN, lock, counter));
    }
    // The TestEventHandler will increment counter when it starts.
    int tries = 0;
    while (counter.get() < maxThreads && tries < maxTries) {
        LOG.info("Waiting for all event handlers to start...");
        Thread.sleep(sleepInterval);
        tries++;
    }
    // Assert that pool is at max threads.
    assertEquals(maxThreads, counter.get());
    assertEquals(maxThreads, pool.getPoolSize());
    ExecutorStatus status = executor.getStatus();
    assertTrue(status.queuedEvents.isEmpty());
    assertEquals(5, status.running.size());
    checkStatusDump(status);
    // Now interrupt the running Executor
    synchronized (lock) {
        lock.set(false);
        lock.notifyAll();
    }
    // Executor increments counter again on way out so.... test that happened.
    while (counter.get() < (maxThreads * 2) && tries < maxTries) {
        System.out.println("Waiting for all event handlers to finish...");
        Thread.sleep(sleepInterval);
        tries++;
    }
    assertEquals(maxThreads * 2, counter.get());
    assertEquals(maxThreads, pool.getPoolSize());
    // Make sure we don't get RejectedExecutionException.
    for (int i = 0; i < (2 * maxThreads); i++) {
        executorService.submit(new TestEventHandler(mockedServer, EventType.M_SERVER_SHUTDOWN, lock, counter));
    }
    // Now interrupt the running Executor
    synchronized (lock) {
        lock.set(false);
        lock.notifyAll();
    }
    // Make sure threads are still around even after their timetolive expires.
    Thread.sleep(ExecutorService.Executor.keepAliveTimeInMillis * 2);
    assertEquals(maxThreads, pool.getPoolSize());
    executorService.shutdown();
    assertEquals(0, executorService.getAllExecutorStatuses().size());
    // Test that submit doesn't throw NPEs
    executorService.submit(new TestEventHandler(mockedServer, EventType.M_SERVER_SHUTDOWN, lock, counter));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Executor(org.apache.hadoop.hbase.executor.ExecutorService.Executor) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ExecutorStatus(org.apache.hadoop.hbase.executor.ExecutorService.ExecutorStatus) Test(org.junit.Test)

Example 74 with AtomicBoolean

use of java.util.concurrent.atomic.AtomicBoolean in project hbase by apache.

the class TestTaskMonitor method testTasksGetAbortedOnLeak.

@Test
public void testTasksGetAbortedOnLeak() throws InterruptedException {
    final TaskMonitor tm = new TaskMonitor();
    assertTrue("Task monitor should start empty", tm.getTasks().isEmpty());
    final AtomicBoolean threadSuccess = new AtomicBoolean(false);
    // Make a task in some other thread and leak it
    Thread t = new Thread() {

        @Override
        public void run() {
            MonitoredTask task = tm.createStatus("Test task");
            assertEquals(MonitoredTask.State.RUNNING, task.getState());
            threadSuccess.set(true);
        }
    };
    t.start();
    t.join();
    // Make sure the thread saw the correct state
    assertTrue(threadSuccess.get());
    // Make sure the leaked reference gets cleared
    System.gc();
    System.gc();
    System.gc();
    // Now it should be aborted 
    MonitoredTask taskFromTm = tm.getTasks().get(0);
    assertEquals(MonitoredTask.State.ABORTED, taskFromTm.getState());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test)

Example 75 with AtomicBoolean

use of java.util.concurrent.atomic.AtomicBoolean in project hbase by apache.

the class TestHRegion method testParallelAppendWithMemStoreFlush.

/**
   * Test case to check append function with memstore flushing
   * @throws Exception
   */
@Test
public void testParallelAppendWithMemStoreFlush() throws Exception {
    byte[] family = Appender.family;
    this.region = initHRegion(tableName, method, CONF, family);
    final HRegion region = this.region;
    final AtomicBoolean appendDone = new AtomicBoolean(false);
    Runnable flusher = new Runnable() {

        @Override
        public void run() {
            while (!appendDone.get()) {
                try {
                    region.flush(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    };
    // After all append finished, the value will append to threadNum *
    // appendCounter Appender.CHAR
    int threadNum = 20;
    int appendCounter = 100;
    byte[] expected = new byte[threadNum * appendCounter];
    for (int i = 0; i < threadNum * appendCounter; i++) {
        System.arraycopy(Appender.CHAR, 0, expected, i, 1);
    }
    Thread[] appenders = new Thread[threadNum];
    Thread flushThread = new Thread(flusher);
    for (int i = 0; i < threadNum; i++) {
        appenders[i] = new Thread(new Appender(this.region, appendCounter));
        appenders[i].start();
    }
    flushThread.start();
    for (int i = 0; i < threadNum; i++) {
        appenders[i].join();
    }
    appendDone.set(true);
    flushThread.join();
    Get get = new Get(Appender.appendRow);
    get.addColumn(Appender.family, Appender.qualifier);
    get.setMaxVersions(1);
    Result res = this.region.get(get);
    List<Cell> kvs = res.getColumnCells(Appender.family, Appender.qualifier);
    // we just got the latest version
    assertEquals(kvs.size(), 1);
    Cell kv = kvs.get(0);
    byte[] appendResult = new byte[kv.getValueLength()];
    System.arraycopy(kv.getValueArray(), kv.getValueOffset(), appendResult, 0, kv.getValueLength());
    assertArrayEquals(expected, appendResult);
    this.region = null;
}
Also used : FailedSanityCheckException(org.apache.hadoop.hbase.exceptions.FailedSanityCheckException) RegionTooBusyException(org.apache.hadoop.hbase.RegionTooBusyException) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) NotServingRegionException(org.apache.hadoop.hbase.NotServingRegionException) DroppedSnapshotException(org.apache.hadoop.hbase.DroppedSnapshotException) RepeatingTestThread(org.apache.hadoop.hbase.MultithreadedTestUtil.RepeatingTestThread) TestThread(org.apache.hadoop.hbase.MultithreadedTestUtil.TestThread) Result(org.apache.hadoop.hbase.client.Result) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Get(org.apache.hadoop.hbase.client.Get) Cell(org.apache.hadoop.hbase.Cell) Test(org.junit.Test)

Aggregations

AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2412 Test (org.junit.Test)1002 CountDownLatch (java.util.concurrent.CountDownLatch)394 IOException (java.io.IOException)336 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)301 ArrayList (java.util.ArrayList)214 AtomicReference (java.util.concurrent.atomic.AtomicReference)202 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)108 Test (org.testng.annotations.Test)106 List (java.util.List)98 Ignite (org.apache.ignite.Ignite)98 AtomicLong (java.util.concurrent.atomic.AtomicLong)94 HashMap (java.util.HashMap)93 ExecutorService (java.util.concurrent.ExecutorService)90 Map (java.util.Map)88 ExecutionException (java.util.concurrent.ExecutionException)87 File (java.io.File)68 Random (java.util.Random)68 CyclicBarrier (java.util.concurrent.CyclicBarrier)68 HashSet (java.util.HashSet)63