public FindKeyResult FindKey(byte[] keyBuf, int keyOfs, int keyLen, FindKeyStrategy strategy) { lock (_log) { _log.WriteUInt8((byte)KVReplayOperation.FindKey); _log.WriteVUInt32(TrIndex); _log.WriteVInt32(keyLen); _log.WriteVInt32(keyOfs); _log.WriteBlock(keyBuf, keyOfs, keyLen); _log.WriteVUInt32((uint)strategy); _log.FlushBuffer(); } return(_tr.FindKey(keyBuf, keyOfs, keyLen, strategy)); }
public static bool CreateKey(this IKeyValueDBTransaction transaction, byte[] keyBuf) { return(transaction.FindKey(keyBuf, 0, keyBuf.Length, FindKeyStrategy.Create) == FindKeyResult.Created); }
public IEnumerable <object> Enumerate(Type type) { if (type == typeof(object)) { type = null; } else if (type != null) { AutoRegisterType(type); } var taken = false; ulong oid = 0; ulong finalOid = _owner.GetLastAllocatedOid(); long prevProtectionCounter = 0; try { while (true) { if (!taken) { _keyValueTrProtector.Start(ref taken); } if (oid == 0) { prevProtectionCounter = _keyValueTrProtector.ProtectionCounter; _keyValueTr.SetKeyPrefix(ObjectDB.AllObjectsPrefix); if (!_keyValueTr.FindFirstKey()) { break; } } else { if (_keyValueTrProtector.WasInterupted(prevProtectionCounter)) { _keyValueTr.SetKeyPrefix(ObjectDB.AllObjectsPrefix); oid++; byte[] key = BuildKeyFromOid(oid); if (_keyValueTr.FindKey(key, 0, key.Length, FindKeyStrategy.OnlyNext) == FindKeyResult.NotFound) { oid--; break; } } else { if (!_keyValueTr.FindNextKey()) { break; } } } oid = ReadOidFromCurrentKeyInTransaction(); WeakReference weakObj; if (_objCache.TryGetValue(oid, out weakObj)) { var o = weakObj.Target; if (o != null) { if (type == null || type.IsAssignableFrom(o.GetType())) { _keyValueTrProtector.Stop(ref taken); yield return(o); continue; } continue; } } TableInfo tableInfo; KeyValueDBValueReader reader = ReadObjStart(oid, out tableInfo); if (type != null && !type.IsAssignableFrom(tableInfo.ClientType)) { continue; } object obj = ReadObjFinish(oid, tableInfo, reader); _keyValueTrProtector.Stop(ref taken); yield return(obj); } } finally { if (taken) { _keyValueTrProtector.Stop(); } } var dirtyObjsToEnum = _dirtyObjSet.Where(p => p.Key > oid && p.Key <= finalOid).ToList(); dirtyObjsToEnum.Sort((p1, p2) => { if (p1.Key < p2.Key) { return(-1); } if (p1.Key > p2.Key) { return(1); } return(0); }); foreach (var dObjPair in dirtyObjsToEnum) { object obj = dObjPair.Value; if (type != null && !type.IsAssignableFrom(obj.GetType())) { continue; } yield return(obj); } }
public static bool FindExactKey(this IKeyValueDBTransaction transaction, byte[] keyBuf) { return(transaction.FindKey(keyBuf, 0, keyBuf.Length, FindKeyStrategy.ExactMatch) == FindKeyResult.FoundExact); }