Esempio n. 1
0
        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)

            if (_initialized)
                throw new IOException("TableIndex is already initialized.");
            
            _initialized = true;
            
            CreateIfDoesNotExist(_directory);

            try
            {
                _indexMap = IndexMap.FromFile(Path.Combine(_directory, IndexMapFilename), IsHashCollision, _maxTablesPerLevel);
                if (_indexMap.IsCorrupt(_directory))
                {
                    foreach (var ptable in _indexMap.InOrder())
                    {
                        ptable.MarkForDestruction();
                    }
                    foreach (var ptable in _indexMap.InOrder())
                    {
                        ptable.WaitForDestroy(5000);
                    }
                    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;
        }
Esempio n. 3
0
        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;
        }