Package org.kiji.schema.avro

Examples of org.kiji.schema.avro.TableLayoutDesc


          .withFamily("family")
          .withQualifier("qual0").withValue(1L, "string1")
          .withQualifier("qual0").withValue(2L, "string2")
          .build();

      final TableLayoutDesc update = KijiTableLayouts.getLayout(TEST_LAYOUT_V2);
      update.setReferenceLayout(table.getLayout().getDesc().getLayoutId());
      mKiji.modifyTableLayout(update);

      final KijiDataRequest dataRequest = KijiDataRequest.builder()
          .addColumns(ColumnsDef.create().addFamily("family"))
          .build();
View Full Code Here


    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);
View Full Code Here

    // 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);
View Full Code Here

   * @return the parsed table layout.
   * @throws IOException on I/O error.
   */
  public static KijiTableLayout createFromEffectiveJson(InputStream istream) throws IOException {
    try {
      final TableLayoutDesc desc = readTableLayoutDescFromJSON(istream);
      final KijiTableLayout layout = new KijiTableLayout(desc, null);
      return layout;
    } finally {
      ResourceUtils.closeOrLog(istream);
    }
View Full Code Here

   * @throws IOException on I/O error.
   */
  public static TableLayoutDesc readTableLayoutDescFromJSON(InputStream istream)
      throws IOException {
    final String json = IOUtils.toString(istream);
    final TableLayoutDesc desc =
        (TableLayoutDesc) FromJson.fromJsonString(json, TableLayoutDesc.SCHEMA$);
    return desc;
  }
View Full Code Here

    // 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());
    }
    if (tableLayoutDesc.getMemstoreFlushsize() != null) {
        tableDescriptor.setMemStoreFlushSize(tableLayoutDesc.getMemstoreFlushsize());
    }

    HBaseColumnNameTranslator translator = HBaseColumnNameTranslator.from(tableLayout);

    // Add the columns.
View Full Code Here

  @Test
  public void testSetTableLayoutModify() throws Exception {
    getKiji().createTable(mLayoutDesc);

    final TableLayoutDesc newTableLayoutDesc = TableLayoutDesc.newBuilder(mLayoutDesc).build();
    assertEquals(3, (int) newTableLayoutDesc.getLocalityGroups().get(0).getMaxVersions());
    newTableLayoutDesc.getLocalityGroups().get(0).setMaxVersions(1);
    newTableLayoutDesc.setReferenceLayout(getLayout("table").getDesc().getLayoutId());

    final KijiTableLayout newTableLayout = getKiji().modifyTableLayout(newTableLayoutDesc);
    assertEquals(
        newTableLayout.getLocalityGroupMap().get("default").getDesc().getMaxVersions(),
        getLayout("table").getLocalityGroupMap().get("default").getDesc().getMaxVersions());
View Full Code Here

    // TODO: Assert that the underlying Cassandra stuff is correct also.
  }

  @Test
  public void testSetTableLayoutOnNonExistentTable() throws Exception {
    final TableLayoutDesc tableLayoutDesc = KijiTableLayouts.getLayout(KijiTableLayouts.SIMPLE);
    try {
      getKiji().modifyTableLayout(tableLayoutDesc);
      fail("An exception should have been thrown.");
    } catch (KijiTableNotFoundException ktnfe) {
      assertTrue(ktnfe.toString(),
View Full Code Here

    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(
            "Reference layout ID %s does not match current layout ID %s.",
            update.getReferenceLayout(), currentLayout.getDesc().getLayoutId()));
      }

      final TableLayoutUpdateValidator validator = new TableLayoutUpdateValidator(mKiji);
      final KijiTableLayout updatedLayout =
          KijiTableLayout.createUpdatedLayout(update , currentLayout);
      validateCassandraTableLayout(updatedLayout.getDesc());
      validator.validate(currentLayout, updatedLayout);

      final TableLayoutTracker layoutTracker =
          new TableLayoutTracker(mZKClient, mTableURI, mLayoutUpdateHandler).start();
      try {
        final UsersTracker usersTracker = ZooKeeperUtils.newTableUsersTracker(mZKClient, mTableURI);
        usersTracker.registerUpdateHandler(mUsersUpdateHandler);
        try {
          usersTracker.start();
          final String currentLayoutId = mLayoutUpdateHandler.getCurrentLayoutId();
          LOG.info("Table {} has current layout ID {}.", mTableURI, currentLayoutId);
          if (!Objects.equal(currentLayoutId, currentLayout.getDesc().getLayoutId())) {
            throw new InternalKijiError(String.format(
                "Inconsistency between meta-table and ZooKeeper: "
                + "meta-table layout has ID %s while ZooKeeper has layout ID %s.",
                currentLayout.getDesc().getLayoutId(), currentLayoutId));
          }

          final String consistentLayoutId = waitForConsistentView();
          if ((consistentLayoutId != null) && !Objects.equal(consistentLayoutId, currentLayoutId)) {
            throw new InternalKijiError(String.format(
                "Consistent layout ID %s does not match current layout %s for table %s.",
                consistentLayoutId, currentLayout, mTableURI));
          }

          writeMetaTable(update);
          final TableLayoutDesc newLayoutDesc = mNewLayout.getDesc();
          writeZooKeeper(newLayoutDesc);

          mLayoutUpdateHandler.waitForLayoutNotification(newLayoutDesc.getLayoutId());

          // The following is not necessary:
          while (true) {
            final String newLayoutId = waitForConsistentView();
            if (newLayoutId == null) {
              LOG.info("Layout update complete for table {}: table has no users.", mTableURI);
              break;
            } else if (Objects.equal(newLayoutId, newLayoutDesc.getLayoutId())) {
              LOG.info("Layout update complete for table {}: all users switched to layout ID {}.",
                  mTableURI, newLayoutId);
              break;
            } else {
              LOG.info("Layout update in progress for table {}: users still using layout ID {}.",
View Full Code Here

  public KijiTableLayout updateTableLayout(String tableName, TableLayoutDesc layoutUpdate)
      throws IOException {

    // Normalize the new layout to use schema UIDs:
    final TableLayoutBuilder layoutBuilder = new TableLayoutBuilder(mSchemaTable);
    final TableLayoutDesc update = layoutBuilder.normalizeTableLayoutDesc(
        layoutUpdate,
        new LayoutOptions()
            .setSchemaFormat(SchemaFormat.UID));

    // Fetch all the layout history:
    final List<KijiTableLayout> layouts =
        getTableLayoutVersions(tableName, HConstants.ALL_VERSIONS);
    final KijiTableLayout currentLayout = layouts.isEmpty() ? null : layouts.get(0);
    final KijiTableLayout tableLayout = KijiTableLayout.createUpdatedLayout(update, currentLayout);

    Preconditions.checkArgument(tableName.equals(tableLayout.getName()));

    // Set of all the former layout IDs:
    final Set<String> layoutIDs = Sets.newHashSet();
    for (KijiTableLayout layout : layouts) {
      layoutIDs.add(layout.getDesc().getLayoutId());
    }

    final String refLayoutIdStr = update.getReferenceLayout();

    final boolean hasCurrentLayout = (null != currentLayout);
    final boolean hasRefLayoutId = (null != refLayoutIdStr);
    if (hasCurrentLayout && !hasRefLayoutId) {
      throw new IOException(String.format(
View Full Code Here

TOP

Related Classes of org.kiji.schema.avro.TableLayoutDesc

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.