Ejemplo n.º 1
0
        internal void Stop()
        {
            stop = true;

            if (heartbeatthd != null)
            {
                try
                {
                    heartbeatthd.Abort();
                    heartbeatthd = null;
                    System.IO.File.Delete(heartbeattempfile);
                }
                catch
                {
                }
            }

            if (tattlethd != null)
            {
                try
                {
                    tattlethd.Abort();
                    tattlethd = null;
                }
                catch
                {
                }
            }
            RogueHosts.Clear(jobid);
        }
Ejemplo n.º 2
0
        void TattleThreadProc()
        {
            string        localhost = System.Net.Dns.GetHostName();
            List <string> badhosts  = new List <string>(10);

            while (!stop)
            {
                long newlastupdated = RogueHosts.Get(jobid, tattlelastupdated, badhosts);
                if (newlastupdated != tattlelastupdated) // has new tattled host
                {
                    tattlelastupdated = newlastupdated;
                    if (badhosts.Count > 0)
                    {
                        string strbhs = "";
                        for (int i = 0; i < badhosts.Count; i++)
                        {
                            if (i > 0)
                            {
                                strbhs += ";";
                            }
                            strbhs += badhosts[i];

                            if (string.Compare(badhosts[i], localhost, true) == 0)
                            {
                                badlocalhost = true;
                            }
                        }
                        lock (clientstm)
                        {
                            clientstm.WriteByte((byte)'e');
                            XContent.SendXContent(clientstm, strbhs);
                        }
#if FAILOVER_DEBUG
                        System.IO.File.AppendAllText(@"c:\temp\vitalsreporter_A5B1E053-9A32-417b-8068-91A7CD5CDEAB.txt", DateTime.Now.ToString() + " rogues sent:" + strbhs + Environment.NewLine);
#endif
                    }
                }
                System.Threading.Thread.Sleep(tattletimeout);
            }
        }
Ejemplo n.º 3
0
        internal void ThreadProc()
        {
            try
            {
                Random rnd = new Random(unchecked (System.DateTime.Now.Millisecond + System.Threading.Thread.CurrentThread.ManagedThreadId));
                List <PullFileInfo> infos = new List <PullFileInfo>(stop - start);
                for (int i = start; i < stop; i++)
                {
                    PullFileInfo info;
                    info.PullFile = allpullfiles[i];
                    string destfn;
                    {
                        int ix;
                        ix = info.PullFile.LastIndexOf('\u0002');
                        if (-1 != ix)
                        {
                            destfn        = info.PullFile.Substring(ix + 1);
                            info.PullFile = info.PullFile.Substring(0, ix);
                        }
                        else
                        {
                            ix = info.PullFile.LastIndexOf('\\');
                            if (-1 != ix)
                            {
                                destfn = info.PullFile.Substring(ix + 1);
                            }
                            else
                            {
                                destfn = info.PullFile;
                            }
                        }
                    }
                    info.DestFile       = destfn;
                    info.DestFileStream = null;
                    info.Position       = 0;
                    info.Retries        = 0;
                    infos.Add(info);
                }

                byte[] fbuf = new byte[MAX_SIZE_PER_RECEIVE];

                for (int i = 0; i < infos.Count; i++)
                {
                    PullFileInfo info = infos[i];
                    for (; ;)  //cooking
                    {
                        bool cooking_is_read = false;

                        try
                        {
                            if (info.DestFileStream == null)
                            {
                                if (info.Retries == 0)
                                {
                                    cooking_is_read = true;

#if TESTFAULTTOLERANT
                                    {
                                        int    dgdel  = info.PullFile.IndexOf(@"\", 2);
                                        string dghost = info.PullFile.Substring(2, dgdel - 2).ToLower();
                                        fttest.BreakPoint(dghost, "replication", new Exception("FAULTTOLERANT replication test exception"));
                                    }
#endif
                                    System.IO.File.Copy(info.PullFile, info.DestFile, true);
                                    cooking_is_read = false;
                                    break; // done with this pullfile
                                }
                                else
                                {
                                    info.DestFileStream = new System.IO.FileStream(info.DestFile, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.Read, FILE_BUFFER_SIZE);
                                }
                            }

                            if (info.DestFileStream != null)
                            {
                                cooking_is_read = true;
                                using (System.IO.FileStream pullfs = new System.IO.FileStream(info.PullFile, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read, FILE_BUFFER_SIZE))
                                {
#if TESTFAULTTOLERANT
                                    {
                                        int    dgdel  = info.PullFile.IndexOf(@"\", 2);
                                        string dghost = info.PullFile.Substring(2, dgdel - 2).ToLower();
                                        fttest.BreakPoint(dghost, "replication", new Exception("FAULTTOLERANT replication test exception"));
                                    }
#endif
                                    if (info.Position != 0)
                                    {
                                        pullfs.Position = info.Position;
                                    }
                                    for (; ;)
                                    {
                                        //----------------------------COOKING--------------------------------
                                        cooking_is_read = true;
                                        //----------------------------COOKING--------------------------------
                                        int xread = pullfs.Read(fbuf, 0, MAX_SIZE_PER_RECEIVE);
                                        info.Position += xread;
                                        //----------------------------COOKING--------------------------------
                                        cooking_is_read = false;
                                        //----------------------------COOKING--------------------------------
                                        if (xread <= 0)
                                        {
                                            break;
                                        }
                                        info.DestFileStream.Write(fbuf, 0, xread);
                                    }
                                    break;
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            if (!cooking_is_read)
                            {
                                if (info.DestFileStream != null)
                                {
                                    info.DestFileStream.Close();
                                }

                                try
                                {
                                    XLog.errorlog("Non-reading error; retries=" + info.Retries.ToString() +
                                                  ";puller machine=" + System.Net.Dns.GetHostName() +
                                                  ";pulling file=" + info.PullFile +
                                                  ";error=" + e.ToString());
                                }
                                catch
                                {
                                }

                                throw;
                            }

                            if (++info.Retries > ftretries)
                            {
                                if (info.DestFileStream != null)
                                {
                                    info.DestFileStream.Close();
                                }

                                //Report this host with corrupt file
                                int    del     = info.PullFile.IndexOf(@"\", 2);
                                string badhost = info.PullFile.Substring(2, del - 2);
                                RogueHosts.Add(jid, badhost);
                                lock (tattledhosts)
                                {
                                    tattledhosts[badhost] = 1;
                                }

                                try
                                {
                                    XLog.errorlog("Retries exceeded ftretries; retries=" + info.Retries.ToString() +
                                                  ";ftretries=" + ftretries.ToString() +
                                                  ";puller machine=" + System.Net.Dns.GetHostName() +
                                                  ";pulling file=" + info.PullFile +
                                                  ";tattled host=" + badhost);
                                }
                                catch
                                {
                                }

                                goto next_pullfile;
                            }

                            //Random swap with the rest of the list of pullfiles
                            int iswapwith = rnd.Next(i, infos.Count);
                            infos[i]         = infos[iswapwith];
                            infos[iswapwith] = info;
                            info             = infos[i];
                            continue;
                        }
                    }
next_pullfile:
                    int xxx = 10;
                }
            }
            catch (Exception ex)
            {
                exception = ex;
            }
        }