boolean clearAddrMap(final long addr,final int latchedAddr) throws IllegalStateException, InterruptedException {
  final ByteBuffer tmp=acquire();
  try {
    if (m_closedForWrites) {
      return false;
    }
    final RecordMetadata removed=recordMap.remove(addr);
    if (removed == null) {
      throw new AssertionError();
    }
    removed.deleted=true;
    if (!prefixWrites) {
      m_removed+=removed.recordLength;
      return true;
    }
    final int addr_offset=removed.bufferOffset - SIZEOF_PREFIX_WRITE_METADATA;
    tmp.putLong(addr_offset,-removed.fileOffset);
    if (m_written && recordMap.isEmpty()) {
      m_written=false;
    }
    m_removed+=removed.recordLength;
    return true;
  }
  finally {
    release();
  }
}

boolean clearAddrMap ( final long addr , final int latchedAddr ) throws IllegalStateException , InterruptedException { final ByteBuffer tmp = acquire ( ) ; try { if ( m_closedForWrites ) { return false ; } final RecordMetadata removed = recordMap . remove ( addr ) ; if ( removed == null ) { throw new AssertionError ( ) ; } removed . deleted = true ; if ( ! prefixWrites ) { m_removed += removed . recordLength ; return true ; } final int addr_offset = removed . bufferOffset - SIZEOF_PREFIX_WRITE_METADATA ; tmp . putLong ( addr_offset , - removed . fileOffset ) ; if ( m_written && recordMap . isEmpty ( ) ) { m_written = false ; } m_removed += removed . recordLength ; return true ; } finally { release ( ) ; } }
to support deletion we will remove any entries for the provided address . this is just to yank something out of the cache which was created and then immediately deleted on the rw store before it could be written through to the disk . this does not reclaim any space in the write cache since allocations are strictly sequential within the cache and can only be used with the rw store . the rw store uses write prefixes in the cache buffer so we must zero the long address element as well to indicate that the record was removed from the buffer . this approach has now been refined to avoid problems with incremental checksums which otherwise would invalidate the buffer checksum to date . rather than zeroing the address of the deleted block a new zero - length prefix is written that when processed will ensure any current recordmap entry is removed . todo : an issue to be worked through is whether there remains a problem with a full buffer where there is not room for the dummy " remove " prefix . whilst we could of course ensure that a buffer with less than the space required for prefixwrites should be moved immediately to the dirtlylist , there would still exist the possibility that the clear could be requested on a buffer already on the dirtylist . it looks like this should not matter , since each buffer update can be considered as an atomic update even if the set of writes are individually not atomic ( the updates from a previous buffer will always have been completed before the next buffer is processed ) . in that case it appears we could ignore the situation where there is no room for the dummy " remove " prefix , since there will be no room for a new write also and the buffer will be flushed either on commit or a subsequent write . a problem previously existed with unsynchronized access to the bytebuffer . resulting in a conflict over the position ( ) and buffer corruption . if the writecache is closed then it must not be modified at all otherwise any ha replication will not be binary compatible .
