Package org.kiji.schema.hbase

Examples of org.kiji.schema.hbase.KijiManagedHBaseTableName


    final HTableSchemaTranslator translator = new HTableSchemaTranslator();
    final HTableDescriptor newTableDescriptor =
        translator.toHTableDescriptor(tableURI.getInstance(), newLayout);

    LOG.debug("Reading existing HBase schema");
    final KijiManagedHBaseTableName hbaseTableName =
        KijiManagedHBaseTableName.getKijiTableName(mURI.getInstance(), tableName);
    HTableDescriptor currentTableDescriptor = null;
    byte[] tableNameAsBytes = hbaseTableName.toBytes();
    try {
      currentTableDescriptor = getHBaseAdmin().getTableDescriptor(tableNameAsBytes);
    } catch (TableNotFoundException tnfe) {
      if (!dryRun) {
        throw tnfe; // Not in dry-run mode; table needs to exist. Rethrow exception.
      }
    }
    if (currentTableDescriptor == null) {
      if (dryRun) {
        printStream.println("Would create new table: " + tableName);
        currentTableDescriptor = HTableDescriptorComparator.makeEmptyTableDescriptor(
            hbaseTableName);
      } else {
        throw new RuntimeException("Table " + hbaseTableName.getKijiTableName()
            + " does not exist");
      }
    }
    LOG.debug("Existing table descriptor: {}", currentTableDescriptor);
    LOG.debug("New table descriptor: {}", newTableDescriptor);

    LOG.debug("Checking for differences between the new HBase schema and the existing one");
    final HTableDescriptorComparator comparator = new HTableDescriptorComparator();
    if (0 == comparator.compare(currentTableDescriptor, newTableDescriptor)) {
      LOG.debug("HBase schemas are the same.  No need to change HBase schema");
      if (dryRun) {
        printStream.println("This layout does not require any physical table schema changes.");
      }
    } else {
      LOG.debug("HBase schema must be changed, but no columns will be deleted");

      if (dryRun) {
        printStream.println("Changes caused by this table layout:");
      } else {
        LOG.debug("Disabling HBase table");
        getHBaseAdmin().disableTable(hbaseTableName.toString());
      }

      for (HColumnDescriptor newColumnDescriptor : newTableDescriptor.getFamilies()) {
        final String columnName = Bytes.toString(newColumnDescriptor.getName());
        final ColumnId columnId = ColumnId.fromString(columnName);
        final String lgName = newLayout.getLocalityGroupIdNameMap().get(columnId);
        final HColumnDescriptor currentColumnDescriptor =
            currentTableDescriptor.getFamily(newColumnDescriptor.getName());
        if (null == currentColumnDescriptor) {
          if (dryRun) {
            printStream.println("  Creating new locality group: " + lgName);
          } else {
            LOG.debug("Creating new column " + columnName);
            getHBaseAdmin().addColumn(hbaseTableName.toString(), newColumnDescriptor);
          }
        } else if (!newColumnDescriptor.equals(currentColumnDescriptor)) {
          if (dryRun) {
            printStream.println("  Modifying locality group: " + lgName);
          } else {
            LOG.debug("Modifying column " + columnName);
            getHBaseAdmin().modifyColumn(hbaseTableName.toString(), newColumnDescriptor);
          }
        } else {
          LOG.debug("No changes needed for column " + columnName);
        }
      }

      if (dryRun) {
        if (newTableDescriptor.getMaxFileSize() != currentTableDescriptor.getMaxFileSize()) {
          printStream.printf("  Changing max_filesize from %d to %d: %n",
            currentTableDescriptor.getMaxFileSize(),
            newTableDescriptor.getMaxFileSize());
        }
        if (newTableDescriptor.getMaxFileSize() != currentTableDescriptor.getMaxFileSize()) {
          printStream.printf("  Changing memstore_flushsize from %d to %d: %n",
            currentTableDescriptor.getMemStoreFlushSize(),
            newTableDescriptor.getMemStoreFlushSize());
        }
      } else {
        LOG.debug("Modifying table descriptor");
        getHBaseAdmin().modifyTable(tableNameAsBytes, newTableDescriptor);
      }

      if (!dryRun) {
        LOG.debug("Re-enabling HBase table");
        getHBaseAdmin().enableTable(hbaseTableName.toString());
      }
    }

    return newLayout;
  }
View Full Code Here


   * @return The HTableDescriptor to use for storing the Kiji table data.
   */
  public HTableDescriptor toHTableDescriptor(String kijiInstanceName, KijiTableLayout tableLayout) {
    // Figure out the name of the table.
    final String tableName = tableLayout.getName();
    final KijiManagedHBaseTableName hbaseTableName =
        KijiManagedHBaseTableName.getKijiTableName(kijiInstanceName, tableName);
    final HTableDescriptor tableDescriptor = new HTableDescriptor(hbaseTableName.toString());
    TableLayoutDesc tableLayoutDesc = tableLayout.getDesc();

    if (tableLayoutDesc.getMaxFilesize() != null) {
        tableDescriptor.setMaxFileSize(tableLayoutDesc.getMaxFilesize());
    }
View Full Code Here

    BloomType actualBloomFilterType = columnDescriptor.getBloomFilterType();
    assertEquals(BloomType.ROW, actualBloomFilterType);
  }

  private HTableDescriptor getHbaseTableDescriptor(String kijiTableName) throws IOException {
    KijiManagedHBaseTableName mPhysicalTableName =
      KijiManagedHBaseTableName.getKijiTableName(getKijiURI().getInstance(), kijiTableName);
    return mKiji.getHBaseAdmin().getTableDescriptor(mPhysicalTableName.toBytes());
  }
View Full Code Here

   * @throws InterruptedException If the thread is interrupted.
   */
  private void flushMetaTables(HBaseAdmin hbaseAdmin, String instanceName)
      throws IOException, InterruptedException {
    LOG.debug("Flushing schema hash table");
    KijiManagedHBaseTableName hbaseTableName = KijiManagedHBaseTableName.getSchemaHashTableName(
        instanceName);
    hbaseAdmin.flush(hbaseTableName.toString());

    LOG.debug("Flushing schema id table");
    hbaseTableName = KijiManagedHBaseTableName.getSchemaIdTableName(instanceName);
    hbaseAdmin.flush(hbaseTableName.toString());

    LOG.debug("Flushing meta table");
    hbaseTableName = KijiManagedHBaseTableName.getMetaTableName(
        instanceName);
    hbaseAdmin.flush(hbaseTableName.toString());

    LOG.debug("Flushing system table");
    hbaseTableName = KijiManagedHBaseTableName.getSystemTableName(instanceName);
    hbaseAdmin.flush(hbaseTableName.toString());

    LOG.debug("Flushing -ROOT-");
    hbaseAdmin.flush("-ROOT-");

    LOG.debug("Flushing .META.");
View Full Code Here

   * @throws IOException If there is an error.
   * @throws InterruptedException If the thread is interrupted.
   */
  private static void flushTable(HBaseAdmin hbaseAdmin, KijiURI tableURI)
      throws IOException, InterruptedException {
    final KijiManagedHBaseTableName hbaseTableName =
        KijiManagedHBaseTableName.getKijiTableName(tableURI.getInstance(), tableURI.getTable());
    hbaseAdmin.flush(hbaseTableName.toString());
  }
View Full Code Here

TOP

Related Classes of org.kiji.schema.hbase.KijiManagedHBaseTableName

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.