org.apache.hadoop.hive.metastore.api.LockResponse Java Examples

The following examples show how to use org.apache.hadoop.hive.metastore.api.LockResponse. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HiveTableOperations.java    From iceberg with Apache License 2.0 6 votes vote down vote up
private long acquireLock() throws UnknownHostException, TException {
  final LockComponent lockComponent = new LockComponent(LockType.EXCLUSIVE, LockLevel.TABLE, database);
  lockComponent.setTablename(tableName);
  final LockRequest lockRequest = new LockRequest(Lists.newArrayList(lockComponent),
          System.getProperty("user.name"),
          InetAddress.getLocalHost().getHostName());
  LockResponse lockResponse = metaStoreClient.lock(lockRequest);
  LockState state = lockResponse.getState();
  long lockId = lockResponse.getLockid();
  //TODO add timeout
  while (state.equals(LockState.WAITING)) {
    lockResponse = metaStoreClient.check_lock(new CheckLockRequest(lockResponse.getLockid()));
    state = lockResponse.getState();
  }

  if (!state.equals(LockState.ACQUIRED)) {
    throw new CommitFailedException(format("Could not acquire the lock on %s.%s, " +
            "lock request ended in state %s", database, tableName, state));
  }
  return lockId;
}
 
Example #2
Source File: FederatedHMSHandlerTest.java    From waggle-dance with Apache License 2.0 5 votes vote down vote up
@Test
public void check_lock() throws TException {
  CheckLockRequest request = new CheckLockRequest();
  LockResponse expected = new LockResponse();
  when(primaryClient.check_lock(request)).thenReturn(expected);
  LockResponse result = handler.check_lock(request);
  assertThat(result, is(expected));
}
 
Example #3
Source File: FederatedHMSHandlerTest.java    From waggle-dance with Apache License 2.0 5 votes vote down vote up
@Test
public void lock() throws TException {
  LockComponent lockComponent = new LockComponent(LockType.EXCLUSIVE, LockLevel.DB, DB_P);
  LockRequest lockRequest = new LockRequest(Collections.singletonList(lockComponent), "user", "host");
  LockRequest inboundRequest = new LockRequest();
  LockResponse expected = new LockResponse();
  when(primaryMapping.transformInboundLockRequest(lockRequest)).thenReturn(inboundRequest);
  when(primaryClient.lock(inboundRequest)).thenReturn(expected);
  LockResponse result = handler.lock(lockRequest);
  assertThat(result, is(expected));
  verify(primaryMapping).checkWritePermissions(DB_P);
}
 
Example #4
Source File: FederatedHMSHandler.java    From waggle-dance with Apache License 2.0 5 votes vote down vote up
@Override
@Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
public LockResponse lock(LockRequest rqst) throws NoSuchTxnException, TxnAbortedException, TException {
  DatabaseMapping mapping = databaseMappingService.primaryDatabaseMapping();
  List<LockComponent> components = rqst.getComponent();
  for (LockComponent component : components) {
    mapping.checkWritePermissions(component.getDbname());
  }
  return mapping.getClient().lock(mapping.transformInboundLockRequest(rqst));
}
 
Example #5
Source File: HiveTableOperations.java    From iceberg with Apache License 2.0 5 votes vote down vote up
private long acquireLock() throws UnknownHostException, TException, InterruptedException {
  final LockComponent lockComponent = new LockComponent(LockType.EXCLUSIVE, LockLevel.TABLE, database);
  lockComponent.setTablename(tableName);
  final LockRequest lockRequest = new LockRequest(Lists.newArrayList(lockComponent),
      System.getProperty("user.name"),
      InetAddress.getLocalHost().getHostName());
  LockResponse lockResponse = metaClients.run(client -> client.lock(lockRequest));
  LockState state = lockResponse.getState();
  long lockId = lockResponse.getLockid();

  final long start = System.currentTimeMillis();
  long duration = 0;
  boolean timeout = false;
  while (!timeout && state.equals(LockState.WAITING)) {
    lockResponse = metaClients.run(client -> client.checkLock(lockId));
    state = lockResponse.getState();

    // check timeout
    duration = System.currentTimeMillis() - start;
    if (duration > lockAcquireTimeout) {
      timeout = true;
    } else {
      Thread.sleep(50);
    }
  }

  // timeout and do not have lock acquired
  if (timeout && !state.equals(LockState.ACQUIRED)) {
    throw new CommitFailedException(String.format("Timed out after %s ms waiting for lock on %s.%s",
        duration, database, tableName));
  }

  if (!state.equals(LockState.ACQUIRED)) {
    throw new CommitFailedException(String.format("Could not acquire the lock on %s.%s, " +
        "lock request ended in state %s", database, tableName, state));
  }
  return lockId;
}
 
Example #6
Source File: ThriftMetastoreClient.java    From presto with Apache License 2.0 4 votes vote down vote up
LockResponse checkLock(long lockId)
throws TException;
 
Example #7
Source File: CatalogThriftHiveMetastore.java    From metacat with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public LockResponse lock(final LockRequest rqst) throws TException {
    throw unimplemented("lock", new Object[]{rqst});
}
 
Example #8
Source File: CatalogThriftHiveMetastore.java    From metacat with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public LockResponse check_lock(final CheckLockRequest rqst) throws TException {
    throw unimplemented("check_lock", new Object[]{rqst});
}
 
Example #9
Source File: FederatedHMSHandler.java    From waggle-dance with Apache License 2.0 4 votes vote down vote up
@Override
@Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
public LockResponse check_lock(CheckLockRequest rqst)
    throws NoSuchTxnException, TxnAbortedException, NoSuchLockException, TException {
  return getPrimaryClient().check_lock(rqst);
}
 
Example #10
Source File: MockThriftMetastoreClient.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
public LockResponse checkLock(long lockId)
{
    throw new UnsupportedOperationException();
}
 
Example #11
Source File: MockThriftMetastoreClient.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
public LockResponse acquireLock(LockRequest lockRequest)
{
    throw new UnsupportedOperationException();
}
 
Example #12
Source File: GlueMetastoreClientDelegate.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 4 votes vote down vote up
public LockResponse checkLock(long lockId) throws TException {
  throw new UnsupportedOperationException("checkLock is not supported");
}
 
Example #13
Source File: ThriftMetastoreClient.java    From presto with Apache License 2.0 4 votes vote down vote up
LockResponse acquireLock(LockRequest lockRequest)
throws TException;
 
Example #14
Source File: ThriftHiveMetastoreClient.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
public LockResponse checkLock(long lockId)
        throws TException
{
    return client.check_lock(new CheckLockRequest(lockId));
}
 
Example #15
Source File: ThriftHiveMetastoreClient.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
public LockResponse acquireLock(LockRequest lockRequest)
        throws TException
{
    return client.lock(lockRequest);
}
 
Example #16
Source File: FailureAwareThriftMetastoreClient.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
public LockResponse checkLock(long lockId)
        throws TException
{
    return runWithHandle(() -> delegate.checkLock(lockId));
}
 
Example #17
Source File: FailureAwareThriftMetastoreClient.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
public LockResponse acquireLock(LockRequest lockRequest)
        throws TException
{
    return runWithHandle(() -> delegate.acquireLock(lockRequest));
}
 
Example #18
Source File: AWSCatalogMetastoreClient.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 4 votes vote down vote up
@Override
public LockResponse lock(LockRequest lockRequest) throws NoSuchTxnException, TxnAbortedException, TException {
  return glueMetastoreClientDelegate.lock(lockRequest);
}
 
Example #19
Source File: AWSCatalogMetastoreClient.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 4 votes vote down vote up
@Override
public LockResponse checkLock(long lockId)
    throws NoSuchTxnException, TxnAbortedException, NoSuchLockException, TException {
  return glueMetastoreClientDelegate.checkLock(lockId);
}
 
Example #20
Source File: AWSCatalogMetastoreClient.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 4 votes vote down vote up
@Override
public LockResponse lock(LockRequest lockRequest) throws NoSuchTxnException, TxnAbortedException, TException {
  return glueMetastoreClientDelegate.lock(lockRequest);
}
 
Example #21
Source File: AWSCatalogMetastoreClient.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 4 votes vote down vote up
@Override
public LockResponse checkLock(long lockId)
    throws NoSuchTxnException, TxnAbortedException, NoSuchLockException, TException {
  return glueMetastoreClientDelegate.checkLock(lockId);
}
 
Example #22
Source File: GlueMetastoreClientDelegate.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 4 votes vote down vote up
public LockResponse lock(LockRequest lockRequest) throws TException {
  throw new UnsupportedOperationException("lock is not supported");
}