Exemple #1
0
        private void ReceiveDelete(IKey key, IWriteConsistency consistency, object request)
        {
            var envelope = GetData(key.Id);

            if (envelope != null)
            {
                if (envelope.Data is DeletedData)
                {
                    Sender.Tell(new DataDeleted(key, request));
                }
                else
                {
                    SetData(key.Id, DeletedEnvelope);
                    var durable = IsDurable(key.Id);
                    if (IsLocalUpdate(consistency))
                    {
                        if (durable)
                        {
                            var reply = new StoreReply(
                                successMessage: new DeleteSuccess(key, request),
                                failureMessage: new StoreFailure(key, request),
                                replyTo: Sender);
                            _durableStore.Tell(new Store(key.Id, new DurableDataEnvelope(DeletedEnvelope), reply));
                        }
                        Sender.Tell(new DeleteSuccess(key, request));
                    }
                    else
                    {
                        var writeAggregator = Context.ActorOf(WriteAggregator.Props(key, DeletedEnvelope, consistency, null, _nodes, _unreachable, Sender, durable)
                                                              .WithDispatcher(Context.Props.Dispatcher));

                        if (durable)
                        {
                            var reply = new StoreReply(
                                successMessage: new DeleteSuccess(key, request),
                                failureMessage: new StoreFailure(key, request),
                                replyTo: writeAggregator);
                            _durableStore.Tell(new Store(key.Id, new DurableDataEnvelope(DeletedEnvelope), reply));
                        }
                    }
                }
            }
        }
Exemple #2
0
        private void ReceiveUpdate(IKey key, Func <IReplicatedData, IReplicatedData> modify, IWriteConsistency consistency, object request)
        {
            try
            {
                var             localValue = GetData(key.Id);
                IReplicatedData modifiedValue;
                if (localValue == null)
                {
                    modifiedValue = modify(null);
                }
                else if (localValue.Data is DeletedData)
                {
                    _log.Debug("Received update for deleted key {0}", key);
                    Sender.Tell(new DataDeleted(key, request));
                    return;
                }
                else
                {
                    var existing = localValue.Data;
                    modifiedValue = existing.Merge(modify(existing));
                }

                _log.Debug("Received Update for key {0}, old data {1}, new data {2}", key, localValue, modifiedValue);
                var envelope = new DataEnvelope(PruningCleanupTombstoned(modifiedValue));
                SetData(key.Id, envelope);
                var durable = IsDurable(key.Id);
                if (IsLocalUpdate(consistency))
                {
                    if (durable)
                    {
                        var reply = new StoreReply(
                            successMessage: new UpdateSuccess(key, request),
                            failureMessage: new StoreFailure(key, request),
                            replyTo: Sender);
                        _durableStore.Tell(new Store(key.Id, new DurableDataEnvelope(envelope), reply));
                    }
                    else
                    {
                        Sender.Tell(new UpdateSuccess(key, request));
                    }
                }
                else
                {
                    var writeAggregator = Context.ActorOf(WriteAggregator.Props(key, envelope, consistency, request, _nodes, _unreachable, Sender, durable).WithDispatcher(Context.Props.Dispatcher));

                    if (durable)
                    {
                        var reply = new StoreReply(
                            successMessage: new UpdateSuccess(key, request),
                            failureMessage: new StoreFailure(key, request),
                            replyTo: writeAggregator);
                        _durableStore.Tell(new Store(key.Id, new DurableDataEnvelope(envelope), reply));
                    }
                }
            }
            catch (Exception ex)
            {
                _log.Debug("Received update for key {0}, failed {1}", key, ex.Message);
                Sender.Tell(new ModifyFailure(key, "Update failed: " + ex.Message, ex, request));
            }
        }