protected EventProcessedResult InternalCommittedEventProcessed( string partition, EventReaderSubscriptionMessage.CommittedEventReceived message, EmittedEventEnvelope[] emittedEvents, PartitionState newPartitionState) { if (!ValidateEmittedEvents(emittedEvents)) { return(null); } var oldState = _partitionStateCache.GetLockedPartitionState(partition); bool eventsWereEmitted = emittedEvents != null; bool changed = oldState.IsChanged(newPartitionState); PartitionState partitionState1 = null; // NOTE: projectionResult cannot change independently unless projection definition has changed if (changed) { var lockPartitionStateAt = partition != "" ? message.CheckpointTag : null; partitionState1 = newPartitionState; _partitionStateCache.CacheAndLockPartitionState(partition, partitionState1, lockPartitionStateAt); } if (changed || eventsWereEmitted) { var correlationId = message.Data.IsJson ? message.Data.Metadata.ParseCheckpointTagCorrelationId() : null; return(new EventProcessedResult( partition, message.CheckpointTag, oldState, partitionState1, emittedEvents, message.Data.EventId, correlationId)); } else { return(null); } }
public void Handle(CoreProjectionProcessingMessage.CheckpointLoaded message) { EnsureState(State.LoadStateRequested); try { var checkpointTag = message.CheckpointTag; var phase = checkpointTag == null ? 0 : checkpointTag.Phase; var projectionProcessingPhase = _projectionProcessingPhases[phase]; if (checkpointTag == null) checkpointTag = projectionProcessingPhase.MakeZeroCheckpointTag(); checkpointTag = projectionProcessingPhase.AdjustTag(checkpointTag); //TODO: initialize projection state here (test it) //TODO: write test to ensure projection state is correctly loaded from a checkpoint and posted back when enough empty records processed //TODO: handle errors _coreProjectionCheckpointWriter.StartFrom(checkpointTag, message.CheckpointEventNumber); PartitionState rootPartitionState = null; if (_requiresRootPartition) { rootPartitionState = PartitionState.Deserialize(message.CheckpointData, checkpointTag); _partitionStateCache.CacheAndLockPartitionState("", rootPartitionState, null); } BeginPhase(projectionProcessingPhase, checkpointTag, rootPartitionState); GoToState(State.StateLoaded); if (_startOnLoad) { if (_slaveProjections != null) _projectionProcessingPhase.AssignSlaves(_slaveProjections); _projectionProcessingPhase.Subscribe(checkpointTag, fromCheckpoint: true); } else GoToState(State.Stopped); } catch (Exception ex) { SetFaulted(ex); } }
public void setup() { //given _cache = new PartitionStateCache(); _cachedAtCheckpointTag1 = CheckpointTag.FromPosition(1000, 900); _cachedAtCheckpointTag2 = CheckpointTag.FromPosition(1200, 1100); _cachedAtCheckpointTag3 = CheckpointTag.FromPosition(1400, 1300); _cache.CacheAndLockPartitionState("partition1", "data1", _cachedAtCheckpointTag1); _cache.CacheAndLockPartitionState("partition2", "data2", _cachedAtCheckpointTag2); _cache.CacheAndLockPartitionState("partition3", "data3", _cachedAtCheckpointTag3); // when _cache.Unlock(_cachedAtCheckpointTag2); }
public void given() { //given _cache = new PartitionStateCache(CheckpointTag.FromPosition(0, -1)); _cachedAtCheckpointTag = CheckpointTag.FromPosition(1000, 900); _cache.CacheAndLockPartitionState("partition", new PartitionStateCache.State("data", _cachedAtCheckpointTag), _cachedAtCheckpointTag); }
public void setup() { //given _cache = new PartitionStateCache(); _cachedAtCheckpointTag1 = CheckpointTag.FromPosition(0, 1000, 900); _cachedAtCheckpointTag2 = CheckpointTag.FromPosition(0, 1200, 1100); _cachedAtCheckpointTag3 = CheckpointTag.FromPosition(0, 1400, 1300); _cache.CacheAndLockPartitionState( "partition1", new PartitionState("data1", null, _cachedAtCheckpointTag1), _cachedAtCheckpointTag1); _cache.CacheAndLockPartitionState( "partition2", new PartitionState("data2", null, _cachedAtCheckpointTag2), _cachedAtCheckpointTag2); _cache.CacheAndLockPartitionState( "partition3", new PartitionState("data3", null, _cachedAtCheckpointTag3), _cachedAtCheckpointTag3); // when _cache.Unlock(_cachedAtCheckpointTag2, forgetUnlocked: true); }
private void EnterInitial() { _handlerPartition = null; foreach (var requestId in _loadStateRequests) { _readDispatcher.Cancel(requestId); } _loadStateRequests.Clear(); _partitionStateCache.Initialize(); _processingQueue.Initialize(); _checkpointManager.Initialize(); _tickPending = false; _partitionStateCache.CacheAndLockPartitionState("", new PartitionStateCache.State("", null), null); _expectedSubscriptionMessageSequenceNumber = -1; // this is to be overridden when subscribing // NOTE: this is to workaround exception in GetState requests submitted by client }
public void given() { //given _cache = new PartitionStateCache(); _cachedAtCheckpointTag = CheckpointTag.FromPosition(1000, 900); _cache.CacheAndLockPartitionState("partition", new PartitionStateCache.State("data", _cachedAtCheckpointTag), _cachedAtCheckpointTag); _relockedData = _cache.TryGetAndLockPartitionState("partition", CheckpointTag.FromPosition(2000, 1900)); }
public void setup() { //given _cache = new PartitionStateCache(10); _cachedAtCheckpointTag1 = CheckpointTag.FromPosition(1000, 900); for (var i = 0; i < 15; i++) _cache.CacheAndLockPartitionState( "partition1", "data1", CheckpointTag.FromPosition(1000 + (i*100), 1000 + (i*100) - 50)); _cachedAtCheckpointTag2 = CheckpointTag.FromPosition(20100, 20050); _cachedAtCheckpointTag3 = CheckpointTag.FromPosition(20200, 20150); _cache.CacheAndLockPartitionState("partition1", "data1", _cachedAtCheckpointTag1); _cache.CacheAndLockPartitionState("partition2", "data2", _cachedAtCheckpointTag2); _cache.CacheAndLockPartitionState("partition3", "data3", _cachedAtCheckpointTag3); // when _cache.Unlock(_cachedAtCheckpointTag2); }
public void setup() { //given _cache = new PartitionStateCache(10); _cachedAtCheckpointTag1 = CheckpointTag.FromPosition(0, 1000, 900); for (var i = 0; i < 15; i++) { CheckpointTag at = CheckpointTag.FromPosition(0, 1000 + (i*100), 1000 + (i*100) - 50); _cache.CacheAndLockPartitionState("partition1", new PartitionState("data1", null, at), at); } _cachedAtCheckpointTag2 = CheckpointTag.FromPosition(0, 20100, 20050); _cachedAtCheckpointTag3 = CheckpointTag.FromPosition(0, 20200, 20150); _cache.CacheAndLockPartitionState( "partition1", new PartitionState("data1", null, _cachedAtCheckpointTag1), _cachedAtCheckpointTag1); _cache.CacheAndLockPartitionState( "partition2", new PartitionState("data2", null, _cachedAtCheckpointTag2), _cachedAtCheckpointTag2); _cache.CacheAndLockPartitionState( "partition3", new PartitionState("data3", null, _cachedAtCheckpointTag3), _cachedAtCheckpointTag3); _cache.Unlock(_cachedAtCheckpointTag2); // when _cache.Initialize(); }
public void when() { _cache = new PartitionStateCache(); _cachedAtCheckpointTag = CheckpointTag.FromPosition(0, 1000, 900); _cache.CacheAndLockPartitionState("partition", new PartitionState("data", null, _cachedAtCheckpointTag), _cachedAtCheckpointTag); }
private void EnterInitial() { _partitionStateCache.CacheAndLockPartitionState("", "", null); // NOTE: this is to workaround exception in GetState requests submitted by client }