Exemple #1
0
        internal static void SkipHeader(ref SpanReader reader)
        {
            var magic    = reader.ReadByteArrayRaw(MagicStartOfFile.Length);
            var withGuid = BitArrayManipulation.CompareByteArray(magic, magic.Length,
                                                                 MagicStartOfFileWithGuid, MagicStartOfFileWithGuid.Length) == 0;

            if (withGuid)
            {
                reader.SkipGuid();
            }
        }
Exemple #2
0
        void LoadInfoAboutFiles()
        {
            foreach (var file in _fileCollection.Enumerate())
            {
                try
                {
                    var  readerController = file.GetExclusiveReader();
                    var  reader           = new SpanReader(readerController);
                    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(ref reader, guid);
                        break;

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

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

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

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

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

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

                    case KVFileType.HashKeyIndex:
                        fileInfo = new HashKeyIndex(ref 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();
            }
        }