Esempio n. 1
0
        public ScratchBufferPoolInfo InfoForDebug(long oldestActiveTransaction)
        {
            var currentFile           = _current.File;
            var scratchBufferPoolInfo = new ScratchBufferPoolInfo
            {
                OldestActiveTransaction     = oldestActiveTransaction,
                NumberOfScratchFiles        = _scratchBuffers.Count,
                CurrentFileNumber           = currentFile.Number,
                CurrentFileSizeInMB         = currentFile.Size / 1024L / 1024L,
                PerScratchFileSizeLimitInMB = _options.MaxScratchBufferSize / 1024L / 1024L,
                CurrentUtcTime = DateTime.UtcNow
            };

            foreach (var scratchBufferItem in _scratchBuffers.Values.OrderBy(x => x.Number))
            {
                var current          = _current;
                var scratchFileUsage = new ScratchFileUsage
                {
                    Name                = StorageEnvironmentOptions.ScratchBufferName(scratchBufferItem.File.Number),
                    SizeInKB            = scratchBufferItem.File.Size / 1024,
                    NumberOfAllocations = scratchBufferItem.File.NumberOfAllocations,
                    AllocatedPagesCount = scratchBufferItem.File.AllocatedPagesCount,
                    CanBeDeleted        = scratchBufferItem != current && scratchBufferItem.File.HasActivelyUsedBytes(oldestActiveTransaction) == false,
                    TxIdAfterWhichLatestFreePagesBecomeAvailable = scratchBufferItem.File.TxIdAfterWhichLatestFreePagesBecomeAvailable,
                    IsInRecycleArea = _recycleArea.Contains(scratchBufferItem),
                    NumberOfResets  = scratchBufferItem.File.DebugInfo.NumberOfResets,
                    LastResetTime   = scratchBufferItem.File.DebugInfo.LastResetTime,
                    LastFreeTime    = scratchBufferItem.File.DebugInfo.LastFreeTime
                };

                foreach (var freePage in scratchBufferItem.File.DebugInfo.GetMostAvailableFreePagesBySize())
                {
                    scratchFileUsage.MostAvailableFreePages.Add(new MostAvailableFreePagesBySize
                    {
                        Size = freePage.Key,
                        ValidAfterTransactionId = freePage.Value
                    });
                }

                foreach (var allocatedPage in scratchBufferItem.File.DebugInfo.GetFirst10AllocatedPages())
                {
                    scratchFileUsage.First10AllocatedPages.Add(new AllocatedPageInScratchBuffer()
                    {
                        NumberOfPages           = allocatedPage.NumberOfPages,
                        PositionInScratchBuffer = allocatedPage.PositionInScratchBuffer,
                        ScratchFileNumber       = allocatedPage.ScratchFileNumber,
                        ScratchPageNumber       = allocatedPage.ScratchPageNumber,
                        Size = allocatedPage.Size
                    });
                }

                scratchBufferPoolInfo.ScratchFilesUsage.Add(scratchFileUsage);
            }

            return(scratchBufferPoolInfo);
        }
Esempio n. 2
0
        public ScratchBufferPoolInfo InfoForDebug(long oldestActiveTransaction)
        {
            var currentFile           = _current.File;
            var scratchBufferPoolInfo = new ScratchBufferPoolInfo
            {
                OldestActiveTransaction     = oldestActiveTransaction,
                NumberOfScratchFiles        = _scratchBuffers.Count,
                CurrentFileNumber           = currentFile.Number,
                CurrentFileSizeInMB         = currentFile.Size / 1024L / 1024L,
                PerScratchFileSizeLimitInMB = _options.MaxScratchBufferSize / 1024L / 1024L
            };

            foreach (var scratchBufferItem in _scratchBuffers.Values.OrderBy(x => x.Number))
            {
                var current          = _current;
                var scratchFileUsage = new ScratchFileUsage
                {
                    Name                = StorageEnvironmentOptions.ScratchBufferName(scratchBufferItem.File.Number),
                    SizeInKB            = scratchBufferItem.File.Size / 1024,
                    NumberOfAllocations = scratchBufferItem.File.NumberOfAllocations,
                    AllocatedPagesCount = scratchBufferItem.File.AllocatedPagesCount,
                    CanBeDeleted        = scratchBufferItem != current && scratchBufferItem.File.HasActivelyUsedBytes(oldestActiveTransaction) == false,
                    TxIdAfterWhichLatestFreePagesBecomeAvailable = scratchBufferItem.File.TxIdAfterWhichLatestFreePagesBecomeAvailable
                };

                foreach (var freePage in scratchBufferItem.File.GetMostAvailableFreePagesBySize())
                {
                    scratchFileUsage.MostAvailableFreePages.Add(new MostAvailableFreePagesBySize
                    {
                        Size = freePage.Key,
                        ValidAfterTransactionId = freePage.Value
                    });
                }

                scratchBufferPoolInfo.ScratchFilesUsage.Add(scratchFileUsage);
            }

            return(scratchBufferPoolInfo);
        }