Beispiel #1
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();
      }
    }
Beispiel #2
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();
      }
    }