public static FromFile ( string filename, int maxTablesPerLevel = 4, bool loadPTables = true, int cacheDepth = 16 ) : |
||
filename | string | |
maxTablesPerLevel | int | |
loadPTables | bool | |
cacheDepth | int | |
return |
public void Initialize() { //NOT THREAD SAFE (assumes one thread) CreateIfDoesNotExist(_directory); try { _indexMap = IndexMap.FromFile(Path.Combine(_directory, IndexMapFilename), IsHashCollision, _maxTablesPerLevel); if (_indexMap.IsCorrupt(_directory)) { throw new CorruptIndexException("IndexMap is in unsafe state."); } } catch (CorruptIndexException exc) { Log.ErrorException(exc, "ReadIndex was corrupted. Rebuilding from scratch..."); foreach (var filePath in Directory.EnumerateFiles(_directory)) { File.Delete(filePath); } _indexMap = IndexMap.FromFile(Path.Combine(_directory, IndexMapFilename), IsHashCollision, _maxTablesPerLevel); } _prepareCheckpoint = _indexMap.PrepareCheckpoint; _commitCheckpoint = _indexMap.CommitCheckpoint; }
public void Initialize() { //NOT THREAD SAFE (assumes one thread) CreateIfDoesNotExist(_directory); _indexMap = IndexMap.FromFile(Path.Combine(_directory, IndexMapFilename), IsHashCollision, _maxTablesPerLevel); _prepareCheckpoint = _indexMap.PrepareCheckpoint; _commitCheckpoint.Write(_indexMap.CommitCheckpoint); }
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); } }
public void Initialize(long writerCheckpoint) { Ensure.Nonnegative(writerCheckpoint, "writerCheckpoint"); //NOT THREAD SAFE (assumes one thread) if (_initialized) { throw new IOException("TableIndex is already initialized."); } _initialized = true; CreateIfDoesNotExist(_directory); var indexmapFile = Path.Combine(_directory, IndexMapFilename); var backupFile = Path.Combine(_directory, IndexMapBackupFilename); // 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 { if (IsCorrupt(_directory)) { throw new CorruptIndexException("IndexMap is in unsafe state."); } _indexMap = IndexMap.FromFile(indexmapFile, IsHashCollision, _maxTablesPerLevel); if (_indexMap.CommitCheckpoint >= writerCheckpoint) { _indexMap.Dispose(TimeSpan.FromMilliseconds(5000)); throw new CorruptIndexException("IndexMap's CommitCheckpoint is greater than WriterCheckpoint."); } } catch (CorruptIndexException exc) { Log.ErrorException(exc, "ReadIndex is corrupted..."); LogIndexMapContent(indexmapFile); DumpAndCopyIndex(); File.Delete(indexmapFile); bool createEmptyIndexMap = true; if (File.Exists(backupFile)) { File.Copy(backupFile, indexmapFile); try { _indexMap = IndexMap.FromFile(indexmapFile, IsHashCollision, _maxTablesPerLevel); if (_indexMap.CommitCheckpoint >= writerCheckpoint) { _indexMap.Dispose(TimeSpan.FromMilliseconds(5000)); throw new CorruptIndexException("Back-up IndexMap's CommitCheckpoint is still greater than WriterCheckpoint."); } createEmptyIndexMap = false; Log.Info("Using back-up index map..."); } catch (CorruptIndexException ex) { Log.ErrorException(ex, "Backup IndexMap is also corrupted..."); LogIndexMapContent(backupFile); File.Delete(indexmapFile); File.Delete(backupFile); } } if (createEmptyIndexMap) { _indexMap = IndexMap.FromFile(indexmapFile, IsHashCollision, _maxTablesPerLevel); } if (IsCorrupt(_directory)) { LeaveUnsafeState(_directory); } } _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, IndexMapBackupFilename }); 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); } }