/** * Gets a table's row-key hash resolution (in number of bytes) * for use in evenly spacing HBase row keys. * * @param tableLayout the layout of the table * @return the table's hash resolution. */ public static int getRowKeyResolution(TableLayoutDesc tableLayout) { // Get hashSize from layout. int hashSize = 16; // No assumptions make about the RKF. if (RowKeyFormat.class.equals(tableLayout.getKeysFormat().getClass())) { hashSize = ((RowKeyFormat) tableLayout.getKeysFormat()).getHashSize(); } else if (RowKeyFormat2.class.equals(tableLayout.getKeysFormat().getClass())) { RowKeyFormat2 format = (RowKeyFormat2) tableLayout.getKeysFormat(); if (null == format.getSalt()) { throw new IllegalArgumentException( "This table layout defines an entityId format without hashing enabled."); } hashSize = ((RowKeyFormat2) tableLayout.getKeysFormat()).getSalt().getHashSize(); } return hashSize; }
/** * Writes the new layout to ZooKeeper. * * <p> This pushes a layout update to all table users. </p> * * @param update Layout update to push to ZooKeeper. * * @throws IOException on I/O error. * @throws KeeperException on ZooKeeper error. */ private void writeZooKeeper(TableLayoutDesc update) throws IOException, KeeperException { LOG.info("Updating layout for table {} from layout ID {} to layout ID {} in ZooKeeper.", mTableURI, update.getReferenceLayout(), update.getLayoutId()); ZooKeeperUtils.setTableLayout(mZKClient, mTableURI, update.getLayoutId()); }
/** * Creates a new {@link CassandraColumnNameTranslator} instance. Supports the * {@link ShortColumnNameTranslator} based on the table layout. * * @param tableLayout The layout of the table to translate column names for. * @return {@link CassandraColumnNameTranslator} of the appropriate type. */ public static CassandraColumnNameTranslator from(FijiTableLayout tableLayout) { switch (tableLayout.getDesc().getColumnNameTranslator()) { case SHORT: return new ShortColumnNameTranslator(tableLayout); default: throw new UnsupportedOperationException(String.format( "Unsupported CassandraColumnNameTranslator: %s for column: %s.", tableLayout.getDesc().getColumnNameTranslator(), tableLayout.getName())); } }
/** * Writes the new table layout to the meta-table. * * @param update Layout update to write to the meta-table. * @throws java.io.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); }
mDesc = TableLayoutDesc.newBuilder(Preconditions.checkNotNull(desc)).build(); mDesc.setLocalityGroups(Lists.newArrayList(mDesc.getLocalityGroups())); mLayoutVersion = computeLayoutVersion(mDesc.getVersion()); if (mDesc.getMaxFilesize() != null) { if (mDesc.getMemstoreFlushsize() != null) { if (mDesc.getMaxFilesize() != null && mDesc.getMaxFilesize() <= 0) { throw new InvalidLayoutException("max_filesize must be greater than 0"); if (mDesc.getMemstoreFlushsize() != null && mDesc.getMemstoreFlushsize() <= 0) { throw new InvalidLayoutException("memstore_flushsize must be greater than 0"); if (mDesc.getColumnNameTranslator() != ColumnNameTranslator.SHORT) { throw new InvalidLayoutException( "Support for specifiying non-short column name translators begins with layout version " && mDesc.getKeysFormat() instanceof RowKeyFormat2) { if (!mDesc.getKeysFormat().equals(reference.getDesc().getKeysFormat())) { throw new InvalidLayoutException(String.format( "Invalid layout update from reference row keys format '%s' to row keys format '%s'.", reference.getDesc().getKeysFormat(), mDesc.getKeysFormat())); if (mDesc.getLayoutId() == null) { try {
final FijiURI tableURI = FijiURI.newBuilder(mURI).withTableName(tableLayout.getName()).build(); CassandraTableLayoutUpdater.validateCassandraTableLayout(tableLayout); if (getMetaTable().tableExists(tableLayout.getName())) { throw new FijiAlreadyExistsException( String.format("Fiji table '%s' already exists.", tableURI), tableURI); if (tableLayout.getKeysFormat() instanceof RowKeyFormat) { throw new InvalidLayoutException( "CassandraFiji does not support 'RowKeyFormat', instead use 'RowKeyFormat2'."); getMetaTable().updateTableLayout(tableLayout.getName(), tableLayout); ZooKeeperUtils.setTableLayout(mZKClient, tableURI, layout.getDesc().getLayoutId()); Lists.newArrayListWithCapacity(tableLayout.getLocalityGroups().size());
TableLayoutDesc tableLayout, byte[][] splitKeys) throws IOException { final FijiURI tableURI = FijiURI.newBuilder(mURI).withTableName(tableLayout.getName()).build(); if (getMetaTable().tableExists(tableLayout.getName())) { throw new FijiAlreadyExistsException( String.format("Fiji table '%s' already exists.", tableURI), tableURI); if (tableLayout.getKeysFormat() instanceof RowKeyFormat) { LOG.warn("Usage of 'RowKeyFormat' is deprecated. New tables should use 'RowKeyFormat2'."); getMetaTable().updateTableLayout(tableLayout.getName(), tableLayout); mZKClient, tableURI, fijiTableLayout.getDesc().getLayoutId()); } catch (Exception e) { ZooKeeperUtils.wrapAndRethrow(e);
/** {@inheritDoc} */ @Override public String toString() { return Objects.toStringHelper(CassandraFijiTable.class) .add("id", System.identityHashCode(this)) .add("uri", mTableURI) .add("retain_counter", mRetainCount.get()) .add("layout_id", getLayout().getDesc().getLayoutId()) .add("state", mState.get()) .toString(); }
final FSDataInputStream inputStream = fs.open(path); final TableLayoutDesc tableLayout = FijiTableLayout.readTableLayoutDescFromJSON(inputStream); final String tableName = tableLayout.getName(); Preconditions.checkArgument( (mTableURI.getTable() == null) || tableName.equals(mTableURI.getTable()), switch (FijiTableLayout.getEncoding(tableLayout.getKeysFormat())) { case HASH: case HASH_PREFIX: throw new RuntimeException( "Unexpected row key encoding: " + FijiTableLayout.getEncoding(tableLayout.getKeysFormat()));
final ProtocolVersion layoutVersion = ProtocolVersion.parse(tableLayoutDesc.getVersion()); if (Versions.LAYOUT_VALIDATION_VERSION.compareTo(layoutVersion) > 0) { throw new InvalidLayoutException("Schema validation is available from " mDescBuilder = TableLayoutDesc.newBuilder(tableLayoutDesc) .setReferenceLayout(tableLayoutDesc.getLayoutId()) .setLayoutId(nextLayoutId(tableLayoutDesc.getLayoutId()));
/** * Returns the table name. * @return the table name. */ public String getName() { return mDesc.getName(); }
for (final LocalityGroupDesc localityGroup : layout.getLocalityGroups()) { for (final FamilyDesc family : localityGroup.getFamilies()) { if (family.getMapSchema() != null) { throw new IllegalArgumentException(String.format( "Fiji Cassandra does not support counter map type families. Family: %s, table: %s.", layout.getName(), family.getName())); "Fiji Cassandra does not support counter columns." + " Table: %s, family: %s, column: %s.", layout.getName(), family.getName(), column.getName()));
final ProtocolVersion layoutVersion = ProtocolVersion.parse(layout.getVersion()); final ProtocolVersion systemVersion = getSystemTable().getDataVersion();
/** {@inheritDoc} */ @Override public String toString() { String layoutId = mState.get() == State.OPEN ? mLayoutMonitor.getLayout().getDesc().getLayoutId() : "unknown"; return Objects.toStringHelper(HBaseFijiTable.class) .add("id", System.identityHashCode(this)) .add("uri", mTableURI) .add("retain_counter", mRetainCount.get()) .add("layout_id", layoutId) .add("state", mState.get()) .toString(); }
/** * 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); }
/** {@inheritDoc} */ @Deprecated @Override public FijiTableLayout modifyTableLayout(String tableName, TableLayoutDesc update) throws IOException { if (!tableName.equals(update.getName())) { throw new InvalidLayoutException(String.format( "Name of table in descriptor '%s' does not match table name '%s'.", update.getName(), tableName)); } return modifyTableLayout(update); }
final ProtocolVersion layoutVersion = ProtocolVersion.parse(layout.getVersion()); final ProtocolVersion systemVersion = getSystemTable().getDataVersion();
/** * Gets the RowKeyFormat2 of the provided layout, if it exists. Otherwise, null. * * @param layout of the table to find the RowKeyFormat2. * @return the RowKeyFormat2, null if the layout has RowKeyFormat1. * @throws IOException if the keys format can not be ascertained. */ private static RowKeyFormat2 getRKF2(final FijiTableLayout layout) throws IOException { if (null != layout && RowKeyEncoding.FORMATTED == getEncoding(layout.getDesc().getKeysFormat())) { return (RowKeyFormat2) layout.getDesc().getKeysFormat(); } else { return null; } }
/** * Writes the new layout to ZooKeeper. * * <p> This pushes a layout update to all table users. </p> * * @param update Layout update to push to ZooKeeper. * * @throws java.io.IOException on I/O error. * @throws org.apache.zookeeper.KeeperException on ZooKeeper error. */ private void writeZooKeeper(TableLayoutDesc update) throws IOException, KeeperException { LOG.info("Updating layout for table {} from layout ID {} to layout ID {} in ZooKeeper.", mTableURI, update.getReferenceLayout(), update.getLayoutId()); ZooKeeperUtils.setTableLayout(mZKClient, mTableURI, update.getLayoutId()); }
/** {@inheritDoc} */ @Override public String toString() { return Objects.toStringHelper(CassandraFijiTableReader.class) .add("id", System.identityHashCode(this)) .add("table", mTable.getURI()) .add("layout-version", mReaderLayoutCapsule.getLayout().getDesc().getLayoutId()) .add("state", mState.get()) .toString(); }