/** * Create a connection to a Fiji meta table backed by an HTable within HBase. * * <p>This class takes ownership of the HTable. It will be closed when this instance is * closed.</p> * * @param fijiURI URI of the Fiji instance this meta-table belongs to. * @param htable The HTable to use for storing Fiji meta data. * @param schemaTable The Fiji schema table. * @throws IOException If there is an error. */ private HBaseMetaTable( FijiURI fijiURI, HTableInterface htable, FijiSchemaTable schemaTable) throws IOException { this( fijiURI, htable, new HBaseTableLayoutDatabase(fijiURI, htable, LAYOUT_COLUMN_FAMILY, schemaTable), new HBaseTableKeyValueDatabase(htable, META_COLUMN_FAMILY)); }
/** * Install the meta table into a Fiji instance. * * @param admin The HBase Admin interface for the HBase cluster to install into. * @param uri The uri of the Fiji instance to install. * @throws IOException If there is an error. */ public static void install(HBaseAdmin admin, FijiURI uri) throws IOException { HTableDescriptor tableDescriptor = new HTableDescriptor( FijiManagedHBaseTableName.getMetaTableName(uri.getInstance()).toString()); tableDescriptor.addFamily( HBaseTableLayoutDatabase.getHColumnDescriptor(LAYOUT_COLUMN_FAMILY)); tableDescriptor.addFamily( HBaseTableLayoutDatabase.getHColumnDescriptor(META_COLUMN_FAMILY)); admin.createTable(tableDescriptor); }
/** {@inheritDoc} */ @Override public FijiTableLayout getTableLayout(String table) throws IOException { final List<FijiTableLayout> layouts = getTableLayoutVersions(table, 1); if (layouts.isEmpty()) { throw new FijiTableNotFoundException( FijiURI.newBuilder(mFijiURI).withTableName(table).build()); } return layouts.get(0); }
getTableLayoutVersions(tableName, HConstants.ALL_VERSIONS); final FijiTableLayout currentLayout = layouts.isEmpty() ? null : layouts.get(0); final FijiTableLayout tableLayout = FijiTableLayout.createUpdatedLayout(update, currentLayout); .add(mFamilyBytes, QUALIFIER_UPDATE_BYTES, encodeTableLayoutDesc(update)) .add(mFamilyBytes, QUALIFIER_LAYOUT_BYTES, encodeTableLayoutDesc(tableLayout.getDesc())) .add(mFamilyBytes, QUALIFIER_LAYOUT_ID_BYTES, Bytes.toBytes(layoutId));
/** {@inheritDoc} */ @Override public NavigableMap<Long, FijiTableLayout> getTimedTableLayoutVersions( String table, int numVersions) throws IOException { Preconditions.checkArgument(numVersions >= 1, "numVersions must be positive"); // Gather the layout data from the Htable. final Get get = new Get(Bytes.toBytes(table)) .addColumn(mFamilyBytes, QUALIFIER_LAYOUT_BYTES) .setMaxVersions(numVersions); final Result result = mTable.get(get); /** Map from timestamp to table layout. */ final NavigableMap<Long, FijiTableLayout> timedLayouts = Maps.newTreeMap(); // Pull out the full map: family -> qualifier -> timestamp -> TableLayoutDesc. // Family and qualifier are already specified : the 2 outer maps must be size 11. final NavigableMap<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> familyMap = result.getMap(); Preconditions.checkState(familyMap.size() == 1); final NavigableMap<byte[], NavigableMap<Long, byte[]>> qualifierMap = familyMap.get(familyMap.firstKey()); Preconditions.checkState(qualifierMap.size() == 1); final NavigableMap<Long, byte[]> timeSerieMap = qualifierMap.get(qualifierMap.firstKey()); for (Map.Entry<Long, byte[]> timeSerieEntry : timeSerieMap.entrySet()) { final long timestamp = timeSerieEntry.getKey(); final byte[] bytes = timeSerieEntry.getValue(); final FijiTableLayout layout = FijiTableLayout.newLayout(decodeTableLayoutDesc(bytes)); Preconditions.checkState(timedLayouts.put(timestamp, layout) == null); } return timedLayouts; }
/** {@inheritDoc} */ @Override public void restoreLayoutsFromBackup(String tableName, TableLayoutsBackup layoutBackup) throws IOException { LOG.info(String.format("Restoring layout history for table '%s'.", tableName)); for (TableLayoutBackupEntry lbe : layoutBackup.getLayouts()) { final byte[] layoutBytes = encodeTableLayoutDesc(lbe.getLayout()); final Put put = new Put(Bytes.toBytes(tableName)) .add(mFamilyBytes, QUALIFIER_LAYOUT_BYTES, layoutBytes); if (lbe.getUpdate() != null) { final byte[] updateBytes = encodeTableLayoutDesc(lbe.getUpdate()); final long timestamp = lbe.getTimestamp(); put.add(mFamilyBytes, QUALIFIER_UPDATE_BYTES, timestamp, updateBytes); } mTable.put(put); } mTable.flushCommits(); }
/** {@inheritDoc} */ @Override public List<FijiTableLayout> getTableLayoutVersions(String table, int numVersions) throws IOException { Preconditions.checkArgument(numVersions >= 1, "numVersions must be positive"); final Get get = new Get(Bytes.toBytes(table)) .addColumn(mFamilyBytes, QUALIFIER_LAYOUT_BYTES) .setMaxVersions(numVersions); final Result result = mTable.get(get); final List<FijiTableLayout> layouts = Lists.newArrayList(); for (KeyValue column : result.getColumn(mFamilyBytes, QUALIFIER_LAYOUT_BYTES)) { layouts.add(FijiTableLayout.newLayout(decodeTableLayoutDesc(column.getValue()))); } return layouts; }
final TableLayoutDesc layout = decodeTableLayoutDesc(serieEntry.getValue()); TableLayoutDesc update = null; if (updateSerieMap != null) { final byte[] bytes = updateSerieMap.get(timestamp); if (bytes != null) { update = decodeTableLayoutDesc(bytes);