예제 #1
0
        static void _MemCacheRelease(dfs.DfsFile df, bool force)
        {
            dfs    dc        = LoadDfsConfig();
            string exception = "";

            string[] slaves = dc.Slaves.SlaveList.Split(';');
            {
                //foreach (string slave in slaves)
                MySpace.DataMining.Threading.ThreadTools <string> .Parallel(
                    new Action <string>(
                        delegate(string slave)
                {
                    System.Net.Sockets.NetworkStream nstm = Surrogate.ConnectService(slave);
                    nstm.WriteByte((byte)'C');
                    nstm.WriteByte((byte)'r');
                    XContent.SendXContent(nstm, df.Name);
                    XContent.SendXContent(nstm, new byte[1] {
                        (byte)(force ? 1 : 0)
                    });
                    int ich = nstm.ReadByte();
                    if ('+' != ich)
                    {
                        string errmsg = null;
                        if ('-' == ich)
                        {
                            try
                            {
                                errmsg = XContent.ReceiveXString(nstm, null);
                            }
                            catch
                            {
                            }
                        }
                        lock (slaves)
                        {
                            string newexception;
                            if (null != errmsg)
                            {
                                newexception = ("Error received from DO service during MemCache rollback from " + slave + ": " + errmsg);
                            }
                            else
                            {
                                newexception = ("Did not receive a success signal from DO service during MemCache rollback from " + slave);
                            }
                            if (string.IsNullOrEmpty(exception) ||
                                -1 != exception.IndexOf("MemCacheWarning"))
                            {
                                exception = newexception;
                            }
                        }
                    }
                }), slaves, slaves.Length);
            }
            if (!string.IsNullOrEmpty(exception))
            {
                throw new Exception(exception);
            }
        }
예제 #2
0
        static void _MemCacheLoad(dfs.DfsFile df)
        {
            dfs dc = LoadDfsConfig();

            string[] slaves = dc.Slaves.SlaveList.Split(';');
            {
                //foreach (string slave in slaves)
                MySpace.DataMining.Threading.ThreadTools <string> .Parallel(
                    new Action <string>(
                        delegate(string slave)
                {
                    System.Net.Sockets.NetworkStream nstm = Surrogate.ConnectService(slave);
                    nstm.WriteByte((byte)'C');
                    nstm.WriteByte((byte)'l');
                    XContent.SendXContent(nstm, df.Name);
                    int ich = nstm.ReadByte();
                    if ('+' != ich)
                    {
                        string errmsg = null;
                        if ('-' == ich)
                        {
                            try
                            {
                                errmsg = XContent.ReceiveXString(nstm, null);
                            }
                            catch
                            {
                            }
                        }
                        if (null != errmsg)
                        {
                            throw new Exception("Error received from DO service during MemCache load from " + slave + ": " + errmsg);
                        }
                        throw new Exception("Did not receive a success signal from DO service during MemCache load from " + slave);
                    }
                }), slaves, slaves.Length);
            }
        }
예제 #3
0
        public static void MemCacheFlush(string mcname)
        {
            if (mcname.StartsWith("dfs://", StringComparison.OrdinalIgnoreCase))
            {
                mcname = mcname.Substring(6);
            }
            dfs dc = LoadDfsConfig();

            dfs.DfsFile df = dc.FindAny(mcname);
            if (null == df || df.MemCache == null)
            {
                Console.Error.WriteLine("Error: '{0}' is not a MemCache", (null == df ? mcname : df.Name));
                SetFailure();
                return;
            }

            string tempdfsname = mcname + Guid.NewGuid() + dfs.TEMP_FILE_MARKER;

            string[] slaves      = dc.Slaves.SlaveList.Split(';');
            long     dfsfilesize = 0;
            {
                string tempfp = "bp-mcflush" + Guid.NewGuid() + ".tmp";
                try
                {
                    using (System.IO.StreamWriter sw = new System.IO.StreamWriter(tempfp))
                    {
                        //foreach (string slave in slaves)
                        MySpace.DataMining.Threading.ThreadTools <string> .Parallel(
                            new Action <string>(
                                delegate(string slave)
                        {
                            System.Net.Sockets.NetworkStream nstm = Surrogate.ConnectService(slave);
                            nstm.WriteByte((byte)'C');
                            nstm.WriteByte((byte)'f');
                            XContent.SendXContent(nstm, df.Name);
                            int ich = nstm.ReadByte();
                            if ('+' != ich)
                            {
                                string errmsg = null;
                                if ('-' == ich)
                                {
                                    try
                                    {
                                        errmsg = XContent.ReceiveXString(nstm, null);
                                    }
                                    catch
                                    {
                                    }
                                }
                                if (null != errmsg)
                                {
                                    throw new Exception("Error received from DO service during MemCache commit: " + errmsg);
                                }
                                throw new Exception("Did not receive a success signal from DO service during MemCache commit");
                            }
                            // flushinfos: chunk name, chunk size (without header)
                            string[] flushinfos = XContent.ReceiveXString(nstm, null).Split(
                                new char[] { '\r', '\n' },
                                StringSplitOptions.RemoveEmptyEntries);
                            foreach (string flushinfo in flushinfos)
                            {
                                lock (slaves)
                                {
                                    sw.WriteLine("{0} {1}", slave, flushinfo);
                                    dfsfilesize += int.Parse(flushinfo.Split(' ')[1]);
                                }
                            }
                        }), slaves, slaves.Length);
                    }
                    DfsBulkPut(new string[] { tempfp, tempdfsname, "rbin@" + df.RecordLength });
                }
                finally
                {
                    try
                    {
                        System.IO.File.Delete(tempfp);
                    }
                    catch
                    {
                    }
                }
            }

            Dictionary <string, bool> newchunknames = new Dictionary <string, bool>(StringComparer.OrdinalIgnoreCase);

            using (LockDfsMutex())
            {
                dc = LoadDfsConfig();
                dfs.DfsFile df2 = dc.FindAny(tempdfsname);
                if (null == df2)
                {
                    throw new Exception("DEBUG:  Temp DFS file not found: " + tempdfsname);
                }
                for (int i = 0; i < dc.Files.Count; i++)
                {
                    if (0 == string.Compare(dc.Files[i].Name, mcname, true))
                    {
                        dc.Files.RemoveAt(i);
                        break;
                    }
                }
                foreach (dfs.DfsFile.FileNode fn in df2.Nodes)
                {
                    newchunknames[fn.Name] = true;
                }
                df2.MemCache = df.MemCache;
                df2.Size     = dfsfilesize;
                df2.Name     = df.Name;
                UpdateDfsXml(dc);
            }

            {
                // Just kill the old chunks, not the MemCache stuff.
                List <string> delfnodes = new List <string>();
                {
                    //Collect file node paths.
                    for (int dn = 0; dn < df.Nodes.Count; dn++)
                    {
                        if (newchunknames.ContainsKey(df.Nodes[dn].Name))
                        {
                            continue;
                        }
                        foreach (string chost in df.Nodes[dn].Host.Split(';'))
                        {
                            delfnodes.Add(NetworkPathForHost(chost) + @"\" + df.Nodes[dn].Name);
                        }
                    }
                }
                _KillDataFileChunksInternal_unlocked_mt(delfnodes);
            }
        }