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

public sortedWalk ( ) : RecordUpdate>>.IEnumerable
Результат RecordUpdate>>.IEnumerable
Пример #1
0
        public void handleCommand(LogCommands cmd, byte[] cmddata)
        {
            if (cmd == LogCommands.UPDATE) {
                // decode basic block key/value writes
                BlockAccessor ba = new BlockAccessor(cmddata);
                ISegmentBlockDecoder decoder = new SegmentBlockBasicDecoder(ba);
                foreach (KeyValuePair<RecordKey, RecordUpdate> kvp in decoder.sortedWalk()) {
                    // add the updates to our working segment...
                    lock (mylayer.segmentlayers) {
            #if false
                            // some status debug code...
                            if (RangemapManager.RangeKey.isRangeKey(kvp.Key)) {
                                System.Console.WriteLine("LayerManager.handleCommand : setValue() {0} => {1}",
                                    kvp.Key.ToString(), kvp.Value.ToString());
                                if (kvp.Value.type != RecordUpdateTypes.DELETION_TOMBSTONE && kvp.Value.data.Length != 16) {
                                    throw new Exception("!!! corrupted rangekey appeared in handleCommand");
                                }
                            }
            #endif

                        mylayer.workingSegment.setRecord(kvp.Key, kvp.Value);
                    }
                }
            } else if (cmd == LogCommands.CHECKPOINT_START) {
                // here we move aside the checkpoint segment...
                //   - if this is during live operation, the checkpoint is running as soon as we return.
                //   - if this is during recovery, there is no checkpoint running and we'll need to

                // TODO: we need some kind of key/checksum to be sure that we CHECKPOINT and DROP the right dataF
                checkpointSegment = mylayer.workingSegment;
                SegmentMemoryBuilder newsegment = new SegmentMemoryBuilder();
                lock (mylayer.segmentlayers) {
                    mylayer.workingSegment = newsegment;
                    mylayer.segmentlayers.Insert(0, mylayer.workingSegment);
                }
            } else if (cmd == LogCommands.CHECKPOINT_DROP) {
                // TODO: we need some kind of key/checksum to be sure that we CHECKPOINT and DROP the right data
                if (checkpointSegment != null) {
                    lock (mylayer.segmentlayers) {
                        mylayer.segmentlayers.Remove(checkpointSegment);
                        checkpointSegment = null;
                    }
                } else {
                    throw new Exception("can't drop, no segment to drop");
                }
            } else {
                throw new Exception("unimplemented command");
            }
        }
Пример #2
0
        public static void T01_BlockEncodeDecodeTest()
        {
            MemoryStream ms = new MemoryStream();
            byte[] testdata = { 0x00, 0x10, 0x78, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00 };

            // init an encoder and add one key which requires escaping
            {
                ISegmentBlockEncoder enc = new SegmentBlockBasicEncoder();
                enc.setStream(ms);

                RecordKey key = new RecordKey().appendParsedKey("TESTSETEST");
                RecordUpdate update = RecordUpdate.WithPayload(testdata);

                enc.add(key, update);
                enc.flush();
                ms.Flush();

                System.Console.WriteLine("Test Update: " + update.ToString());
            }

            byte[] block_contents = ms.ToArray();
            System.Console.WriteLine("Block Output: " + BitConverter.ToString(block_contents));

            // init the decoder
            {
                ISegmentBlockDecoder dec = new SegmentBlockBasicDecoder(new BlockAccessor(ms.ToArray()));

                foreach (var kvp in dec.sortedWalk()) {
                    System.Console.WriteLine("Payload Update: " + kvp.Value.ToString());

                    byte[] payload = kvp.Value.data;
                    Assert.AreEqual(testdata, payload, "payload data mismatch!");
                }
            }
        }
Пример #3
0
        internal void applyLogEntry(string from_server_guid, long logstamp, RecordUpdate logdata)
        {
            // (0) unpack the data
            BlockAccessor ba = new BlockAccessor(logdata.data);
            ISegmentBlockDecoder decoder = new SegmentBlockBasicDecoder(ba);

            // (1) add it to our copy of that server's log

            this._recordLogEntry(from_server_guid, logstamp, logdata);
            // (2) add it to the database

            foreach (var kvp in decoder.sortedWalk()) {
                RecordKey local_data_key = new RecordKey()
                    .appendKeyPart("_data");
                foreach (var part in kvp.Key.key_parts) {
                    local_data_key.appendKeyPart(part);
                }
                next_stage.setValue(local_data_key, kvp.Value);
            }
        }