Example #1
0
 public virtual void MarkSuspectBlock(ExtendedBlock block)
 {
     lock (this)
     {
         if (stopping)
         {
             Log.Debug("{}: Not scheduling suspect block {} for " + "rescanning, because this volume scanner is stopping."
                       , this, block);
             return;
         }
         bool recent = recentSuspectBlocks.GetIfPresent(block);
         if (recent != null)
         {
             Log.Debug("{}: Not scheduling suspect block {} for " + "rescanning, because we rescanned it recently."
                       , this, block);
             return;
         }
         if (suspectBlocks.Contains(block))
         {
             Log.Debug("{}: suspect block {} is already queued for " + "rescanning.", this, block
                       );
             return;
         }
         suspectBlocks.AddItem(block);
         recentSuspectBlocks.Put(block, true);
         Log.Debug("{}: Scheduling suspect block {} for rescanning.", this, block);
         Sharpen.Runtime.Notify(this);
     }
 }
Example #2
0
        public static int[] Random(int min, int max, int count)
        {
            int[] result            = new int[Math.Min(count, max - min + 1)];
            int   index             = 0;
            LinkedHashSet <int> set = new LinkedHashSet <int>();

            for (int i = min; i <= max; i++)
            {
                set.AddItem(i);
            }
            while (index < result.Length)
            {
                int r = Random(0, set.Count - 1);
                if (r < set.Count)
                {
                    result[index] = GetInt(set, r);
                    set.Remove(result[index]);
                }
                else
                {
                    break;
                }
                index++;
            }
            return(result);
        }
Example #3
0
        /// <summary>given user name - get all the groups.</summary>
        /// <remarks>
        /// given user name - get all the groups.
        /// Needs to happen before creating the test users
        /// </remarks>
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.Exception"/>
        public virtual void TestGetServerSideGroups()
        {
            // get the user name
            SystemProcess  pp = Runtime.GetRuntime().Exec("whoami");
            BufferedReader br = new BufferedReader(new InputStreamReader(pp.GetInputStream())
                                                   );
            string userName = br.ReadLine().Trim();

            // If on windows domain, token format is DOMAIN\\user and we want to
            // extract only the user name
            if (Shell.Windows)
            {
                int sp = userName.LastIndexOf('\\');
                if (sp != -1)
                {
                    userName = Runtime.Substring(userName, sp + 1);
                }
                // user names are case insensitive on Windows. Make consistent
                userName = StringUtils.ToLowerCase(userName);
            }
            // get the groups
            pp = Runtime.GetRuntime().Exec(Shell.Windows ? Shell.Winutils + " groups -F" : "id -Gn"
                                           );
            br = new BufferedReader(new InputStreamReader(pp.GetInputStream()));
            string line = br.ReadLine();

            System.Console.Out.WriteLine(userName + ":" + line);
            ICollection <string> groups = new LinkedHashSet <string>();

            string[] tokens = line.Split(Shell.TokenSeparatorRegex);
            foreach (string s in tokens)
            {
                groups.AddItem(s);
            }
            UserGroupInformation login = UserGroupInformation.GetCurrentUser();
            string loginUserName       = login.GetShortUserName();

            if (Shell.Windows)
            {
                // user names are case insensitive on Windows. Make consistent
                loginUserName = StringUtils.ToLowerCase(loginUserName);
            }
            Assert.Equal(userName, loginUserName);
            string[] gi = login.GetGroupNames();
            Assert.Equal(groups.Count, gi.Length);
            for (int i = 0; i < gi.Length; i++)
            {
                Assert.True(groups.Contains(gi[i]));
            }
            UserGroupInformation fakeUser = UserGroupInformation.CreateRemoteUser("foo.bar");

            fakeUser.DoAs(new _PrivilegedExceptionAction_248(login, fakeUser));
        }
        public override ICollection <KeyValuePair <K, V> > EntrySet()
        {
            PruneDeadReferences();
            ICollection <KeyValuePair <K, V> > entries = new LinkedHashSet <KeyValuePair <K, V> >();

            foreach (KeyValuePair <K, WeakValueHashMap.WeakValue <V> > entry in references.EntrySet
                         ())
            {
                entries.AddItem(new AbstractMap.SimpleEntry <K, V>(entry.Key, GetReferenceValue(entry
                                                                                                .Value)));
            }
            return(entries);
        }
Example #5
0
        /// <exception cref="System.IO.IOException"/>
        private static INodeFile[] VerifySrcFiles(FSDirectory fsd, string[] srcs, INodesInPath
                                                  targetIIP, FSPermissionChecker pc)
        {
            // to make sure no two files are the same
            ICollection <INodeFile> si  = new LinkedHashSet <INodeFile>();
            INodeFile      targetINode  = targetIIP.GetLastINode().AsFile();
            INodeDirectory targetParent = targetINode.GetParent();

            // now check the srcs
            foreach (string src in srcs)
            {
                INodesInPath iip = fsd.GetINodesInPath4Write(src);
                // permission check for srcs
                if (pc != null)
                {
                    fsd.CheckPathAccess(pc, iip, FsAction.Read);
                    // read the file
                    fsd.CheckParentAccess(pc, iip, FsAction.Write);
                }
                // for delete
                INode     srcINode     = iip.GetLastINode();
                INodeFile srcINodeFile = INodeFile.ValueOf(srcINode, src);
                // make sure the src file and the target file are in the same dir
                if (srcINodeFile.GetParent() != targetParent)
                {
                    throw new HadoopIllegalArgumentException("Source file " + src + " is not in the same directory with the target "
                                                             + targetIIP.GetPath());
                }
                // make sure all the source files are not in snapshot
                if (srcINode.IsInLatestSnapshot(iip.GetLatestSnapshotId()))
                {
                    throw new SnapshotException("Concat: the source file " + src + " is in snapshot");
                }
                // check if the file has other references.
                if (srcINode.IsReference() && ((INodeReference.WithCount)srcINode.AsReference().GetReferredINode
                                                   ()).GetReferenceCount() > 1)
                {
                    throw new SnapshotException("Concat: the source file " + src + " is referred by some other reference in some snapshot."
                                                );
                }
                // source file cannot be the same with the target file
                if (srcINode == targetINode)
                {
                    throw new HadoopIllegalArgumentException("concat: the src file " + src + " is the same with the target file "
                                                             + targetIIP.GetPath());
                }
                // source file cannot be under construction or empty
                if (srcINodeFile.IsUnderConstruction() || srcINodeFile.NumBlocks() == 0)
                {
                    throw new HadoopIllegalArgumentException("concat: source file " + src + " is invalid or empty or underConstruction"
                                                             );
                }
                // source file's preferred block size cannot be greater than the target
                // file
                if (srcINodeFile.GetPreferredBlockSize() > targetINode.GetPreferredBlockSize())
                {
                    throw new HadoopIllegalArgumentException("concat: source file " + src + " has preferred block size "
                                                             + srcINodeFile.GetPreferredBlockSize() + " which is greater than the target file's preferred block size "
                                                             + targetINode.GetPreferredBlockSize());
                }
                si.AddItem(srcINodeFile);
            }
            // make sure no two files are the same
            if (si.Count < srcs.Length)
            {
                // it means at least two files are the same
                throw new HadoopIllegalArgumentException("concat: at least two of the source files are the same"
                                                         );
            }
            return(Sharpen.Collections.ToArray(si, new INodeFile[si.Count]));
        }