Search in sources :

Example 1 with ScheduledChore

use of org.apache.hadoop.hbase.ScheduledChore in project hbase by apache.

the class TestServerNonceManager method testCleanup.

@Test
public void testCleanup() throws Exception {
    ManualEnvironmentEdge edge = new ManualEnvironmentEdge();
    EnvironmentEdgeManager.injectEdge(edge);
    try {
        ServerNonceManager nm = createManager(6);
        ScheduledChore cleanup = nm.createCleanupScheduledChore(Mockito.mock(Stoppable.class));
        edge.setValue(1);
        assertTrue(nm.startOperation(NO_NONCE, 1, createStoppable()));
        assertTrue(nm.startOperation(NO_NONCE, 2, createStoppable()));
        assertTrue(nm.startOperation(NO_NONCE, 3, createStoppable()));
        edge.setValue(2);
        nm.endOperation(NO_NONCE, 1, true);
        edge.setValue(4);
        nm.endOperation(NO_NONCE, 2, true);
        edge.setValue(9);
        cleanup.choreForTesting();
        // Nonce 1 has been cleaned up.
        assertTrue(nm.startOperation(NO_NONCE, 1, createStoppable()));
        // Nonce 2 has not been cleaned up.
        assertFalse(nm.startOperation(NO_NONCE, 2, createStoppable()));
        // Nonce 3 was active and active ops should never be cleaned up; try to end and start.
        nm.endOperation(NO_NONCE, 3, false);
        assertTrue(nm.startOperation(NO_NONCE, 3, createStoppable()));
        edge.setValue(11);
        cleanup.choreForTesting();
        // Now, nonce 2 has been cleaned up.
        assertTrue(nm.startOperation(NO_NONCE, 2, createStoppable()));
    } finally {
        EnvironmentEdgeManager.reset();
    }
}
Also used : ScheduledChore(org.apache.hadoop.hbase.ScheduledChore) Stoppable(org.apache.hadoop.hbase.Stoppable) ManualEnvironmentEdge(org.apache.hadoop.hbase.util.ManualEnvironmentEdge) Test(org.junit.Test)

Example 2 with ScheduledChore

use of org.apache.hadoop.hbase.ScheduledChore in project hbase by apache.

the class TestRSChoresScheduled method testDefaultScheduledChores.

@Test
public void testDefaultScheduledChores() throws Exception {
    // test if compactedHFilesDischarger chore is scheduled by default in HRegionServer init
    TestChoreField<CompactedHFilesDischarger> compactedHFilesDischargerTestChoreField = new TestChoreField<>();
    CompactedHFilesDischarger compactedHFilesDischarger = compactedHFilesDischargerTestChoreField.getChoreObj("compactedFileDischarger");
    compactedHFilesDischargerTestChoreField.testIfChoreScheduled(compactedHFilesDischarger);
    // test if compactionChecker chore is scheduled by default in HRegionServer init
    TestChoreField<ScheduledChore> compactionCheckerTestChoreField = new TestChoreField<>();
    ScheduledChore compactionChecker = compactionCheckerTestChoreField.getChoreObj("compactionChecker");
    compactionCheckerTestChoreField.testIfChoreScheduled(compactionChecker);
    // test if periodicFlusher chore is scheduled by default in HRegionServer init
    TestChoreField<ScheduledChore> periodicMemstoreFlusherTestChoreField = new TestChoreField<>();
    ScheduledChore periodicFlusher = periodicMemstoreFlusherTestChoreField.getChoreObj("periodicFlusher");
    periodicMemstoreFlusherTestChoreField.testIfChoreScheduled(periodicFlusher);
    // test if nonceManager chore is scheduled by default in HRegionServer init
    TestChoreField<ScheduledChore> nonceManagerTestChoreField = new TestChoreField<>();
    ScheduledChore nonceManagerChore = nonceManagerTestChoreField.getChoreObj("nonceManagerChore");
    nonceManagerTestChoreField.testIfChoreScheduled(nonceManagerChore);
    // test if executorStatusChore chore is scheduled by default in HRegionServer init
    TestChoreField<ExecutorStatusChore> executorStatusChoreTestChoreField = new TestChoreField<>();
    ExecutorStatusChore executorStatusChore = executorStatusChoreTestChoreField.getChoreObj("executorStatusChore");
    executorStatusChoreTestChoreField.testIfChoreScheduled(executorStatusChore);
}
Also used : ExecutorStatusChore(org.apache.hadoop.hbase.ExecutorStatusChore) ScheduledChore(org.apache.hadoop.hbase.ScheduledChore) Test(org.junit.Test)

Example 3 with ScheduledChore

use of org.apache.hadoop.hbase.ScheduledChore in project hbase by apache.

the class Canary method run.

@Override
public int run(String[] args) throws Exception {
    int index = parseArgs(args);
    ChoreService choreService = null;
    // Launches chore for refreshing kerberos credentials if security is enabled.
    // Please see http://hbase.apache.org/book.html#_running_canary_in_a_kerberos_enabled_cluster
    // for more details.
    final ScheduledChore authChore = AuthUtil.getAuthChore(conf);
    if (authChore != null) {
        choreService = new ChoreService("CANARY_TOOL");
        choreService.scheduleChore(authChore);
    }
    // Start to prepare the stuffs
    Monitor monitor = null;
    Thread monitorThread = null;
    long startTime = 0;
    long currentTimeLength = 0;
    // Get a connection to use in below.
    try (Connection connection = ConnectionFactory.createConnection(this.conf)) {
        do {
            // Do monitor !!
            try {
                monitor = this.newMonitor(connection, index, args);
                monitorThread = new Thread(monitor, "CanaryMonitor-" + System.currentTimeMillis());
                startTime = System.currentTimeMillis();
                monitorThread.start();
                while (!monitor.isDone()) {
                    // wait for 1 sec
                    Thread.sleep(1000);
                    // exit if any error occurs
                    if (this.failOnError && monitor.hasError()) {
                        monitorThread.interrupt();
                        if (monitor.initialized) {
                            return monitor.errorCode;
                        } else {
                            return INIT_ERROR_EXIT_CODE;
                        }
                    }
                    currentTimeLength = System.currentTimeMillis() - startTime;
                    if (currentTimeLength > this.timeout) {
                        LOG.error("The monitor is running too long (" + currentTimeLength + ") after timeout limit:" + this.timeout + " will be killed itself !!");
                        if (monitor.initialized) {
                            return TIMEOUT_ERROR_EXIT_CODE;
                        } else {
                            return INIT_ERROR_EXIT_CODE;
                        }
                    }
                }
                if (this.failOnError && monitor.finalCheckForErrors()) {
                    monitorThread.interrupt();
                    return monitor.errorCode;
                }
            } finally {
                if (monitor != null)
                    monitor.close();
            }
            Thread.sleep(interval);
        } while (interval > 0);
    }
    if (choreService != null) {
        choreService.shutdown();
    }
    return monitor.errorCode;
}
Also used : ChoreService(org.apache.hadoop.hbase.ChoreService) Connection(org.apache.hadoop.hbase.client.Connection) ScheduledChore(org.apache.hadoop.hbase.ScheduledChore)

Example 4 with ScheduledChore

use of org.apache.hadoop.hbase.ScheduledChore in project hbase by apache.

the class ChaosService method main.

public static void main(String[] args) throws Exception {
    Configuration conf = HBaseConfiguration.create();
    new GenericOptionsParser(conf, args);
    ChoreService choreChaosService = null;
    ScheduledChore authChore = AuthUtil.getAuthChore(conf);
    try {
        if (authChore != null) {
            choreChaosService = new ChoreService(ChaosConstants.CHORE_SERVICE_PREFIX);
            choreChaosService.scheduleChore(authChore);
        }
        execute(args, conf);
    } finally {
        if (authChore != null)
            choreChaosService.shutdown();
    }
}
Also used : ChoreService(org.apache.hadoop.hbase.ChoreService) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) Configuration(org.apache.hadoop.conf.Configuration) ScheduledChore(org.apache.hadoop.hbase.ScheduledChore) GenericOptionsParser(org.apache.hadoop.util.GenericOptionsParser)

Example 5 with ScheduledChore

use of org.apache.hadoop.hbase.ScheduledChore in project hbase by apache.

the class CanaryTool method runMonitor.

private int runMonitor(String[] monitorTargets) throws Exception {
    ChoreService choreService = null;
    // Launches chore for refreshing kerberos credentials if security is enabled.
    // Please see http://hbase.apache.org/book.html#_running_canary_in_a_kerberos_enabled_cluster
    // for more details.
    final ScheduledChore authChore = AuthUtil.getAuthChore(conf);
    if (authChore != null) {
        choreService = new ChoreService("CANARY_TOOL");
        choreService.scheduleChore(authChore);
    }
    // Start to prepare the stuffs
    Monitor monitor = null;
    Thread monitorThread;
    long startTime = 0;
    long currentTimeLength = 0;
    boolean failOnError = conf.getBoolean(HBASE_CANARY_FAIL_ON_ERROR, true);
    long timeout = conf.getLong(HBASE_CANARY_TIMEOUT, DEFAULT_TIMEOUT);
    // Get a connection to use in below.
    try (Connection connection = ConnectionFactory.createConnection(this.conf)) {
        do {
            // Do monitor !!
            try {
                monitor = this.newMonitor(connection, monitorTargets);
                startTime = EnvironmentEdgeManager.currentTime();
                monitorThread = new Thread(monitor, "CanaryMonitor-" + startTime);
                monitorThread.start();
                while (!monitor.isDone()) {
                    // wait for 1 sec
                    Thread.sleep(1000);
                    // exit if any error occurs
                    if (failOnError && monitor.hasError()) {
                        monitorThread.interrupt();
                        if (monitor.initialized) {
                            return monitor.errorCode;
                        } else {
                            return INIT_ERROR_EXIT_CODE;
                        }
                    }
                    currentTimeLength = EnvironmentEdgeManager.currentTime() - startTime;
                    if (currentTimeLength > timeout) {
                        LOG.error("The monitor is running too long (" + currentTimeLength + ") after timeout limit:" + timeout + " will be killed itself !!");
                        if (monitor.initialized) {
                            return TIMEOUT_ERROR_EXIT_CODE;
                        } else {
                            return INIT_ERROR_EXIT_CODE;
                        }
                    }
                }
                if (failOnError && monitor.finalCheckForErrors()) {
                    monitorThread.interrupt();
                    return monitor.errorCode;
                }
            } finally {
                if (monitor != null) {
                    monitor.close();
                }
            }
            Thread.sleep(interval);
        } while (interval > 0);
    }
    if (choreService != null) {
        choreService.shutdown();
    }
    return monitor.errorCode;
}
Also used : ChoreService(org.apache.hadoop.hbase.ChoreService) Connection(org.apache.hadoop.hbase.client.Connection) ScheduledChore(org.apache.hadoop.hbase.ScheduledChore)

Aggregations

ScheduledChore (org.apache.hadoop.hbase.ScheduledChore)7 Test (org.junit.Test)4 ChoreService (org.apache.hadoop.hbase.ChoreService)3 Stoppable (org.apache.hadoop.hbase.Stoppable)2 Connection (org.apache.hadoop.hbase.client.Connection)2 ManualEnvironmentEdge (org.apache.hadoop.hbase.util.ManualEnvironmentEdge)2 Configuration (org.apache.hadoop.conf.Configuration)1 ExecutorStatusChore (org.apache.hadoop.hbase.ExecutorStatusChore)1 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)1 BalancerChore (org.apache.hadoop.hbase.master.balancer.BalancerChore)1 ClusterStatusChore (org.apache.hadoop.hbase.master.balancer.ClusterStatusChore)1 HFileCleaner (org.apache.hadoop.hbase.master.cleaner.HFileCleaner)1 LogCleaner (org.apache.hadoop.hbase.master.cleaner.LogCleaner)1 ReplicationBarrierCleaner (org.apache.hadoop.hbase.master.cleaner.ReplicationBarrierCleaner)1 CatalogJanitor (org.apache.hadoop.hbase.master.janitor.CatalogJanitor)1 GenericOptionsParser (org.apache.hadoop.util.GenericOptionsParser)1