// 락이 없는 함수로 푸시 말고는 쓰기 동작이 없어야 한다. // Stop이 불리고 나서도 로그가 푸시될 수 있는 것을 감안한다(이런 로그는 Stop에서 처리). private Int64 PushImpl(String type, Object log, Boolean doSerialize) { try { if (CheckAvailablePush(type, log) == false) { return(INVALID_SEQUENCE); } DateTime now = Now.NowDateTime(); Int64 sequence = _sequenceGenerator.Generate(); Boolean successPush = _logQueue.Push(new Log() { Sequence = sequence, LogType = type, LogObject = log, TimeStamp = Now.TimestampSec(now), TimeStampNS = Now.TimestampNS(now), IsRawString = doSerialize }); if (successPush) { Watcher.IncrementPushLogCount(); return(sequence); } return(INVALID_SEQUENCE); } catch (Exception exception) { ErrorCounter.RaiseError($"Fail Push: {exception.Message}"); return(INVALID_SEQUENCE); } }
internal Byte[] Encode(Log log) { try { return(EncodeImpl(log)); } catch (Exception exception) { _errorCounter.RaiseError($"Encode Error: {exception.Message}"); return(null); } }
private void PutInternal(PutContext putContext) { try { Byte[] post = _kinesisPutAPI.CreatePost(putContext.PutLog.EncodedLogs); _kinesisPutAPI.Put(post, putContext); if (_config.UseThroughputControl == 1) { _throughputController.UseCapacity(putContext.PutLog.TotalEncodedLogByte, putContext.PutLog.EncodedLogs.Length); } } catch (Exception exception) { _errorCounter.RaiseError($"{exception.Message}\n{exception.InnerException?.Message}"); // 여기서 예외는 재시도해도 소용없기 때문에 로그를 바로 버린다. DropLog(putContext.PutLog, putContext.RetryCount); } }
internal void Start() { lock (_lock) { if (_thread != null) { throw new LoggerException($"Fail {nameof(ThroughputController)}::{nameof(Start)} {nameof(_thread)} is not null"); } _putLogs = new QueueMT <PutLog>(); _remainPutLogs = new List <PutLog>(); _isThrottling = false; // 샤드가 최소 1개는 존재할 것이므로 1개 기준으로 초기화. _shardCount = 1; _byteCapacity = Const.BYTE_FOR_SECOND_PER_SHARD_BYTE; _recordCapacity = Const.RECORD_FOR_SECOND_PER_SHARD_COUNT; _thread = new NaiveLoopThread(() => ThroughputControl(DateTime.UtcNow), THROUGHPUT_CONTROL_MS, e => _errorCounter.RaiseError(e), nameof(ThroughputController)); _thread.Start(); } }
private void CreateAndStartLoggerThread() { for (Int32 i = 0; i < Config.WorkThreadCount; ++i) { var thread = new NaiveLoopThread(Tick, Config.WorkThreadIntervalMS, e => ErrorCounter.RaiseError(e), $"{nameof(Tick)}:{i}"); _loggerThreads.Add(thread); thread.Start(); } }
internal void Start() { lock (_lock) { if (_thread != null) { throw new LoggerException($"Fail {nameof(CompletePutNotifier)}::{nameof(Start)} ${nameof(_thread)} is not null"); } _completePuts = new QueueMT <CompletePutNotice>(); _thread = new NaiveLoopThread(HandleCompletePut, _config.CompletePutIntervalMS, e => _errorCounter.RaiseError(e), nameof(CompletePutNotifier)); _thread.Start(); } }