Bend.LayerWriteGroup.finish C# (CSharp) Метод

finish() публичный Метод

public finish ( ) : void
Результат void
        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();
        }

Usage Example

Пример #1
0
        // move the pending address into the freelist
        private void handleRegionSafeToFree(long start_addr, FreespaceExtent extent, LayerWriteGroup wg)
        {
            System.Console.WriteLine("*\n*\n*\n* handleRegionSafeToFree {0} \n*\n*\n*", start_addr);
            // (1) remove pending entry
            wg.setValue(pendingKeyForAddr(start_addr), RecordUpdate.DeletionTombstone());

            // (2) write real freelist entry (TODO: merge with neighboring entries)
            {
                RecordKey key = new RecordKey().appendParsedKey(".ROOT/FREELIST/EXTENTS");
                key.appendKeyPart(new RecordKeyType_Long(extent.end_addr));
                wg.setValue(key, RecordUpdate.WithPayload(extent.pack()));
            }
            wg.finish();
        }