/** * Called by the ProcedureExecutor after the procedure step is completed, * to add the step to the rollback list (or procedure stack) */ protected synchronized void addRollbackStep(Procedure<TEnvironment> proc) { if (proc.isFailed()) { state = State.FAILED; } if (subprocStack == null) { subprocStack = new ArrayList<>(); } proc.addStackIndex(subprocStack.size()); LOG.debug("Add procedure {} as the {}th rollback step", proc, subprocStack.size()); subprocStack.add(proc); }
public static String describe(Procedure<?> proc) { Map<String, Object> description = new LinkedHashMap<>(); description.put("ID", proc.getProcId()); description.put("PARENT_ID", proc.getParentProcId()); description.put("STATE", proc.getState()); description.put("OWNER", proc.getOwner()); description.put("TYPE", proc.getProcName()); description.put("START_TIME", new Date(proc.getSubmittedTime())); description.put("LAST_UPDATE", new Date(proc.getLastUpdate())); if (proc.isFailed()) { description.put("ERRORS", MasterProcedureUtil.unwrapRemoteIOException(proc).getMessage()); } description.put("PARAMETERS", parametersToObject(proc)); return JRubyFormat.print(description); }
public static void assertProcNotFailed(final Procedure<?> result) { assertFalse("found exception: " + result.getException(), result.isFailed()); }
public static Throwable getExceptionCause(final Procedure<?> procInfo) { assert procInfo.isFailed(); Throwable cause = procInfo.getException().getCause(); return cause == null ? procInfo.getException() : cause; }
@Test public void testAbortTimeoutWithChildren() { List<String> state = new ArrayList<>(); Procedure<Void> proc = new TestWaitingProcedure("wproc", state, true); proc.setTimeout(2500); long rootId = ProcedureTestingUtility.submitAndWait(procExecutor, proc); LOG.info(Objects.toString(state)); Procedure<?> result = procExecutor.getResult(rootId); assertTrue(state.toString(), result.isFailed()); ProcedureTestingUtility.assertIsTimeoutException(result); assertEquals(state.toString(), 3, state.size()); assertEquals("wproc-execute", state.get(0)); assertEquals("wproc-child-execute", state.get(1)); assertEquals("wproc-rollback", state.get(2)); } }
public static Throwable assertProcFailed(final Procedure<?> result) { assertEquals(true, result.isFailed()); LOG.info("procId=" + result.getProcId() + " exception: " + result.getException().getMessage()); return getExceptionCause(result); }
@Test public void testAbortTimeout() { final int PROC_TIMEOUT_MSEC = 2500; List<String> state = new ArrayList<>(); Procedure<Void> proc = new TestWaitingProcedure("wproc", state, false); proc.setTimeout(PROC_TIMEOUT_MSEC); long startTime = EnvironmentEdgeManager.currentTime(); long rootId = ProcedureTestingUtility.submitAndWait(procExecutor, proc); long execTime = EnvironmentEdgeManager.currentTime() - startTime; LOG.info(Objects.toString(state)); assertTrue("we didn't wait enough execTime=" + execTime, execTime >= PROC_TIMEOUT_MSEC); Procedure<?> result = procExecutor.getResult(rootId); assertTrue(state.toString(), result.isFailed()); ProcedureTestingUtility.assertIsTimeoutException(result); assertEquals(state.toString(), 2, state.size()); assertEquals("wproc-execute", state.get(0)); assertEquals("wproc-rollback", state.get(1)); }
private void assertProcFailed(long procId) { assertTrue("expected completed proc", procExecutor.isFinished(procId)); Procedure<?> result = procExecutor.getResult(procId); assertEquals(true, result.isFailed()); LOG.info(result.getException().getMessage()); }
@Test public void testRollbackRetriableFailure() { long procId = ProcedureTestingUtility.submitAndWait(procExecutor, new TestFaultyRollback()); Procedure<?> result = procExecutor.getResult(procId); assertTrue("expected a failure", result.isFailed()); LOG.info(result.getException().getMessage()); Throwable cause = ProcedureTestingUtility.getExceptionCause(result); assertTrue("expected TestProcedureException, got " + cause, cause instanceof TestProcedureException); }
@Test public void testRestoreSnapshotToDifferentTable() throws Exception { final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); final TableName restoredTableName = TableName.valueOf(name.getMethodName()); final HTableDescriptor newHTD = createHTableDescriptor(restoredTableName, CF1, CF2); long procId = ProcedureTestingUtility.submitAndWait( procExec, new RestoreSnapshotProcedure(procExec.getEnvironment(), newHTD, snapshot)); Procedure<?> result = procExec.getResult(procId); assertTrue(result.isFailed()); LOG.debug("Restore snapshot failed with exception: " + result.getException()); assertTrue( ProcedureTestingUtility.getExceptionCause(result) instanceof TableNotFoundException); }
@Test public void testCloneSnapshotToSameTable() throws Exception { // take the snapshot SnapshotProtos.SnapshotDescription snapshotDesc = getSnapshot(); final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); final TableName clonedTableName = TableName.valueOf(snapshotDesc.getTable()); final TableDescriptor htd = createTableDescriptor(clonedTableName, CF); long procId = ProcedureTestingUtility.submitAndWait( procExec, new CloneSnapshotProcedure(procExec.getEnvironment(), htd, snapshotDesc)); Procedure<?> result = procExec.getResult(procId); assertTrue(result.isFailed()); LOG.debug("Clone snapshot failed with exception: " + result.getException()); assertTrue( ProcedureTestingUtility.getExceptionCause(result) instanceof TableExistsException); }
@Test public void testDeleteSystemNamespace() throws Exception { final String namespaceName = NamespaceDescriptor.SYSTEM_NAMESPACE.getName(); final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); long procId = procExec.submitProcedure( new DeleteNamespaceProcedure(procExec.getEnvironment(), namespaceName)); // Wait the completion ProcedureTestingUtility.waitProcedure(procExec, procId); Procedure<?> result = procExec.getResult(procId); assertTrue(result.isFailed()); LOG.debug("Delete namespace failed with exception: " + result.getException()); assertTrue(ProcedureTestingUtility.getExceptionCause(result) instanceof ConstraintException); }
@Test public void testDeleteNonEmptyNamespace() throws Exception { final String namespaceName = "testDeleteNonExistNamespace"; final TableName tableName = TableName.valueOf("testDeleteNonExistNamespace:" + name.getMethodName()); final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); // create namespace createNamespaceForTesting(namespaceName); // create the table under the new namespace MasterProcedureTestingUtility.createTable(procExec, tableName, null, "f1"); long procId = procExec.submitProcedure( new DeleteNamespaceProcedure(procExec.getEnvironment(), namespaceName)); // Wait the completion ProcedureTestingUtility.waitProcedure(procExec, procId); Procedure<?> result = procExec.getResult(procId); assertTrue(result.isFailed()); LOG.debug("Delete namespace failed with exception: " + result.getException()); assertTrue(ProcedureTestingUtility.getExceptionCause(result) instanceof ConstraintException); }
@Test public void testDeleteNonExistNamespace() throws Exception { final String namespaceName = "testDeleteNonExistNamespace"; final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); validateNamespaceNotExist(namespaceName); long procId = procExec.submitProcedure( new DeleteNamespaceProcedure(procExec.getEnvironment(), namespaceName)); // Wait the completion ProcedureTestingUtility.waitProcedure(procExec, procId); // Expect fail with NamespaceNotFoundException Procedure<?> result = procExec.getResult(procId); assertTrue(result.isFailed()); LOG.debug("Delete namespace failed with exception: " + result.getException()); assertTrue( ProcedureTestingUtility.getExceptionCause(result) instanceof NamespaceNotFoundException); }
@Test public void testCreateSystemNamespace() throws Exception { final NamespaceDescriptor nsd = UTIL.getAdmin().getNamespaceDescriptor(NamespaceDescriptor.SYSTEM_NAMESPACE.getName()); final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); long procId = procExec.submitProcedure( new CreateNamespaceProcedure(procExec.getEnvironment(), nsd)); // Wait the completion ProcedureTestingUtility.waitProcedure(procExec, procId); Procedure<?> result = procExec.getResult(procId); assertTrue(result.isFailed()); LOG.debug("Create namespace failed with exception: " + result.getException()); assertTrue( ProcedureTestingUtility.getExceptionCause(result) instanceof NamespaceExistException); }
@Test public void testCreateNamespaceWithInvalidRegionCount() throws Exception { final NamespaceDescriptor nsd = NamespaceDescriptor.create("testCreateNamespaceWithInvalidRegionCount").build(); final String nsKey = "hbase.namespace.quota.maxregions"; final String nsValue = "-1"; final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); nsd.setConfiguration(nsKey, nsValue); long procId = procExec.submitProcedure( new CreateNamespaceProcedure(procExec.getEnvironment(), nsd)); // Wait the completion ProcedureTestingUtility.waitProcedure(procExec, procId); Procedure<?> result = procExec.getResult(procId); assertTrue(result.isFailed()); LOG.debug("Create namespace failed with exception: " + result.getException()); assertTrue(ProcedureTestingUtility.getExceptionCause(result) instanceof ConstraintException); }
@Test public void testCreateNamespaceWithInvalidTableCount() throws Exception { final NamespaceDescriptor nsd = NamespaceDescriptor.create("testCreateNamespaceWithInvalidTableCount").build(); final String nsKey = "hbase.namespace.quota.maxtables"; final String nsValue = "-1"; final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); nsd.setConfiguration(nsKey, nsValue); long procId = procExec.submitProcedure( new CreateNamespaceProcedure(procExec.getEnvironment(), nsd)); // Wait the completion ProcedureTestingUtility.waitProcedure(procExec, procId); Procedure<?> result = procExec.getResult(procId); assertTrue(result.isFailed()); LOG.debug("Create namespace failed with exception: " + result.getException()); assertTrue(ProcedureTestingUtility.getExceptionCause(result) instanceof ConstraintException); }
@Test public void testRestoreSnapshotToEnabledTable() throws Exception { final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); try { UTIL.getAdmin().enableTable(snapshotTableName); long procId = ProcedureTestingUtility.submitAndWait( procExec, new RestoreSnapshotProcedure(procExec.getEnvironment(), snapshotHTD, snapshot)); Procedure<?> result = procExec.getResult(procId); assertTrue(result.isFailed()); LOG.debug("Restore snapshot failed with exception: " + result.getException()); assertTrue( ProcedureTestingUtility.getExceptionCause(result) instanceof TableNotDisabledException); } finally { UTIL.getAdmin().disableTable(snapshotTableName); } }
@Test public void testModifyNamespaceWithInvalidTableCount() throws Exception { final NamespaceDescriptor nsd = NamespaceDescriptor.create("testModifyNamespaceWithInvalidTableCount").build(); final String nsKey = "hbase.namespace.quota.maxtables"; final String nsValue = "-1"; final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); createNamespaceForTesting(nsd); // Modify nsd.setConfiguration(nsKey, nsValue); long procId = procExec.submitProcedure( new ModifyNamespaceProcedure(procExec.getEnvironment(), nsd)); // Wait the completion ProcedureTestingUtility.waitProcedure(procExec, procId); Procedure<?> result = procExec.getResult(procId); assertTrue(result.isFailed()); LOG.debug("Modify namespace failed with exception: " + result.getException()); assertTrue(ProcedureTestingUtility.getExceptionCause(result) instanceof ConstraintException); }
@Test public void testModifyNamespaceWithInvalidRegionCount() throws Exception { final NamespaceDescriptor nsd = NamespaceDescriptor.create("testModifyNamespaceWithInvalidRegionCount").build(); final String nsKey = "hbase.namespace.quota.maxregions"; final String nsValue = "-1"; final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); createNamespaceForTesting(nsd); // Modify nsd.setConfiguration(nsKey, nsValue); long procId = procExec.submitProcedure( new ModifyNamespaceProcedure(procExec.getEnvironment(), nsd)); // Wait the completion ProcedureTestingUtility.waitProcedure(procExec, procId); Procedure<?> result = procExec.getResult(procId); assertTrue(result.isFailed()); LOG.debug("Modify namespace failed with exception: " + result.getException()); assertTrue(ProcedureTestingUtility.getExceptionCause(result) instanceof ConstraintException); }