/** {@inheritDoc} */ @Override public FijiBufferedWriter openBufferedWriter() throws IOException { return new HBaseFijiBufferedWriter(mTable); } }
/** {@inheritDoc} */ @Override public void deleteCell(EntityId entityId, String family, String qualifier) throws IOException { deleteCell(entityId, family, qualifier, HConstants.LATEST_TIMESTAMP); }
/** {@inheritDoc} */ @Override public void deleteColumn(EntityId entityId, String family, String qualifier) throws IOException { deleteColumn(entityId, family, qualifier, HConstants.LATEST_TIMESTAMP); }
/** {@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); }
/** {@inheritDoc} */ @Override public void deleteRow(EntityId entityId, long upToTimestamp) throws IOException { final Delete delete = SchemaPlatformBridge.get() .createDelete(entityId.getHBaseRowKey(), upToTimestamp); updateBuffer(delete); }
/** {@inheritDoc} */ @Override public void setBufferSize(long bufferSize) throws IOException { synchronized (mInternalLock) { Preconditions.checkState(mState == State.OPEN, "Cannot set buffer size of BufferedWriter instance %s in state %s.", this, mState); Preconditions.checkArgument(bufferSize > 0, "Buffer size cannot be negative, got %s.", bufferSize); mMaxWriteBufferSize = bufferSize; if (mCurrentWriteBufferSize > mMaxWriteBufferSize) { flush(); } SchemaPlatformBridge.get().setWriteBufferSize(mHTable, bufferSize); } }
/** {@inheritDoc} */ @Override public <T> void put(EntityId entityId, String family, String qualifier, T value) throws IOException { put(entityId, family, qualifier, HConstants.LATEST_TIMESTAMP, value); }
/** {@inheritDoc} */ @Override public void deleteRow(EntityId entityId) throws IOException { deleteRow(entityId, HConstants.LATEST_TIMESTAMP); }
/** {@inheritDoc} */ @Override public void deleteFamily(EntityId entityId, String family) throws IOException { deleteFamily(entityId, family, HConstants.LATEST_TIMESTAMP); }
/** {@inheritDoc} */ @Override public void deleteColumn(EntityId entityId, String family, String qualifier, long upToTimestamp) throws IOException { final HBaseColumnName hbaseColumnName = mWriterLayoutCapsule.getColumnNameTranslator() .toHBaseColumnName(FijiColumnName.create(family, qualifier)); final Delete delete = new Delete(entityId.getHBaseRowKey()) .deleteColumns(hbaseColumnName.getFamily(), hbaseColumnName.getQualifier(), upToTimestamp); updateBuffer(delete); }
/** * Add a Delete to the buffer and update the current buffer size. * * @param d A delete to add to the buffer. * @throws IOException in case of an error on flush. */ private void updateBuffer(Delete d) throws IOException { synchronized (mInternalLock) { mDeleteBuffer.add(d); long heapSize = mDeleteSize; heapSize += ClassSize.align(ClassSize.ARRAY + d.getRow().length); mCurrentWriteBufferSize += heapSize; if (mCurrentWriteBufferSize > mMaxWriteBufferSize) { flush(); } } }
/** {@inheritDoc} */ @Override public void deleteCell(EntityId entityId, String family, String qualifier, long timestamp) throws IOException { final HBaseColumnName hbaseColumnName = mTable.getColumnNameTranslator() .toHBaseColumnName(FijiColumnName.create(family, qualifier)); final Delete delete = new Delete(entityId.getHBaseRowKey()) .deleteColumn(hbaseColumnName.getFamily(), hbaseColumnName.getQualifier(), timestamp); updateBuffer(delete); }
/** * Deletes all cells from a group-type family with a timestamp less than or equal to a * specified timestamp. * * @param entityId The entity (row) to delete from. * @param familyLayout The family layout. * @param upToTimestamp A timestamp. * @throws IOException If there is an IO error. */ private void deleteGroupFamily( EntityId entityId, FamilyLayout familyLayout, long upToTimestamp) throws IOException { final String familyName = Preconditions.checkNotNull(familyLayout.getName()); // Delete each column in the group according to the layout. final Delete delete = new Delete(entityId.getHBaseRowKey()); for (ColumnLayout columnLayout : familyLayout.getColumnMap().values()) { final String qualifier = columnLayout.getName(); final FijiColumnName column = FijiColumnName.create(familyName, qualifier); final HBaseColumnName hbaseColumnName = mWriterLayoutCapsule.getColumnNameTranslator().toHBaseColumnName(column); delete.deleteColumns( hbaseColumnName.getFamily(), hbaseColumnName.getQualifier(), upToTimestamp); } // Buffer the delete. updateBuffer(delete); }
/** {@inheritDoc} */ @Override public void close() throws IOException { synchronized (mInternalLock) { flush(); Preconditions.checkState(mState == State.OPEN, "Cannot close BufferedWriter instance %s in state %s.", this, mState); mState = State.CLOSED; ResourceTracker.get().unregisterResource(this); mLayoutConsumerRegistration.close(); mHTable.close(); mTable.release(); } } }
/** {@inheritDoc} */ @Override public <T> void put(EntityId entityId, String family, String qualifier, long timestamp, T value) throws IOException { final FijiColumnName columnName = FijiColumnName.create(family, qualifier); final HBaseFijiTableWriter.WriterLayoutCapsule capsule = mWriterLayoutCapsule; final HBaseColumnName hbaseColumnName = capsule.getColumnNameTranslator().toHBaseColumnName(columnName); final FijiCellEncoder cellEncoder = capsule.getCellEncoderProvider().getEncoder(family, qualifier); final byte[] encoded = cellEncoder.encode(value); updateBuffer(entityId, hbaseColumnName.getFamily(), hbaseColumnName.getQualifier(), timestamp, encoded); }
LOG.info("Flushing buffer from HBaseFijiBufferedWriter for table: {} in preparation for" + " layout update.", mTable.getURI()); flush();
delete.deleteColumns(hbaseColumnName.getFamily(), hbaseQualifier, upToTimestamp); updateBuffer(delete);