/** {@inheritDoc} */ @Override public Fiji open(FijiURI uri, Configuration conf) throws IOException { return new HBaseFiji(uri, conf, HBaseFactory.Provider.get().getHTableInterfaceFactory(uri)); }
/** {@inheritDoc} */ @Override public void release() throws IOException { LOG.debug("Releasing {}", this); final int counter = mRetainCount.decrementAndGet(); Preconditions.checkState(counter >= 0, "Cannot release Fiji instance %s: retain counter is now %s.", this, counter); if (counter == 0) { close(); } }
/** {@inheritDoc} */ @Override public void createTable(TableLayoutDesc tableLayout) throws IOException { createTable(tableLayout, 1); }
/** {@inheritDoc} */ @Override public void deleteTable(String tableName) throws IOException { final State state = mState.get(); Preconditions.checkState(state == State.OPEN, "Cannot delete table in Fiji instance %s in state %s.", this, state); if (mSystemVersion.compareTo(Versions.SYSTEM_2_0) < 0) { deleteTableSystem_1_0(tableName); } else if (mSystemVersion.compareTo(Versions.SYSTEM_2_0) == 0) { deleteTableSystem_2_0(tableName); } else { throw new InternalFijiError(String.format("Unknown System version %s.", mSystemVersion)); } }
/** {@inheritDoc} */ @Override public void createTable(TableLayoutDesc tableLayout, byte[][] splitKeys) throws IOException { final State state = mState.get(); Preconditions.checkState(state == State.OPEN, "Cannot create table in Fiji instance %s in state %s.", this, state); final FijiURI tableURI = FijiURI.newBuilder(mURI).withTableName(tableLayout.getName()).build(); LOG.debug("Creating Fiji table '{}'.", tableURI); ensureValidationCompatibility(tableLayout); // If security is enabled, apply the permissions to the new table. if (isSecurityEnabled()) { getSecurityManager().lock(); try { createTableUnchecked(tableLayout, splitKeys); getSecurityManager().applyPermissionsToNewTable(tableURI); } finally { getSecurityManager().unlock(); } } else { createTableUnchecked(tableLayout, splitKeys); } }
/** {@inheritDoc} */ @Override public synchronized FijiSecurityManager getSecurityManager() throws IOException { final State state = mState.get(); Preconditions.checkState(state == State.OPEN, "Cannot get security manager for Fiji instance %s in state %s.", this, state); if (null == mSecurityManager) { if (isSecurityEnabled()) { mSecurityManager = FijiSecurityManager.Factory.create(mURI, getConf(), mHTableFactory); } else { throw new FijiSecurityException("Cannot create a FijiSecurityManager for security version " + mSystemTable.getSecurityVersion() + ". Version must be " + Versions.MIN_SECURITY_VERSION + " or higher."); } } return mSecurityManager; }
Preconditions.checkNotNull(update); ensureValidationCompatibility(update); final FijiMetaTable metaTable = getMetaTable(); byte[] tableNameAsBytes = hbaseTableName.toBytes(); try { currentTableDescriptor = getHBaseAdmin().getTableDescriptor(tableNameAsBytes); } catch (TableNotFoundException tnfe) { if (!dryRun) { } else { LOG.debug("Disabling HBase table"); getHBaseAdmin().disableTable(hbaseTableName.toString()); } else { LOG.debug("Creating new column " + columnName); getHBaseAdmin().addColumn(hbaseTableName.toString(), newColumnDescriptor); } else { LOG.debug("Modifying column " + columnName); getHBaseAdmin().modifyColumn(hbaseTableName.toString(), newColumnDescriptor); getHBaseAdmin().modifyTable(tableNameAsBytes, newTableDescriptor); getHBaseAdmin().enableTable(hbaseTableName.toString());
/** * Attempt to delete a table from this System_1_0 Fiji instance. * * @param tableName to delete * @throws IOException on unrecoverable error. */ private void deleteTableSystem_1_0(String tableName) throws IOException { // Delete from HBase. String hbaseTable = FijiManagedHBaseTableName.getFijiTableName(mURI.getInstance(), tableName).toString(); getHBaseAdmin().disableTable(hbaseTable); getHBaseAdmin().deleteTable(hbaseTable); // Delete from the meta table. getMetaTable().deleteTable(tableName); // If the table persists immediately after deletion attempt, then give up. if (getHBaseAdmin().tableExists(hbaseTable)) { LOG.warn("HBase table " + hbaseTable + " survives deletion attempt. Giving up..."); } }
/** {@inheritDoc} */ @Deprecated @Override public void createTable(String tableName, FijiTableLayout tableLayout, byte[][] splitKeys) throws IOException { if (getMetaTable().tableExists(tableName)) { final FijiURI tableURI = FijiURI.newBuilder(mURI).withTableName(tableName).build(); throw new FijiAlreadyExistsException(String.format( "Fiji table '%s' already exists.", tableURI), tableURI); } if (!tableName.equals(tableLayout.getName())) { throw new RuntimeException(String.format( "Table name from layout descriptor '%s' does match table name '%s'.", tableLayout.getName(), tableName)); } createTable(tableLayout.getDesc(), splitKeys); }
/** {@inheritDoc} */ @Override public List<String> getTableNames() throws IOException { final State state = mState.get(); Preconditions.checkState(state == State.OPEN, "Cannot get table names in Fiji instance %s in state %s.", this, state); return getMetaTable().listTables(); }
Preconditions.checkState(state == State.OPEN, "Cannot get the regions for a FijiTable in state %s.", state); final HBaseAdmin hbaseAdmin = ((HBaseFiji) getFiji()).getHBaseAdmin(); final HTableInterface htable = mHTableFactory.create(mConf, mHBaseTableName); try {
/** * Gets the current HBaseAdmin instance for this Fiji. 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 Fiji. */ public synchronized HBaseAdmin getHBaseAdmin() throws IOException { final State state = mState.get(); Preconditions.checkState(state == State.OPEN, "Cannot get HBase admin for Fiji instance %s in state %s.", this, state); if (null == mAdmin) { final HBaseFactory hbaseFactory = HBaseFactory.Provider.get(); mAdmin = hbaseFactory.getHBaseAdminFactory(mURI).create(getConf()); } return mAdmin; }
/** * Attempt to delete a table from this System_2_0 Fiji instance. * * @param tableName to delete * @throws IOException on unrecoverable error. */ private void deleteTableSystem_2_0(String tableName) throws IOException { final FijiURI tableURI = FijiURI.newBuilder(mURI).withTableName(tableName).build(); final String tableZKPath = ZooKeeperUtils.getTableDir(tableURI).getPath(); final UsersTracker usersTracker = ZooKeeperUtils.newTableUsersTracker(mZKClient, tableURI); try { usersTracker.start(); final Set<String> users = usersTracker.getUsers().keySet(); if (!users.isEmpty()) { LOG.warn( "Uninstalling Fiji table '{}' with registered users." + " Current registered users: {}. Stale table metadata will remain in" + " ZooKeeper at path {}.", tableName, users, tableZKPath); } } finally { usersTracker.close(); } // The delete of tables from HBase is the same as System_1_0 deleteTableSystem_1_0(tableName); // Delete ZNodes from ZooKeeper if table delete was successful ZooKeeperUtils.atomicRecursiveDelete(mZKClient, tableZKPath); } // CSON
if (getMetaTable().tableExists(tableLayout.getName())) { throw new FijiAlreadyExistsException( String.format("Fiji table '%s' already exists.", tableURI), tableURI); getMetaTable().updateTableLayout(tableLayout.getName(), tableLayout); LOG.debug("Creating HBase table '{}'.", desc.getNameAsString()); if (null != splitKeys) { getHBaseAdmin().createTable(desc, splitKeys); } else { getHBaseAdmin().createTable(desc);
/** * Writes the new table layout to the meta-table. * * @param update Layout update to write to the meta-table. * @throws IOException on I/O error. */ private void writeMetaTable(TableLayoutDesc update) throws IOException { LOG.info("Updating layout for table {} from layout ID {} to layout ID {} in meta-table.", mTableURI, update.getReferenceLayout(), update.getLayoutId()); final String table = update.getName(); mNewLayout = mFiji.getMetaTable().updateTableLayout(table, update); }
mAdmin = ((HBaseFiji) mFiji).getHBaseAdmin();
/** {@inheritDoc} */ @Deprecated @Override public void createTable(String tableName, FijiTableLayout tableLayout) throws IOException { if (!tableName.equals(tableLayout.getName())) { throw new RuntimeException(String.format( "Table name from layout descriptor '%s' does match table name '%s'.", tableLayout.getName(), tableName)); } createTable(tableLayout.getDesc()); }
final FijiMetaTable metaTable = mFiji.getMetaTable();
/** {@inheritDoc} */ @Deprecated @Override public void createTable(String tableName, FijiTableLayout tableLayout, int numRegions) throws IOException { if (!tableName.equals(tableLayout.getName())) { throw new RuntimeException(String.format( "Table name from layout descriptor '%s' does match table name '%s'.", tableLayout.getName(), tableName)); } createTable(tableLayout.getDesc(), numRegions); }