Search in sources :

Example 1 with SplitLogTask

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

the class TestSplitLogWorker method testAcquireMultiTasksByAvgTasksPerRS.

/**
   * The test checks SplitLogWorker should not spawn more splitters than expected num of tasks per
   * RS
   * @throws Exception
   */
@Test(timeout = 60000)
public void testAcquireMultiTasksByAvgTasksPerRS() throws Exception {
    LOG.info("testAcquireMultiTasks");
    SplitLogCounters.resetCounters();
    final String TATAS = "tatas";
    final ServerName RS = ServerName.valueOf("rs,1,1");
    final ServerName RS2 = ServerName.valueOf("rs,1,2");
    final int maxTasks = 3;
    Configuration testConf = HBaseConfiguration.create(TEST_UTIL.getConfiguration());
    testConf.setInt("hbase.regionserver.wal.max.splitters", maxTasks);
    RegionServerServices mockedRS = getRegionServer(RS);
    // create two RS nodes
    String rsPath = ZKUtil.joinZNode(zkw.znodePaths.rsZNode, RS.getServerName());
    zkw.getRecoverableZooKeeper().create(rsPath, null, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
    rsPath = ZKUtil.joinZNode(zkw.znodePaths.rsZNode, RS2.getServerName());
    zkw.getRecoverableZooKeeper().create(rsPath, null, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
    for (int i = 0; i < maxTasks; i++) {
        zkw.getRecoverableZooKeeper().create(ZKSplitLog.getEncodedNodeName(zkw, TATAS + i), new SplitLogTask.Unassigned(ServerName.valueOf("mgr,1,1"), this.mode).toByteArray(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    }
    SplitLogWorker slw = new SplitLogWorker(ds, testConf, mockedRS, neverEndingTask);
    slw.start();
    try {
        int acquiredTasks = 0;
        waitForCounter(SplitLogCounters.tot_wkr_task_acquired, 0, 2, WAIT_TIME);
        for (int i = 0; i < maxTasks; i++) {
            byte[] bytes = ZKUtil.getData(zkw, ZKSplitLog.getEncodedNodeName(zkw, TATAS + i));
            SplitLogTask slt = SplitLogTask.parseFrom(bytes);
            if (slt.isOwned(RS)) {
                acquiredTasks++;
            }
        }
        assertEquals(2, acquiredTasks);
    } finally {
        stopSplitLogWorker(slw);
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) ServerName(org.apache.hadoop.hbase.ServerName) SplitLogTask(org.apache.hadoop.hbase.SplitLogTask) Test(org.junit.Test)

Example 2 with SplitLogTask

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

the class ZkSplitLogWorkerCoordination method attemptToOwnTask.

/**
   * Try to own the task by transitioning the zk node data from UNASSIGNED to OWNED.
   * <p>
   * This method is also used to periodically heartbeat the task progress by transitioning the node
   * from OWNED to OWNED.
   * <p>
   * @param isFirstTime shows whther it's the first attempt.
   * @param zkw zk wathcer
   * @param server name
   * @param task to own
   * @param taskZKVersion version of the task in zk
   * @return non-negative integer value when task can be owned by current region server otherwise -1
   */
protected static int attemptToOwnTask(boolean isFirstTime, ZooKeeperWatcher zkw, ServerName server, String task, RecoveryMode mode, int taskZKVersion) {
    int latestZKVersion = FAILED_TO_OWN_TASK;
    try {
        SplitLogTask slt = new SplitLogTask.Owned(server, mode);
        Stat stat = zkw.getRecoverableZooKeeper().setData(task, slt.toByteArray(), taskZKVersion);
        if (stat == null) {
            LOG.warn("zk.setData() returned null for path " + task);
            SplitLogCounters.tot_wkr_task_heartbeat_failed.incrementAndGet();
            return FAILED_TO_OWN_TASK;
        }
        latestZKVersion = stat.getVersion();
        SplitLogCounters.tot_wkr_task_heartbeat.incrementAndGet();
        return latestZKVersion;
    } catch (KeeperException e) {
        if (!isFirstTime) {
            if (e.code().equals(KeeperException.Code.NONODE)) {
                LOG.warn("NONODE failed to assert ownership for " + task, e);
            } else if (e.code().equals(KeeperException.Code.BADVERSION)) {
                LOG.warn("BADVERSION failed to assert ownership for " + task, e);
            } else {
                LOG.warn("failed to assert ownership for " + task, e);
            }
        }
    } catch (InterruptedException e1) {
        LOG.warn("Interrupted while trying to assert ownership of " + task + " " + StringUtils.stringifyException(e1));
        Thread.currentThread().interrupt();
    }
    SplitLogCounters.tot_wkr_task_heartbeat_failed.incrementAndGet();
    return FAILED_TO_OWN_TASK;
}
Also used : Stat(org.apache.zookeeper.data.Stat) SplitLogTask(org.apache.hadoop.hbase.SplitLogTask) KeeperException(org.apache.zookeeper.KeeperException)

Example 3 with SplitLogTask

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

the class ZKSplitLogManagerCoordination method createNode.

private void createNode(String path, Long retry_count) {
    SplitLogTask slt = new SplitLogTask.Unassigned(details.getServerName());
    ZKUtil.asyncCreate(this.watcher, path, slt.toByteArray(), new CreateAsyncCallback(), retry_count);
    SplitLogCounters.tot_mgr_node_create_queued.increment();
    return;
}
Also used : SplitLogTask(org.apache.hadoop.hbase.SplitLogTask)

Example 4 with SplitLogTask

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

the class ZKSplitLogManagerCoordination method rescan.

/**
 * signal the workers that a task was resubmitted by creating the RESCAN node.
 */
private void rescan(long retries) {
    // The RESCAN node will be deleted almost immediately by the
    // SplitLogManager as soon as it is created because it is being
    // created in the DONE state. This behavior prevents a buildup
    // of RESCAN nodes. But there is also a chance that a SplitLogWorker
    // might miss the watch-trigger that creation of RESCAN node provides.
    // Since the TimeoutMonitor will keep resubmitting UNASSIGNED tasks
    // therefore this behavior is safe.
    SplitLogTask slt = new SplitLogTask.Done(this.details.getServerName());
    this.watcher.getRecoverableZooKeeper().getZooKeeper().create(ZKSplitLog.getRescanNode(watcher), slt.toByteArray(), Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL, new CreateRescanAsyncCallback(), Long.valueOf(retries));
}
Also used : SplitLogTask(org.apache.hadoop.hbase.SplitLogTask)

Example 5 with SplitLogTask

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

the class ZkSplitLogWorkerCoordination method getDataSetWatchSuccess.

void getDataSetWatchSuccess(String path, byte[] data) {
    SplitLogTask slt;
    try {
        slt = SplitLogTask.parseFrom(data);
    } catch (DeserializationException e) {
        LOG.warn("Failed parse", e);
        return;
    }
    synchronized (grabTaskLock) {
        if (workerInGrabTask) {
            // currentTask can change but that's ok
            String taskpath = currentTask;
            if (taskpath != null && taskpath.equals(path)) {
                // worker to unassigned to owned by another worker
                if (!slt.isOwned(serverName) && !slt.isDone(serverName) && !slt.isErr(serverName) && !slt.isResigned(serverName)) {
                    LOG.info("task " + taskpath + " preempted from " + serverName + ", current task state and owner=" + slt.toString());
                    worker.stopTask();
                }
            }
        }
    }
}
Also used : SplitLogTask(org.apache.hadoop.hbase.SplitLogTask) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException)

Aggregations

SplitLogTask (org.apache.hadoop.hbase.SplitLogTask)28 Test (org.junit.Test)19 ServerName (org.apache.hadoop.hbase.ServerName)17 TaskBatch (org.apache.hadoop.hbase.master.SplitLogManager.TaskBatch)9 KeeperException (org.apache.zookeeper.KeeperException)6 DeserializationException (org.apache.hadoop.hbase.exceptions.DeserializationException)4 Stat (org.apache.zookeeper.data.Stat)3 IOException (java.io.IOException)2 InterruptedIOException (java.io.InterruptedIOException)2 Configuration (org.apache.hadoop.conf.Configuration)2 Path (org.apache.hadoop.fs.Path)2 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)2 Task (org.apache.hadoop.hbase.master.SplitLogManager.Task)2 MutableInt (org.apache.commons.lang3.mutable.MutableInt)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 RecoveryMode (org.apache.hadoop.hbase.shaded.protobuf.generated.ZooKeeperProtos.SplitLogTask.RecoveryMode)1