예제 #1
0
 @Override
 public long isReady(long tid, Master environment) throws Exception {
   try {
     String namespaceId = Tables.getNamespaceId(environment.getInstance(), tableId);
     return Utils.reserveNamespace(namespaceId, tid, false, false, TableOperation.DELETE)
         + Utils.reserveTable(tableId, tid, true, true, TableOperation.DELETE);
   } catch (IllegalArgumentException ex) {
     if (ex.getCause() != null && ex.getCause() instanceof TableNotFoundException) {
       return 0;
     }
     throw ex;
   }
 }
예제 #2
0
 @Override
 public Repo<Master> call(long tid, Master environment) throws Exception {
   try {
     String namespaceId = Tables.getNamespaceId(environment.getInstance(), tableId);
     TableManager.getInstance().transitionTableState(tableId, TableState.DELETING);
     environment.getEventCoordinator().event("deleting table %s ", tableId);
     return new CleanUp(tableId, namespaceId);
   } catch (IllegalArgumentException ex) {
     if (ex.getCause() != null && ex.getCause() instanceof TableNotFoundException) {
       return null;
     }
     throw ex;
   }
 }
예제 #3
0
  @Override
  public Repo<Master> call(long id, Master master) throws Exception {

    Instance instance = master.getInstance();

    IZooReaderWriter zoo = ZooReaderWriter.getInstance();

    Utils.tableNameLock.lock();
    try {
      Utils.checkNamespaceDoesNotExist(instance, newName, namespaceId, TableOperation.RENAME);

      final String tap =
          ZooUtil.getRoot(instance)
              + Constants.ZNAMESPACES
              + "/"
              + namespaceId
              + Constants.ZNAMESPACE_NAME;

      zoo.mutate(
          tap,
          null,
          null,
          new Mutator() {
            @Override
            public byte[] mutate(byte[] current) throws Exception {
              final String currentName = new String(current);
              if (currentName.equals(newName))
                return null; // assume in this case the operation is running again, so we are done
              if (!currentName.equals(oldName)) {
                throw new AcceptableThriftTableOperationException(
                    null,
                    oldName,
                    TableOperation.RENAME,
                    TableOperationExceptionType.NAMESPACE_NOTFOUND,
                    "Name changed while processing");
              }
              return newName.getBytes();
            }
          });
      Tables.clearCache(instance);
    } finally {
      Utils.tableNameLock.unlock();
      Utils.unreserveNamespace(namespaceId, id, true);
    }

    LoggerFactory.getLogger(RenameNamespace.class)
        .debug("Renamed namespace " + namespaceId + " " + oldName + " " + newName);

    return null;
  }
예제 #4
0
 @Override
 public void undo(long tid, Master environment) throws Exception {
   String namespaceId = Tables.getNamespaceId(environment.getInstance(), tableId);
   Utils.unreserveNamespace(namespaceId, tid, false);
   Utils.unreserveTable(tableId, tid, true);
 }