Beispiel #1
0
        void StoreHashIndex()
        {
            RemoveAllHashIndexAndUnknownFiles();
            var file             = _fileCollection.AddFile("chi");
            var writerController = file.GetExclusiveAppenderWriter();
            var writer           = new SpanWriter(writerController);
            var keyCount         = _cache.Count;
            var fileInfo         = new FileHashIndex(AllocNewFileGeneration(), _keySize, keyCount);

            _fileInfos.TryAdd(file.Index, fileInfo);
            fileInfo.WriteHeader(ref writer);
            var keyBuf = ByteBuffer.NewSync(new byte[_keySize]);

            foreach (var cachePair in _cache)
            {
                cachePair.Key.FillBuffer(keyBuf);
                writer.WriteVUInt32(cachePair.Value.FileOfs);
                writer.WriteVUInt32(cachePair.Value.FileId);
                writer.WriteVUInt32(cachePair.Value.AccessRate);
                writer.WriteVUInt32(cachePair.Value.ContentLength);
                writer.WriteBlock(keyBuf);
            }
            writer.WriteVUInt32(0); // Zero FileOfs as End of file mark
            writer.Sync();
            file.HardFlushTruncateSwitchToDisposedMode();
        }
Beispiel #2
0
        void LoadContent()
        {
            SpanReader reader;

            foreach (var collectionFile in _fileCollection.Enumerate())
            {
                reader = new SpanReader(collectionFile.GetExclusiveReader());
                if (!reader.CheckMagic(MagicStartOfFile))
                {
                    continue;                                       // Don't touch files alien files
                }
                var fileType = (DiskChunkFileType)reader.ReadUInt8();
                var fileInfo = fileType switch
                {
                    DiskChunkFileType.HashIndex => new FileHashIndex(ref reader),
                    DiskChunkFileType.PureValues => new FilePureValues(ref reader),
                    _ => UnknownFile.Instance
                };
                if (_fileGeneration < fileInfo.Generation)
                {
                    _fileGeneration = fileInfo.Generation;
                }
                _fileInfos.TryAdd(collectionFile.Index, fileInfo);
            }
            var hashFilePair =
                _fileInfos.Where(f => f.Value.FileType == DiskChunkFileType.HashIndex).OrderByDescending(
                    f => f.Value.Generation).FirstOrDefault();

            if (hashFilePair.Value == null)
            {
                return;
            }
            reader = new SpanReader(_fileCollection.GetFile(hashFilePair.Key).GetExclusiveReader());
            FileHashIndex.SkipHeader(ref reader);
            if (((FileHashIndex)hashFilePair.Value).KeySize != _keySize)
            {
                return;
            }
            var keyBuf = ByteBuffer.NewSync(new byte[_keySize]);

            while (true)
            {
                var cacheValue = new CacheValue();
                cacheValue.FileOfs = reader.ReadVUInt32();
                if (cacheValue.FileOfs == 0)
                {
                    break;
                }
                cacheValue.FileId        = reader.ReadVUInt32();
                cacheValue.AccessRate    = reader.ReadVUInt32();
                cacheValue.ContentLength = reader.ReadVUInt32();
                reader.ReadBlock(keyBuf);
                _cache.TryAdd(new ByteStructs.Key20(keyBuf), cacheValue);
            }
        }
Beispiel #3
0
 void LoadContent()
 {
     AbstractBufferedReader reader;
     foreach (var collectionFile in _fileCollection.Enumerate())
     {
         reader = collectionFile.GetExclusiveReader();
         if (!reader.CheckMagic(MagicStartOfFile)) continue; // Don't touch files alien files
         var fileType = (DiskChunkFileType)reader.ReadUInt8();
         IFileInfo fileInfo;
         switch (fileType)
         {
             case DiskChunkFileType.HashIndex:
                 fileInfo = new FileHashIndex(reader);
                 break;
             case DiskChunkFileType.PureValues:
                 fileInfo = new FilePureValues(reader);
                 break;
             default:
                 fileInfo = UnknownFile.Instance;
                 break;
         }
         if (_fileGeneration < fileInfo.Generation) _fileGeneration = fileInfo.Generation;
         _fileInfos.TryAdd(collectionFile.Index, fileInfo);
     }
     var hashFilePair =
         _fileInfos.Where(f => f.Value.FileType == DiskChunkFileType.HashIndex).OrderByDescending(
             f => f.Value.Generation).FirstOrDefault();
     if (hashFilePair.Value == null) return;
     reader = _fileCollection.GetFile(hashFilePair.Key).GetExclusiveReader();
     FileHashIndex.SkipHeader(reader);
     if (((FileHashIndex)hashFilePair.Value).KeySize != _keySize) return;
     var keyBuf = ByteBuffer.NewSync(new byte[_keySize]);
     while (true)
     {
         var cacheValue = new CacheValue();
         cacheValue.FileOfs = reader.ReadVUInt32();
         if (cacheValue.FileOfs == 0) break;
         cacheValue.FileId = reader.ReadVUInt32();
         cacheValue.AccessRate = reader.ReadVUInt32();
         cacheValue.ContentLength = reader.ReadVUInt32();
         reader.ReadBlock(keyBuf);
         _cache.TryAdd(new ByteStructs.Key20(keyBuf), cacheValue);
     }
 }
Beispiel #4
0
 void StoreHashIndex()
 {
     RemoveAllHashIndexAndUnknownFiles();
     var file = _fileCollection.AddFile("chi");
     var writer = file.GetAppenderWriter();
     var keyCount = _cache.Count;
     var fileInfo = new FileHashIndex(AllocNewFileGeneration(), _keySize, keyCount);
     _fileInfos.TryAdd(file.Index, fileInfo);
     fileInfo.WriteHeader(writer);
     var keyBuf = ByteBuffer.NewSync(new byte[_keySize]);
     foreach (var cachePair in _cache)
     {
         cachePair.Key.FillBuffer(keyBuf);
         writer.WriteVUInt32(cachePair.Value.FileOfs);
         writer.WriteVUInt32(cachePair.Value.FileId);
         writer.WriteVUInt32(cachePair.Value.AccessRate);
         writer.WriteVUInt32(cachePair.Value.ContentLength);
         writer.WriteBlock(keyBuf);
     }
     writer.WriteVUInt32(0); // Zero FileOfs as End of file mark
     file.HardFlush();
 }