internal void BeginStatePartitionLoad( ProjectionMessage.Projections.CommittedEventReceived @event, Action loadCompleted) { string statePartition = _checkpointStrategy.StatePartitionSelector.GetStatePartition(@event); if (statePartition == "") // root is always cached { loadCompleted(); return; } string state = _partitionStateCache.TryGetAndLockPartitionState(statePartition, @event.CheckpointTag); if (state != null) { loadCompleted(); } else { string partitionStateStreamName = MakePartitionStateStreamName(statePartition); _readRequestsInProgress++; _readDispatcher.Publish( new ClientMessage.ReadStreamEventsBackward( Guid.NewGuid(), _readDispatcher.Envelope, partitionStateStreamName, -1, 1, resolveLinks: false), m => OnLoadStatePartitionCompleted(statePartition, @event, m, loadCompleted)); } }
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 BeginGetPartitionStateAt( string statePartition, CheckpointTag at, Action <PartitionState> loadCompleted, bool lockLoaded) { if (statePartition == "") // root is always cached { // root partition is always locked var state = _partitionStateCache.TryGetAndLockPartitionState(statePartition, null); loadCompleted(state); } else { var s = lockLoaded ? _partitionStateCache.TryGetAndLockPartitionState(statePartition, at) : _partitionStateCache.TryGetPartitionState(statePartition); if (s != null) { loadCompleted(s); } else { Action <PartitionState> completed = state => { if (lockLoaded) { _partitionStateCache.CacheAndLockPartitionState(statePartition, state, at); } else { _partitionStateCache.CachePartitionState(statePartition, state); } loadCompleted(state); }; if (_projectionConfig.CheckpointsEnabled) { _checkpointManager.BeginLoadPartitionStateAt(statePartition, at, completed); } else { var state = new PartitionState("", null, _zeroCheckpointTag); completed(state); } } } }
internal void BeginStatePartitionLoad(string statePartition, CheckpointTag eventCheckpointTag, Action loadCompleted) { if (statePartition == "") // root is always cached { loadCompleted(); return; } var state = _partitionStateCache.TryGetAndLockPartitionState(statePartition, eventCheckpointTag); if (state != null) { loadCompleted(); } else { string partitionStateStreamName = MakePartitionStateStreamName(statePartition); _readRequestsInProgress++; var requestId = _readDispatcher.Publish(new ClientMessage.ReadStreamEventsBackward(Guid.NewGuid(), _readDispatcher.Envelope, partitionStateStreamName, -1, 1, resolveLinks: false), m => OnLoadStatePartitionCompleted(statePartition, m, loadCompleted, eventCheckpointTag)); if (requestId != Guid.Empty) { _loadStateRequests.Add(requestId); } } }