Example #1
0
        public Task <BoolResult> RegisterCheckpointAsync(OperationContext context, string checkpointId, EventSequencePoint sequencePoint)
        {
            return(context.PerformOperationWithTimeoutAsync(
                       Tracer,
                       async nestedContext =>
            {
                Contract.Assert(sequencePoint.SequenceNumber != null);

                var checkpoint = new RedisCheckpointInfo(checkpointId, sequencePoint.SequenceNumber.Value, _clock.UtcNow, Configuration.PrimaryMachineLocation.ToString());
                Tracer.Debug(nestedContext, $"Saving checkpoint '{checkpoint}' into the central store.");

                var slotNumber = await _checkpointsKey.UseNonConcurrentReplicatedHashAsync(
                    nestedContext,
                    Configuration.RetryWindow,
                    RedisOperation.UploadCheckpoint,
                    (batch, key) => batch.AddCheckpointAsync(key, checkpoint, MaxCheckpointSlotCount),
                    timeout: Configuration.ClusterRedisOperationTimeout)
                                 .ThrowIfFailureAsync();

                Tracer.Debug(nestedContext, $"Saved checkpoint into slot '{slotNumber}'.");
                return BoolResult.Success;
            },
                       Counters[GlobalStoreCounters.RegisterCheckpoint],
                       timeout: Configuration.ClusterRedisOperationTimeout));
        }
Example #2
0
        public void TestParsingLogic()
        {
            var checkpoints = new[]
            {
                new RedisCheckpointInfo(
                    "cid42",
                    32523,
                    DateTime.UtcNow,
                    "machine1",
                    slotNumber: 123),
                new RedisCheckpointInfo(
                    "mycheckpoint",
                    2,
                    DateTime.FromFileTimeUtc(9520329320),
                    "m02",
                    slotNumber: 0)
            };

            List <HashEntry> entries = new List <HashEntry>();

            foreach (var checkpoint in checkpoints)
            {
                AddHashEntries(entries, checkpoint);
            }

            var parsedCheckpoints = RedisCheckpointInfo.ParseCheckpoints(entries.ToArray());

            Assert.Equal(checkpoints.Length, parsedCheckpoints.Length);
            Assert.Equal(checkpoints, parsedCheckpoints, new RedisCheckpointInfoEqualityComparer());
        }
Example #3
0
        private void AddHashEntries(List <HashEntry> entries, RedisCheckpointInfo checkpoint)
        {
            Assert.True(checkpoint.SlotNumber >= 0);

            entries.AddRange(new[]
            {
                new HashEntry($"Slot#{checkpoint.SlotNumber}.CheckpointId", checkpoint.CheckpointId),
                new HashEntry($"Slot#{checkpoint.SlotNumber}.SequenceNumber", checkpoint.SequenceNumber),
                new HashEntry($"Slot#{checkpoint.SlotNumber}.CheckpointCreationTime", checkpoint.CheckpointCreationTime.ToFileTimeUtc()),
                new HashEntry($"Slot#{checkpoint.SlotNumber}.MachineName", checkpoint.MachineName),
            });
        }
Example #4
0
        public Task <BoolResult> RegisterCheckpointAsync(OperationContext context, string checkpointId, EventSequencePoint sequencePoint)
        {
            return(context.PerformOperationAsync(
                       Tracer,
                       () =>
            {
                Contract.Assert(sequencePoint.SequenceNumber != null);

                var checkpoint = new RedisCheckpointInfo(checkpointId, sequencePoint.SequenceNumber.Value, _clock.UtcNow, LocalMachineLocation.ToString());
                Tracer.Debug(context, $"Saving checkpoint '{checkpoint}' into the central store.");

                return ExecuteRedisAsync(context, async redisDb =>
                {
                    var slotNumber = await redisDb.ExecuteBatchAsync(context, batch =>
                    {
                        return batch.AddCheckpointAsync(_checkpointsKey, checkpoint, MaxCheckpointSlotCount);
                    }, RedisOperation.UploadCheckpoint);

                    Tracer.Debug(context, $"Saved checkpoint into slot '{slotNumber}' on {GetDbName(redisDb)}.");
                    return BoolResult.Success;
                });
            },
                       Counters[GlobalStoreCounters.RegisterCheckpoint]));
        }