@Override public long length() { return other.length() ; }
public TransObjectFile(ObjectFile objFile, ComponentId cid, BufferChannel bufferChannel) { super(cid) ; stateMgr = new ObjectFileState(bufferChannel, 0L, 0L) ; this.objFile = objFile ; // These may be updated by recovery. Start by setting to the // "clean start" settings. length = new AtomicLong(objFile.length()) ; position = new AtomicLong(objFile.position()) ; }
@Override protected void _commit(TxnId txnId, TxnObjectFile state) { if ( isWriteTxn() ) { // Force to disk. objFile.sync(); stateMgr.writeState(); // Move visible commit point forward. length.set(objFile.length()) ; position.set(objFile.position()) ; } }
@Override public long length() { super.checkTxn(); if ( isReadTxn() ) return getDataState().length ; // Reader. Check bounds. return objFile.length() ; }
@Override protected ByteBuffer _commitPrepare(TxnId txnId, TxnObjectFile state) { stateMgr.length(objFile.length()) ; stateMgr.position(objFile.position()); return stateMgr.getState() ; }
@Test public void transObjectFile_4() { String str1 = "Test4" ; String str2 = "TheNext" ; long x1 = writeOne(transactional, transObjectFile, str1) ; ByteBuffer bb = str2bb(str2) ; long x2 = baseObjectFile.write(bb) ; baseObjectFile.sync(); long x3 = Txn.calculateRead(transactional, ()->transObjectFile.length()) ; assertEquals(x2, x3); assertNotEquals(x3, baseObjectFile.length()); // Fake recovery. ByteBuffer bbj = ByteBuffer.allocate(2*Long.BYTES) ; bbj.putLong(x3) ; bbj.putLong(0) ; bbj.rewind() ; journal.write(JournalEntryType.REDO, transObjectFile.getComponentId(), bbj) ; journal.writeJournal(JournalEntry.COMMIT) ; // Recovery. //transObjectFile.recover(bb); TransactionalBase transBase = (TransactionalBase)TransactionalFactory.createTransactional(journal, transObjectFile) ; ByteBuffer bb1 = Txn.calculateRead(transBase, ()->transObjectFile.read(x3)) ; String s1 = Bytes.fromByteBuffer(bb1) ; assertEquals(str2, s1); // Woot! transBase.getTxnMgr().shutdown(); } }