Search in sources :

Example 46 with LockResponse

use of org.apache.hadoop.hive.metastore.api.LockResponse in project hive by apache.

the class DbTxnManager method acquireMaterializationRebuildLock.

@Override
public LockResponse acquireMaterializationRebuildLock(String dbName, String tableName, long txnId) throws LockException {
    // Acquire lock
    LockResponse lockResponse;
    try {
        lockResponse = getMS().lockMaterializationRebuild(dbName, tableName, txnId);
    } catch (TException e) {
        throw new LockException(ErrorMsg.METASTORE_COMMUNICATION_FAILED.getMsg(), e);
    }
    if (lockResponse.getState() == LockState.ACQUIRED) {
        // If lock response is ACQUIRED, we can create the heartbeater
        long initialDelay = 0L;
        long heartbeatInterval = getHeartbeatInterval(conf);
        assert heartbeatInterval > 0;
        MaterializationRebuildLockHeartbeater heartbeater = new MaterializationRebuildLockHeartbeater(this, dbName, tableName, queryId, txnId);
        ScheduledFuture<?> task = startHeartbeat(initialDelay, heartbeatInterval, heartbeater);
        heartbeater.task.set(task);
        LOG.debug("Started heartbeat for materialization rebuild lock for {} with delay/interval = {}/{} {} for query: {}", AcidUtils.getFullTableName(dbName, tableName), initialDelay, heartbeatInterval, TimeUnit.MILLISECONDS, queryId);
    }
    return lockResponse;
}
Also used : TException(org.apache.thrift.TException) LockResponse(org.apache.hadoop.hive.metastore.api.LockResponse) NoSuchLockException(org.apache.hadoop.hive.metastore.api.NoSuchLockException)

Example 47 with LockResponse

use of org.apache.hadoop.hive.metastore.api.LockResponse in project hive by apache.

the class TestTxnHandler method testLockEWEWEW.

@Test
public void testLockEWEWEW() throws Exception {
    // Test that write blocks two writes
    LockComponent comp = new LockComponent(LockType.EXCL_WRITE, LockLevel.DB, "mydb");
    comp.setTablename("mytable");
    comp.setPartitionname("mypartition=myvalue");
    comp.setOperationType(DataOperationType.DELETE);
    List<LockComponent> components = new ArrayList<LockComponent>(1);
    components.add(comp);
    LockRequest req = new LockRequest(components, "me", "localhost");
    req.setTxnid(openTxn());
    LockResponse res = txnHandler.lock(req);
    assertTrue(res.getState() == LockState.ACQUIRED);
    comp = new LockComponent(LockType.EXCL_WRITE, LockLevel.DB, "mydb");
    comp.setTablename("mytable");
    comp.setPartitionname("mypartition=myvalue");
    comp.setOperationType(DataOperationType.DELETE);
    components.clear();
    components.add(comp);
    req = new LockRequest(components, "me", "localhost");
    req.setTxnid(openTxn());
    res = txnHandler.lock(req);
    assertTrue(res.getState() == LockState.WAITING);
    comp = new LockComponent(LockType.EXCL_WRITE, LockLevel.DB, "mydb");
    comp.setTablename("mytable");
    comp.setPartitionname("mypartition=myvalue");
    comp.setOperationType(DataOperationType.DELETE);
    components.clear();
    components.add(comp);
    req = new LockRequest(components, "me", "localhost");
    req.setTxnid(openTxn());
    res = txnHandler.lock(req);
    assertTrue(res.getState() == LockState.WAITING);
}
Also used : LockComponent(org.apache.hadoop.hive.metastore.api.LockComponent) LockResponse(org.apache.hadoop.hive.metastore.api.LockResponse) ArrayList(java.util.ArrayList) LockRequest(org.apache.hadoop.hive.metastore.api.LockRequest) CheckLockRequest(org.apache.hadoop.hive.metastore.api.CheckLockRequest) Test(org.junit.Test)

Example 48 with LockResponse

use of org.apache.hadoop.hive.metastore.api.LockResponse in project hive by apache.

the class TestTxnHandler method testUnlockOnAbort.

@Test
public void testUnlockOnAbort() throws Exception {
    // Test that committing unlocks
    long txnid = openTxn();
    LockComponent comp = new LockComponent(LockType.SHARED_WRITE, LockLevel.DB, "mydb");
    comp.setOperationType(DataOperationType.UPDATE);
    List<LockComponent> components = new ArrayList<LockComponent>(1);
    components.add(comp);
    LockRequest req = new LockRequest(components, "me", "localhost");
    req.setTxnid(txnid);
    LockResponse res = txnHandler.lock(req);
    assertTrue(res.getState() == LockState.ACQUIRED);
    txnHandler.abortTxn(new AbortTxnRequest(txnid));
    assertEquals(0, txnHandler.numLocksInLockTable());
}
Also used : LockComponent(org.apache.hadoop.hive.metastore.api.LockComponent) LockResponse(org.apache.hadoop.hive.metastore.api.LockResponse) ArrayList(java.util.ArrayList) AbortTxnRequest(org.apache.hadoop.hive.metastore.api.AbortTxnRequest) LockRequest(org.apache.hadoop.hive.metastore.api.LockRequest) CheckLockRequest(org.apache.hadoop.hive.metastore.api.CheckLockRequest) Test(org.junit.Test)

Example 49 with LockResponse

use of org.apache.hadoop.hive.metastore.api.LockResponse in project hive by apache.

the class TestTxnHandler method showLocks.

@Test
public void showLocks() throws Exception {
    long begining = System.currentTimeMillis();
    LockComponent comp = new LockComponent(LockType.EXCLUSIVE, LockLevel.DB, "mydb");
    comp.setOperationType(DataOperationType.NO_TXN);
    List<LockComponent> components = new ArrayList<LockComponent>(1);
    components.add(comp);
    LockRequest req = new LockRequest(components, "me", "localhost");
    LockResponse res = txnHandler.lock(req);
    // Open txn
    long txnid = openTxn();
    comp = new LockComponent(LockType.SHARED_READ, LockLevel.TABLE, "mydb");
    comp.setTablename("mytable");
    comp.setOperationType(DataOperationType.SELECT);
    components = new ArrayList<LockComponent>(1);
    components.add(comp);
    req = new LockRequest(components, "me", "localhost");
    req.setTxnid(txnid);
    res = txnHandler.lock(req);
    // Locks not associated with a txn
    components = new ArrayList<LockComponent>(1);
    comp = new LockComponent(LockType.SHARED_READ, LockLevel.PARTITION, "yourdb");
    comp.setTablename("yourtable");
    comp.setPartitionname("yourpartition=yourvalue");
    comp.setOperationType(DataOperationType.INSERT);
    components.add(comp);
    req = new LockRequest(components, "you", "remotehost");
    res = txnHandler.lock(req);
    ShowLocksResponse rsp = txnHandler.showLocks(new ShowLocksRequest());
    List<ShowLocksResponseElement> locks = rsp.getLocks();
    assertEquals(3, locks.size());
    boolean[] saw = new boolean[locks.size()];
    for (int i = 0; i < saw.length; i++) saw[i] = false;
    for (ShowLocksResponseElement lock : locks) {
        if (lock.getLockid() == 1) {
            assertEquals(0, lock.getTxnid());
            assertEquals("mydb", lock.getDbname());
            assertNull(lock.getTablename());
            assertNull(lock.getPartname());
            assertEquals(LockState.ACQUIRED, lock.getState());
            assertEquals(LockType.EXCLUSIVE, lock.getType());
            assertTrue(lock.toString(), 0 != lock.getLastheartbeat());
            assertTrue("Expected acquired at " + lock.getAcquiredat() + " to be between " + begining + " and " + System.currentTimeMillis(), begining <= lock.getAcquiredat() && System.currentTimeMillis() >= lock.getAcquiredat());
            assertEquals("me", lock.getUser());
            assertEquals("localhost", lock.getHostname());
            saw[0] = true;
        } else if (lock.getLockid() == 2) {
            assertEquals(1, lock.getTxnid());
            assertEquals("mydb", lock.getDbname());
            assertEquals("mytable", lock.getTablename());
            assertNull(lock.getPartname());
            assertEquals(LockState.WAITING, lock.getState());
            assertEquals(LockType.SHARED_READ, lock.getType());
            assertTrue(lock.toString(), 0 == lock.getLastheartbeat() && lock.getTxnid() != 0);
            assertEquals(0, lock.getAcquiredat());
            assertEquals("me", lock.getUser());
            assertEquals("localhost", lock.getHostname());
            saw[1] = true;
        } else if (lock.getLockid() == 3) {
            assertEquals(0, lock.getTxnid());
            assertEquals("yourdb", lock.getDbname());
            assertEquals("yourtable", lock.getTablename());
            assertEquals("yourpartition=yourvalue", lock.getPartname());
            assertEquals(LockState.ACQUIRED, lock.getState());
            assertEquals(LockType.SHARED_READ, lock.getType());
            assertTrue(lock.toString(), begining <= lock.getLastheartbeat() && System.currentTimeMillis() >= lock.getLastheartbeat());
            assertTrue(begining <= lock.getAcquiredat() && System.currentTimeMillis() >= lock.getAcquiredat());
            assertEquals("you", lock.getUser());
            assertEquals("remotehost", lock.getHostname());
            saw[2] = true;
        } else {
            fail("Unknown lock id");
        }
    }
    for (int i = 0; i < saw.length; i++) assertTrue("Didn't see lock id " + i, saw[i]);
}
Also used : LockComponent(org.apache.hadoop.hive.metastore.api.LockComponent) ArrayList(java.util.ArrayList) ShowLocksResponseElement(org.apache.hadoop.hive.metastore.api.ShowLocksResponseElement) ShowLocksRequest(org.apache.hadoop.hive.metastore.api.ShowLocksRequest) LockResponse(org.apache.hadoop.hive.metastore.api.LockResponse) ShowLocksResponse(org.apache.hadoop.hive.metastore.api.ShowLocksResponse) LockRequest(org.apache.hadoop.hive.metastore.api.LockRequest) CheckLockRequest(org.apache.hadoop.hive.metastore.api.CheckLockRequest) Test(org.junit.Test)

Example 50 with LockResponse

use of org.apache.hadoop.hive.metastore.api.LockResponse in project hive by apache.

the class TestTxnHandler method testLockTableLocksPartition.

@Test
public void testLockTableLocksPartition() throws Exception {
    // Test that locking a table prevents locking of partitions of the table
    LockComponent comp = new LockComponent(LockType.EXCLUSIVE, LockLevel.DB, "mydb");
    comp.setTablename("mytable");
    comp.setOperationType(DataOperationType.NO_TXN);
    List<LockComponent> components = new ArrayList<LockComponent>(1);
    components.add(comp);
    LockRequest req = new LockRequest(components, "me", "localhost");
    LockResponse res = txnHandler.lock(req);
    assertTrue(res.getState() == LockState.ACQUIRED);
    comp = new LockComponent(LockType.EXCLUSIVE, LockLevel.DB, "mydb");
    comp.setTablename("mytable");
    comp.setPartitionname("mypartition=myvalue");
    comp.setOperationType(DataOperationType.NO_TXN);
    components.clear();
    components.add(comp);
    req = new LockRequest(components, "me", "localhost");
    res = txnHandler.lock(req);
    assertTrue(res.getState() == LockState.WAITING);
}
Also used : LockComponent(org.apache.hadoop.hive.metastore.api.LockComponent) LockResponse(org.apache.hadoop.hive.metastore.api.LockResponse) ArrayList(java.util.ArrayList) LockRequest(org.apache.hadoop.hive.metastore.api.LockRequest) CheckLockRequest(org.apache.hadoop.hive.metastore.api.CheckLockRequest) Test(org.junit.Test)

Aggregations

LockResponse (org.apache.hadoop.hive.metastore.api.LockResponse)85 LockRequest (org.apache.hadoop.hive.metastore.api.LockRequest)78 LockComponent (org.apache.hadoop.hive.metastore.api.LockComponent)75 Test (org.junit.Test)74 ArrayList (java.util.ArrayList)73 Table (org.apache.hadoop.hive.metastore.api.Table)38 CheckLockRequest (org.apache.hadoop.hive.metastore.api.CheckLockRequest)34 ShowCompactRequest (org.apache.hadoop.hive.metastore.api.ShowCompactRequest)31 ShowCompactResponse (org.apache.hadoop.hive.metastore.api.ShowCompactResponse)31 CommitTxnRequest (org.apache.hadoop.hive.metastore.api.CommitTxnRequest)27 ShowCompactResponseElement (org.apache.hadoop.hive.metastore.api.ShowCompactResponseElement)24 Partition (org.apache.hadoop.hive.metastore.api.Partition)20 AbortTxnRequest (org.apache.hadoop.hive.metastore.api.AbortTxnRequest)12 CompactionRequest (org.apache.hadoop.hive.metastore.api.CompactionRequest)7 UnlockRequest (org.apache.hadoop.hive.metastore.api.UnlockRequest)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 TException (org.apache.thrift.TException)5 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)4 NoSuchLockException (org.apache.hadoop.hive.metastore.api.NoSuchLockException)4 OpenTxnRequest (org.apache.hadoop.hive.metastore.api.OpenTxnRequest)4