Exemplo n.º 1
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);
     }
 }
Exemplo n.º 2
0
 void StartNewValueFile()
 {
     lock (_startNewValueFileLocker)
     {
         QuickFinishCompaction();
         var fileInfo = new FilePureValues(AllocNewFileGeneration());
         if (_cacheValueWriter != null)
         {
             lock (_cacheValueWriter)
             {
                 _cacheValueFile.HardFlush();
                 SetNewValueFile();
             }
         }
         else
         {
             SetNewValueFile();
         }
         fileInfo.WriteHeader(_cacheValueWriter);
         _fileInfos.TryAdd(_cacheValueFileId, fileInfo);
         _compactionCts = new CancellationTokenSource();
         _compactionTask = Task.Factory.StartNew(CompactionCore, _compactionCts.Token,
                                                 TaskCreationOptions.LongRunning, TaskScheduler.Default);
     }
 }