示例#1
0
            public static void DeleteFile(string dfsfile)
            {
                if (dfsfile.StartsWith("dfs://", StringComparison.OrdinalIgnoreCase))
                {
                    dfsfile = dfsfile.Substring(6);
                }
                ValidateDfsProtocolDfsFileName(dfsfile);
                FastXml fx;
                List<string> oldfilenodepaths;
                using (LockDfsMutex())
                {
                    fx = new FastXml(ReadDfs_unlocked(DfsDir + @"\dfs.xml"));
                    {
                        int filestart, fileend;
                        if (!DfsFindFile(fx, dfsfile, out filestart, out fileend))
                        {
                            throw new Exception("File not found in DFS: " + dfsfile);
                        }
                        oldfilenodepaths = GetFileNodePaths(fx, filestart, fileend);
                        fx.Replace(filestart, fileend, "");
                        {
                            string metabackupdir = null;
                            metabackupdir = fx.GetTagInnerText("MetaBackup");
                            if (null != metabackupdir && 0 == metabackupdir.Length)
                            {
                                metabackupdir = null;
                            }
                            WriteDfsXml_unlocked(fx.ToString(), DfsDir + @"\dfs.xml", metabackupdir);
                        }
                    }

                }
                MySpace.DataMining.Threading.ThreadTools<string>.Parallel(
                    new Action<string>(
                    delegate(string chunkpath)
                    {
                        try
                        {
                            System.IO.File.Delete(chunkpath);
                            System.IO.File.Delete(chunkpath + ".zsa");
                        }
                        catch
                        {
                        }
                    }), oldfilenodepaths);
            }
示例#2
0
            public static void SetFileContent(string dfsfile, string dfsfiletype, byte[] content, int contentlength)
            {
                if (dfsfile.StartsWith("dfs://", StringComparison.OrdinalIgnoreCase))
                {
                    dfsfile = dfsfile.Substring(6);
                }
                ValidateDfsProtocolDfsFileName(dfsfile);

                FastXml fx;
                using (LockDfsMutex())
                {
                    fx = new FastXml(ReadDfs_unlocked(DfsDir + @"\dfs.xml"));
                }

                string[] slaves = fx.GetTagInnerText("SlaveList").Split(';');
                int replfactor;
                if (!int.TryParse(fx.GetTagInnerText("Replication"), out replfactor))
                {
                    replfactor = 1;
                }
                string dfsfilexml = WriteDfsFileContent(dfsfile, dfsfiletype, content, contentlength, slaves, replfactor);
                List<string> oldfilenodepaths = null;
                using (LockDfsMutex())
                {
                    fx = new FastXml(ReadDfs_unlocked(DfsDir + @"\dfs.xml"));
                    int fstart, fend;
                    if (DfsFindFile(fx, dfsfile, out fstart, out fend))
                    {
                        oldfilenodepaths = GetFileNodePaths(fx, fstart, fend);
                        fx.Replace(fstart, fend, dfsfilexml);
                    }
                    else
                    {
                        if (fx.FindTag("Files", out fstart, out fend))
                        {
                            fx.AppendChild(fstart, fend, dfsfilexml);
                        }
                        else
                        {
                            if (fx.FindTag("dfs", out fstart, out fend))
                            {
                                fx.AppendChild(fstart, fend, "<Files>" + dfsfilexml + "</Files>");
                            }
                            else
                            {
                                throw new Exception("Corrupt DFS.XML: dfs root tag not found");
                            }
                        }
                    }
                    {
                        string metabackupdir = null;
                        metabackupdir = fx.GetTagInnerText("MetaBackup");
                        if (null != metabackupdir && 0 == metabackupdir.Length)
                        {
                            metabackupdir = null;
                        }
                        WriteDfsXml_unlocked(fx.ToString(), DfsDir + @"\dfs.xml", metabackupdir);
                    }
                }
                if (null != oldfilenodepaths)
                {
                    MySpace.DataMining.Threading.ThreadTools<string>.Parallel(
                        new Action<string>(
                        delegate(string chunkpath)
                        {
                           try
                           {
                               System.IO.File.Delete(chunkpath);
                               System.IO.File.Delete(chunkpath + ".zsa");
                           }
                           catch
                           {
                           }
                        }), oldfilenodepaths);
                }
            }