示例#1
0
    @Override
    public ReturnState alterTablespace(RpcController controller, AlterTablespaceProto request) {
      wlock.lock();
      try {

        if (linkedMetadataManager.getTablespace(request.getSpaceName()).isPresent()) {
          return errInsufficientPrivilege("alter tablespace '" + request.getSpaceName() + "'");
        }

        if (request.getCommandList().size() > 0) {
          for (AlterTablespaceCommand command : request.getCommandList()) {
            if (command.getType() == AlterTablespaceProto.AlterTablespaceType.LOCATION) {
              try {
                URI uri = URI.create(command.getLocation().getUri());
                Preconditions.checkArgument(uri.getScheme() != null);
              } catch (Exception e) {
                throw new ServiceException(
                    "ALTER TABLESPACE's LOCATION must be a URI form (scheme:///.../), but "
                        + command.getLocation().getUri());
              }
            }
          }
        }

        store.alterTablespace(request);

        return OK;

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

      } finally {
        wlock.unlock();
      }
    }
示例#2
0
  @Test
  public void testGetTablespace() throws Exception {
    //////////////////////////////////////////////////////////////////////////////
    // Create two table spaces
    //////////////////////////////////////////////////////////////////////////////

    assertFalse(catalog.existTablespace("space1"));
    catalog.createTablespace("space1", "hdfs://xxx.com/warehouse");
    assertTrue(catalog.existTablespace("space1"));

    assertFalse(catalog.existTablespace("space2"));
    catalog.createTablespace("space2", "hdfs://yyy.com/warehouse");
    assertTrue(catalog.existTablespace("space2"));

    //////////////////////////////////////////////////////////////////////////////
    // ALTER TABLESPACE space1
    //////////////////////////////////////////////////////////////////////////////

    // pre verification
    CatalogProtos.TablespaceProto space1 = catalog.getTablespace("space1");
    assertEquals("space1", space1.getSpaceName());
    assertEquals("hdfs://xxx.com/warehouse", space1.getUri());

    // ALTER TABLESPACE space1 LOCATION 'hdfs://zzz.com/warehouse';
    AlterTablespaceProto.AlterTablespaceCommand.Builder commandBuilder =
        AlterTablespaceProto.AlterTablespaceCommand.newBuilder();
    commandBuilder.setType(AlterTablespaceType.LOCATION);
    commandBuilder.setLocation("hdfs://zzz.com/warehouse");
    AlterTablespaceProto.Builder alter = AlterTablespaceProto.newBuilder();
    alter.setSpaceName("space1");
    alter.addCommand(commandBuilder.build());
    catalog.alterTablespace(alter.build());

    // Verify ALTER TABLESPACE space1
    space1 = catalog.getTablespace("space1");
    assertEquals("space1", space1.getSpaceName());
    assertEquals("hdfs://zzz.com/warehouse", space1.getUri());

    //////////////////////////////////////////////////////////////////////////////
    // ALTER TABLESPACE space1
    //////////////////////////////////////////////////////////////////////////////

    // pre verification
    CatalogProtos.TablespaceProto space2 = catalog.getTablespace("space2");
    assertEquals("space2", space2.getSpaceName());
    assertEquals("hdfs://yyy.com/warehouse", space2.getUri());

    // ALTER TABLESPACE space1 LOCATION 'hdfs://zzz.com/warehouse';
    commandBuilder = AlterTablespaceProto.AlterTablespaceCommand.newBuilder();
    commandBuilder.setType(AlterTablespaceType.LOCATION);
    commandBuilder.setLocation("hdfs://www.com/warehouse");
    alter = AlterTablespaceProto.newBuilder();
    alter.setSpaceName("space2");
    alter.addCommand(commandBuilder.build());
    catalog.alterTablespace(alter.build());

    // post verification
    space1 = catalog.getTablespace("space2");
    assertEquals("space2", space1.getSpaceName());
    assertEquals("hdfs://www.com/warehouse", space1.getUri());

    //////////////////////////////////////////////////////////////////////////////
    // Clean up
    //////////////////////////////////////////////////////////////////////////////
    catalog.dropTablespace("space1");
    assertFalse(catalog.existTablespace("space1"));
    catalog.dropTablespace("space2");
    assertFalse(catalog.existTablespace("space2"));
  }