Package org.kiji.schema.zookeeper

Examples of org.kiji.schema.zookeeper.TableLayoutTracker


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

      final TableLayoutTracker layoutTracker =
          new TableLayoutTracker(mZKClient, mTableURI, mLayoutUpdateHandler);
      try {
        layoutTracker.start();
        final UsersTracker usersTracker =
            ZooKeeperUtils
                .newTableUsersTracker(mZKClient, mTableURI)
                .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 {}.",
                  mTableURI, newLayoutId);
              Time.sleep(1.0);
            }
          }

        } finally {
          usersTracker.close();
        }
      } finally {
        layoutTracker.close();
      }
    } finally {
      lock.unlock();
      lock.close();
    }
View Full Code Here


      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 {}.",
                  mTableURI, newLayoutId);
              Time.sleep(1.0);
            }
          }

        } finally {
          usersTracker.close();
        }

      } finally {
        layoutTracker.close();
      }
    } finally {
      lock.unlock();
      lock.close();
    }
View Full Code Here

      final KijiTable table = kiji.openTable("table_name");
      try {
        final BlockingQueue<String> layoutQueue = Queues.newArrayBlockingQueue(1);

        final TableLayoutTracker tracker =
            new TableLayoutTracker(((HBaseKiji) kiji).getZKClient(), table.getURI(),
                new QueuingTableLayoutUpdateHandler(layoutQueue))
              .start();

        Assert.assertEquals("1", layoutQueue.poll(5, TimeUnit.SECONDS));

        final HBaseTableLayoutUpdater updater =
            new HBaseTableLayoutUpdater((HBaseKiji) kiji, table.getURI(), layout2);
        try {
          final Thread thread =
              new Thread() {
                /** {@inheritDoc} */
                @Override
                public void run() {
                  try {
                    updater.update();
                  } catch (Exception exn) {
                    throw new RuntimeException(exn);
                  }
                }
              };
          thread.start();
          thread.join(5000);

          Assert.assertEquals("2", layoutQueue.poll(5, TimeUnit.SECONDS));

          tracker.close();
        } finally {
          updater.close();
        }
      } finally {
        table.release();
View Full Code Here

        mUserRegistration = null;
        mInitializationLatch = null;
      } else {
        mUserRegistration = new TableUserRegistration(zkClient, tableURI, generateTableUserID());
        mInitializationLatch = new CountDownLatch(1);
        mTableLayoutTracker = new TableLayoutTracker(
            zkClient,
            mTableURI,
            new InnerLayoutUpdater(
                mUserRegistration,
                mInitializationLatch,
View Full Code Here

TOP

Related Classes of org.kiji.schema.zookeeper.TableLayoutTracker

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.