类org.apache.hadoop.hive.metastore.api.LockLevel源码实例Demo

下面列出了怎么用org.apache.hadoop.hive.metastore.api.LockLevel的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: iceberg   文件: HiveTableOperations.java
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;
}
 
源代码2 项目: iceberg   文件: HiveTableOperations.java
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;
}
 
源代码3 项目: waggle-dance   文件: FederatedHMSHandlerTest.java
@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);
}
 
 类方法
 同包方法