/** * This procedure runs on the unisolated index. The raw data is written directly onto the {@link * Journal} and the index is added/updated using the given file, version and block and the address * of the block's data on the {@link Journal}. * * @return A {@link Boolean} whose value is <code>true</code> iff the block was overwritten. */ @Override public Object apply(final IIndex ndx) { // tunnel through to the backing journal. final AbstractJournal journal = (AbstractJournal) ((AbstractBTree) ndx).getStore(); // obtain the thread-local key builder for that journal. final IKeyBuilder keyBuilder = ndx.getIndexMetadata().getKeyBuilder(); /* * Write the block on the journal, obtaining the address at which it * was written - use 0L as the address for an empty block. */ final long addr = len == 0 ? 0L : journal.write(ByteBuffer.wrap(b, off, len)); // form the key for the index entry for this block. final byte[] key = keyBuilder .reset() .appendText(id, true /* unicode */, false /* successor */) .append(version) .append(block) .getKey(); // record the address of the block in the index. final boolean overwrite; { final DataOutputBuffer out = new DataOutputBuffer(Bytes.SIZEOF_LONG); // encode the value for the entry. out.reset().putLong(addr); final byte[] val = out.toByteArray(); // insert the entry into the index. overwrite = ndx.insert(key, val) != null; } log.info( "Wrote " + len + " bytes : id=" + id + ", version=" + version + ", block#=" + block + " @ addr" + journal.toString(addr) + ", overwrite=" + overwrite); return Boolean.valueOf(overwrite); }