@Override
    public final boolean cancel(String errMsg) {
        isCancelling.set(true);
        try {
            // If waitingCreatingReplica == false, we will assume that
            // cancel thread will get the object lock very quickly.
            if (waitingCreatingReplica.get()) {
                Preconditions.checkState(createReplicaLatch != null);
                createReplicaLatch.countDownToZero(new Status(TStatusCode.OK, ""));
            }
            synchronized (this) {
                return cancelImpl(errMsg);
            }
        } finally {
            isCancelling.set(false);
        }
    }
@Test
    public void testDropTableBeforeCancel() {
        db.dropTable(table.getName());

        schemaChangeJob.cancel("test");
        Assert.assertEquals(AlterJobV2.JobState.CANCELLED, schemaChangeJob.getJobState());
    }