예제 #1
0
        private void InitCompleted(bool verifyHash)
        {
            var fileInfo = new FileInfo(_filename);

            if (!fileInfo.Exists)
            {
                throw new CorruptDatabaseException(new ChunkNotFoundException(_filename));
            }

            _fileSize   = (int)fileInfo.Length;
            _isReadOnly = true;
            SetAttributes();
            CreateReaderStreams();

            var reader = GetReaderWorkItem();

            try
            {
                _chunkHeader = ReadHeader(reader.Stream);
                if (_chunkHeader.Version != CurrentChunkVersion)
                {
                    throw new CorruptDatabaseException(new WrongFileVersionException(_filename, _chunkHeader.Version, CurrentChunkVersion));
                }

                _chunkFooter = ReadFooter(reader.Stream);
                if (!_chunkFooter.IsCompleted)
                {
                    throw new CorruptDatabaseException(new BadChunkInDatabaseException(
                                                           string.Format("Chunk file '{0}' should be completed, but is not.", _filename)));
                }

                _logicalDataSize  = _chunkFooter.LogicalDataSize;
                _physicalDataSize = _chunkFooter.PhysicalDataSize;

                var expectedFileSize = _chunkFooter.PhysicalDataSize + _chunkFooter.MapSize + ChunkHeader.Size + ChunkFooter.Size;
                if (reader.Stream.Length != expectedFileSize)
                {
                    throw new CorruptDatabaseException(new BadChunkInDatabaseException(
                                                           string.Format("Chunk file '{0}' should have file size {1} bytes, but instead has {2} bytes length.",
                                                                         _filename,
                                                                         expectedFileSize,
                                                                         reader.Stream.Length)));
                }
            }
            finally
            {
                ReturnReaderWorkItem(reader);
            }

            _readSide = _chunkHeader.IsScavenged ? (IChunkReadSide) new TFChunkReadSideScavenged(this) : new TFChunkReadSideUnscavenged(this);
            _readSide.Cache();

            if (verifyHash)
            {
                VerifyFileHash();
            }
        }
예제 #2
0
        private void InitCompleted(bool verifyHash)
        {
            var fileInfo = new FileInfo(_filename);

            if (!fileInfo.Exists)
            {
                throw new CorruptDatabaseException(new ChunkNotFoundException(_filename));
            }

            _fileSize   = (int)fileInfo.Length;
            _isReadOnly = true;
            SetAttributes(_filename, true);
            CreateReaderStreams();

            var reader = GetReaderWorkItem();

            try
            {
                _chunkHeader = ReadHeader(reader.Stream);
                Log.Debug("Opened completed " + _filename + " as version " + _chunkHeader.Version);
                if (_chunkHeader.Version != (byte)ChunkVersions.Unaligned && _chunkHeader.Version != (byte)ChunkVersions.Aligned)
                {
                    throw new CorruptDatabaseException(new WrongFileVersionException(_filename, _chunkHeader.Version, CurrentChunkVersion));
                }

                if (_chunkHeader.Version != (byte)ChunkVersions.Aligned && _unbuffered)
                {
                    throw new Exception("You can only run unbuffered mode on v3 or higher chunk files. Please run scavenge on your database to upgrade your transaction file to v3.");
                }

                _chunkFooter = ReadFooter(reader.Stream);
                if (!_chunkFooter.IsCompleted)
                {
                    throw new CorruptDatabaseException(new BadChunkInDatabaseException(
                                                           string.Format("Chunk file '{0}' should be completed, but is not.", _filename)));
                }

                _logicalDataSize  = _chunkFooter.LogicalDataSize;
                _physicalDataSize = _chunkFooter.PhysicalDataSize;
                var expectedFileSize = _chunkFooter.PhysicalDataSize + _chunkFooter.MapSize + ChunkHeader.Size + ChunkFooter.Size;
                if (_chunkHeader.Version == (byte)ChunkVersions.Unaligned && reader.Stream.Length != expectedFileSize)
                {
                    throw new CorruptDatabaseException(new BadChunkInDatabaseException(
                                                           string.Format("Chunk file '{0}' should have a file size of {1} bytes, but it has a size of {2} bytes.",
                                                                         _filename,
                                                                         expectedFileSize,
                                                                         reader.Stream.Length)));
                }
            }
            finally
            {
                ReturnReaderWorkItem(reader);
            }

            _readSide = _chunkHeader.IsScavenged ? (IChunkReadSide) new TFChunkReadSideScavenged(this) : new TFChunkReadSideUnscavenged(this);
            _readSide.Cache();

            if (verifyHash)
            {
                VerifyFileHash();
            }
        }
예제 #3
0
        private void InitCompleted(bool verifyHash)
        {
            var fileInfo = new FileInfo(_filename);
            if (!fileInfo.Exists)
                throw new CorruptDatabaseException(new ChunkNotFoundException(_filename));

            _fileSize = (int)fileInfo.Length;
            _isReadOnly = true;
            SetAttributes();
            CreateReaderStreams();

            var reader = GetReaderWorkItem();
            try
            {
                _chunkHeader = ReadHeader(reader.Stream);
                if (_chunkHeader.Version != CurrentChunkVersion)
                    throw new CorruptDatabaseException(new WrongFileVersionException(_filename, _chunkHeader.Version, CurrentChunkVersion));

                _chunkFooter = ReadFooter(reader.Stream);
                if (!_chunkFooter.IsCompleted)
                {
                    throw new CorruptDatabaseException(new BadChunkInDatabaseException(
                        string.Format("Chunk file '{0}' should be completed, but is not.", _filename)));
                }

                _logicalDataSize = _chunkFooter.LogicalDataSize;
                _physicalDataSize = _chunkFooter.PhysicalDataSize;

                var expectedFileSize = _chunkFooter.PhysicalDataSize + _chunkFooter.MapSize + ChunkHeader.Size + ChunkFooter.Size;
                if (reader.Stream.Length != expectedFileSize)
                {
                    throw new CorruptDatabaseException(new BadChunkInDatabaseException(
                        string.Format("Chunk file '{0}' should have file size {1} bytes, but instead has {2} bytes length.",
                                      _filename,
                                      expectedFileSize,
                                      reader.Stream.Length)));
                }
            }
            finally
            {
                ReturnReaderWorkItem(reader);
            }

            _readSide = _chunkHeader.IsScavenged ? (IChunkReadSide) new TFChunkReadSideScavenged(this) : new TFChunkReadSideUnscavenged(this);
            _readSide.Cache();

            if (verifyHash)
                VerifyFileHash();
        }