Exemple #1
0
 internal virtual void ChangeLease(string src, string dst)
 {
     lock (this)
     {
         if (Log.IsDebugEnabled())
         {
             Log.Debug(GetType().Name + ".changelease: " + " src=" + src + ", dest=" + dst);
         }
         int len = src.Length;
         foreach (KeyValuePair <string, LeaseManager.Lease> entry in FindLeaseWithPrefixPath
                      (src, sortedLeasesByPath))
         {
             string             oldpath = entry.Key;
             LeaseManager.Lease lease   = entry.Value;
             // replace stem of src with new destination
             string newpath = dst + Sharpen.Runtime.Substring(oldpath, len);
             if (Log.IsDebugEnabled())
             {
                 Log.Debug("changeLease: replacing " + oldpath + " with " + newpath);
             }
             lease.ReplacePath(oldpath, newpath);
             Sharpen.Collections.Remove(sortedLeasesByPath, oldpath);
             sortedLeasesByPath[newpath] = lease;
         }
     }
 }
        /// <returns>
        /// the timestamp of the last renewal of the given lease,
        /// or -1 in the case that the lease doesn't exist.
        /// </returns>
        public static long GetLeaseRenewalTime(NameNode nn, string path)
        {
            LeaseManager lm = nn.GetNamesystem().leaseManager;

            LeaseManager.Lease l = lm.GetLeaseByPath(path);
            if (l == null)
            {
                return(-1);
            }
            return(l.GetLastUpdate());
        }
Exemple #3
0
 internal virtual void RenewLease(LeaseManager.Lease lease)
 {
     lock (this)
     {
         if (lease != null)
         {
             sortedLeases.Remove(lease);
             lease.Renew();
             sortedLeases.AddItem(lease);
         }
     }
 }
Exemple #4
0
 /// <summary>Reassign lease for file src to the new holder.</summary>
 internal virtual LeaseManager.Lease ReassignLease(LeaseManager.Lease lease, string
                                                   src, string newHolder)
 {
     lock (this)
     {
         System.Diagnostics.Debug.Assert(newHolder != null, "new lease holder is null");
         if (lease != null)
         {
             RemoveLease(lease, src);
         }
         return(AddLease(newHolder, src));
     }
 }
Exemple #5
0
        /// <exception cref="System.IO.IOException"/>
        private void TestPersistHelper(Configuration conf)
        {
            MiniDFSCluster cluster = null;

            try
            {
                cluster = new MiniDFSCluster.Builder(conf).Build();
                cluster.WaitActive();
                FSNamesystem          fsn = cluster.GetNamesystem();
                DistributedFileSystem fs  = cluster.GetFileSystem();
                Path dir   = new Path("/abc/def");
                Path file1 = new Path(dir, "f1");
                Path file2 = new Path(dir, "f2");
                // create an empty file f1
                fs.Create(file1).Close();
                // create an under-construction file f2
                FSDataOutputStream @out = fs.Create(file2);
                @out.WriteBytes("hello");
                ((DFSOutputStream)@out.GetWrappedStream()).Hsync(EnumSet.Of(HdfsDataOutputStream.SyncFlag
                                                                            .UpdateLength));
                // checkpoint
                fs.SetSafeMode(HdfsConstants.SafeModeAction.SafemodeEnter);
                fs.SaveNamespace();
                fs.SetSafeMode(HdfsConstants.SafeModeAction.SafemodeLeave);
                cluster.RestartNameNode();
                cluster.WaitActive();
                fs = cluster.GetFileSystem();
                NUnit.Framework.Assert.IsTrue(fs.IsDirectory(dir));
                NUnit.Framework.Assert.IsTrue(fs.Exists(file1));
                NUnit.Framework.Assert.IsTrue(fs.Exists(file2));
                // check internals of file2
                INodeFile file2Node = fsn.dir.GetINode4Write(file2.ToString()).AsFile();
                NUnit.Framework.Assert.AreEqual("hello".Length, file2Node.ComputeFileSize());
                NUnit.Framework.Assert.IsTrue(file2Node.IsUnderConstruction());
                BlockInfoContiguous[] blks = file2Node.GetBlocks();
                NUnit.Framework.Assert.AreEqual(1, blks.Length);
                NUnit.Framework.Assert.AreEqual(HdfsServerConstants.BlockUCState.UnderConstruction
                                                , blks[0].GetBlockUCState());
                // check lease manager
                LeaseManager.Lease lease = fsn.leaseManager.GetLeaseByPath(file2.ToString());
                NUnit.Framework.Assert.IsNotNull(lease);
            }
            finally
            {
                if (cluster != null)
                {
                    cluster.Shutdown();
                }
            }
        }
Exemple #6
0
 /// <summary>Remove the lease for the specified holder and src</summary>
 internal virtual void RemoveLease(string holder, string src)
 {
     lock (this)
     {
         LeaseManager.Lease lease = GetLease(holder);
         if (lease != null)
         {
             RemoveLease(lease, src);
         }
         else
         {
             Log.Warn("Removing non-existent lease! holder=" + holder + " src=" + src);
         }
     }
 }
Exemple #7
0
 /// <summary>Adds (or re-adds) the lease for the specified file.</summary>
 internal virtual LeaseManager.Lease AddLease(string holder, string src)
 {
     lock (this)
     {
         LeaseManager.Lease lease = GetLease(holder);
         if (lease == null)
         {
             lease          = new LeaseManager.Lease(this, holder);
             leases[holder] = lease;
             sortedLeases.AddItem(lease);
         }
         else
         {
             RenewLease(lease);
         }
         sortedLeasesByPath[src] = lease;
         lease.paths.AddItem(src);
         return(lease);
     }
 }
Exemple #8
0
 /// <summary>Remove the specified lease and src.</summary>
 internal virtual void RemoveLease(LeaseManager.Lease lease, string src)
 {
     lock (this)
     {
         Sharpen.Collections.Remove(sortedLeasesByPath, src);
         if (!lease.RemovePath(src))
         {
             if (Log.IsDebugEnabled())
             {
                 Log.Debug(src + " not found in lease.paths (=" + lease.paths + ")");
             }
         }
         if (!lease.HasPath())
         {
             Sharpen.Collections.Remove(leases, lease.holder);
             if (!sortedLeases.Remove(lease))
             {
                 Log.Error(lease + " not found in sortedLeases");
             }
         }
     }
 }
 public static string GetLeaseHolderForPath(NameNode namenode, string path)
 {
     LeaseManager.Lease l = namenode.GetNamesystem().leaseManager.GetLeaseByPath(path);
     return(l == null ? null : l.GetHolder());
 }
Exemple #10
0
 internal virtual bool CheckLeases()
 {
     lock (this)
     {
         bool needSync = false;
         System.Diagnostics.Debug.Assert(fsnamesystem.HasWriteLock());
         LeaseManager.Lease leaseToCheck = null;
         try
         {
             leaseToCheck = sortedLeases.First();
         }
         catch (NoSuchElementException)
         {
         }
         while (leaseToCheck != null)
         {
             if (!leaseToCheck.ExpiredHardLimit())
             {
                 break;
             }
             Log.Info(leaseToCheck + " has expired hard limit");
             IList <string> removing = new AList <string>();
             // need to create a copy of the oldest lease paths, because
             // internalReleaseLease() removes paths corresponding to empty files,
             // i.e. it needs to modify the collection being iterated over
             // causing ConcurrentModificationException
             string[] leasePaths = new string[leaseToCheck.GetPaths().Count];
             Sharpen.Collections.ToArray(leaseToCheck.GetPaths(), leasePaths);
             foreach (string p in leasePaths)
             {
                 try
                 {
                     INodesInPath iip       = fsnamesystem.GetFSDirectory().GetINodesInPath(p, true);
                     bool         completed = fsnamesystem.InternalReleaseLease(leaseToCheck, p, iip, HdfsServerConstants
                                                                                .NamenodeLeaseHolder);
                     if (Log.IsDebugEnabled())
                     {
                         if (completed)
                         {
                             Log.Debug("Lease recovery for " + p + " is complete. File closed.");
                         }
                         else
                         {
                             Log.Debug("Started block recovery " + p + " lease " + leaseToCheck);
                         }
                     }
                     // If a lease recovery happened, we need to sync later.
                     if (!needSync && !completed)
                     {
                         needSync = true;
                     }
                 }
                 catch (IOException e)
                 {
                     Log.Error("Cannot release the path " + p + " in the lease " + leaseToCheck, e);
                     removing.AddItem(p);
                 }
             }
             foreach (string p_1 in removing)
             {
                 RemoveLease(leaseToCheck, p_1);
             }
             leaseToCheck = sortedLeases.Higher(leaseToCheck);
         }
         try
         {
             if (leaseToCheck != sortedLeases.First())
             {
                 Log.Warn("Unable to release hard-limit expired lease: " + sortedLeases.First());
             }
         }
         catch (NoSuchElementException)
         {
         }
         return(needSync);
     }
 }