public TaskIndexRecord FormatIndexRecord([NotNull] TaskMetaInformation taskMeta) { var taskTopic = taskDataRegistry.GetTaskTopic(taskMeta.Name); var taskIndexShardKey = new TaskIndexShardKey(taskTopic, taskMeta.State); return(new TaskIndexRecord(taskMeta.Id, taskMeta.MinimalStartTicks, taskIndexShardKey)); }
public IEnumerable <TaskIndexRecord> GetRecords([NotNull] TaskIndexShardKey taskIndexShardKey, long toTicks, int batchSize) { var fromTicks = TryGetFromTicks(taskIndexShardKey, out var liveRecordTicksMarker); if (!fromTicks.HasValue) { return(new TaskIndexRecord[0]); } return(new GetEventsEnumerable(liveRecordTicksMarker, serializer, RetrieveColumnFamilyConnection(), fromTicks.Value, toTicks, batchSize, logger)); }
private ILiveRecordTicksMarker DoTryGetCurrentMarkerValue([NotNull] TaskIndexShardKey taskIndexShardKey) { lock (locker) { long currentTicks; if (!ticksByShardKey.TryGetValue(taskIndexShardKey, out currentTicks)) { return(null); } return(new LiveRecordTicksMarker(new LiveRecordTicksMarkerState(taskIndexShardKey, currentTicks), this)); } }
private TimeSpan GetOverlapDuration([NotNull] TaskIndexShardKey taskIndexShardKey) { lock (locker) { var now = Timestamp.Now; if (!lastBigOverlapMomentsByShardKey.TryGetValue(taskIndexShardKey, out var lastBigOverlapMoment) || now - lastBigOverlapMoment > TimeSpan.FromMinutes(1)) { lastBigOverlapMomentsByShardKey[taskIndexShardKey] = now; //Сложно рассчитать математически правильный размер отката, и код постановки таски может измениться, //что потребует изменения этого отката. Поэтому берется, как кажется, с запасом return(TimeSpan.FromMinutes(8)); // Против адских затупов кассандры } return(TimeSpan.FromMinutes(1)); // Штатная зона нестабильности } }
public ILiveRecordTicksMarker TryGetCurrentMarkerValue([NotNull] TaskIndexShardKey taskIndexShardKey) { var currentMarkerValue = DoTryGetCurrentMarkerValue(taskIndexShardKey); if (currentMarkerValue != null) { return(currentMarkerValue); } var persistedTicks = minTicksHolder.GetMinTicks(taskIndexShardKey.ToCassandraKey()); if (persistedTicks == 0) { return(null); } return(DoGetCurrentMarkerValue(taskIndexShardKey, persistedTicks)); }
public bool TryMoveForward([NotNull] TaskIndexShardKey taskIndexShardKey, long oldTicks, long newTicks) { lock (locker) { long currentTicks; if (!ticksByShardKey.TryGetValue(taskIndexShardKey, out currentTicks)) { throw new InvalidOperationException(string.Format("Not found CurrentTicks for: {0}", taskIndexShardKey)); } if (currentTicks < oldTicks) { return(false); } ticksByShardKey[taskIndexShardKey] = newTicks; return(true); } }
private long?TryGetFromTicks([NotNull] TaskIndexShardKey taskIndexShardKey, out ILiveRecordTicksMarker liveRecordTicksMarker) { liveRecordTicksMarker = oldestLiveRecordTicksHolder.TryGetCurrentMarkerValue(taskIndexShardKey); if (liveRecordTicksMarker == null) { return(null); } var overlapDuration = GetOverlapDuration(taskIndexShardKey); var fromTicks = liveRecordTicksMarker.State.CurrentTicks - overlapDuration.Ticks; var safetyBelt = (Timestamp.Now - TimeSpan.FromHours(6)).Ticks; if (fromTicks < safetyBelt) { logger.Warn("fromTicks ({FromTicks}) < safetyBelt ({SafetyBelt})", new { FromTicks = new Timestamp(fromTicks), SafetyBelt = new Timestamp(safetyBelt) }); return(safetyBelt); } return(fromTicks); }
private void DoMoveBackwardIfNecessary([NotNull] TaskIndexShardKey taskIndexShardKey, long newTicks) { lock (locker) { long currentTicks; if (!ticksByShardKey.TryGetValue(taskIndexShardKey, out currentTicks)) { ticksByShardKey.Add(taskIndexShardKey, newTicks); } else { if (newTicks < currentTicks) { ticksByShardKey[taskIndexShardKey] = newTicks; } } } }
private ILiveRecordTicksMarker DoGetCurrentMarkerValue([NotNull] TaskIndexShardKey taskIndexShardKey, long persistedTicks) { lock (locker) { long currentTicks; if (!ticksByShardKey.TryGetValue(taskIndexShardKey, out currentTicks)) { currentTicks = persistedTicks; ticksByShardKey.Add(taskIndexShardKey, currentTicks); } else { if (persistedTicks < currentTicks) { currentTicks = persistedTicks; ticksByShardKey[taskIndexShardKey] = currentTicks; } } return(new LiveRecordTicksMarker(new LiveRecordTicksMarkerState(taskIndexShardKey, currentTicks), this)); } }
public LiveRecordTicksMarkerState TryGetCurrentLiveRecordTicksMarker([NotNull] TaskIndexShardKey taskIndexShardKey) { return(minimalStartTicksIndex.TryGetCurrentLiveRecordTicksMarker(taskIndexShardKey)); }
public static string ToCassandraKey([NotNull] this TaskIndexShardKey taskIndexShardKey) { var taskStateCassandraName = taskIndexShardKey.TaskState.GetCassandraName(); return(string.Format("{0}_{1}", taskIndexShardKey.TaskTopic, taskStateCassandraName)); }
public static string GetRowKey([NotNull] TaskIndexShardKey taskIndexShardKey, long ticks) { return(string.Format("{0}_{1}", GetTicksRowNumber(ticks), taskIndexShardKey.ToCassandraKey())); }
public LiveRecordTicksMarkerState TryGetCurrentLiveRecordTicksMarker([NotNull] TaskIndexShardKey taskIndexShardKey) { return(oldestLiveRecordTicksHolder.TryGetCurrentMarkerValue(taskIndexShardKey)?.State); }
public LiveRecordTicksMarkerState([NotNull] TaskIndexShardKey taskIndexShardKey, long currentTicks) { TaskIndexShardKey = taskIndexShardKey; CurrentTicks = currentTicks; }
public void MoveMarkerBackwardIfNecessary([NotNull] TaskIndexShardKey taskIndexShardKey, long newTicks) { minTicksHolder.UpdateMinTicks(taskIndexShardKey.ToCassandraKey(), newTicks); DoMoveBackwardIfNecessary(taskIndexShardKey, newTicks); }