Пример #1
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;
  }