private LongIntComboListPart(int capacity) { ZBlock.CleanZBlockFiles("unsorted", "sorted"); b12buffer = new List <B12>(0); this.enums = new LongIntComboListPartEnumerator[32]; // Pre-set with defaults. int numzblocks = 139; int zblockbufsize = 131072; // 128 KB default. if (null != DistributedObjectsSlave.xslave) { System.Xml.XmlNode xzblocks = DistributedObjectsSlave.xslave["zblocks"]; if (null != xzblocks) { { System.Xml.XmlAttribute xnzb = xzblocks.Attributes["count"]; if (null != xnzb) { numzblocks = int.Parse(xnzb.Value); } } { System.Xml.XmlAttribute xzbs = xzblocks.Attributes["addbuffersize"]; if (null != xzbs) { zblockbufsize = DistributedObjectsSlave.ParseCapacity(xzbs.Value); } } } } if (XLog.logging) { XLog.log("Creating " + numzblocks.ToString() + " ZBlock`s"); } zblocks = new ZBlock[numzblocks]; for (int i = 0; i != numzblocks; i++) { zblocks[i] = new ZBlock(this, i, zblockbufsize); } }
protected override void ProcessCommand(NetworkStream nstm, char tag) { //string s; int len; switch (tag) { case 'e': // Batch 'get next' enumeration. { try { int ienumid = nstm.ReadByte(); if (ienumid >= 0) { byte enumid = (byte)ienumid; if (enumid >= this.enums.Length) { nstm.WriteByte((byte)'-'); } else { if (null == this.enums[enumid]) { this.enums[enumid] = new LongIntComboListPartEnumerator(this); } int offset = 0; if (null == buf || buf.Length < 60) { throw new Exception("Enumeration batch buffer too small!"); } //if (uniquecompression) // Compressed... { for (; ;) { if (!this.enums[enumid].MoveNext()) { break; } B12 b12 = this.enums[enumid].Current; // Using Big Endian! b12.CopyToArray(buf, offset); offset += 12; if (offset + 12 > buf.Length) { break; } } } if (offset > 0) { nstm.WriteByte((byte)'+'); XContent.SendXContent(nstm, buf, offset); } else { nstm.WriteByte((byte)'-'); } } } } catch { nstm.WriteByte((byte)'-'); throw; } } break; case 'n': // Reset next in enumeration.. { int ienumid = nstm.ReadByte(); if (ienumid >= 0) { byte enumid = (byte)ienumid; if (XLog.logging) { XLog.log("Starting enumeration (enumid:" + enumid.ToString() + ")"); } if (enumid < this.enums.Length && null != this.enums[enumid]) { //this.enums[enumid].Reset(); this.enums[enumid] = null; } } } break; case 's': { try { #if ENABLE_TIMING long start = 0; if (XLog.logging) { QueryPerformanceCounter(out start); } #endif int readbuflen = 1048576; if (null != DistributedObjectsSlave.xslave) { System.Xml.XmlNode xzblocks = DistributedObjectsSlave.xslave["zblocks"]; if (null != xzblocks) { { System.Xml.XmlAttribute xzbs = xzblocks.Attributes["readbuffersize"]; if (null != xzbs) { readbuflen = DistributedObjectsSlave.ParseCapacity(xzbs.Value); } } } } foreach (ZBlock zb in zblocks) { zb.LeaveAddMode(readbuflen); } foreach (ZBlock zb in zblocks) { zb.Sort(b12buffer, this.buf); } #if ENABLE_TIMING if (XLog.logging) { long stop; QueryPerformanceCounter(out stop); long freq; if (QueryPerformanceFrequency(out freq)) { long secs = (stop - start) / freq; if (secs > 10) { XLog.log("IntComboListPart sort seconds: " + secs.ToString()); } } } #endif } finally { nstm.WriteByte((byte)'+'); } } break; case 'p': // Batch push/publish... { buf = XContent.ReceiveXBytes(nstm, out len, buf); uint gbfree = (uint)(GetCurrentDiskFreeBytes() / 1073741824); #if DEBUG { string computer_name = System.Environment.GetEnvironmentVariable("COMPUTERNAME"); if (computer_name == "MAPDDRULE" || computer_name == "MAPDCMILLER" || computer_name == "computer_name") { gbfree = uint.MaxValue; } } #endif if (gbfree > 20) { int pcount = len / 12; // size of B12 int y = 0; for (int i = 0; i != pcount; i++) { TimedAdd(buf, y); y += 12; } } else { if (!nofreedisklog) { nofreedisklog = true; XLog.errorlog("Low free disk space; now dropping entries."); } } } break; default: base.ProcessCommand(nstm, tag); break; } }