Exemplo n.º 1
0
 /**
  * Gets the current HBaseAdmin instance for this Kiji. This method will open a new HBaseAdmin if
  * one doesn't exist already.
  *
  * @throws IOException If there is an error opening the HBaseAdmin.
  * @return The current HBaseAdmin instance for this Kiji.
  */
 public synchronized HBaseAdmin getHBaseAdmin() throws IOException {
   final State state = mState.get();
   Preconditions.checkState(
       state == State.OPEN,
       "Cannot get HBase admin for Kiji instance %s in state %s.",
       this,
       state);
   if (null == mAdmin) {
     final HBaseFactory hbaseFactory = HBaseFactory.Provider.get();
     mAdmin = hbaseFactory.getHBaseAdminFactory(mURI).create(getConf());
   }
   return mAdmin;
 }
Exemplo n.º 2
0
  /**
   * Creates a new <code>HBaseKiji</code> instance.
   *
   * <p>Should only be used by Kiji.Factory.open().
   *
   * <p>Caller does not need to use retain(), but must call release() when done with it.
   *
   * @param kijiURI the KijiURI.
   * @param conf Hadoop Configuration. Deep copied internally.
   * @param tableFactory HTableInterface factory.
   * @param lockFactory Factory for locks.
   * @throws IOException on I/O error.
   */
  HBaseKiji(
      KijiURI kijiURI,
      Configuration conf,
      HTableInterfaceFactory tableFactory,
      LockFactory lockFactory)
      throws IOException {

    mConstructorStack = CLEANUP_LOG.isDebugEnabled() ? Debug.getStackTrace() : null;

    // Deep copy the configuration.
    mConf = new Configuration(conf);

    // Validate arguments.
    mHTableFactory = Preconditions.checkNotNull(tableFactory);
    mLockFactory = Preconditions.checkNotNull(lockFactory);
    mURI = Preconditions.checkNotNull(kijiURI);

    // Configure the ZooKeeper quorum:
    mConf.setStrings("hbase.zookeeper.quorum", mURI.getZookeeperQuorum().toArray(new String[0]));
    mConf.setInt("hbase.zookeeper.property.clientPort", mURI.getZookeeperClientPort());

    // Check for an instance name.
    Preconditions.checkArgument(
        mURI.getInstance() != null, "KijiURI '%s' does not specify a Kiji instance name.", mURI);

    if (LOG.isDebugEnabled()) {
      Debug.logConfiguration(mConf);
      LOG.debug(
          "Opening kiji instance '{}'"
              + " with client software version '{}'"
              + " and client data version '{}'.",
          mURI,
          VersionInfo.getSoftwareVersion(),
          VersionInfo.getClientDataVersion());
    }

    // Load these lazily.
    mSchemaTable = null;
    mMetaTable = null;
    mSecurityManager = null;

    mSystemTable = new HBaseSystemTable(mURI, mConf, mHTableFactory);

    mRetainCount.set(1);
    final State oldState = mState.getAndSet(State.OPEN);
    Preconditions.checkState(
        oldState == State.UNINITIALIZED, "Cannot open Kiji instance in state %s.", oldState);
    LOG.debug("Kiji instance '{}' is now opened.", mURI);

    mSystemVersion = mSystemTable.getDataVersion();
    LOG.debug("Kiji instance '{}' has data version '{}'.", mURI, mSystemVersion);

    // Make sure the data version for the client matches the cluster.
    LOG.debug("Validating version for Kiji instance '{}'.", mURI);
    try {
      VersionInfo.validateVersion(this);
    } catch (IOException ioe) {
      // If an IOException occurred the object will not be constructed so need to clean it up.
      close();
      throw ioe;
    } catch (KijiNotInstalledException kie) {
      // Some clients handle this unchecked Exception so do the same here.
      close();
      throw kie;
    }

    // TODO(SCHEMA-491) Share ZooKeeperClient instances when possible.
    if (mSystemVersion.compareTo(Versions.MIN_SYS_VER_FOR_LAYOUT_VALIDATION) >= 0) {
      // system-2.0 clients must connect to ZooKeeper:
      //  - to register themselves as table users;
      //  - to receive table layout updates.
      mZKClient = HBaseFactory.Provider.get().getZooKeeperClient(mURI);
      try {
        mMonitor = new ZooKeeperMonitor(mZKClient);
        mMonitor.registerInstanceUser(mURI, mKijiClientId, mSystemVersion.toString());
      } catch (KeeperException ke) {
        // Unrecoverable KeeperException:
        throw new IOException(ke);
      }
    } else {
      // system-1.x clients do not need a ZooKeeper connection.
      mZKClient = null;
      mMonitor = null;
    }
  }