Exemplo n.º 1
0
    @Override
    public ReturnState existsTable(RpcController controller, TableIdentifierProto request) {
      String dbName = request.getDatabaseName();
      String tbName = request.getTableName();

      if (linkedMetadataManager.existsDatabase(dbName)) {
        return linkedMetadataManager.existsTable(dbName, "", tbName)
            ? OK
            : errUndefinedTable(tbName);
      }

      if (metaDictionary.isSystemDatabase(dbName)) {
        return metaDictionary.existTable(tbName) ? OK : errUndefinedTable(tbName);

      } else {
        rlock.lock();
        try {

          if (store.existTable(dbName, tbName)) {
            return OK;
          } else {
            return errUndefinedTable(tbName);
          }

        } catch (Throwable t) {
          printStackTraceIfError(LOG, t);
          return returnError(t);

        } finally {
          rlock.unlock();
        }
      }
    }
Exemplo n.º 2
0
    @Override
    public IndexResponse getIndexByColumnNames(
        RpcController controller, GetIndexByColumnNamesRequest request) throws ServiceException {

      TableIdentifierProto identifier = request.getTableIdentifier();
      String databaseName = identifier.getDatabaseName();
      String tableName = identifier.getTableName();
      List<String> columnNamesList = request.getColumnNamesList();
      String[] columnNames = new String[columnNamesList.size()];
      columnNames = columnNamesList.toArray(columnNames);

      rlock.lock();
      try {

        if (!store.existIndexByColumns(databaseName, tableName, columnNames)) {
          return IndexResponse.newBuilder()
              .setState(errUndefinedIndex(tableName, columnNamesList))
              .build();
        }
        return IndexResponse.newBuilder()
            .setState(OK)
            .setIndexDesc(store.getIndexByColumns(databaseName, tableName, columnNames))
            .build();
      } catch (Throwable t) {
        printStackTraceIfError(LOG, t);

        return IndexResponse.newBuilder().setState(returnError(t)).build();
      } finally {
        rlock.unlock();
      }
    }
Exemplo n.º 3
0
    @Override
    public ReturnState dropTable(RpcController controller, TableIdentifierProto request)
        throws ServiceException {

      String dbName = request.getDatabaseName();
      String tbName = request.getTableName();

      if (linkedMetadataManager.existsDatabase(dbName)) {
        return errInsufficientPrivilege("drop a table in database '" + dbName + "'");
      }

      if (metaDictionary.isSystemDatabase(dbName)) {
        return errInsufficientPrivilege("drop a table in database '" + dbName + "'");
      }

      wlock.lock();
      try {
        store.dropTable(dbName, tbName);
        LOG.info(
            String.format(
                "relation \"%s\" is deleted from the catalog (%s)",
                CatalogUtil.getCanonicalTableName(dbName, tbName), bindAddressStr));

        return OK;

      } catch (Throwable t) {
        printStackTraceIfError(LOG, t);
        return returnError(t);

      } finally {
        wlock.unlock();
      }
    }
Exemplo n.º 4
0
    @Override
    public ReturnState existIndexesByTable(RpcController controller, TableIdentifierProto request)
        throws ServiceException {
      String databaseName = request.getDatabaseName();
      String tableName = request.getTableName();

      try {
        // linked meta data do not support index. The request will be failed.
        if (linkedMetadataManager.existsDatabase(databaseName)) {
          return errUndefinedIndex(tableName);
        }
      } catch (Throwable t) {
        printStackTraceIfError(LOG, t);
        return returnError(t);
      }

      rlock.lock();
      try {
        return store.existIndexesByTable(databaseName, tableName)
            ? OK
            : errUndefinedIndex(tableName);

      } catch (Throwable t) {
        printStackTraceIfError(LOG, t);
        return returnError(t);
      } finally {
        rlock.unlock();
      }
    }
Exemplo n.º 5
0
    @Override
    public ReturnState existIndexByColumnNames(
        RpcController controller, GetIndexByColumnNamesRequest request) throws ServiceException {

      TableIdentifierProto identifier = request.getTableIdentifier();
      String databaseName = identifier.getDatabaseName();
      String tableName = identifier.getTableName();
      List<String> columnNames = request.getColumnNamesList();

      try {
        // linked meta data do not support index. The request will be failed.
        if (linkedMetadataManager.existsDatabase(databaseName)) {
          return errUndefinedIndex(tableName);
        }
      } catch (Throwable t) {
        printStackTraceIfError(LOG, t);
        return returnError(t);
      }

      rlock.lock();
      try {
        return store.existIndexByColumns(
                databaseName, tableName, columnNames.toArray(new String[columnNames.size()]))
            ? OK
            : errUndefinedIndex(tableName, columnNames);

      } catch (Throwable t) {
        printStackTraceIfError(LOG, t);
        return returnError(t);
      } finally {
        rlock.unlock();
      }
    }
Exemplo n.º 6
0
    @Override
    public TableResponse getTableDesc(RpcController controller, TableIdentifierProto request)
        throws ServiceException {
      String dbName = request.getDatabaseName();
      String tbName = request.getTableName();

      try {
        if (linkedMetadataManager.existsDatabase(dbName)) {
          return TableResponse.newBuilder()
              .setState(OK)
              .setTable(linkedMetadataManager.getTable(dbName, "", tbName).getProto())
              .build();
        }
      } catch (Throwable t) {
        printStackTraceIfError(LOG, t);
        return TableResponse.newBuilder().setState(returnError(t)).build();
      }

      if (metaDictionary.isSystemDatabase(dbName)) {
        try {
          return TableResponse.newBuilder()
              .setState(OK)
              .setTable(metaDictionary.getTableDesc(tbName))
              .build();
        } catch (UndefinedTableException e) {
          return TableResponse.newBuilder().setState(errUndefinedTable(tbName)).build();
        }
      }

      rlock.lock();
      try {
        return TableResponse.newBuilder()
            .setState(OK)
            .setTable(store.getTable(dbName, tbName))
            .build();

      } catch (Throwable t) {
        printStackTraceIfError(LOG, t);

        return TableResponse.newBuilder().setState(returnError(t)).build();

      } finally {
        rlock.unlock();
      }
    }
Exemplo n.º 7
0
    @Override
    public GetPartitionMethodResponse getPartitionMethodByTableName(
        RpcController controller, TableIdentifierProto request) throws ServiceException {
      String dbName = request.getDatabaseName();
      String tbName = request.getTableName();

      try {
        // linked meta data do not support partition.
        // So, the request that wants to get partitions in this db will be failed.
        if (linkedMetadataManager.existsDatabase(dbName)) {
          return GetPartitionMethodResponse.newBuilder()
              .setState(errUndefinedPartitionMethod(tbName))
              .build();
        }
      } catch (Throwable t) {
        printStackTraceIfError(LOG, t);
        return GetPartitionMethodResponse.newBuilder().setState(returnError(t)).build();
      }

      if (metaDictionary.isSystemDatabase(dbName)) {
        return GetPartitionMethodResponse.newBuilder()
            .setState(errUndefinedPartitionMethod(tbName))
            .build();
      }

      rlock.lock();
      try {

        return GetPartitionMethodResponse.newBuilder()
            .setState(OK)
            .setPartition(store.getPartitionMethod(dbName, tbName))
            .build();

      } catch (Throwable t) {
        printStackTraceIfError(LOG, t);
        return GetPartitionMethodResponse.newBuilder().setState(returnError(t)).build();

      } finally {
        rlock.unlock();
      }
    }
Exemplo n.º 8
0
    @Override
    public ReturnState addPartitions(RpcController controller, AddPartitionsProto request) {

      TableIdentifierProto identifier = request.getTableIdentifier();
      String databaseName = identifier.getDatabaseName();
      String tableName = identifier.getTableName();

      rlock.lock();
      try {

        store.addPartitions(
            databaseName, tableName, request.getPartitionDescList(), request.getIfNotExists());
        return OK;

      } catch (Throwable t) {
        printStackTraceIfError(LOG, t);
        return returnError(t);
      } finally {
        rlock.unlock();
      }
    }
Exemplo n.º 9
0
    @Override
    public ReturnState existPartitionMethod(
        RpcController controller, TableIdentifierProto request) {
      String dbName = request.getDatabaseName();
      String tableName = request.getTableName();

      try {
        // linked meta data do not support partition.
        // So, the request that wants to get partitions in this db will be failed.
        if (linkedMetadataManager.existsDatabase(dbName)) {
          return errUndefinedPartitionMethod(tableName);
        }
      } catch (Throwable t) {
        printStackTraceIfError(LOG, t);
        return returnError(t);
      }

      if (metaDictionary.isSystemDatabase(dbName)) {
        ReturnStateUtil.errFeatureNotSupported("partition feature in virtual tables");
      }

      rlock.lock();
      try {
        if (store.existPartitionMethod(dbName, tableName)) {
          return OK;
        } else {
          return errUndefinedPartitionMethod(tableName);
        }

      } catch (Throwable t) {
        printStackTraceIfError(LOG, t);
        return returnError(t);

      } finally {
        rlock.unlock();
      }
    }
Exemplo n.º 10
0
    @Override
    public IndexListResponse getAllIndexesByTable(
        RpcController controller, TableIdentifierProto request) throws ServiceException {
      final String databaseName = request.getDatabaseName();
      final String tableName = request.getTableName();

      try {
        // linked meta data do not support index.
        // So, the request that wants to check the index in this db will get empty list.
        if (linkedMetadataManager.existsDatabase(databaseName)) {
          return IndexListResponse.newBuilder().setState(OK).build();
        }
      } catch (Throwable t) {
        printStackTraceIfError(LOG, t);
        return IndexListResponse.newBuilder().setState(returnError(t)).build();
      }

      rlock.lock();
      try {

        if (!store.existIndexesByTable(databaseName, tableName)) {
          return IndexListResponse.newBuilder().setState(errUndefinedIndex(tableName)).build();
        }
        IndexListResponse.Builder builder = IndexListResponse.newBuilder().setState(OK);
        for (String eachIndexName : store.getAllIndexNamesByTable(databaseName, tableName)) {
          builder.addIndexDesc(store.getIndexByName(databaseName, eachIndexName));
        }
        return builder.build();
      } catch (Throwable t) {
        printStackTraceIfError(LOG, t);

        return IndexListResponse.newBuilder().setState(returnError(t)).build();
      } finally {
        rlock.unlock();
      }
    }