public void freeSegment(LayerWriteGroup tx, FreespaceExtent segment_extent)
{
// (1) add the segment to the pending list (pending free)
if (tx.type != LayerWriteGroup.WriteGroupType.DISK_ATOMIC_FLUSH) {
throw new Exception("freeSegment() requires DISK_ATOMIC write group");
}
// NOTE: DISK_ATOMIC writes are not seen in the memory segment until the atomic write group applies
// so these changes will not be seen until then
RecordKey key = new RecordKey().appendParsedKey(".ROOT/FREELIST/PENDING")
.appendKeyPart(new RecordKeyType_Long(segment_extent.end_addr));
RecordUpdate payload = RecordUpdate.WithPayload(segment_extent.pack());
tx.setValue(key, payload);
// (2) add a handler to get notified when the block is no longer referenced, so it can
// be moved from pending to actually free.
LayerWriteGroup fwg = this.store.newWriteGroup(LayerWriteGroup.WriteGroupType.DISK_ATOMIC_NOFLUSH);
// we don't want to ask for the notification until the write-group freeing this segment is finished
tx.addCompletion(delegate() {
tx.mylayer.regionmgr.notifyRegionSafeToFree(segment_extent.start_addr,
delegate(long addr) { this.handleRegionSafeToFree(addr, segment_extent, fwg); });
});
}