/** * 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(); }
if (familyLayout.getLocalityGroup().getFamilyMap().size() > 1) {
/** {@inheritDoc}*/ @Override public HBaseColumnName toHBaseColumnName(FijiColumnName fijiColumnName) throws NoSuchColumnException { final String familyName = fijiColumnName.getFamily(); final String qualifierName = fijiColumnName.getQualifier(); // Validate the Fiji family final FamilyLayout family = mLayout.getFamilyMap().get(familyName); if (family == null) { throw new NoSuchColumnException(fijiColumnName.toString()); } // Validate the Fiji qualifier if (family.isGroupType() && !family.getColumnMap().containsKey(qualifierName)) { throw new NoSuchColumnException(fijiColumnName.toString()); } final byte[] localityGroupBytes = Bytes.toBytes(family.getLocalityGroup().getName()); final byte[] familyBytes = Bytes.toBytes(familyName); final byte[] qualifierBytes = Bytes.toBytes(qualifierName); final byte[] hbaseQualifierBytes = ShortColumnNameTranslator.concatWithSeparator(SEPARATOR, familyBytes, qualifierBytes); return new HBaseColumnName(localityGroupBytes, hbaseQualifierBytes); }
final LocalityGroupLayout lgLayout = new LocalityGroupLayout(lgDesc, refLGLayout); localityGroups.add(lgLayout); for (String lgName : lgLayout.getNames()) { Preconditions.checkState(lgMap.put(lgName, lgLayout) == null, "Duplicate locality group name: " + lgName); if (lgLayout.getId() != null) { final String previous = idMap.put(lgLayout.getId(), lgLayout.getName()); Preconditions.checkState(previous == null, String.format("Duplicate locality group ID '%s' associated to '%s' and '%s'.", lgLayout.getId(), lgLayout.getName(), previous)); } else { unassigned.add(lgLayout); families.addAll(lgLayout.getFamilies()); for (FamilyLayout familyLayout : lgLayout.getFamilies()) { for (String familyName : familyLayout.getNames()) { if (null != familyMap.put(familyName, familyLayout)) { Preconditions.checkState(localityGroup.getId() == null); while (true) { final ColumnId columnId = new ColumnId(nextColumnId); if (!idMap.containsKey(columnId)) { localityGroup.setId(columnId); idMap.put(columnId, localityGroup.getName()); break;
final ColumnId lgid = flayout.getLocalityGroup().getId(); if (refLGLayout != null) { final String refFamilyName = refLGLayout.getFamilyIdNameMap().get(familyId); if (refFamilyName != null) { refFamilyLayout = refLGLayout.getFamilyMap().get(refFamilyName); final String refFamilyName = refLGLayout.getFamilyIdNameMap().get(familyId); if (refFamilyName != null) { refFamilyLayout = refLGLayout.getFamilyMap().get(refFamilyName);
throw new InvalidLayoutException(String.format( "Invalid TTL seconds for locality group '%s': TTL must be positive, got %d.", getName(), mDesc.getTtlSeconds())); getName(), mDesc.getMaxVersions())); 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.", getName(), mId, reference.getId())); mId = reference.getId(); lgDesc.setId(mId.getId()); ? HashBiMap.create(reference.getFamilyIdNameMap().inverse()) : HashBiMap.<String, ColumnId>create(); throw new InvalidLayoutException(String.format( "Invalid rename: no reference locality group '%s' for family '%s'.", getName(), refFName)); (reference != null) ? reference.getFamilyMap().get(refFName) : null; if (isRename && (refFLayout == null)) { throw new InvalidLayoutException(String.format( "Invalid rename: cannot find reference family '%s' in locality group '%s'.", refFName, getName())); throw new InvalidLayoutException(String.format( "Deleted family '%s' unknown in reference locality group '%s'.",
layout.getFamilyMap().get(column.getFamily()).getLocalityGroup().getId(); final CassandraTableName tableName = CassandraTableName.getLocalityGroupTableName(tableURI, localityGroupId);
layout.getFamilyMap().get(columnRequest.getFamily()).getLocalityGroup().getId(); localityGroups.add(localityGroupId);
localityGroup.getFamilyMap().get(localityGroup.getFamilyIdNameMap().get(familyID)); if (family == null) { throw new NoSuchColumnException(String.format( "No family with ID %s in locality group %s of table %s.", familyID.getId(), localityGroup.getName(), mLayout.getName()));
if (familyLayout.getLocalityGroup().getFamilyMap().size() > 1) {
final ColumnId localityGroupId = familyLayout.getLocalityGroup().getId(); if (mTableName == null) { tableURI, familyLayout.getLocalityGroup().getId()); } else { Preconditions.checkArgument(mTableName.getLocalityGroupId().equals(localityGroupId), int ttl = familyLayout.getLocalityGroup().getDesc().getTtlSeconds();
localityGroup.getFamilyMap().get(localityGroup.getFamilyIdNameMap().get(familyID)); if (family == null) { throw new NoSuchColumnException(String.format( "No family with ID %s in locality group %s of table %s.", familyID.getId(), localityGroup.getName(), mLayout.getName()));
tables.add(CassandraTableName.getLocalityGroupTableName(tableURI, localityGroup.getId()));
final ColumnId localityGroupID = family.getLocalityGroup().getId(); final ColumnId familyID = family.getId();
CassandraTableName.getLocalityGroupTableName( tableURI, familyLayout.getLocalityGroup().getId());
CassandraTableName.getLocalityGroupTableName( tableURI, familyLayout.getLocalityGroup().getId());
/** {@inheritDoc} */ @Override public void deleteFamily(EntityId entityId, String family, long upToTimestamp) throws IOException { final HBaseFijiTableWriter.WriterLayoutCapsule capsule = mWriterLayoutCapsule; final FamilyLayout familyLayout = capsule.getLayout().getFamilyMap().get(family); if (null == familyLayout) { throw new NoSuchColumnException(String.format("Family '%s' not found.", family)); } if (familyLayout.getLocalityGroup().getFamilyMap().size() > 1) { // There are multiple families within the locality group, so we need to be clever. if (familyLayout.isGroupType()) { deleteGroupFamily(entityId, familyLayout, upToTimestamp); } else if (familyLayout.isMapType()) { deleteMapFamily(entityId, familyLayout, upToTimestamp); } else { throw new RuntimeException("Internal error: family is neither map-type nor group-type."); } return; } // The only data in this HBase family is the one Fiji family, so we can delete everything. final HBaseColumnName hbaseColumnName = capsule.getColumnNameTranslator() .toHBaseColumnName(FijiColumnName.create(family)); final Delete delete = new Delete(entityId.getHBaseRowKey()); delete.deleteFamily(hbaseColumnName.getFamily(), upToTimestamp); // Buffer the delete. updateBuffer(delete); }
/** * 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); } }
/** * Translates a Fiji locality group into an HColumnDescriptor. * * @param localityGroup A Fiji locality group. * @param hbaseColumnNameTranslator to convert the locality group into the HBase family. * @return The HColumnDescriptor to use for storing the data in the locality group. */ private static HColumnDescriptor toHColumnDescriptor( final LocalityGroupLayout localityGroup, final HBaseColumnNameTranslator hbaseColumnNameTranslator ) { byte[] hbaseFamilyName = hbaseColumnNameTranslator.toHBaseFamilyName(localityGroup); LocalityGroupDesc groupDesc = localityGroup.getDesc(); return new HColumnDescriptor( hbaseFamilyName, groupDesc.getMaxVersions(), groupDesc.getCompressionType().toString(), groupDesc.getInMemory(), true, // block cache groupDesc.getBlockSize() != null ? groupDesc.getBlockSize() : HColumnDescriptor.DEFAULT_BLOCKSIZE, groupDesc.getTtlSeconds(), groupDesc.getBloomType() != null ? groupDesc.getBloomType().toString() : HColumnDescriptor.DEFAULT_BLOOMFILTER, HColumnDescriptor.DEFAULT_REPLICATION_SCOPE); } }