public void EnqueueTask(StagedTask workItem, CheckpointTag workItemCheckpointTag) { if (_queueState == QueueState.Stopped) throw new InvalidOperationException("Queue is Stopped"); ValidateQueueingOrder(workItemCheckpointTag); _queuePendingEvents.Enqueue(workItem); }
public SubscriptionStarted( Guid subscriptionId, CheckpointTag checkpointTag, long startingLastCommitPosition, long subscriptionMessageSequenceNumber, object source = null) : base(subscriptionId, checkpointTag, 0f, subscriptionMessageSequenceNumber, source) { _startingLastCommitPosition = startingLastCommitPosition; }
public CheckpointLoaded(Guid projectionId, CheckpointTag checkpointTag, string checkpointData) : base(projectionId) { if (checkpointTag == null) throw new ArgumentNullException("checkpointTag"); _checkpointTag = checkpointTag; _checkpointData = checkpointData; }
public void UpdateToZero() { var zero = new EventPosition(0, -1); if (_lastEventPosition != zero || _lastTag != null) throw new InvalidOperationException("Posistion tagger has be already updated"); _lastTag = _positionTagger.MakeZeroCheckpointTag(); }
public void UpdateByCheckpointTagForward(CheckpointTag newTag) { if (newTag <= _lastTag) throw new InvalidOperationException( string.Format("Event at checkpoint tag {0} has been already processed", newTag)); _lastTag = newTag; }
private void WriteResult( string partition, string resultBody, CheckpointTag causedBy, Guid causedByGuid, string correlationId) { var resultEvents = ResultUpdated(partition, resultBody, causedBy); if (resultEvents != null) _coreProjectionCheckpointManager.EventsEmitted(resultEvents, causedByGuid, correlationId); }
public ProjectionCheckpoint( RequestResponseDispatcher <ClientMessage.ReadStreamEventsBackward, ClientMessage.ReadStreamEventsBackwardCompleted> readDispatcher, RequestResponseDispatcher<ClientMessage.WriteEvents, ClientMessage.WriteEventsCompleted> writeDispatcher, ProjectionVersion projectionVersion, IPrincipal runAs, IProjectionCheckpointManager readyHandler, CheckpointTag from, PositionTagger positionTagger, CheckpointTag zero, int maxWriteBatchLength, ILogger logger = null) { if (readDispatcher == null) throw new ArgumentNullException("readDispatcher"); if (writeDispatcher == null) throw new ArgumentNullException("writeDispatcher"); if (readyHandler == null) throw new ArgumentNullException("readyHandler"); if (positionTagger == null) throw new ArgumentNullException("positionTagger"); if (zero == null) throw new ArgumentNullException("zero"); if (from.CommitPosition <= from.PreparePosition) throw new ArgumentException("from"); //NOTE: fromCommit can be equal fromPrepare on 0 position. Is it possible anytime later? Ignoring for now. _readDispatcher = readDispatcher; _writeDispatcher = writeDispatcher; _projectionVersion = projectionVersion; _runAs = runAs; _readyHandler = readyHandler; _positionTagger = positionTagger; _zero = zero; _from = _last = from; _maxWriteBatchLength = maxWriteBatchLength; _logger = logger; }
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 override CheckpointTag AdjustTag(CheckpointTag tag) { if (tag.Phase < Phase) return tag; if (tag.Phase > Phase) throw new ArgumentException( string.Format("Invalid checkpoint tag phase. Expected less or equal to: {0} Was: {1}", Phase, tag.Phase), "tag"); if (tag.Mode_ == CheckpointTag.Mode.Stream) { int p; return CheckpointTag.FromStreamPosition( tag.Phase, _stream, tag.Streams.TryGetValue(_stream, out p) ? p : -1); } switch (tag.Mode_) { case CheckpointTag.Mode.EventTypeIndex: throw new NotSupportedException( "Conversion from EventTypeIndex to Stream position tag is not supported"); case CheckpointTag.Mode.PreparePosition: throw new NotSupportedException( "Conversion from PreparePosition to Stream position tag is not supported"); case CheckpointTag.Mode.MultiStream: int p; return CheckpointTag.FromStreamPosition( tag.Phase, _stream, tag.Streams.TryGetValue(_stream, out p) ? p : -1); case CheckpointTag.Mode.Position: throw new NotSupportedException("Conversion from Position to Stream position tag is not supported"); default: throw new Exception(); } }
public override CheckpointTag AdjustTag(CheckpointTag tag) { if (tag.Phase < Phase) return tag; if (tag.Phase > Phase) throw new ArgumentException( string.Format("Invalid checkpoint tag phase. Expected less or equal to: {0} Was: {1}", Phase, tag.Phase), "tag"); if (tag.Mode_ == CheckpointTag.Mode.Position) return tag; switch (tag.Mode_) { case CheckpointTag.Mode.EventTypeIndex: return CheckpointTag.FromPosition( tag.Phase, tag.Position.CommitPosition, tag.Position.PreparePosition); case CheckpointTag.Mode.Stream: throw new NotSupportedException("Conversion from Stream to Position position tag is not supported"); case CheckpointTag.Mode.MultiStream: throw new NotSupportedException( "Conversion from MultiStream to Position position tag is not supported"); case CheckpointTag.Mode.PreparePosition: throw new NotSupportedException( "Conversion from PreparePosition to Position position tag is not supported"); default: throw new Exception(); } }
public bool ProcessEvent( string partition, CheckpointTag eventPosition, string category1, ResolvedEvent data, out string newState, out string newSharedState, out EmittedEventEnvelope[] emittedEvents) { newSharedState = null; emittedEvents = null; newState = null; if (data.PositionSequenceNumber != 0) return false; // not our event var category = _streamCategoryExtractor.GetCategoryByStreamId(data.PositionStreamId); if (category == null) return true; // handled but not interesting emittedEvents = new[] { new EmittedEventEnvelope( new EmittedDataEvent( "$category" + "-" + category, Guid.NewGuid(), SystemEventTypes.StreamReference, false, data.PositionStreamId, null, eventPosition, expectedTag: null)) }; return true; }
protected ReaderSubscriptionBase( IPublisher publisher, Guid subscriptionId, CheckpointTag @from, IReaderStrategy readerStrategy, ITimeProvider timeProvider, long? checkpointUnhandledBytesThreshold, int? checkpointProcessedEventsThreshold, bool stopOnEof, int? stopAfterNEvents) { if (publisher == null) throw new ArgumentNullException("publisher"); if (readerStrategy == null) throw new ArgumentNullException("readerStrategy"); if (timeProvider == null) throw new ArgumentNullException("timeProvider"); if (checkpointProcessedEventsThreshold > 0 && stopAfterNEvents > 0) throw new ArgumentException("checkpointProcessedEventsThreshold > 0 && stopAfterNEvents > 0"); _publisher = publisher; _readerStrategy = readerStrategy; _timeProvider = timeProvider; _checkpointUnhandledBytesThreshold = checkpointUnhandledBytesThreshold; _checkpointProcessedEventsThreshold = checkpointProcessedEventsThreshold; _stopOnEof = stopOnEof; _stopAfterNEvents = stopAfterNEvents; _subscriptionId = subscriptionId; _lastPassedOrCheckpointedEventPosition = null; _eventFilter = readerStrategy.EventFilter; _positionTagger = readerStrategy.PositionTagger; _positionTracker = new PositionTracker(_positionTagger); _positionTracker.UpdateByCheckpointTagInitial(@from); }
public override void Start(CheckpointTag checkpointTag) { base.Start(checkpointTag); _lastOrderCheckpointTag = checkpointTag; _orderStream = CreateOrderStream(); _orderStream.Start(); }
protected CoreProjectionCheckpointManager( IPublisher publisher, Guid projectionCorrelationId, ProjectionConfig projectionConfig, string name, PositionTagger positionTagger, ProjectionNamesBuilder namingBuilder, bool usePersistentCheckpoints, bool producesRunningResults) { if (publisher == null) throw new ArgumentNullException("publisher"); if (projectionConfig == null) throw new ArgumentNullException("projectionConfig"); if (name == null) throw new ArgumentNullException("name"); if (positionTagger == null) throw new ArgumentNullException("positionTagger"); if (namingBuilder == null) throw new ArgumentNullException("namingBuilder"); if (name == "") throw new ArgumentException("name"); _lastProcessedEventPosition = new PositionTracker(positionTagger); _zeroTag = positionTagger.MakeZeroCheckpointTag(); _publisher = publisher; _projectionCorrelationId = projectionCorrelationId; _projectionConfig = projectionConfig; _logger = LogManager.GetLoggerFor<CoreProjectionCheckpointManager>(); _namingBuilder = namingBuilder; _usePersistentCheckpoints = usePersistentCheckpoints; _producesRunningResults = producesRunningResults; _requestedCheckpointState = new PartitionState("", null, _zeroTag); _currentProjectionState = new PartitionState("", null, _zeroTag); }
private EmittedEventEnvelope[] CreateResultUpdatedEvents(string partition, string projectionResult, CheckpointTag at) { var streamId = _namesBuilder.MakePartitionResultStreamName(partition); var allResultsStreamId = _namesBuilder.GetResultStreamName(); if (string.IsNullOrEmpty(partition)) { var result = new EmittedEventEnvelope( projectionResult == null ? new EmittedDataEvent( streamId, Guid.NewGuid(), "ResultRemoved", true, null, null, at, null) : new EmittedDataEvent( streamId, Guid.NewGuid(), "Result", true, projectionResult, null, at, null), _resultStreamMetadata); return new[] {result}; } else { var linkTo = new EmittedLinkTo(allResultsStreamId, Guid.NewGuid(), streamId, at, null); var linkToEnvelope = new EmittedEventEnvelope(linkTo, _resultStreamMetadata); var result = new EmittedEventEnvelope( projectionResult == null ? new EmittedDataEvent( streamId, Guid.NewGuid(), "ResultRemoved", true, null, null, at, null, linkTo.SetTargetEventNumber) : new EmittedDataEvent( streamId, Guid.NewGuid(), "Result", true, projectionResult, null, at, null, linkTo.SetTargetEventNumber), _resultStreamMetadata); return new[] {result, linkToEnvelope}; } }
private void LoadCompleted(CheckpointTag checkpointTag, string state) { _envelope.ReplyWith( new CoreProjectionManagementMessage.StateReport( _correlationId, _projectionId, _partition, state)); NextStage(); }
protected DataReportBase(Guid correlationId, Guid projectionId, string partition, CheckpointTag position) : base(projectionId) { _correlationId = correlationId; _partition = partition; _position = position; }
public EmittedLinkTo( string streamId, Guid eventId, string targetStreamId, CheckpointTag causedByTag, CheckpointTag expectedTag, Action<int> onCommitted = null) : base(streamId, eventId, "$>", causedByTag, expectedTag, onCommitted) { _targetStreamId = targetStreamId; }
public void when() { _cache = new PartitionStateCache(CheckpointTag.FromPosition(0, -1)); _cachedAtCheckpointTag = CheckpointTag.FromPosition(1000, 900); _cache.CachePartitionState( "partition", new PartitionState("data", null, _cachedAtCheckpointTag)); }
public override void Initialize() { base.Initialize(); _lastOrderCheckpointTag = null; if (_orderStream != null) _orderStream.Dispose(); _orderStream = null; }
public EventDistributionPoint CreatePausedEventDistributionPoint(Guid distributionPointId, IPublisher publisher, CheckpointTag checkpointTag) { if (_allStreams) { var distributionPoint = new TransactionFileReaderEventDistributionPoint( publisher, distributionPointId, new EventPosition(checkpointTag.CommitPosition.Value, checkpointTag.PreparePosition.Value)); return distributionPoint; } else if (_streams != null && _streams.Count == 1) { var streamName = checkpointTag.Streams.Keys.First(); //TODO: handle if not the same return CreatePausedStreamReaderEventDistributionPoint(distributionPointId, publisher, checkpointTag, streamName, resolveLinkTos: true, category: null); } else if (_categories != null && _categories.Count == 1) { var streamName = checkpointTag.Streams.Keys.First(); return CreatePausedStreamReaderEventDistributionPoint(distributionPointId, publisher, checkpointTag, streamName, resolveLinkTos: true, category: _categories.First()); } else throw new NotSupportedException(); }
public bool ProcessEvent( string partition, CheckpointTag eventPosition, string category1, ResolvedEvent data, out string newState, out EmittedEventEnvelope[] emittedEvents) { emittedEvents = null; newState = null; if (data.PositionStreamId.StartsWith("$")) return false; var lastSlashPos = data.PositionStreamId.LastIndexOf(_separator); if (lastSlashPos < 0) return true; // handled but not interesting to us var category = data.PositionStreamId.Substring(0, lastSlashPos); string linkTarget; if (data.EventType == SystemEventTypes.LinkTo) linkTarget = data.Data; else linkTarget = data.EventSequenceNumber + "@" + data.EventStreamId; emittedEvents = new[] { new EmittedEventEnvelope( new EmittedLinkToWithRecategorization( _categoryStreamPrefix + category, Guid.NewGuid(), linkTarget, eventPosition, expectedTag: null, originalStreamId: data.PositionStreamId)) }; return true; }
public string GetStatePartition( CheckpointTag eventPosition, string streamId, string eventType, string category, Guid eventid, int sequenceNumber, string metadata, string data) { _logger("GetStatePartition(" + "..." + ")"); throw new NotImplementedException(); }
public override bool IsMessageAfterCheckpointTag( CheckpointTag previous, ReaderSubscriptionMessage.CommittedEventDistributed committedEvent) { if (previous.Mode_ != CheckpointTag.Mode.Position) throw new ArgumentException("Mode.Position expected", "previous"); return committedEvent.Data.Position > previous.Position; }
public override bool IsMessageAfterCheckpointTag( CheckpointTag previous, ReaderSubscriptionMessage.CommittedEventDistributed committedEvent) { if (previous.Phase < Phase) return true; return committedEvent.Data.Position.PreparePosition > previous.PreparePosition; }
public string GetStatePartition( CheckpointTag eventPosition, string streamId, string eventType, string category, Guid eventid, int sequenceNumber, string metadata, string data) { _logger("GetStatePartition(" + "..." + ")"); return streamId; }
public bool ProcessEvent( string partition, CheckpointTag eventPosition, string category1, ResolvedEvent data, out string newState, out string newSharedState, out EmittedEventEnvelope[] emittedEvents) { newSharedState = null; emittedEvents = null; newState = null; if (data.EventStreamId != data.PositionStreamId) return false; var indexedEventType = data.EventType; if (indexedEventType == "$>") return false; string positionStreamId; var isStreamDeletedEvent = StreamDeletedHelper.IsStreamDeletedEvent( data.PositionStreamId, data.EventType, data.Data, out positionStreamId); if (isStreamDeletedEvent) indexedEventType = "$deleted"; emittedEvents = new[] { new EmittedEventEnvelope( new EmittedDataEvent( _indexStreamPrefix + indexedEventType, Guid.NewGuid(), "$>", false, data.EventSequenceNumber + "@" + positionStreamId, isStreamDeletedEvent ? new ExtraMetaData(new Dictionary<string, JRaw> {{"$deleted", new JRaw(-1)}}) : null, eventPosition, expectedTag: null)) }; return true; }
public bool ProcessEvent( string partition, CheckpointTag eventPosition, string category, ResolvedEvent data, out string newState, out string newSharedState, out EmittedEventEnvelope[] emittedEvents) { newSharedState = null; if (!data.EventStreamId.StartsWith(UserStreamPrefix)) throw new InvalidOperationException( string.Format( "Invalid stream name: '{0}' The IndexUsersProjectionHandler cannot handle events from other streams than named after the '$user-' pattern", data.EventStreamId)); var loginName = data.EventStreamId.Substring(UserStreamPrefix.Length); var userData = data.Data.ParseJson<UserData>(); if (userData.LoginName != loginName) throw new InvalidOperationException( string.Format( "Invalid $UserCreated event found. '{0}' login name expected, but '{1}' found", loginName, userData.LoginName)); emittedEvents = new[] { new EmittedEventEnvelope( new EmittedDataEvent( UsersStream, Guid.NewGuid(), UserEventType, false, loginName, null, eventPosition, null)) }; newState = ""; return true; }
public bool ProcessEvent( string partition, CheckpointTag eventPosition, string category1, ResolvedEvent data, out string newState, out string newSharedState, out EmittedEventEnvelope[] emittedEvents) { newSharedState = null; emittedEvents = null; newState = null; var category = _streamCategoryExtractor.GetCategoryByStreamId(data.PositionStreamId); if (category == null) return true; // handled but not interesting string linkTarget; if (data.EventType == SystemEventTypes.LinkTo) linkTarget = data.Data; else linkTarget = data.EventSequenceNumber + "@" + data.EventStreamId; emittedEvents = new[] { new EmittedEventEnvelope( new EmittedLinkToWithRecategorization( _categoryStreamPrefix + category, Guid.NewGuid(), linkTarget, eventPosition, expectedTag: null, originalStreamId: data.PositionStreamId)) }; return true; }
public void WriteEofResult( Guid subscriptionId, string partition, string resultBody, CheckpointTag causedBy, Guid causedByGuid, string correlationId) { if (resultBody != null) WriteResult(partition, resultBody, causedBy, causedByGuid, correlationId); }
public void BeginLoadState() { _publisher.Publish( new CoreProjectionProcessingMessage.CheckpointLoaded( _projectionCorrelationId, CheckpointTag.FromPosition(0, 0, -1), "", 0)); }
public ProjectionState( string name, string partition, string state, CheckpointTag position, Exception exception = null) : base(name, partition, position, exception) { _state = state; }
public void partitions_locked_at_the_unlock_position_can_be_retrieved_and_relocked_at_later_position() { var data = _cache.TryGetAndLockPartitionState("partition2", CheckpointTag.FromPosition(25000, 24000)); Assert.AreEqual("data2", data.Data); }
the_first_partition_locked_before_the_unlock_position_cannot_be_retrieved_and_relocked_at_later_position() { var data = _cache.TryGetAndLockPartitionState("partition1", CheckpointTag.FromPosition(25000, 24000)); Assert.AreEqual("data1", data.Data); }
public ResultReport( Guid correlationId, Guid projectionId, string partition, string result, CheckpointTag position, Exception exception = null) : base(correlationId, projectionId, partition, position, exception) { _result = result; }
public StateReport( Guid correlationId, Guid projectionId, string partition, string state, CheckpointTag position, Exception exception = null) : base(correlationId, projectionId, partition, position, exception) { _state = state; }
public void setup() { _readyHandler = new TestCheckpointManagerMessageHandler(); _stream = new EmittedStream( "test_stream", new EmittedStream.WriterConfiguration(new EmittedStreamsWriter(_ioDispatcher), new EmittedStream.WriterConfiguration.StreamMetadata(), null, maxWriteBatchLength: 50), new ProjectionVersion(1, 0, 0), new TransactionFilePositionTagger(0), CheckpointTag.FromPosition(0, 0, -1), _bus, _ioDispatcher, _readyHandler); _stream.Start(); }
public void BeginLoadPartitionStateAt(string statePartition, CheckpointTag requestedStateCheckpointTag, Action <PartitionState> loadCompleted) { throw new NotImplementedException(); }
public static CommittedEventReceived Sample( ResolvedEvent data, CheckpointTag checkpointTag, Guid subscriptionId, long subscriptionMessageSequenceNumber) { return(new CommittedEventReceived( subscriptionId, checkpointTag, null, data, 77.7f, subscriptionMessageSequenceNumber, null)); }
public IEventReader CreatePausedEventReader( Guid eventReaderId, IPublisher publisher, IODispatcher ioDispatcher, CheckpointTag checkpointTag, bool stopOnEof, int?stopAfterNEvents) { throw new NotImplementedException(); }
public IReaderSubscription CreateReaderSubscription( IPublisher publisher, CheckpointTag fromCheckpointTag, Guid subscriptionId, ReaderSubscriptionOptions readerSubscriptionOptions) { throw new NotImplementedException(); }
public void RecordEventOrder(ResolvedEvent resolvedEvent, CheckpointTag orderCheckpointTag, Action committed) { throw new NotImplementedException(); }
public void EventProcessed(CheckpointTag checkpointTag, float progress) { _lastEvent = checkpointTag; }
public void BeginLoadPrerecordedEvents(CheckpointTag checkpointTag) { _publisher.Publish( new CoreProjectionProcessingMessage.PrerecordedEventsLoaded(_projectionCorrelationId, checkpointTag)); }
public void Start(CheckpointTag checkpointTag, PartitionState rootPartitionState) { _started = true; _startedAt = checkpointTag; _lastEvent = checkpointTag; }
public bool CheckpointSuggested(CheckpointTag checkpointTag, float progress) { throw new NotImplementedException(); }
public void Subscribe(CheckpointTag from, bool fromCheckpoint) { _subscribeInvoked++; _subscriptionId = Guid.NewGuid(); _specification._coreProjection.Subscribed(); }
public void NewPartition(string partition, CheckpointTag eventCheckpointTag) { throw new NotImplementedException(); }
public CheckpointTag AdjustTag(CheckpointTag tag) { return(tag); }
public CheckpointTag MakeZeroCheckpointTag() { return(CheckpointTag.FromPhase(_phase, completed: false)); }
public void setup() { _readyHandler = new TestCheckpointManagerMessageHandler(); _stream = new EmittedStream( "test_stream", new EmittedStream.WriterConfiguration(new EmittedStream.WriterConfiguration.StreamMetadata(), null, maxWriteBatchLength: 50), new ProjectionVersion(1, 2, 2), new TransactionFilePositionTagger(0), CheckpointTag.FromPosition(0, 20, 10), _ioDispatcher, _readyHandler); _stream.Start(); _stream.EmitEvents(CreateEventBatch()); OneWriteCompletes(); }
public void InitializeFromCheckpoint(CheckpointTag checkpointTag) { _initializedFromCheckpoint = true; _initializedFromCheckpointAt = checkpointTag; }
public bool ProcessPartitionCreated(string partition, CheckpointTag createPosition, ResolvedEvent data, out EmittedEventEnvelope[] emittedEvents) { throw new NotImplementedException(); }
public void null_ready_handler_throws_argumenbt_null_exception() { new EmittedStream( "test", new EmittedStream.WriterConfiguration(new EmittedStream.WriterConfiguration.StreamMetadata(), null, 50), new ProjectionVersion(1, 0, 0), new TransactionFilePositionTagger(0), CheckpointTag.FromPosition(0, 0, -1), _ioDispatcher, null); }
public override string ToString() { return(CheckpointTag.ToString()); }
public bool ProcessPartitionDeleted(string partition, CheckpointTag deletePosition, out string newState) { throw new NotImplementedException(); }
public NotAuthorized( Guid subscriptionId, CheckpointTag checkpointTag, float progress, long subscriptionMessageSequenceNumber, object source = null) : base(subscriptionId, checkpointTag, progress, subscriptionMessageSequenceNumber, source) { }
public void position_checkpoint_tag_is_incompatible() { var t = new EventByTypeIndexPositionTagger(0, new[] { "type1", "type2" }); Assert.IsFalse(t.IsCompatible(CheckpointTag.FromPosition(0, 1000, 500))); }
public EofReached( Guid subscriptionId, CheckpointTag checkpointTag, long subscriptionMessageSequenceNumber, object source = null) : base(subscriptionId, checkpointTag, 100.0f, subscriptionMessageSequenceNumber, source) { }
public string TransformCatalogEvent(CheckpointTag eventPosition, ResolvedEvent data) { throw new NotImplementedException(); }