public void finish()
{
// TODO: make a higher level TX commit that finalizes pending writes into final writes
// and cleans up locks and state
// TODO: this is a flush not a commmit. When other
// writers are concurrent, some of their stuff is also written to the
// log when we flush. Therefore, as soon as you write, your write is
// "likely to occur" whether you commit or not. We need to layer
// an MVCC on top of this
if (this.state == WriteGroupState.CLOSED) {
System.Console.WriteLine("finish() called on closed WriteGroup"); // TODO: add LSN/info
return;
}
if (mylayer == null || mylayer.logwriter == null) {
System.Console.WriteLine("finish() called on torn-down LayerManager"); // TODO: add LSN/info
return;
}
switch (type) {
case WriteGroupType.DISK_INCREMENTAL:
// we've been incrementally writing commands, so ask them to flush
if (this.last_logwaitnumber != 0) {
mylayer.logwriter.flushPendingCommandsThrough(last_logwaitnumber);
}
break;
case WriteGroupType.DISK_ATOMIC_FLUSH:
// send the group of commands to the log and clear the pending list
mylayer.logwriter.addCommands(this.pending_cmds, ref this.last_logwaitnumber);
this.pending_cmds.Clear();
// wait until the atomic log packet is flushed
mylayer.logwriter.flushPendingCommandsThrough(last_logwaitnumber);
break;
case WriteGroupType.DISK_ATOMIC_NOFLUSH:
// send the group of commands to the log and clear the pending list
mylayer.logwriter.addCommands(this.pending_cmds, ref this.last_logwaitnumber);
this.pending_cmds.Clear();
break;
case WriteGroupType.MEMORY_ONLY:
// we turned off logging, so the only way to commit is to checkpoint!
// TODO: force checkpoint ??
break;
default:
throw new Exception("unknown write group type in .finish(): " + type.ToString());
}
if (this.pending_cmds.Count != 0) {
throw new Exception("pending commands left after finish!!");
}
state = WriteGroupState.CLOSED;
mylayer.pending_txns.Remove(this.tsn);
// call each of the pending completions.
foreach (handleWriteGroupCompletion completion_fn in pending_completions) {
completion_fn();
}
pending_completions.Clear();
}