public void RebuildStarted(IProjection projection, Int64 lastCommitId) { var projectionName = projection.GetCommonName(); _checkpoints.UpdateOne( Builders <Checkpoint> .Filter.Eq("_id", projectionName), Builders <Checkpoint> .Update.Set(x => x.RebuildStart, DateTime.UtcNow) .Set(x => x.RebuildStop, null) .Set(x => x.RebuildTotalSeconds, 0) .Set(x => x.RebuildActualSeconds, 0) .Set(x => x.Current, null) .Set(x => x.Events, 0) .Set(x => x.Details, null) ); //Check if some commit was deleted and lastCommitId in Eventstore //is lower than the latest dispatched commit. var trackerLastValue = _checkpointTracker[projection.GetCommonName()]; var lastCommitIdLong = lastCommitId; if (trackerLastValue > 0) { //new projection, it has no dispatched checkpoint. _slotRebuildTracker[_projectionToSlot[projectionName]] = true; } if (lastCommitIdLong < trackerLastValue) { _checkpointTracker[projection.GetCommonName()] = lastCommitId; _checkpoints.UpdateOne( Builders <Checkpoint> .Filter.Eq("_id", projectionName), Builders <Checkpoint> .Update.Set(x => x.Value, lastCommitId)); } _higherCheckpointToDispatchInRebuild = Math.Max( _higherCheckpointToDispatchInRebuild, Math.Min(trackerLastValue, lastCommitIdLong)); }
void Add(IProjection projection, Int64 defaultValue) { var id = projection.GetCommonName(); var projectionSignature = projection.GetSignature(); var projectionSlotName = projection.GetSlotName(); var checkPoint = _checkpoints.FindOneById(id) ?? new Checkpoint(id, defaultValue, projectionSignature); //Check if some projection is changed and rebuild is not active if ( checkPoint.Signature != projectionSignature && !RebuildSettings.ShouldRebuild) { _checkpointErrors.Add(String.Format("Projection {0} [slot {1}] has signature {2} but checkpoint on database has signature {3}.\n REBUILD NEEDED", id, projectionSlotName, projectionSignature, checkPoint.Signature)); } else { checkPoint.Signature = projectionSignature; } checkPoint.Slot = projectionSlotName; checkPoint.Active = true; _checkpoints.Save(checkPoint, checkPoint.Id); _checkpointTracker[id] = checkPoint.Value; _projectionToSlot[id] = checkPoint.Slot; }
public Int64 GetCheckpoint(IProjection projection) { var id = projection.GetCommonName(); if (_checkpointTracker.ContainsKey(id)) { return(_checkpointTracker[id]); } return(0); }
public Int64 GetCurrent(IProjection projection) { var checkpoint = _checkpoints.FindOneById(projection.GetCommonName()); if (checkpoint == null) { return(0); } return(checkpoint.Current ?? 0); }
public string GetCurrent(IProjection projection) { var checkpoint = _checkpoints.FindOneById(projection.GetCommonName()); if (checkpoint == null) { return(null); } return(checkpoint.Current); }
void Add(IProjection projection, string defaultValue) { var id = projection.GetCommonName(); var checkPoint = _checkpoints.FindOneById(id) ?? new Checkpoint(id, defaultValue); checkPoint.Signature = projection.GetSignature(); checkPoint.Slot = projection.GetSlotName(); checkPoint.Active = true; _checkpoints.Save(checkPoint); _checkpointTracker[id] = checkPoint.Value; _projectionToSlot[id] = checkPoint.Slot; }
public void event_is_dispatched() { CreateAggregate(); //prepare the tracker _tracker.SetCheckpoint(_projection.GetCommonName(), 1); //Set the projection as dispatched var status = sut.Rebuild(); WaitForFinish(status); Assert.That(_writer.All.Count(), Is.EqualTo(1)); }
public void RebuildEnded(IProjection projection, ProjectionMetrics.Meter meter) { var projectionName = projection.GetCommonName(); _slotRebuildTracker[_projectionToSlot[projectionName]] = false; var checkpoint = _checkpoints.FindOneById(projectionName); checkpoint.RebuildStop = DateTime.UtcNow; checkpoint.RebuildTotalSeconds = (long)(checkpoint.RebuildStop - checkpoint.RebuildStart).Value.TotalSeconds; checkpoint.Events = meter.TotalEvents; checkpoint.RebuildActualSeconds = (double)meter.TotalElapsed / TimeSpan.TicksPerSecond; checkpoint.Details = meter; _checkpoints.Save(checkpoint); }
public void event_is_dispatched() { CreateAggregate(); ConcurrentCheckpointTracker thisTracker = new ConcurrentCheckpointTracker(_db); thisTracker.SetUp(new[] { _projection1, _projection3 }, 1, false); thisTracker.UpdateSlotAndSetCheckpoint(_projection1.GetSlotName(), new[] { _projection1.GetCommonName() }, 1); thisTracker.UpdateSlotAndSetCheckpoint(_projection3.GetSlotName(), new[] { _projection3.GetCommonName() }, 1); var status = sut.Rebuild(); WaitForFinish(status); Assert.That(_writer1.All.Count(), Is.EqualTo(1)); Assert.That(_writer3.All.Count(), Is.EqualTo(1)); }
public void event_is_dispatched() { CreateAggregate(); ConcurrentCheckpointTracker thisTracker = new ConcurrentCheckpointTracker(_db); thisTracker.SetUp(new[] { _projection1, _projection3 }, 1, false); thisTracker.UpdateSlotAndSetCheckpoint(_projection1.GetSlotName(), new[] { _projection1.GetCommonName() }, 1); thisTracker.UpdateSlotAndSetCheckpoint(_projection3.GetSlotName(), new[] { _projection3.GetCommonName() }, 1); var status = sut.Rebuild(); WaitForFinish(status); var coll = _db.GetCollection <BsonDocument>("Sample"); var allRecord = coll.FindAll().ToList(); Assert.That(allRecord, Has.Count.EqualTo(1)); }