Example #1
0
        public TaskIndexRecord AddMeta([NotNull] TaskMetaInformation taskMeta, [CanBeNull] TaskIndexRecord oldTaskIndexRecord)
        {
            var metricsContext = MetricsContext.For(taskMeta).SubContext("HandleTasksMetaStorage.AddMeta");
            var globalNowTicks = globalTime.UpdateNowTimestamp().Ticks;
            var nowTicks       = Math.Max((taskMeta.LastModificationTicks ?? 0) + PreciseTimestampGenerator.TicksPerMicrosecond, globalNowTicks);

            taskMeta.LastModificationTicks = nowTicks;
            using (metricsContext.Timer("EventLogRepository_AddEvent").NewContext())
                eventLogRepository.AddEvent(taskMeta, eventTimestamp: new Timestamp(nowTicks), eventId: Guid.NewGuid());
            var newIndexRecord = FormatIndexRecord(taskMeta);

            using (metricsContext.Timer("MinimalStartTicksIndex_AddRecord").NewContext())
                minimalStartTicksIndex.AddRecord(newIndexRecord, globalNowTicks, taskMeta.GetTtl());
            if (taskMeta.State == TaskState.New)
            {
                using (metricsContext.Timer("ChildTaskIndex_WriteIndexRecord").NewContext())
                    childTaskIndex.WriteIndexRecord(taskMeta, globalNowTicks);
            }
            using (metricsContext.Timer("TaskMetaStorage_Write").NewContext())
                taskMetaStorage.Write(taskMeta, globalNowTicks);
            if (oldTaskIndexRecord != null)
            {
                using (metricsContext.Timer("MinimalStartTicksIndex_RemoveRecord").NewContext())
                    minimalStartTicksIndex.RemoveRecord(oldTaskIndexRecord, globalNowTicks);
            }
            return(newIndexRecord);
        }
        public void Write([NotNull] TaskMetaInformation taskMeta, long timestamp)
        {
            var blobId        = GetBlobId(taskMeta.Id);
            var taskMetaBytes = serializer.Serialize(taskMeta);

            timeBasedBlobStorage.Write(blobId, taskMetaBytes, timestamp, taskMeta.GetTtl());
        }
        public void SetOrUpdateTtl_Now()
        {
            var now  = Timestamp.Now;
            var meta = new TaskMetaInformation("Test_name", "Test-id");
            var ttl  = TimeSpan.FromMilliseconds(3342);

            meta.SetOrUpdateTtl(ttl);
            Assert.That(meta.GetTtl(), Is.InRange(ttl - TimeSpan.FromSeconds(1), ttl));
            Assert.That(meta.ExpirationTimestampTicks, Is.GreaterThanOrEqualTo((now + ttl).Ticks));
        }
        public BlobId Write([NotNull] TaskMetaInformation taskMeta, [NotNull] byte[] taskData)
        {
            if (!taskMeta.IsTimeBased())
            {
                throw new InvalidOperationException(string.Format("TaskId is not time-based: {0}", taskMeta.Id));
            }
            var blobId    = TimeBasedBlobStorage.GenerateNewBlobId(taskData.Length);
            var timestamp = blobId.Id.GetTimestamp().Ticks;

            timeBasedBlobStorage.Write(blobId, taskData, timestamp, taskMeta.GetTtl());
            return(blobId);
        }
Example #5
0
        public void AddEvent([NotNull] TaskMetaInformation taskMeta, [NotNull] Timestamp eventTimestamp, Guid eventId)
        {
            minTicksHolder.UpdateMinTicks(firstEventTicksRowName, eventTimestamp.Ticks);
            var ttl = taskMeta.GetTtl();

            cfConnection.AddColumn(EventPointerFormatter.GetPartitionKey(eventTimestamp.Ticks), new Column
            {
                Name      = EventPointerFormatter.GetColumnName(eventTimestamp.Ticks, eventId),
                Value     = serializer.Serialize(new TaskMetaUpdatedEvent(taskMeta.Id, eventTimestamp.Ticks)),
                Timestamp = eventTimestamp.Ticks,
                TTL       = ttl.HasValue ? (int)ttl.Value.TotalSeconds : (int?)null,
            });
        }
        public void SetOrUpdateTtl_MinimalStartTicks()
        {
            var minimalStart = Timestamp.Now + TimeSpan.FromHours(1);
            var ttl          = TimeSpan.FromMilliseconds(3342);
            var meta         = new TaskMetaInformation("Test_name", "Test-id")
            {
                MinimalStartTicks = minimalStart.Ticks
            };

            meta.SetOrUpdateTtl(ttl);
            Assert.That(meta.GetTtl(), Is.InRange(TimeSpan.FromHours(1) - ttl, TimeSpan.FromHours(1) + ttl));
            Assert.That(meta.ExpirationTimestampTicks, Is.GreaterThanOrEqualTo((minimalStart + ttl).Ticks));
        }
        public void WriteIndexRecord([NotNull] TaskMetaInformation taskMeta, long timestamp)
        {
            if (string.IsNullOrEmpty(taskMeta.ParentTaskId))
            {
                return;
            }
            var ttl = taskMeta.GetTtl();

            cassandraCluster.RetrieveColumnFamilyConnection(rtqSettings.QueueKeyspace, ColumnFamilyName).AddColumn(taskMeta.ParentTaskId, new Column
            {
                Name      = taskMeta.Id,
                Timestamp = timestamp,
                Value     = serializer.Serialize(taskMeta.Id),
                TTL       = ttl.HasValue ? (int)ttl.Value.TotalSeconds : (int?)null,
            });
        }
Example #8
0
        public void ProlongMetaTtl([NotNull] TaskMetaInformation taskMeta)
        {
            var globalNowTicks = globalTime.UpdateNowTimestamp().Ticks;

            minimalStartTicksIndex.WriteRecord(FormatIndexRecord(taskMeta), globalNowTicks, taskMeta.GetTtl());
            childTaskIndex.WriteIndexRecord(taskMeta, globalNowTicks);
            taskMetaStorage.Write(taskMeta, globalNowTicks);
        }
 public void Overwrite([NotNull] TaskMetaInformation taskMeta, [NotNull] byte[] taskData)
 {
     if (!taskMeta.IsTimeBased())
     {
         throw new InvalidOperationException(string.Format("TaskMeta is not time-based: {0}", taskMeta));
     }
     timeBasedBlobStorage.Write(taskMeta.GetTaskDataId(), taskData, timestamp: Timestamp.Now.Ticks, ttl: taskMeta.GetTtl());
 }
        public void ProlongExceptionInfosTtl([NotNull] TaskMetaInformation taskMeta)
        {
            if (!taskMeta.IsTimeBased())
            {
                throw new InvalidOperationException(string.Format("TaskMeta is not time-based: {0}", taskMeta));
            }
            var oldExceptionInfos = timeBasedBlobStorage.Read(taskMeta.Id, taskMeta.GetTaskExceptionInfoIds().ToArray());
            var timestamp         = Timestamp.Now.Ticks;

            foreach (var exceptionInfo in oldExceptionInfos)
            {
                timeBasedBlobStorage.Write(taskMeta.Id, exceptionInfo.Key, exceptionInfo.Value, timestamp, taskMeta.GetTtl());
            }
        }
        public bool TryAddNewExceptionInfo([NotNull] TaskMetaInformation taskMeta, [NotNull] Exception exception, out List <TimeGuid> newExceptionInfoIds)
        {
            if (!taskMeta.IsTimeBased())
            {
                throw new InvalidOperationException(string.Format("TaskMeta is not time-based: {0}", taskMeta));
            }
            newExceptionInfoIds = null;
            var newExceptionInfo  = new TaskExceptionInfo(exception);
            var lastExceptionInfo = TryGetLastExceptionInfo(taskMeta);

            if (lastExceptionInfo != null && lastExceptionInfo.ExceptionMessageInfo == newExceptionInfo.ExceptionMessageInfo)
            {
                return(false);
            }
            var      newExceptionInfoId = TimeGuid.NowGuid();
            var      timestamp          = newExceptionInfoId.GetTimestamp().Ticks;
            TimeGuid oldExceptionInfoId;

            newExceptionInfoIds = taskMeta.AddExceptionInfoId(newExceptionInfoId, out oldExceptionInfoId);
            var newExceptionInfoBytes = serializer.Serialize(newExceptionInfo);

            timeBasedBlobStorage.Write(taskMeta.Id, newExceptionInfoId, newExceptionInfoBytes, timestamp, taskMeta.GetTtl());
            if (oldExceptionInfoId != null)
            {
                timeBasedBlobStorage.Delete(taskMeta.Id, oldExceptionInfoId, timestamp);
            }
            return(true);
        }