public static CreateEmpty ( int maxTablesPerLevel = 4 ) : |
||
maxTablesPerLevel | int | |
return |
public void Initialize(long chaserCheckpoint) { Ensure.Nonnegative(chaserCheckpoint, "chaserCheckpoint"); //NOT THREAD SAFE (assumes one thread) if (_initialized) { throw new IOException("TableIndex is already initialized."); } _initialized = true; if (_inMem) { _indexMap = IndexMap.CreateEmpty(_maxTablesPerLevel); _prepareCheckpoint = _indexMap.PrepareCheckpoint; _commitCheckpoint = _indexMap.CommitCheckpoint; return; } CreateIfDoesNotExist(_directory); var indexmapFile = Path.Combine(_directory, IndexMapFilename); // if TableIndex's CommitCheckpoint is >= amount of written TFChunk data, // we'll have to remove some of PTables as they point to non-existent data // this can happen (very unlikely, though) on master crash try { _indexMap = IndexMap.FromFile(indexmapFile, maxTablesPerLevel: _maxTablesPerLevel, cacheDepth: _indexCacheDepth); if (_indexMap.CommitCheckpoint >= chaserCheckpoint) { _indexMap.Dispose(TimeSpan.FromMilliseconds(5000)); throw new CorruptIndexException(String.Format("IndexMap's CommitCheckpoint ({0}) is greater than ChaserCheckpoint ({1}).", _indexMap.CommitCheckpoint, chaserCheckpoint)); } } catch (CorruptIndexException exc) { Log.ErrorException(exc, "ReadIndex is corrupted..."); LogIndexMapContent(indexmapFile); DumpAndCopyIndex(); File.Delete(indexmapFile); _indexMap = IndexMap.FromFile(indexmapFile, maxTablesPerLevel: _maxTablesPerLevel, cacheDepth: _indexCacheDepth); } _prepareCheckpoint = _indexMap.PrepareCheckpoint; _commitCheckpoint = _indexMap.CommitCheckpoint; // clean up all other remaining files var indexFiles = _indexMap.InOrder().Select(x => Path.GetFileName(x.Filename)) .Union(new[] { IndexMapFilename }); var toDeleteFiles = Directory.EnumerateFiles(_directory).Select(Path.GetFileName) .Except(indexFiles, StringComparer.OrdinalIgnoreCase); foreach (var filePath in toDeleteFiles) { var file = Path.Combine(_directory, filePath); File.SetAttributes(file, FileAttributes.Normal); File.Delete(file); } }