Inheritance: IFileInfo, IHashKeyIndex
コード例 #1
0
        void StartNewHashIndexFile()
        {
            _hashIndexFile   = _fileCollection.AddFile("hid");
            _hashIndexWriter = _hashIndexFile.GetAppenderWriter();
            var fileInfo = new HashKeyIndex(_subDBId, _fileCollection.NextGeneration(), _fileCollection.Guid, (uint)_keyLen);

            fileInfo.WriteHeader(_hashIndexWriter);
            _fileCollection.SetInfo(_hashIndexFile.Index, fileInfo);
        }
コード例 #2
0
 void LoadInfoAboutFiles()
 {
     foreach (var file in _fileCollection.Enumerate())
     {
         try
         {
             var reader = file.GetExclusiveReader();
             if (reader.CheckMagic(MagicStartOfFile))
             {
                 var fileType = (KVFileType)reader.ReadUInt8();
                 IFileInfo fileInfo;
                 switch (fileType)
                 {
                     case KVFileType.TransactionLog:
                         fileInfo = new FileTransactionLog(reader);
                         break;
                     case KVFileType.KeyIndex:
                         fileInfo = new FileKeyIndex(reader);
                         break;
                     case KVFileType.PureValues:
                         fileInfo = new FilePureValues(reader);
                         break;
                     case KVFileType.PureValuesWithId:
                         fileInfo = new FilePureValuesWithId(reader);
                         break;
                     case KVFileType.HashKeyIndex:
                         fileInfo = new HashKeyIndex(reader);
                         break;
                     default:
                         fileInfo = UnknownFile.Instance;
                         break;
                 }
                 if (_fileGeneration < fileInfo.Generation) _fileGeneration = fileInfo.Generation;
                 _fileInfos.TryAdd(file.Index, fileInfo);
             }
             else
             {
                 _fileInfos.TryAdd(file.Index, UnknownFile.Instance);
             }
         }
         catch (Exception)
         {
             _fileInfos.TryAdd(file.Index, UnknownFile.Instance);
         }
     }
 }
コード例 #3
0
ファイル: ChunkStorageInKV.cs プロジェクト: jhy871167495/BTDB
        void LoadHashKeyIndex(uint hashKeyIndexFileId)
        {
            var reader = _fileCollection.GetFile(hashKeyIndexFileId).GetExclusiveReader();

            _keyLen = (int)((IHashKeyIndex)_fileCollection.FileInfoByIdx(hashKeyIndexFileId)).KeyLen;
            HashKeyIndex.SkipHeader(reader);
            var keyBuf = ByteBuffer.NewSync(new byte[_keyLen]);

            while (!reader.Eof)
            {
                var value = new StorageValue();
                value.FileId  = reader.ReadVUInt32();
                value.FileOfs = reader.ReadVUInt32();
                value.ContentLengthCompressedIsLeaf = reader.ReadVUInt32();
                reader.ReadBlock(keyBuf);
                _dict20.TryAdd(new ByteStructs.Key20(keyBuf), value);
            }
        }
コード例 #4
0
        void LoadInfoAboutFiles()
        {
            foreach (var file in _fileCollection.Enumerate())
            {
                try
                {
                    var  reader = file.GetExclusiveReader();
                    var  magic  = reader.ReadByteArrayRaw(MagicStartOfFile.Length);
                    Guid?guid   = null;
                    if (
                        BitArrayManipulation.CompareByteArray(magic, magic.Length, MagicStartOfFileWithGuid,
                                                              MagicStartOfFileWithGuid.Length) == 0)
                    {
                        guid = reader.ReadGuid();
                        if (Guid.HasValue && Guid.Value != guid)
                        {
                            _fileInfos.TryAdd(file.Index, UnknownFile.Instance);
                            continue;
                        }
                        Guid = guid;
                    }
                    else if (
                        BitArrayManipulation.CompareByteArray(magic, magic.Length, MagicStartOfFile,
                                                              MagicStartOfFile.Length) != 0)
                    {
                        _fileInfos.TryAdd(file.Index, UnknownFile.Instance);
                        continue;
                    }
                    var       fileType = (KVFileType)reader.ReadUInt8();
                    IFileInfo fileInfo;
                    switch (fileType)
                    {
                    case KVFileType.TransactionLog:
                        fileInfo = new FileTransactionLog(reader, guid);
                        break;

                    case KVFileType.KeyIndex:
                        fileInfo = new FileKeyIndex(reader, guid, false, false, false);
                        break;

                    case KVFileType.KeyIndexWithCommitUlong:
                        fileInfo = new FileKeyIndex(reader, guid, true, false, false);
                        break;

                    case KVFileType.ModernKeyIndex:
                        fileInfo = new FileKeyIndex(reader, guid, true, true, false);
                        break;

                    case KVFileType.ModernKeyIndexWithUlongs:
                        fileInfo = new FileKeyIndex(reader, guid, true, true, true);
                        break;

                    case KVFileType.PureValues:
                        fileInfo = new FilePureValues(reader, guid);
                        break;

                    case KVFileType.PureValuesWithId:
                        fileInfo = new FilePureValuesWithId(reader, guid);
                        break;

                    case KVFileType.HashKeyIndex:
                        fileInfo = new HashKeyIndex(reader, guid);
                        break;

                    default:
                        fileInfo = UnknownFile.Instance;
                        break;
                    }
                    if (_fileGeneration < fileInfo.Generation)
                    {
                        _fileGeneration = fileInfo.Generation;
                    }
                    _fileInfos.TryAdd(file.Index, fileInfo);
                }
                catch (Exception)
                {
                    _fileInfos.TryAdd(file.Index, UnknownFile.Instance);
                }
            }
            if (!Guid.HasValue)
            {
                Guid = System.Guid.NewGuid();
            }
        }
コード例 #5
0
 void LoadInfoAboutFiles()
 {
     foreach (var file in _fileCollection.Enumerate())
     {
         try
         {
             var reader = file.GetExclusiveReader();
             var magic = reader.ReadByteArrayRaw(MagicStartOfFile.Length);
             Guid? guid = null;
             if (
                 BitArrayManipulation.CompareByteArray(magic, magic.Length, MagicStartOfFileWithGuid,
                     MagicStartOfFileWithGuid.Length) == 0)
             {
                 guid = reader.ReadGuid();
                 if (Guid.HasValue && Guid.Value != guid)
                 {
                     _fileInfos.TryAdd(file.Index, UnknownFile.Instance);
                     continue;
                 }
                 Guid = guid;
             }
             else if (
                 BitArrayManipulation.CompareByteArray(magic, magic.Length, MagicStartOfFile,
                     MagicStartOfFile.Length) != 0)
             {
                 _fileInfos.TryAdd(file.Index, UnknownFile.Instance);
                 continue;
             }
             var fileType = (KVFileType)reader.ReadUInt8();
             IFileInfo fileInfo;
             switch (fileType)
             {
                 case KVFileType.TransactionLog:
                     fileInfo = new FileTransactionLog(reader, guid);
                     break;
                 case KVFileType.KeyIndex:
                     fileInfo = new FileKeyIndex(reader, guid, false);
                     break;
                 case KVFileType.KeyIndexWithCommitUlong:
                     fileInfo = new FileKeyIndex(reader, guid, true);
                     break;
                 case KVFileType.PureValues:
                     fileInfo = new FilePureValues(reader, guid);
                     break;
                 case KVFileType.PureValuesWithId:
                     fileInfo = new FilePureValuesWithId(reader, guid);
                     break;
                 case KVFileType.HashKeyIndex:
                     fileInfo = new HashKeyIndex(reader, guid);
                     break;
                 default:
                     fileInfo = UnknownFile.Instance;
                     break;
             }
             if (_fileGeneration < fileInfo.Generation) _fileGeneration = fileInfo.Generation;
             _fileInfos.TryAdd(file.Index, fileInfo);
         }
         catch (Exception)
         {
             _fileInfos.TryAdd(file.Index, UnknownFile.Instance);
         }
     }
     if (!Guid.HasValue)
     {
         Guid = System.Guid.NewGuid();
     }
 }
コード例 #6
0
ファイル: ChunkStorageInKV.cs プロジェクト: Xamarui/BTDB
 void StartNewHashIndexFile()
 {
     _hashIndexFile = _fileCollection.AddFile("hid");
     _hashIndexWriter = _hashIndexFile.GetAppenderWriter();
     var fileInfo = new HashKeyIndex(_subDBId, _fileCollection.NextGeneration(), (uint)_keyLen);
     fileInfo.WriteHeader(_hashIndexWriter);
     _fileCollection.SetInfo(_hashIndexFile.Index, fileInfo);
 }