示例#1
0
        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);
            }
        }
示例#2
0
        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;
            }
        }
示例#3
0
        public virtual void ProcessCommands(NetworkStream nstm)
        {
            //nstm = new XNetworkStream(sock);
            int x;

            this.nstm = nstm;
            try
            {
                for (; ;)
                {
                    x = nstm.ReadByte();
                    if (x < 0)
                    {
                        //throw new Exception("Unable to read tag for command");
                        break;
                    }
                    buf[0]         = (byte)x;
                    CurrentCommand = (char)x;

                    if ('\\' == (char)buf[0])
                    {
                        if (XLog.logging)
                        {
                            XLog.log("Received close command from service; closing");
                        }
                        break;
                    }
                    else if ('<' == (char)buf[0])
                    {
                        try
                        {
                            string xml = XContent.ReceiveXString(nstm, buf);
                            System.Xml.XmlDocument xd = new System.Xml.XmlDocument();
                            xd.LoadXml(xml);
                            DistributedObjectsSlave.InitXmlConfig(xd);
                            ReloadConfig();
                        }
                        catch
                        {
                            nstm.WriteByte((byte)'-');
                            throw;
                        }
                        nstm.WriteByte((byte)'+');
                        continue;
                    }
                    else if ('?' == (char)buf[0])
                    {
                        if (null != lasterror)
                        {
                            string lerr = lasterror;
                            lasterror = null; // Also resets error!
                            XContent.SendXContent(nstm, lerr);
                        }
                        else
                        {
                            XContent.SendXContent(nstm, buf, 0); // No error!
                        }
                        continue;
                    }

                    /*
                     * if (XLog.logging)
                     * {
                     *  XLog.log("Slave processing command " + ((char)buf[0]).ToString());
                     * }
                     * */
                    ProcessCommand(nstm, (char)buf[0]);
                }
            }
            catch (System.IO.IOException ioex)
            {
                // Drop SocketException (shutdown during tasks), rethrow others.
                if ((ioex.InnerException as SocketException) == null)
                {
                    throw;
                }
#if DEBUG
                XLog.errorlog("DistributedObjectsSlave Warning: IOException+SocketException during task shutdown: " + ioex.ToString());
#endif
            }

            nstm.Close();
            nstm.Dispose();
        }