Exemple #1
0
 /// <exception cref="System.Exception"/>
 internal virtual void TestScanInfoObject(long blockId, FilePath blockFile, FilePath
                                          metaFile)
 {
     DirectoryScanner.ScanInfo scanInfo = new DirectoryScanner.ScanInfo(blockId, blockFile
                                                                        , metaFile, TestVolume);
     NUnit.Framework.Assert.AreEqual(blockId, scanInfo.GetBlockId());
     if (blockFile != null)
     {
         NUnit.Framework.Assert.AreEqual(blockFile.GetAbsolutePath(), scanInfo.GetBlockFile
                                             ().GetAbsolutePath());
     }
     else
     {
         NUnit.Framework.Assert.IsNull(scanInfo.GetBlockFile());
     }
     if (metaFile != null)
     {
         NUnit.Framework.Assert.AreEqual(metaFile.GetAbsolutePath(), scanInfo.GetMetaFile(
                                             ).GetAbsolutePath());
     }
     else
     {
         NUnit.Framework.Assert.IsNull(scanInfo.GetMetaFile());
     }
     NUnit.Framework.Assert.AreEqual(TestVolume, scanInfo.GetVolume());
 }
 //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);
 }
Exemple #3
0
 /// <exception cref="System.Exception"/>
 internal virtual void TestScanInfoObject(long blockId)
 {
     DirectoryScanner.ScanInfo scanInfo = new DirectoryScanner.ScanInfo(blockId, null,
                                                                        null, null);
     NUnit.Framework.Assert.AreEqual(blockId, scanInfo.GetBlockId());
     NUnit.Framework.Assert.IsNull(scanInfo.GetBlockFile());
     NUnit.Framework.Assert.IsNull(scanInfo.GetMetaFile());
 }
        /// <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());
                }
            }
        }