Ejemplo n.º 1
0
        private Receive WaitingForState(ImmutableHashSet <int> gotKeys) => message =>
        {
            void ReceiveOne(int i)
            {
                var newGotKeys = gotKeys.Add(i);

                if (newGotKeys.Count == NrOfKeys)
                {
                    RecoveryCompleted();
                }
                else
                {
                    Context.Become(WaitingForState(newGotKeys));
                }
            }

            switch (message)
            {
            case GetSuccess success:
                var i   = (int)success.Request;
                var key = _stateKeys[i];
                State = new Shard.ShardState(State.Entries.Union(success.Get(key).Elements));
                ReceiveOne(i);
                break;

            case GetFailure failure:
                Log.Error("The DDataShard was unable to get an initial state within 'waiting-for-state-timeout': {0}", Settings.TunningParameters.WaitingForStateTimeout);
                Context.Stop(Self);
                break;

            case NotFound notFound:
                ReceiveOne((int)notFound.Request);
                break;

            default: Stash.Stash(); break;
            }

            return(true);
        };
Ejemplo n.º 2
0
        protected override bool ReceiveRecover(object message)
        {
            switch (message)
            {
            case Shard.EntityStarted started:
                State = new Shard.ShardState(State.Entries.Add(started.EntityId));
                return(true);

            case Shard.EntityStopped stopped:
                State = new Shard.ShardState(State.Entries.Remove(stopped.EntityId));
                return(true);

            case SnapshotOffer offer when offer.Snapshot is Shard.ShardState:
                State = (Shard.ShardState)offer.Snapshot;
                return(true);

            case RecoveryCompleted _:
                RestartRememberedEntities();
                this.Initialized();
                Log.Debug("PersistentShard recovery completed shard [{0}] with [{1}] entities", ShardId, State.Entries.Count);
                return(true);
            }
            return(false);
        }