/** {@inheritDoc} */ @Override public AtomicFijiPutter openAtomicPutter() throws IOException { return new HBaseAtomicFijiPutter(mTable); }
/** {@inheritDoc} */ @Override public <T> void put(String family, String qualifier, T value) throws IOException { put(family, qualifier, HConstants.LATEST_TIMESTAMP, value); }
/** {@inheritDoc} */ @Override public void rollback() { Preconditions.checkState(mPut != null, "rollback() must be paired with a call to begin()"); final State state = mState.get(); Preconditions.checkState(state == State.OPEN, "Cannot rollback a transaction on an AtomicFijiPutter instance in state %s.", state); reset(); }
/** {@inheritDoc} */ @Override public void commit() throws IOException { Preconditions.checkState(mPut != null, "commit() must be paired with a call to begin()"); final State state = mState.get(); Preconditions.checkState(state == State.OPEN, "Cannot commit a transaction on an AtomicFijiPutter instance in state %s.", state); // We don't actually need the writer layout capsule here, but we want the layout update check. getWriterLayoutCapsule(); SchemaPlatformBridge bridge = SchemaPlatformBridge.get(); for (KeyValue kv : mHopper) { bridge.addKVToPut(mPut, kv); } mHTable.put(mPut); if (!mHTable.isAutoFlush()) { mHTable.flushCommits(); } reset(); }
/** * Get the writer layout capsule ensuring that the layout has not been updated while a transaction * is in progress. * * @return the WriterLayoutCapsule for this writer. * @throws LayoutUpdatedException in case the table layout has been updated while a transaction is * in progress */ private WriterLayoutCapsule getWriterLayoutCapsule() throws LayoutUpdatedException { synchronized (mLock) { if (mLayoutOutOfDate) { // If the layout was updated, roll back the transaction and throw an Exception to indicate // the need to retry. rollback(); // TODO: SCHEMA-468 improve error message for LayoutUpdatedException. throw new LayoutUpdatedException( "Table layout was updated during a transaction, please retry."); } else { return mWriterLayoutCapsule; } } }
/** {@inheritDoc} */ @Override public <T> void put(String family, String qualifier, long timestamp, T value) throws IOException { Preconditions.checkState(mPut != null, "calls to put() must be between calls to begin() and " + "commit(), checkAndCommit(), or rollback()"); final State state = mState.get(); Preconditions.checkState(state == State.OPEN, "Cannot put cell to an AtomicFijiPutter instance in state %s.", state); final WriterLayoutCapsule capsule = getWriterLayoutCapsule(); final FijiColumnName fijiColumnName = FijiColumnName.create(family, qualifier); final HBaseColumnName columnName = capsule.getColumnNameTranslator().toHBaseColumnName(fijiColumnName); final FijiCellEncoder cellEncoder = capsule.getCellEncoderProvider().getEncoder(family, qualifier); final byte[] encoded = cellEncoder.encode(value); mHopper.add(new KeyValue( mId, columnName.getFamily(), columnName.getQualifier(), timestamp, encoded)); }
Preconditions.checkState(state == State.OPEN, "Cannot checkAndCommit a transaction on an AtomicFijiPutter instance in state %s.", state); final WriterLayoutCapsule capsule = getWriterLayoutCapsule(); final FijiColumnName fijiColumnName = FijiColumnName.create(family, qualifier); final HBaseColumnName columnName = mHTable.flushCommits(); reset();
/** {@inheritDoc} */ @Override public void close() throws IOException { final State oldState = mState.getAndSet(State.CLOSED); Preconditions.checkState(oldState == State.OPEN, "Cannot close an AtomicFijiPutter instance in state %s.", oldState); if (mPut != null) { LOG.warn("Closing HBaseAtomicFijiPutter while a transaction on table {} on entity ID {} is " + "in progress. Rolling back transaction.", mTable.getURI(), mEntityId); reset(); } mLayoutConsumerRegistration.close(); mHTable.close(); mTable.release(); } }