Ejemplo n.º 1
0
    @Override
    public GetTablespaceResponse getTablespace(RpcController controller, StringProto request) {
      rlock.lock();

      try {

        // if there exists the tablespace in linked meta data
        Optional<Pair<String, URI>> optional =
            linkedMetadataManager.getTablespace(request.getValue());

        if (optional.isPresent()) {
          Pair<String, URI> spaceInfo = optional.get();
          return GetTablespaceResponse.newBuilder()
              .setState(OK)
              .setTablespace(
                  TablespaceProto.newBuilder()
                      .setSpaceName(spaceInfo.getFirst())
                      .setUri(spaceInfo.getSecond().toString()))
              .build();
        }

        return GetTablespaceResponse.newBuilder()
            .setState(OK)
            .setTablespace(store.getTablespace(request.getValue()))
            .build();

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

      } finally {
        rlock.unlock();
      }
    }
  private List<Tuple> getTablespaces(Schema outSchema) {
    List<TablespaceProto> tablespaces = masterContext.getCatalog().getAllTablespaces();
    List<Tuple> tuples = new ArrayList<Tuple>(tablespaces.size());
    List<Column> columns = outSchema.getRootColumns();
    Tuple aTuple;

    for (TablespaceProto tablespace : tablespaces) {
      aTuple = new VTuple(outSchema.size());

      for (int fieldId = 0; fieldId < columns.size(); fieldId++) {
        Column column = columns.get(fieldId);
        if ("space_id".equalsIgnoreCase(column.getSimpleName())) {
          if (tablespace.hasId()) {
            aTuple.put(fieldId, DatumFactory.createInt4(tablespace.getId()));
          } else {
            aTuple.put(fieldId, DatumFactory.createNullDatum());
          }
        } else if ("space_name".equalsIgnoreCase(column.getSimpleName())) {
          aTuple.put(fieldId, DatumFactory.createText(tablespace.getSpaceName()));
        } else if ("space_handler".equalsIgnoreCase(column.getSimpleName())) {
          if (tablespace.hasHandler()) {
            aTuple.put(fieldId, DatumFactory.createText(tablespace.getHandler()));
          } else {
            aTuple.put(fieldId, DatumFactory.createNullDatum());
          }
        } else if ("space_uri".equalsIgnoreCase(column.getSimpleName())) {
          aTuple.put(fieldId, DatumFactory.createText(tablespace.getUri()));
        }
      }
      tuples.add(aTuple);
    }

    return tuples;
  }