示例#1
0
            internal ZBlock(LongIntComboListPart parent, int zblockID, int addbuflen)
            {
                this.parent   = parent;
                this.zblockID = zblockID;

                this.blockbuflen = addbuflen;

                fzblockfilename = CreateFileName(zblockID, "unsorted");
                ensurefzblock(true, blockbuflen);
            }
 public LongIntComboListPartEnumerator(LongIntComboListPart icl)
 {
     this.icl = icl;
     this.buf = new byte[12];
 }
            internal ZBlock(LongIntComboListPart parent, int zblockID, int addbuflen)
            {
                this.parent = parent;
                this.zblockID = zblockID;

                this.blockbuflen = addbuflen;

                fzblockfilename = CreateFileName(zblockID, "unsorted");
                ensurefzblock(true, blockbuflen);
            }
示例#4
0
 public LongIntComboListPartEnumerator(LongIntComboListPart icl)
 {
     this.icl = icl;
     this.buf = new byte[12];
 }
示例#5
0
        // args: <ipaddr> <portnum> <typechar> <capacity> <logfile> <jid>
        static void Main(string[] args)
        {
            MySpace.DataMining.AELight.Surrogate.LogonMachines();

            try
            {
#if DEBUGnoisy
                XLog.errorlog("DistributedObjectsSlave EntryPoint: " + Environment.CommandLine);
#endif

#if DEBUG
                //System.Threading.Thread.Sleep(1000 * 8);
                {
                    //string computer_name = System.Environment.GetEnvironmentVariable("COMPUTERNAME");
                    //if (computer_name == "MAPDDRULE" || computer_name == "MAPDCMILLER")
                    {
                        if (System.IO.File.Exists("sleep.txt"))
                        {
                            System.Threading.Thread.Sleep(1000 * 8);
                            int i32 = 1 + 32;
                        }
                    }
                }
#endif

#if DEBUG
                SetPriorityClass(GetCurrentProcess(), BELOW_NORMAL_PRIORITY_CLASS);
#endif

                XLog.UserLogFile = args[4];
                if (XLog.UserLogFile.StartsWith("&"))
                {
                    XLog.UserLogFile       = XLog.UserLogFile.Substring(1);
                    XLog.DelimitUserErrors = true;
                }

#if SLAVE_TRACE
                try
                {
                    Thread mainthread             = System.Threading.Thread.CurrentThread;
                    System.Threading.Thread stthd = new System.Threading.Thread(
                        new System.Threading.ThreadStart(
                            delegate
                    {
                        string spid = System.Diagnostics.Process.GetCurrentProcess().Id.ToString();
                        try
                        {
                            string dotracefile          = spid + ".trace";
                            const string tracefiledelim = "{C8683F6C-0655-42e7-ACD9-0DDED6509A7C}";
                            for (; ;)
                            {
                                System.IO.StreamWriter traceout = null;
                                for (System.Threading.Thread.Sleep(1000 * 60)
                                     ; !System.IO.File.Exists(dotracefile)
                                     ; System.Threading.Thread.Sleep(1000 * 60))
                                {
                                }
                                {
                                    string[] tfc;
                                    try
                                    {
                                        tfc = System.IO.File.ReadAllLines(dotracefile);
                                    }
                                    catch
                                    {
                                        continue;
                                    }
                                    if (tfc.Length < 1 || "." != tfc[tfc.Length - 1])
                                    {
                                        continue;
                                    }
                                    try
                                    {
                                        System.IO.File.Delete(dotracefile);
                                    }
                                    catch
                                    {
                                        continue;
                                    }
                                    if ("." != tfc[0])
                                    {
                                        string traceoutfp = tfc[0];
                                        try
                                        {
                                            traceout = System.IO.File.CreateText(traceoutfp);
                                            traceout.Write("BEGIN:");
                                            traceout.WriteLine(tracefiledelim);
                                        }
                                        catch
                                        {
                                            continue;
                                        }
                                    }
                                }
                                if (null == traceout)
                                {
                                    XLog.log("SLAVE_TRACE: " + spid + " Start");
                                }
                                for (; ; System.Threading.Thread.Sleep(1000 * 60))
                                {
                                    {
                                        try
                                        {
#if SLAVE_TRACE_PORT
                                            if (null == traceout)
                                            {
                                                try
                                                {
                                                    StringBuilder sbtp = new StringBuilder();
                                                    sbtp.Append("SLAVE_TRACE_PORT: " + spid + ":");
                                                    for (int i = 0; i < DOSlave_TracePorts.Count; i++)
                                                    {
                                                        sbtp.Append(' ');
                                                        sbtp.Append(DOSlave_TracePorts[i]);
                                                    }
                                                    if (0 == DOSlave_TracePorts.Count)
                                                    {
                                                        sbtp.Append(" None");
                                                    }
                                                    XLog.log(sbtp.ToString());
                                                }
                                                catch
                                                {
                                                }
                                            }
#endif
                                            bool thdsuspended = false;
                                            try
                                            {
                                                mainthread.Suspend();
                                                thdsuspended = true;
                                            }
                                            catch (System.Threading.ThreadStateException)
                                            {
                                            }
                                            try
                                            {
                                                System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace(mainthread, false);
                                                StringBuilder sbst       = new StringBuilder();
                                                const int maxframesprint = 15;
                                                for (int i = 0, imax = Math.Min(maxframesprint, st.FrameCount); i < imax; i++)
                                                {
                                                    if (0 != sbst.Length)
                                                    {
                                                        sbst.Append(", ");
                                                    }
                                                    string mn = "N/A";
                                                    try
                                                    {
                                                        System.Reflection.MethodBase mb = st.GetFrame(i).GetMethod();
                                                        mn = mb.ReflectedType.Name + "." + mb.Name;
                                                    }
                                                    catch
                                                    {
                                                    }
                                                    sbst.Append(mn);
                                                }
                                                if (st.FrameCount > maxframesprint)
                                                {
                                                    sbst.Append(" ... ");
                                                    sbst.Append(st.FrameCount - maxframesprint);
                                                    sbst.Append(" more");
                                                }
                                                if (null == traceout)
                                                {
                                                    XLog.log("SLAVE_TRACE: " + spid + " Trace: " + sbst.ToString());
                                                }
                                                else
                                                {
                                                    traceout.WriteLine(sbst.ToString());
                                                }
                                            }
                                            catch (Exception e)
                                            {
                                                XLog.log("SLAVE_TRACE: " + spid + " Error: " + e.ToString());
                                            }
                                            finally
                                            {
                                                if (thdsuspended)
                                                {
                                                    mainthread.Resume();
                                                }
                                            }
                                        }
                                        catch (Exception e)
                                        {
                                            XLog.log("SLAVE_TRACE: " + spid + " " + mainthread.Name + " Trace Error: Cannot access thread: " + e.ToString());
                                        }
                                    }

                                    if (null != traceout)
                                    {
                                        traceout.Write(tracefiledelim);
                                        traceout.WriteLine(":END");
                                        traceout.Close();
                                        break;
                                    }
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            XLog.log("SLAVE_TRACE: " + spid + " Trace Failure: " + e.Message);
                        }
                    }));
                    stthd.IsBackground = true;
                    stthd.Start();
                }
                catch (Exception est)
                {
                    XLog.log("SLAVE_TRACE: Thread start error: " + est.ToString());
                }
#endif

                sjid = args[5];
                {
                    int ic = sjid.IndexOf(':');
                    if (-1 != ic)
                    {
                        jobdesc = Encoding.UTF8.GetString(Convert.FromBase64String(sjid.Substring(ic + 1)));
                        sjid    = sjid.Substring(0, ic);
                    }
                }
                jid = long.Parse(sjid);

                try
                {
                    Environment.SetEnvironmentVariable("DOSLAVE", "DO5");
                }
                catch
                {
                }

                System.Xml.XmlDocument xd = new System.Xml.XmlDocument();
#if DEBUGslaveconfigload
                Random _scsr = new Random(DateTime.Now.Millisecond / 2 + System.Threading.Thread.CurrentThread.ManagedThreadId / 2);
                //for (int i = 0; i < 50; i++)
                {
                    System.Threading.Thread.Sleep(_scsr.Next(50, 200));
                    try
                    {
                        xd.Load("slaveconfig.j" + sjid + ".xml");
                        InitXmlConfig(xd);
                    }
                    catch (System.IO.FileNotFoundException e)
                    {
                        //System.Diagnostics.Debugger.Launch();
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Debugger.Launch();
                        throw;
                    }
                }
#else
                try
                {
                    xd.Load("slaveconfig.j" + sjid + ".xml");
                    InitXmlConfig(xd);
                }
                catch (System.IO.FileNotFoundException e)
                {
                }
#endif

                if (XLog.logging)
                {
                    XLog.log("New Sub Process: '" + args[0] + "' '" + args[1] + "' '" + args[2] + "' '" + args[3] + "' '" + args[4] + "' '" + args[5] + "'");
                }

                Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
                string host    = args[0];
                int    portnum = ushort.Parse(args[1]);
#if SLAVE_TRACE_PORT
                DOSlave_TracePorts.Add(portnum);
#endif
                char typechar = args[2][0];
                try
                {
                    Thread.Sleep(100); // Give DLL a chance to start accepting.
                    sock.Connect(host, portnum);
                }
                catch (Exception e)
                {
                    throw new Exception("Sub-process-to-client(dll) connection error: " + e.ToString() + "  [Note: ensure port " + portnum.ToString() + " is free / not blocked]");
                }
                IDistObject dop;
                if ('H' == typechar)
                {
                    int capacity = ParseCapacity(args[3]);
                    if (XLog.logging)
                    {
                        XLog.log("Connected; creating Hashtable with capacity " + args[3]);
                    }
                    dop = HashtableObjectPart.Create(capacity);
                }
                else if ('8' == typechar)
                {
                    int capacity = ParseCapacity(args[3]);
                    if (XLog.logging)
                    {
                        XLog.log("Connected; creating IntComboList with capacity " + args[3]);
                    }
                    dop = IntComboListPart.Create(capacity);
                }
                else if ('C' == typechar) // 12 hex
                {
                    int capacity = ParseCapacity(args[3]);
                    if (XLog.logging)
                    {
                        XLog.log("Connected; creating LongIntComboList with capacity " + args[3]);
                    }
                    dop = LongIntComboListPart.Create(capacity);
                }
                else if ('A' == typechar)
                {
                    //int capacity = ParseCapacity(args[3]);
                    string[] a = args[3].Split(';');
                    int      count_capacity         = ParseCapacity(a[0]);
                    int      estimated_row_capacity = ParseCapacity(a[1]);
                    int      keylen = int.Parse(a[2]);
                    if (XLog.logging)
                    {
                        XLog.log("Connected; creating ArrayComboList(keylength=" + keylen.ToString() + ") with capacity " + args[3]);
                    }
                    dop = ArrayComboListPart.Create(count_capacity, estimated_row_capacity, keylen);
                }
                else if ('R' == typechar)
                {
                    if (XLog.logging)
                    {
                        XLog.log("Connected; creating Remote");
                    }
                    dop = RemotePart.Create();
                }
                else if ('F' == typechar)
                {
                    //int capacity = ParseCapacity(args[3]);
                    string[] a        = args[3].Split(';');
                    int      keylen   = ParseCapacity(a[2]);
                    int      valuelen = ParseCapacity(a[3]);
                    if (XLog.logging)
                    {
                        XLog.log("Connected; creating FixedArrayComboList(keylength=" + keylen.ToString() + ";valuelength=" + valuelen.ToString() + ")");
                    }
                    dop = FixedArrayComboListPart.Create(keylen, valuelen);
                }
                else
                {
                    throw new Exception("Data type not supported");
                }

                NetworkStream nstm = new XNetworkStream(sock);
                {
                    // New handshake with client(dll)...
                    nstm.WriteByte(1);
                    // ... and the SlavePID:
                    int    SlavePID = System.Diagnostics.Process.GetCurrentProcess().Id;
                    byte[] bpid     = DistObjectBase.ToBytes(SlavePID);
                    XContent.SendXContent(nstm, bpid);
                }

                {
                    int          pid         = System.Diagnostics.Process.GetCurrentProcess().Id;
                    string       spid        = pid.ToString();
                    string       pidfilename = spid + ".j" + sjid + ".slave.pid";
                    StreamWriter pidfile     = new StreamWriter(pidfilename);
                    pidfile.WriteLine(pid);
                    pidfile.WriteLine(System.DateTime.Now);
                    pidfile.WriteLine("jid={0}", sjid);
                    pidfile.Flush();
                    for (; ;)
                    {
                        try
                        {
                            dop.ProcessCommands(nstm);
                            break;
                        }
                        catch (DistObjectAbortException e)
                        {
                            XLog.errorlog("ProcessCommands exception: " + e.ToString() + " ((DistObjectAbortException))");
                            break; // !
                        }
                        catch (Exception e)
                        {
                            XLog.errorlog("ProcessCommands exception: " + e.ToString() + " ((recovering from this exception))");
                        }
                    }
                    pidfile.Close();
                    try
                    {
                        System.IO.File.Delete(pidfilename);
                    }
                    catch
                    {
                    }
                }
            }
            catch (Exception e)
            {
                XLog.errorlog("Main exception: " + e.ToString());
            }
        }