public static SortedBlockTableFile ( string baseName, int level, int version ) : string | ||
baseName | string | |
level | int | |
version | int | |
return | string |
public void NotifyPageReleased(PageRecord pageRec) { string path = null; path = Config.SortedBlockTableFile(BaseFileName, pageRec.Level, pageRec.Version); Helper.DeleteFile(path); }
public byte[] GetBlock(string baseName, int level, int version, int blockNum) { string blockKey = Config.SortedBlockTableFile(baseName, level, version) + ":" + blockNum.ToString(); byte[] block = null; _blockDataCache.TryGetValue(blockKey, out block); return(block); }
public SortedBlockTable(RazorCache cache, string baseFileName, int level, int version) { PerformanceCounters.SBTConstructed.Increment(); _baseFileName = baseFileName; _level = level; _version = version; _cache = cache; _path = Config.SortedBlockTableFile(baseFileName, level, version); ReadMetadata(); }
public SortedBlockTableWriter(string baseFileName, int level, int version) { string fileName = Config.SortedBlockTableFile(baseFileName, level, version); _fileStream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None, Config.SortedBlockSize, Config.SortedBlockTableFileOptions); _bufferA = new byte[Config.SortedBlockSize]; _bufferB = new byte[Config.SortedBlockSize]; _buffer = _bufferA; _bufferPos = 0; _pageIndex = new List <Key>(); Version = version; WrittenSize = 0; }
// List all the pages in the directory and delete those that are not in the manifest. public void RemoveOrphanedPages() { using (var manifestInst = this.Manifest.GetLatestManifest()) { // find all the sbt files in the data directory var files = Directory.GetFiles(this.Manifest.BaseFileName, "*.sbt").ToDictionary(f => Path.GetFileNameWithoutExtension(f.ToLower())); for (int level = 0; level < manifestInst.NumLevels - 1; level++) { foreach (var page in manifestInst.GetPagesAtLevel(level)) { // Yes this is kind of backwards to add the file path and then strip it off, but I want to make sure we are using the exact same logic // as that which creates the file names. string fileForPage = Path.GetFileNameWithoutExtension(Config.SortedBlockTableFile(this.Manifest.BaseFileName, page.Level, page.Version)); // Remove the page from the file list because it's in the manifest and we've accounted for it. files.Remove(fileForPage); } } // Loop over the leftover files and handle them foreach (var file in files.Keys) { try { var parts = file.Split('-'); int level = int.Parse(parts[0]); int version = int.Parse(parts[1]); // First let's check the version number, we don't want to remove any new files that are being created while this is happening if (level < manifestInst.NumLevels && version < manifestInst.CurrentVersion(level)) { string orphanedFile = Config.SortedBlockTableFile(Manifest.BaseFileName, level, version); // Delete the file. Helper.DeleteFile(orphanedFile, true, (msg) => { Manifest.LogMessage(msg); }); Manifest.LogMessage("Removing Orphaned Pages '{0}'", orphanedFile); } } catch { // Best effort, here. If we fail, continue. } } } // Now process the indexes as well Manifest.LogMessage("Removing Orphaned Index Pages"); lock (_secondaryIndexes) { foreach (var idx in _secondaryIndexes) { idx.Value.RemoveOrphanedPages(); } } }
public void SetBlock(string baseName, int level, int version, int blockNum, byte[] block) { try { string blockKey = Config.SortedBlockTableFile(baseName, level, version) + ":" + blockNum.ToString(); _blockDataCache.Set(blockKey, block); } catch (Exception ex) { if (Config.ExceptionHandling == ExceptionHandling.ThrowAll) { throw; } if (Config.Logger != null) { Config.Logger(string.Format("RazorCache.SetBlock Failed: {0}\nException: {1}", baseName, ex.Message)); } } }
public Key[] GetBlockTableIndex(string baseName, int level, int version) { string fileName = Config.SortedBlockTableFile(baseName, level, version); Key[] index; if (_blockIndexCache.TryGetValue(fileName, out index)) { return(index); } PerformanceCounters.SBTGetBlockTableIndex.Increment(); var sbt = new SortedBlockTable(null, baseName, level, version); try { index = sbt.GetIndex(); _blockIndexCache.Set(fileName, index); return(index); } finally { sbt.Close(); } }