/** * Reports the HBase table name for the specified Fiji table. * * @param table Fiji table to report the HBase table name of. * @return the HBase table name for the specified Fiji table. * @throws java.io.IOException on I/O error. */ private static byte[] getHBaseTableName(FijiTable table) throws IOException { final HBaseFijiTable htable = HBaseFijiTable.downcast(table); final HTableInterface hti = htable.openHTableConnection(); try { return hti.getTableName(); } finally { hti.close(); } }
/** * Loads partitioned HFiles directly into the regions of a Fiji table. * * @param hfilePath The path to the HFiles generated by a bulk-import job. * @param table The target fiji table. * @throws IOException If there is an error. */ public void load(Path hfilePath, FijiTable table) throws IOException { HBaseFijiTable.downcast(table).bulkLoad(hfilePath); } }
/** * Constructor for this AtomicFijiPutter. * * @param table The HBaseFijiTable to which this writer writes. * @throws IOException in case of an error. */ public HBaseAtomicFijiPutter(HBaseFijiTable table) throws IOException { mTable = table; mHTable = mTable.openHTableConnection(); mLayoutConsumerRegistration = mTable.registerLayoutConsumer(new InnerLayoutUpdater()); Preconditions.checkState(mWriterLayoutCapsule != null, "AtomicFijiPutter for table: %s failed to initialize.", mTable.getURI()); // Retain the table only when everything succeeds. table.retain(); final State oldState = mState.getAndSet(State.OPEN); Preconditions.checkState(oldState == State.UNINITIALIZED, "Cannot open AtomicFijiPutter instance in state %s.", oldState); }
/** * Get the column name translator for the current layout of this table. Do not cache this object. * If you need both the table layout and a column name translator within a single short lived * operation, you should use {@link #getLayout()}} and create your own * {@link HBaseColumnNameTranslator} to ensure consistent state. * @return the column name translator for the current layout of this table. */ public HBaseColumnNameTranslator getColumnNameTranslator() { final State state = mState.get(); Preconditions.checkState(state == State.OPEN, "Cannot get the column name translator of a table in state %s.", state); return HBaseColumnNameTranslator.from(getLayout()); }
mColumnNameTranslator = columnNameTranslator; mReopenScannerOnTimeout = reopenScannerOnTimeout; mEidFactory = EntityIdFactory.getFactory(mTable.getLayout()); mHTable = mTable.openHTableConnection(); try { mResultScanner = mHTable.getScanner(scan);
mOnDecoderCacheMiss = onDecoderCacheMiss; final FijiTableLayout layout = mTable.getLayout(); final Set<FijiColumnName> layoutColumns = layout.getColumnNames(); final Map<FijiColumnName, BoundColumnReaderSpec> boundOverrides = Maps.newHashMap(); mCellSpecOverrides = null; mLayoutConsumerRegistration = mTable.registerLayoutConsumer(new InnerLayoutUpdater()); Preconditions.checkState(mReaderLayoutCapsule != null, "FijiTableReader for table: %s failed to initialize.", mTable.getURI()); mTable.retain(); final State oldState = mState.getAndSet(State.OPEN); Preconditions.checkState(oldState == State.UNINITIALIZED,
/** * Sends a batch of HBase Get requests. * * @param get HBase Get requests. * @return the HBase Results. * @throws IOException on I/O error. */ private Result[] doHBaseGet(List<Get> get) throws IOException { final HTableInterface htable = mTable.openHTableConnection(); try { LOG.debug("Sending bulk HBase Get: {}", get); return htable.get(get); } finally { htable.close(); } } }
final HBaseDataRequestAdapter adapter = new HBaseDataRequestAdapter(request, capsule.getColumnNameTranslator()); final FijiTableLayout layout = capsule.getLayout(); validateRequestAgainstLayout(request, layout); final Scan scan = adapter.toScan(layout, scannerOptions.getHBaseScanOptions()); scannerOptions.getFijiRowFilter(), layout, mTable.getFiji().getSchemaTable()); applicator.applyTo(scan); mTable, scan, capsule.getLayout(), capsule.getCellDecoderProvider(), capsule.getColumnNameTranslator(),
"Couldn't create pager: " + "No data request for column {} from table {}.", colName, table.getURI()); Preconditions.checkArgument( table.getLayout().getFamilyMap().get(colName.getFamily()).isMapType(), "Couldn't create pager: " + "Can only generate version pagers from a column family data request for map families. " + "Requested paging on qualifier {} from group family {} in table {}.", colName.getQualifier(), colName.getFamily(), table.getURI()); throw new FijiColumnPagingNotEnabledException( String.format("Paging is not enabled for column '%s' from table %s.", colName, table.getURI())); mTable.retain(); ResourceTracker.get().registerResource(this);
/** {@inheritDoc} */ @Override public String toString() { return Objects.toStringHelper(HBaseFijiTableReader.class) .add("id", System.identityHashCode(this)) .add("table", mTable.getURI()) .add("layout-version", mReaderLayoutCapsule.getLayout().getDesc().getLayoutId()) .add("state", mState.get()) .toString(); }
/** * Get the column name from a meta table key. Does not check if the metaTableKey is a valid * FijiTableAnnotator meta table key. This method is package private for testing. * * @param table HBaseFijiTable in which the column from the specified key lives. This will be used * for column name translation. * @param metaTableKey the meta table key from which to get the column name. * @return the column name stored in the given meta table key. * @throws NoSuchColumnException in case the column does not exist in the table. */ static FijiColumnName columnFromMetaTableKey( final HBaseFijiTable table, final String metaTableKey ) throws NoSuchColumnException { final HBaseColumnNameTranslator translator = table.getColumnNameTranslator(); // Everything between the prefix and the annotation key. final String hbaseColumnString = metaTableKey.substring(METATABLE_KEY_PREFIX.length(), metaTableKey.lastIndexOf('.')); // Everything before the first ':'. final String hbaseFamily = hbaseColumnString.substring(0, hbaseColumnString.indexOf(':')); // Everything after the first ':'. The +1 excludes the ':' itself. final String hbaseQualifier = hbaseColumnString.substring(hbaseColumnString.indexOf(':') + 1); final HBaseColumnName hbaseColumn = new HBaseColumnName(hbaseFamily, hbaseQualifier); return translator.toFijiColumnName(hbaseColumn); }
closeResources(); throw new FijiTableNotFoundException(mTableURI); mEntityIdFactory = createEntityIdFactory(mLayoutMonitor.getLayout());
/** {@inheritDoc} */ @Override public void release() throws IOException { final int counter = mRetainCount.decrementAndGet(); Preconditions.checkState(counter >= 0, "Cannot release closed FijiTable %s: retain counter is now %s.", mTableURI, counter); if (counter == 0) { closeResources(); } }
/** {@inheritDoc} */ @Override public HBaseFijiTable openTable(String tableName) throws IOException { final State state = mState.get(); Preconditions.checkState(state == State.OPEN, "Cannot open table in Fiji instance %s in state %s.", this, state); if (!getTableNames().contains(tableName)) { throw new FijiTableNotFoundException( FijiURI.newBuilder(mURI).withTableName(tableName).build()); } return new HBaseFijiTable( this, tableName, mConf, mHTableFactory, mInstanceMonitor.getTableLayoutMonitor(tableName)); }
final LoadIncrementalHFiles loader = createHFileLoader(mConf);
/** * Creates a non-buffered fiji table writer that sends modifications directly to Fiji. * * @param table A fiji table. * @throws IOException on I/O error. */ public HBaseFijiTableWriter(HBaseFijiTable table) throws IOException { mTable = table; mLayoutConsumerRegistration = mTable.registerLayoutConsumer(new InnerLayoutUpdater()); Preconditions.checkState(mWriterLayoutCapsule != null, "FijiTableWriter for table: %s failed to initialize.", mTable.getURI()); mHTable = table.openHTableConnection(); SchemaPlatformBridge.get().setAutoFlush(mHTable, true); // Retain the table only when everything succeeds. mTable.retain(); final State oldState = mState.getAndSet(State.OPEN); Preconditions.checkState(oldState == State.UNINITIALIZED, "Cannot open FijiTableWriter instance in state %s.", oldState); }
/** * Creates a provider for cell decoders. * * <p> The provider creates decoders for specific Avro records. </p> * * @param table HBase FijiTable to create a CellDecoderProvider for. * @return a new CellDecoderProvider for the specified HBase FijiTable. * @throws IOException on I/O error. */ private static CellDecoderProvider createCellProvider( final HBaseFijiTable table ) throws IOException { return CellDecoderProvider.create( table.getLayout(), ImmutableMap.<FijiColumnName, BoundColumnReaderSpec>of(), ImmutableList.<BoundColumnReaderSpec>of(), FijiTableReaderBuilder.DEFAULT_CACHE_MISS); }
/** * Creates a new <code>FijiRowScanner</code> instance. * * @param options The options for this scanner. * @throws IOException on I/O error. */ public HBaseFijiRowScanner(Options options) throws IOException { mDataRequest = options.getDataRequest(); mTable = options.getTable(); mScan = options.getScan(); mCellDecoderProvider = options.getCellDecoderProvider(); mReopenScannerOnTimeout = options.getReopenScannerOnTimeout(); mEntityIdFactory = EntityIdFactory.getFactory(mTable.getLayout()); mHTable = mTable.openHTableConnection(); try { mResultScanner = openResultScanner(); mNextResult = getNextResult(); } catch (FijiIOException ioe) { if (mHTable != null) { mHTable.close(); } throw ioe; } final State oldState = mState.getAndSet(State.OPEN); Preconditions.checkState(oldState == State.UNINITIALIZED, "Cannot open FijiRowScanner instance in state %s.", oldState); ResourceTracker.get().registerResource(this); }
/** * Sends an HBase Get request. * * @param get HBase Get request. * @return the HBase Result. * @throws IOException on I/O error. */ private Result doHBaseGet(Get get) throws IOException { final HTableInterface htable = mTable.openHTableConnection(); try { LOG.debug("Sending HBase Get: {}", get); return htable.get(get); } finally { htable.close(); } }