Esempio n. 1
0
 //end for
 //end synchronized
 /// <summary>Block is found on the disk.</summary>
 /// <remarks>
 /// Block is found on the disk. In-memory block is missing or does not match
 /// the block on the disk
 /// </remarks>
 private void AddDifference(List <DirectoryScanner.ScanInfo> diffRecord, DirectoryScanner.Stats
                            statsRecord, DirectoryScanner.ScanInfo info)
 {
     statsRecord.missingMetaFile  += info.GetMetaFile() == null ? 1 : 0;
     statsRecord.missingBlockFile += info.GetBlockFile() == null ? 1 : 0;
     diffRecord.AddItem(info);
 }
Esempio n. 2
0
 /// <summary>Block is not found on the disk</summary>
 private void AddDifference(List <DirectoryScanner.ScanInfo> diffRecord, DirectoryScanner.Stats
                            statsRecord, long blockId, FsVolumeSpi vol)
 {
     statsRecord.missingBlockFile++;
     statsRecord.missingMetaFile++;
     diffRecord.AddItem(new DirectoryScanner.ScanInfo(blockId, null, null, vol));
 }
Esempio n. 3
0
        /// <exception cref="System.IO.IOException"/>
        private void Scan(long totalBlocks, int diffsize, long missingMetaFile, long missingBlockFile
                          , long missingMemoryBlocks, long mismatchBlocks, long duplicateBlocks)
        {
            scanner.Reconcile();
            NUnit.Framework.Assert.IsTrue(scanner.diffs.Contains(bpid));
            List <DirectoryScanner.ScanInfo> diff = scanner.diffs[bpid];

            NUnit.Framework.Assert.IsTrue(scanner.stats.Contains(bpid));
            DirectoryScanner.Stats stats = scanner.stats[bpid];
            NUnit.Framework.Assert.AreEqual(diffsize, diff.Count);
            NUnit.Framework.Assert.AreEqual(totalBlocks, stats.totalBlocks);
            NUnit.Framework.Assert.AreEqual(missingMetaFile, stats.missingMetaFile);
            NUnit.Framework.Assert.AreEqual(missingBlockFile, stats.missingBlockFile);
            NUnit.Framework.Assert.AreEqual(missingMemoryBlocks, stats.missingMemoryBlocks);
            NUnit.Framework.Assert.AreEqual(mismatchBlocks, stats.mismatchBlocks);
            NUnit.Framework.Assert.AreEqual(duplicateBlocks, stats.duplicateBlocks);
        }
Esempio n. 4
0
        /// <summary>
        /// Scan for the differences between disk and in-memory blocks
        /// Scan only the "finalized blocks" lists of both disk and memory.
        /// </summary>
        internal virtual void Scan()
        {
            Clear();
            IDictionary <string, DirectoryScanner.ScanInfo[]> diskReport = GetDiskReport();

            // Hold FSDataset lock to prevent further changes to the block map
            lock (dataset)
            {
                foreach (KeyValuePair <string, DirectoryScanner.ScanInfo[]> entry in diskReport)
                {
                    string bpid = entry.Key;
                    DirectoryScanner.ScanInfo[] blockpoolReport = entry.Value;
                    DirectoryScanner.Stats      statsRecord     = new DirectoryScanner.Stats(bpid);
                    stats[bpid] = statsRecord;
                    List <DirectoryScanner.ScanInfo> diffRecord = new List <DirectoryScanner.ScanInfo>(
                        );
                    diffs[bpid]             = diffRecord;
                    statsRecord.totalBlocks = blockpoolReport.Length;
                    IList <FinalizedReplica> bl        = dataset.GetFinalizedBlocks(bpid);
                    FinalizedReplica[]       memReport = Sharpen.Collections.ToArray(bl, new FinalizedReplica
                                                                                     [bl.Count]);
                    Arrays.Sort(memReport);
                    // Sort based on blockId
                    int d = 0;
                    // index for blockpoolReport
                    int m = 0;
                    // index for memReprot
                    while (m < memReport.Length && d < blockpoolReport.Length)
                    {
                        FinalizedReplica          memBlock = memReport[m];
                        DirectoryScanner.ScanInfo info     = blockpoolReport[d];
                        if (info.GetBlockId() < memBlock.GetBlockId())
                        {
                            if (!dataset.IsDeletingBlock(bpid, info.GetBlockId()))
                            {
                                // Block is missing in memory
                                statsRecord.missingMemoryBlocks++;
                                AddDifference(diffRecord, statsRecord, info);
                            }
                            d++;
                            continue;
                        }
                        if (info.GetBlockId() > memBlock.GetBlockId())
                        {
                            // Block is missing on the disk
                            AddDifference(diffRecord, statsRecord, memBlock.GetBlockId(), info.GetVolume());
                            m++;
                            continue;
                        }
                        // Block file and/or metadata file exists on the disk
                        // Block exists in memory
                        if (info.GetBlockFile() == null)
                        {
                            // Block metadata file exits and block file is missing
                            AddDifference(diffRecord, statsRecord, info);
                        }
                        else
                        {
                            if (info.GetGenStamp() != memBlock.GetGenerationStamp() || info.GetBlockFileLength
                                    () != memBlock.GetNumBytes())
                            {
                                // Block metadata file is missing or has wrong generation stamp,
                                // or block file length is different than expected
                                statsRecord.mismatchBlocks++;
                                AddDifference(diffRecord, statsRecord, info);
                            }
                            else
                            {
                                if (info.GetBlockFile().CompareTo(memBlock.GetBlockFile()) != 0)
                                {
                                    // volumeMap record and on-disk files don't match.
                                    statsRecord.duplicateBlocks++;
                                    AddDifference(diffRecord, statsRecord, info);
                                }
                            }
                        }
                        d++;
                        if (d < blockpoolReport.Length)
                        {
                            // There may be multiple on-disk records for the same block, don't increment
                            // the memory record pointer if so.
                            DirectoryScanner.ScanInfo nextInfo = blockpoolReport[Math.Min(d, blockpoolReport.
                                                                                          Length - 1)];
                            if (nextInfo.GetBlockId() != info.blockId)
                            {
                                ++m;
                            }
                        }
                        else
                        {
                            ++m;
                        }
                    }
                    while (m < memReport.Length)
                    {
                        FinalizedReplica current = memReport[m++];
                        AddDifference(diffRecord, statsRecord, current.GetBlockId(), current.GetVolume());
                    }
                    while (d < blockpoolReport.Length)
                    {
                        if (!dataset.IsDeletingBlock(bpid, blockpoolReport[d].GetBlockId()))
                        {
                            statsRecord.missingMemoryBlocks++;
                            AddDifference(diffRecord, statsRecord, blockpoolReport[d]);
                        }
                        d++;
                    }
                    Log.Info(statsRecord.ToString());
                }
            }
        }