Package org.kiji.schema

Examples of org.kiji.schema.KijiMetaTable


        .Provider
        .get()
        .getCassandraAdminFactory(kiji.getURI())
        .create(kiji.getURI());

    final KijiMetaTable metaTable = kiji.getMetaTable();
    try {
      CassandraMetaTable.uninstall(admin, kiji.getURI());
      CassandraMetaTable.install(admin, kiji.getURI());

      final Map<String, TableBackup> tables = backup.getMetaTable().getTables();
View Full Code Here


   *
   * @throws IOException on I/O error.
   * @throws KeeperException on ZooKeeper error.
   */
  public void update() throws IOException, KeeperException {
    final KijiMetaTable metaTable = mKiji.getMetaTable();

    final Lock lock = ZooKeeperUtils.newTableLayoutLock(mZKClient, mTableURI);
    lock.lock();
    try {
      final NavigableMap<Long, KijiTableLayout> layoutMap =
          metaTable.getTimedTableLayoutVersions(mTableURI.getTable(), Integer.MAX_VALUE);

      final KijiTableLayout currentLayout = layoutMap.lastEntry().getValue();
      final TableLayoutDesc update = mLayoutUpdate.apply(currentLayout);
      if (!Objects.equal(currentLayout.getDesc().getLayoutId(), update.getReferenceLayout())) {
        throw new InvalidLayoutException(String.format(
View Full Code Here

    if (dryRun && (null == printStream)) {
      printStream = System.out;
    }

    final KijiMetaTable metaTable = getMetaTable();

    final String tableName = update.getName();
    // Throws a KijiTableNotFoundException if there is no table.
    metaTable.getTableLayout(tableName);

    final KijiURI tableURI = KijiURI.newBuilder(mURI).withTableName(tableName).build();
    LOG.debug("Applying layout update {} on table {}", update, tableURI);

    KijiTableLayout newLayout = null;

    if (dryRun) {
      // Process column ids and perform validation, but don't actually update the meta table.
      final List<KijiTableLayout> layouts = metaTable.getTableLayoutVersions(tableName, 1);
      final KijiTableLayout currentLayout = layouts.isEmpty() ? null : layouts.get(0);
      newLayout = KijiTableLayout.createUpdatedLayout(update, currentLayout);
    } else {
      // Actually set it.
      if (mSystemVersion.compareTo(Versions.SYSTEM_2_0) >= 0) {
        try {
          // Use ZooKeeper to inform all watchers that a new table layout is available.
          final HBaseTableLayoutUpdater updater =
              new HBaseTableLayoutUpdater(this, tableURI, update);
          try {
            updater.update();
            newLayout = updater.getNewLayout();
          } finally {
            updater.close();
          }
        } catch (KeeperException ke) {
          throw new IOException(ke);
        }
      } else {
        // System versions before system-2.0 do not enforce table layout update consistency or
        // validation.
        newLayout = metaTable.updateTableLayout(tableName, update);
      }
    }
    Preconditions.checkNotNull(newLayout);

    if (dryRun) {
View Full Code Here

    assertFalse(kijiBackup.getURI().equals(kijiRestored.getURI()));

    // Create a table and update it's layout
    kijiBackup.createTable(KijiTableLayouts.getLayout(LAYOUT_V1));
    kijiBackup.modifyTableLayout(KijiTableLayouts.getLayout(LAYOUT_V2));
    KijiMetaTable backupMetaTable = kijiBackup.getMetaTable();
    assertEquals(2,
        backupMetaTable.getTableLayoutVersions("table_name", HConstants.ALL_VERSIONS).size());

    // Check that kijiBackup and kijiRestored do not intersect.
    assertFalse(kijiRestored.getTableNames().containsAll(kijiBackup.getTableNames()));

    // Backup metadata for kijiBackup.
    List<String> args = Lists.newArrayList("--kiji=" + kijiBackup.getURI().toOrderedString(),
        "--backup=" + backupFile.getPath());
    MetadataTool tool = new MetadataTool();
    tool.setConf(getConf());
    assertEquals(BaseTool.SUCCESS, tool.toolMain(args));

    // Restore metadata from kijiBackup to kijiRestored.
    args = Lists.newArrayList("--kiji=" + kijiRestored.getURI().toOrderedString(),
        "--restore=" + backupFile.getPath(),
        "--interactive=false");
    tool = new MetadataTool();
    tool.setConf(getConf());
    assertEquals(BaseTool.SUCCESS, tool.toolMain(args));

    // Validate that all tables are present with the correct number of versions
    assertTrue(kijiRestored.getTableNames().containsAll(kijiBackup.getTableNames()));
    KijiMetaTable restoreMetaTable = kijiRestored.getMetaTable();
    assertTrue(
        restoreMetaTable.getTableLayoutVersions("table_name", HConstants.ALL_VERSIONS).size() > 1);
  }
View Full Code Here

    if (dryRun && (null == printStream)) {
      printStream = System.out;
    }

    final KijiMetaTable metaTable = getMetaTable();

    final String tableName = update.getName();
    // Throws a KijiTableNotFoundException if there is no table.
    metaTable.getTableLayout(tableName);

    final KijiURI tableURI = KijiURI.newBuilder(mURI).withTableName(tableName).build();
    LOG.debug("Applying layout update {} on table {}", update, tableURI);

    KijiTableLayout newLayout = null;

    if (dryRun) {
      // Process column ids and perform validation, but don't actually update the meta table.
      final List<KijiTableLayout> layouts = metaTable.getTableLayoutVersions(tableName, 1);
      final KijiTableLayout currentLayout = layouts.isEmpty() ? null : layouts.get(0);
      newLayout = KijiTableLayout.createUpdatedLayout(update, currentLayout);
    } else {
      // Actually set it.
      if (mSystemVersion.compareTo(Versions.SYSTEM_2_0) >= 0) {
        try {
          // Use ZooKeeper to inform all watchers that a new table layout is available.
          final CassandraTableLayoutUpdater updater =
              new CassandraTableLayoutUpdater(this, tableURI, update);
          try {
            updater.update();
            newLayout = updater.getNewLayout();
          } finally {
            updater.close();
          }
        } catch (KeeperException ke) {
          throw new IOException(ke);
        }
      } else {
        // System versions before system-2.0 do not enforce table layout update consistency or
        // validation.
        newLayout = metaTable.updateTableLayout(tableName, update);
      }
    }
    Preconditions.checkState(newLayout != null);

    if (dryRun) {
View Full Code Here

  private static final byte[] BYTES_VALUE = Bytes.toBytes("value");

  @Test
  public void testBackupAndRestore() throws InterruptedException, IOException {
    final Kiji kiji = getKiji();
    final KijiMetaTable metaTable = kiji.getMetaTable();
    final KijiSchemaTable schemaTable = kiji.getSchemaTable();
    final KijiSystemTable systemTable = kiji.getSystemTable();

    // Update the layout for table foo.
    final TableLayoutDesc layout =
        KijiTableLayouts.getLayout(KijiTableLayouts.FOO_TEST_FORMATTED_EID);
    final KijiTableLayout updatedLayout = metaTable.updateTableLayout("foo", layout);

    // Insert a user-level key-value pair for table foo.
    metaTable.putValue("foo", "key", BYTES_VALUE);

    // Insert a key-value pair in the system table
    systemTable.putValue("testKey", Bytes.toBytes("testValue"));

    // The meta table should have a single table, foo, in it.
    assertEquals(1, metaTable.listTables().size());
    assertEquals(1, metaTable.tableSet().size());

    // The meta table should have a single key-value pair, "key"/"value", for table foo.
    assertEquals(1, metaTable.keySet("foo").size());
    assertArrayEquals(BYTES_VALUE, metaTable.getValue("foo", "key"));

    // write to backupBuilder
    final MetadataBackup.Builder backupBuilder = MetadataBackup.newBuilder()
        .setLayoutVersion(kiji.getSystemTable().getDataVersion().toString())
        .setMetaTable(
            MetaTableBackup.newBuilder()
                .setTables(new HashMap<String, TableBackup>())
                .build())
        .setSchemaTable(
            SchemaTableBackup.newBuilder()
                .setEntries(new ArrayList<SchemaTableEntry>())
                .build())
        .setSystemTable(
            SystemTableBackup.newBuilder()
                .setEntries(new ArrayList<SystemTableEntry>())
                .build());
    backupBuilder.setMetaTable(metaTable.toBackup());
    backupBuilder.setSchemaTable(schemaTable.toBackup());
    backupBuilder.setSystemTable(systemTable.toBackup());
    final MetadataBackup backup = backupBuilder.build();

    // make sure metadata key-value pairs are what we expect.
    List<KeyValueBackupEntry> keyValues =
        backup.getMetaTable().getTables().get("foo").getKeyValueBackup().getKeyValues();
    assertEquals(1, keyValues.size());
    assertEquals("key", keyValues.get(0).getKey());
    assertArrayEquals(BYTES_VALUE, keyValues.get(0).getValue().array());

    // make sure layouts are what we expect.
    List<TableLayoutBackupEntry> layoutBackups =
        backup.getMetaTable().getTables().get("foo").getTableLayoutsBackup().getLayouts();
    assertEquals(1, layoutBackups.size());
    assertEquals(updatedLayout.getDesc(), layoutBackups.get(0).getLayout());

    // Delete the entries for "foo" from the meta table.
    metaTable.deleteTable("foo");
    assertTrue(!metaTable.tableSet().contains("foo"));
    LOG.info("metaTable tables = " + metaTable.listTables());
    assertEquals(0, metaTable.listTables().size());
    assertEquals(0, metaTable.tableSet().size());

    final CassandraMetadataRestorer restorer = new CassandraMetadataRestorer();
    restorer.restoreTables(backup, kiji);

    final KijiMetaTable newMetaTable = kiji.getMetaTable();
    assertEquals("The number of tables with layouts is incorrect.", 1,
        newMetaTable.listTables().size());
    assertEquals("The number of tables with kv pairs is incorrect.", 1,
        newMetaTable.tableSet().size());
    assertEquals("The number of keys for the foo table is incorrect.", 1,
        newMetaTable.keySet("foo").size());
    assertArrayEquals(BYTES_VALUE, newMetaTable.getValue("foo", "key"));

    systemTable.putValue("testKey", Bytes.toBytes("changedValue"));
    restorer.restoreSystemVars(backup, kiji);
    assertEquals("testValue", Bytes.toString(systemTable.getValue("testKey")));
  }
View Full Code Here

  }

  @Test
  public void testSameMetaTableOnPut() throws InterruptedException, IOException {
    final Kiji kiji = getKiji();
    final KijiMetaTable metaTable = kiji.getMetaTable();

    final KijiTableKeyValueDatabase<?> outDb = metaTable.putValue("foo", "key", BYTES_VALUE);
    assertEquals("putValue() exposes the delegate", metaTable, outDb);
  }
View Full Code Here

  public void testChainedMetaTable() throws InterruptedException, IOException {
    // Do an operation on the metatable, then set a key with putValue().
    // Use the KijiMetaTable obj returned by this to modify the underlying db.
    // Verify that the original KijiMetaTable sees the change.
    final Kiji kiji = getKiji();
    final KijiMetaTable metaTable = kiji.getMetaTable();

    final TableLayoutDesc layout =
        KijiTableLayouts.getLayout(KijiTableLayouts.FOO_TEST_FORMATTED_EID);
    final KijiTableLayout updatedLayout = metaTable.updateTableLayout("foo", layout);

    final KijiMetaTable outMeta = metaTable.putValue("foo", "key", BYTES_VALUE);
    assertEquals("putValue() exposes the delegate", metaTable, outMeta);

    outMeta.deleteTable("foo");

    assertTrue(!outMeta.tableSet().contains("foo"));
    assertEquals(0, outMeta.listTables().size());
    assertEquals(0, outMeta.tableSet().size());

    assertTrue(!metaTable.tableSet().contains("foo"));
    assertEquals(0, metaTable.listTables().size());
    assertEquals(0, metaTable.tableSet().size());
  }
View Full Code Here

   *
   * @throws java.io.IOException on I/O error.
   * @throws org.apache.zookeeper.KeeperException on ZooKeeper error.
   */
  public void update() throws IOException, KeeperException {
    final KijiMetaTable metaTable = mKiji.getMetaTable();

    final Lock lock = ZooKeeperUtils.newTableLayoutLock(mZKClient, mTableURI);
    lock.lock();
    try {
      final NavigableMap<Long, KijiTableLayout> layoutMap =
          metaTable.getTimedTableLayoutVersions(mTableURI.getTable(), Integer.MAX_VALUE);

      final KijiTableLayout currentLayout = layoutMap.lastEntry().getValue();
      final TableLayoutDesc update = mLayoutUpdate.apply(currentLayout);
      if (!Objects.equal(currentLayout.getDesc().getLayoutId(), update.getReferenceLayout())) {
        throw new InvalidLayoutException(String.format(
View Full Code Here

  public void restoreTables(MetadataBackup backup, Kiji kiji) throws IOException {
    final HBaseFactory hbaseFactory = HBaseFactory.Provider.get();
    final HBaseAdmin hbaseAdmin =
        hbaseFactory.getHBaseAdminFactory(kiji.getURI()).create(kiji.getConf());

    final KijiMetaTable metaTable = kiji.getMetaTable();
    try {
      HBaseMetaTable.uninstall(hbaseAdmin, kiji.getURI());
      HBaseMetaTable.install(hbaseAdmin, kiji.getURI());

      final Map<String, TableBackup> tables = backup.getMetaTable().getTables();
View Full Code Here

TOP

Related Classes of org.kiji.schema.KijiMetaTable

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.