/** * <p>Translates ColumnIds to HBase column names.</p> * * <p>Encodes to a byte array making it as short as possible. We use characters that * HBase allows (no control characters and no colon).</p> * * @return The column id encoded as an HBase-friendly byte array. */ public byte[] toByteArray() { return Bytes.toBytes(toString()); }
/** * Translates HBase column names to ColumnIds. The HBase names are UTF-8 encoded * numbers from our base-64 alphabet. * * @param encoded The family or qualifier bytes from HBase. * @return A ColumnId from the encoded name. */ public static ColumnId fromString(String encoded) { int val = 0; for (int i = 0; i < encoded.length(); i++) { try { val += VALUE_MAP.get(encoded.charAt(i)) << i * BITS_PER_DIGIT; } catch (NullPointerException e) { throw new InvalidColumnNameException("Contained a character not in the alphabet: " + encoded); } } return new ColumnId(val); }
throws NoSuchColumnException { LOG.debug("Translating HBase column name '{}' to Fiji column name...", hbaseColumnName); final ColumnId localityGroupID = ColumnId.fromByteArray(hbaseColumnName.getFamily()); final LocalityGroupLayout localityGroup = mLayout.getLocalityGroupMap().get(mLayout.getLocalityGroupIdNameMap().get(localityGroupID)); if (localityGroup == null) { throw new NoSuchColumnException(String.format("No locality group with ID %s in table %s.", localityGroupID.getId(), mLayout.getName())); "Missing separator in HBase column %s.", hbaseColumnName)); final ColumnId familyID = ColumnId.fromString(Bytes.toString(hbaseQualifier, 0, index)); final String rawQualifier = Bytes.toString(hbaseQualifier, index + 1, hbaseQualifier.length - index - 1); throw new NoSuchColumnException(String.format( "No family with ID %s in locality group %s of table %s.", familyID.getId(), localityGroup.getName(), mLayout.getName())); final ColumnId qualifierID = ColumnId.fromString(rawQualifier); final ColumnLayout qualifier = family.getColumnMap().get(family.getColumnIdNameMap().get(qualifierID)); throw new NoSuchColumnException(String.format( "No column with ID %s in family %s of table %s.", qualifierID.getId(), family.getName(), mLayout.getName()));
final ColumnId familyID = ColumnId.fromByteArray(cassandraColumnName.getFamily()); final FamilyLayout family = localityGroup.getFamilyMap().get(localityGroup.getFamilyIdNameMap().get(familyID)); throw new NoSuchColumnException(String.format( "No family with ID %s in locality group %s of table %s.", familyID.getId(), localityGroup.getName(), mLayout.getName())); if (family.isGroupType()) { final ColumnId qualifierID = ColumnId.fromByteArray(cassandraColumnName.getQualifier()); final ColumnLayout qualifier = family.getColumnMap().get(family.getColumnIdNameMap().get(qualifierID)); throw new NoSuchColumnException(String.format( "No column with ID %s in family %s of table %s.", qualifierID.getId(), family.getName(), mLayout.getName()));
/** {@inheritDoc} */ @Override public void write(HFileKeyValue entry, NullWritable unused) throws IOException { final ColumnId lgId = ColumnId.fromByteArray(entry.getFamily()); getWriter(lgId).write(entry, unused); }
final byte[] familyBytes = familyID.toByteArray(); final byte[] qualifierBytes = qualifierID.toByteArray(); return new CassandraColumnName(familyBytes, qualifierBytes); } else {
tableURI, familyLayout.getLocalityGroup().getId()); } else { Preconditions.checkArgument(mTableName.getLocalityGroupId().equals(localityGroupId), "Fiji Cassandra does not support transactions across multiple locality groups.");
/** * Translates HBase column names to ColumnIds. The HBase byte arrays are UTF-8 encoded * numbers from our base-64 alphabet. * * @param encoded The family or qualifier bytes from HBase. * @return A ColumnId from the byte array. */ public static ColumnId fromByteArray(byte[] encoded) { return fromString(Bytes.toString(encoded)); }
/** * Constructs a column id that encodes the given integer. * * @param id The integer identifier for this column. */ public ColumnId(int id) { Preconditions.checkArgument(id >= 0, "id may not be negative"); mId = id; mStringEncoding = intToBase64(mId); }
mId = new ColumnId(lgDesc.getId()); if ((mId != null) && !mId.equals(reference.getId())) { throw new InvalidLayoutException(String.format( "Descriptor for locality group '%s' has ID %s but reference ID is %s.", lgDesc.setId(mId.getId()); Preconditions.checkState(fLayout.getId() == null); while (true) { final ColumnId fId = new ColumnId(nextFamilyId); nextFamilyId += 1; if (!idMap.containsKey(fId)) {
/** * Delete all cells from a row with a timestamp less than or equal to the specified timestamp. * * <p>Note HBase does not represent row deletions with individual (cross-family) * tombstones. Instead, this method issues a family delete for each locality group * individually.</p> * * @param entityId Entity ID of the row to delete data from. * @param upToTimestamp Delete cells with a timestamp older or equal to this parameter. * @throws IOException on I/O error. */ @Override public void deleteRow(EntityId entityId, long upToTimestamp) throws IOException { for (LocalityGroupLayout localityGroupLayout : mTable.getLayout().getLocalityGroups()) { final HFileKeyValue mrKey = new HFileKeyValue( entityId.getHBaseRowKey(), localityGroupLayout.getId().toByteArray(), HConstants.EMPTY_BYTE_ARRAY, upToTimestamp, HFileKeyValue.Type.DeleteFamily, HConstants.EMPTY_BYTE_ARRAY); write(mrKey); } }
final ColumnId columnId = ColumnId.fromString(columnName); final String lgName = newLayout.getLocalityGroupIdNameMap().get(columnId); final HColumnDescriptor currentColumnDescriptor =
mId = new ColumnId(familyDesc.getId()); if ((mId != null) && !mId.equals(reference.getId())) { throw new InvalidLayoutException(String.format( "Descriptor for family '%s' has ID %s but reference ID is %s.", familyDesc.setId(mId.getId()); Preconditions.checkState(column.getId() == null); while (true) { final ColumnId columnId = new ColumnId(nextColumnId); nextColumnId += 1; if (!idMap.containsKey(columnId)) {
/** {@inheritDoc} */ @Override public int hashCode() { return getId(); } }
/** {@inheritDoc} */ @Override public byte[] toHBaseFamilyName(LocalityGroupLayout localityGroup) { return Bytes.toBytes(localityGroup.getId().toString()); }
Preconditions.checkState(localityGroup.getId() == null); while (true) { final ColumnId columnId = new ColumnId(nextColumnId); nextColumnId += 1; if (!idMap.containsKey(columnId)) {
/** * Assigns the ID of the locality group. * * @param cid the ID of the locality group. * @return this locality group. */ private LocalityGroupLayout setId(ColumnId cid) { Preconditions.checkArgument(cid.getId() >= 1); Preconditions.checkState(null == mId); mId = cid; mDesc.setId(cid.getId()); return this; }
/** * Constructor. * * @param context Task attempt context. * @param lgLayout Layout of the locality group. * @throws IOException on I/O error. */ public LocalityGroupRecordWriter(TaskAttemptContext context, LocalityGroupLayout lgLayout) throws IOException { mLGLayout = Preconditions.checkNotNull(lgLayout); mFamily = lgLayout.getId().toString(); // These parameters might be specific to each locality group: mMaxFileSizeBytes = mConf.getLong(CONF_HREGION_MAX_FILESIZE, DEFAULT_HREGION_MAX_FILESIZE); mBlockSizeBytes = mConf.getInt(CONF_HFILE_BLOCKSIZE, DEFAULT_HFILE_BLOCKSIZE); mFamilyDir = new Path(mOutputDir, mFamily); if (!mFileSystem.exists(mFamilyDir)) { if (!mFileSystem.mkdirs(mFamilyDir)) { throw new IOException(String.format( "Unable to create output directory: %s", mFamilyDir)); } } mCompressionType = mLGLayout.getDesc().getCompressionType().toString().toLowerCase(Locale.ROOT); mWriter = openNewWriter(); }