Exemplo n.º 1
0
        object ReadObjFinish(ulong oid, TableInfo tableInfo, KeyValueDBValueReader reader)
        {
            var tableVersion = reader.ReadVUInt32();
            var obj          = tableInfo.GetLoader(tableVersion)(this, oid, reader);

            _objCache.TryAdd(oid, new WeakReference(obj));
            return(obj);
        }
Exemplo n.º 2
0
        void IterateOid(ulong oid)
        {
            if (!_visitedOids.Add(oid))
            {
                return;
            }
            _tr.TransactionProtector.Start();
            _trkv.SetKeyPrefix(ObjectDB.AllObjectsPrefix);
            if (_trkv.Find(Vuint2ByteBuffer(oid)) != FindResult.Exact)
            {
                return; // Object oid was deleted
            }
            _fastVisitor.MarkCurrentKeyAsUsed(_trkv);
            var reader  = new KeyValueDBValueReader(_trkv);
            var tableId = reader.ReadVUInt32();
            var version = reader.ReadVUInt32();

            MarkTableIdVersionFieldInfo(tableId, version);
            string tableName;

            if (_visitor != null && !_visitor.StartObject(oid, tableId, _tableId2Name.TryGetValue(tableId, out tableName) ? tableName : null,
                                                          version))
            {
                return;
            }
            var tvi           = GetTableVersionInfo(tableId, version);
            var knownInlineId = new HashSet <int>();

            for (var i = 0; i < tvi.FieldCount; i++)
            {
                var fi = tvi[i];
                if (_visitor == null || _visitor.StartField(fi.Name))
                {
                    IterateHandler(reader, fi.Handler, false, knownInlineId);
                    _visitor?.EndField();
                }
                else
                {
                    IterateHandler(reader, fi.Handler, true, knownInlineId);
                }
            }
            _visitor?.EndObject();
        }
Exemplo n.º 3
0
        internal static IEnumerable <KeyValuePair <uint, string> > LoadRelationNamesEnum(IKeyValueDBTransaction tr)
        {
            tr.SetKeyPrefixUnsafe(RelationNamesPrefix);
            var keyReader   = new KeyValueDBKeyReader(tr);
            var valueReader = new KeyValueDBValueReader(tr);

            while (tr.FindNextKey())
            {
                keyReader.Restart();
                valueReader.Restart();
                yield return(new KeyValuePair <uint, string>(valueReader.ReadVUInt32(), keyReader.ReadString()));
            }
        }
Exemplo n.º 4
0
        KeyValueDBValueReader ReadObjStart(ulong oid, out TableInfo tableInfo)
        {
            var reader  = new KeyValueDBValueReader(_keyValueTr);
            var tableId = reader.ReadVUInt32();

            tableInfo = _owner.TablesInfo.FindById(tableId);
            if (tableInfo == null)
            {
                throw new BTDBException(string.Format("Unknown TypeId {0} of Oid {1}", tableId, oid));
            }
            EnsureClientTypeNotNull(tableInfo);
            return(reader);
        }
Exemplo n.º 5
0
 public IEnumerable <UnseenKey> UnseenKeys()
 {
     using (var trkv = _keyValueDb.StartReadOnlyTransaction())
     {
         foreach (var prefix in SupportedKeySpaces())
         {
             trkv.SetKeyPrefixUnsafe(prefix);
             if (!trkv.FindFirstKey())
             {
                 continue;
             }
             var reader = new KeyValueDBValueReader(trkv);
             do
             {
                 reader.Restart();
                 yield return(new UnseenKey
                 {
                     Key = Merge(prefix, trkv.GetKeyAsByteArray()),
                     ValueSize = reader.ReadVUInt32()
                 });
             } while (trkv.FindNextKey());
         }
     }
 }
Exemplo n.º 6
0
        void IterateRelation(uint relationIndex, string name)
        {
            var relationVersions     = new Dictionary <uint, RelationVersionInfo>();
            var lastPersistedVersion = ReadRelationVersions(relationIndex, name, relationVersions);

            _tr.TransactionProtector.Start();

            var o      = ObjectDB.AllRelationsPKPrefix.Length;
            var prefix = new byte[o + PackUnpack.LengthVUInt(relationIndex)];

            Array.Copy(ObjectDB.AllRelationsPKPrefix, prefix, o);
            PackUnpack.PackVUInt(prefix, ref o, relationIndex);

            var  protector             = _tr.TransactionProtector;
            long prevProtectionCounter = 0;
            long pos = 0;

            while (true)
            {
                protector.Start();
                if (pos == 0)
                {
                    _trkv.SetKeyPrefix(prefix);
                    if (!_trkv.FindFirstKey())
                    {
                        break;
                    }
                }
                else
                {
                    if (protector.WasInterupted(prevProtectionCounter))
                    {
                        _trkv.SetKeyPrefix(prefix);
                        if (!_trkv.SetKeyIndex(pos))
                        {
                            break;
                        }
                    }
                    else
                    {
                        if (!_trkv.FindNextKey())
                        {
                            break;
                        }
                    }
                }
                _fastVisitor.MarkCurrentKeyAsUsed(_trkv);
                prevProtectionCounter = protector.ProtectionCounter;
                if (_visitor == null || _visitor.StartRelationKey())
                {
                    var keyReader    = new KeyValueDBKeyReader(_trkv);
                    var relationInfo = relationVersions[lastPersistedVersion];
                    IterateFields(keyReader, relationInfo.GetPrimaryKeyFields(), null);
                    _visitor?.EndRelationKey();
                }
                if (protector.WasInterupted(prevProtectionCounter))
                {
                    _trkv.SetKeyPrefix(prefix);
                    if (!_trkv.SetKeyIndex(pos))
                    {
                        break;
                    }
                }
                if (_visitor == null || _visitor.StartRelationValue())
                {
                    var valueReader  = new KeyValueDBValueReader(_trkv);
                    var version      = valueReader.ReadVUInt32();
                    var relationInfo = relationVersions[version];
                    IterateFields(valueReader, relationInfo.GetValueFields(), new HashSet <int>());
                    _visitor?.EndRelationValue();
                }
                pos++;
            }
        }