Exemple #1
0
        internal ReadResult Read(RavenJToken key, Guid txId)
        {
            byte[] readData = null;

            Guid mofiedByTx;

            if (keysModifiedInTx.TryGetValue(key, out mofiedByTx) && mofiedByTx == txId)
            {
                Command command = operationsInTransactions.GetOrAdd(txId, new List <Command>()).LastOrDefault(
                    x => comparer.Equals(x.Key, key));

                if (command != null)
                {
                    switch (command.Type)
                    {
                    case CommandType.Put:
                        return(new ReadResult
                        {
                            Position = command.Position,
                            Size = command.Size,
                            Data = () => readData ?? (readData = ReadData(command)),
                            Key = command.Key
                        });

                    case CommandType.Delete:
                        return(null);

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
            }

            return(persistentSource.Read(log =>
            {
                PositionInFile pos;
                if (KeyToFilePos.TryGetValue(key, out pos) == false)
                {
                    return null;
                }

                return new ReadResult
                {
                    Position = pos.Position,
                    Size = pos.Size,
                    Data = () => readData ?? (readData = ReadData(pos.Position, pos.Size, pos.Key)),
                    Key = pos.Key
                };
            }));
        }
Exemple #2
0
        private void RemoveInternal(RavenJToken key)
        {
            PositionInFile removedValue;
            bool           removed;

            KeyToFilePos = KeyToFilePos.TryRemove(key, out removed, out removedValue);
            if (removed == false)
            {
                return;
            }
            WasteCount += 1;
            foreach (var index in SecondaryIndices)
            {
                index.Remove(removedValue.Key);
            }
        }
Exemple #3
0
 private void AddInteral(RavenJToken key, PositionInFile position)
 {
     KeyToFilePos = KeyToFilePos.AddOrUpdate(key, position, (token, oldPos) =>
     {
         WasteCount += 1;
         foreach (var index in SecondaryIndices)
         {
             index.Remove(oldPos.Key);
         }
         return(position);
     });
     foreach (var index in SecondaryIndices)
     {
         index.Add(key);
     }
 }
Exemple #4
0
        private void AddInteral(RavenJToken key, PositionInFile position)
        {
            var ravenJObject = key as RavenJObject;

            if (ravenJObject != null)
            {
                ravenJObject.EnsureSnapshot();
            }

            KeyToFilePos = KeyToFilePos.AddOrUpdate(key, position, (token, oldPos) =>
            {
                WasteCount += 1;
                foreach (var index in SecondaryIndices)
                {
                    index.Remove(oldPos.Key);
                }
                return(position);
            });
            foreach (var index in SecondaryIndices)
            {
                index.Add(key);
            }
        }