public void Debug(string format, params object[] args)
 {
     if (args.Length == 0)
     {
         _log.Debug(format);
     }
     else
     {
         _log.Debug(format, args);
     }
 }
Exemple #2
0
        private void PublishByType(Message message, Type type)
        {
            List <IMessageHandler> handlers;

            if (!_typeHash.TryGetValue(type, out handlers))
            {
                return;
            }

            for (int i = 0, n = handlers.Count; i < n; ++i)
            {
                var handler = handlers[i];
                if (_watchSlowMsg)
                {
                    var start = DateTime.UtcNow;

                    handler.TryHandle(message);

                    var elapsed = DateTime.UtcNow - start;
                    if (elapsed > _slowMsgThreshold)
                    {
                        Log.Debug("SLOW BUS MSG [{bus}]: {message} - {elapsed}ms. Handler: {handler}.",
                                  Name, message.GetType().Name, (int)elapsed.TotalMilliseconds, handler.HandlerName);
                    }
                }
                else
                {
                    handler.TryHandle(message);
                }
            }
        }
Exemple #3
0
 public static DiskIo GetDiskIo(int procId, Serilog.ILogger logger)
 {
     try {
         return(OS.IsUnix ? GetOnUnix(procId, logger) : GetOnWindows(logger));
     } catch (Exception exc) {
         Log.Debug("Getting disk IO error: {e}.", exc.Message);
         return(null);
     }
 }
Exemple #4
0
 private PerformanceCounter CreatePerfCounter(string category, string counter, string instance = null)
 {
     try {
         return(string.IsNullOrEmpty(instance)
                                 ? new PerformanceCounter(category, counter)
                                 : new PerformanceCounter(category, counter, instance));
     } catch (Exception ex) {
         _log.Debug(
             "Could not create performance counter: category='{category}', counter='{counter}', instance='{instance}'. Error: {e}",
             category, counter, instance ?? string.Empty, ex.Message);
         return(null);
     }
 }
Exemple #5
0
        public static EsDriveInfo FromDirectory(string path, Serilog.ILogger log)
        {
            try {
                if (OS.IsUnix)
                {
                    return(GetEsDriveInfoUnix(path, log));
                }

                var driveName = Directory.GetDirectoryRoot(path);
                var drive     = new DriveInfo(driveName);
                var esDrive   = new EsDriveInfo(drive.Name, drive.TotalSize, drive.AvailableFreeSpace);
                return(esDrive);
            } catch (Exception ex) {
                log.Debug("Error while reading drive info for path {path}. Message: {e}.", path, ex.Message);
                return(null);
            }
        }
        public async Task ConsumeAsync(string eventType, ResolvedEvent resolvedEvent)
        {
            if (string.IsNullOrWhiteSpace(eventType))
            {
                throw new ArgumentException("Event type required", nameof(eventType));
            }

            if (_dittoSettings.ReadOnly)
            {
                _logger.Debug("Received {EventType} #{EventNumber} from {StreamName} (Original Event: #{OriginalEventNumber})",
                              resolvedEvent.Event.EventType,
                              resolvedEvent.Event.EventNumber,
                              resolvedEvent.Event.EventStreamId,
                              resolvedEvent.OriginalEventNumber
                              );

                return;
            }

            var request = new PutRecordRequest
            {
                StreamName   = _kinesisSettings.StreamName,
                PartitionKey = resolvedEvent.Event.EventStreamId,
                Data         = CreateDataStream(resolvedEvent)
            };

            using (_logger.OperationAt(LogEventLevel.Debug).Time("Replicating {EventType} #{EventNumber} from {StreamName} (Original Event: #{OriginalEventNumber}) to Kinesis",
                                                                 resolvedEvent.Event.EventType,
                                                                 resolvedEvent.Event.EventNumber,
                                                                 resolvedEvent.Event.EventStreamId,
                                                                 resolvedEvent.OriginalEventNumber))
                using (DittoMetrics.IODuration.WithIOLabels("kinesis", _kinesisSettings.StreamName, "put_record").NewTimer())
                {
                    await _kinesis.PutRecordAsync(request);
                }

            if (_dittoSettings.ReplicationThrottleInterval.GetValueOrDefault() > 0)
            {
                await Task.Delay(_dittoSettings.ReplicationThrottleInterval.Value);
            }
        }
        private void GoToState(State state)
        {
            if (_state == State.Suspended)
            {
                _logger.Debug($"Projection {_name} has been suspended for a subsystem restart. Cannot go to state {state}");
                return;
            }
//            _logger.Trace("CP: {projection} {stateFrom} => {stateTo}", _name, _state, state);
            var wasStopped  = _state == State.Stopped || _state == State.Faulted || _state == State.PhaseCompleted;
            var wasStopping = _state == State.Stopping || _state == State.FaultedStopping ||
                              _state == State.CompletingPhase;
            var wasStarting = _state == State.LoadStateRequested || _state == State.StateLoaded ||
                              _state == State.Subscribed;
            var wasStarted = _state == State.Subscribed || _state == State.Running || _state == State.Stopping ||
                             _state == State.FaultedStopping || _state == State.CompletingPhase;
            var wasRunning   = _state == State.Running;
            var stateChanged = _state != state;

            _state = state;             // set state before transition to allow further state change
            switch (state)
            {
            case State.Stopped:
            case State.Faulted:
            case State.PhaseCompleted:
                if (wasStarted && !wasStopped)
                {
                    _checkpointManager.Stopped();
                }
                break;

            case State.Stopping:
            case State.FaultedStopping:
            case State.CompletingPhase:
                if (wasStarted && !wasStopping)
                {
                    _checkpointManager.Stopping();
                }
                break;
            }


            if (_projectionProcessingPhase != null)             // null while loading state
            {
                switch (state)
                {
                case State.LoadStateRequested:
                case State.StateLoaded:
                case State.Subscribed:
                    if (!wasStarting)
                    {
                        _projectionProcessingPhase.SetProjectionState(PhaseState.Starting);
                    }
                    break;

                case State.Running:
                    if (!wasRunning)
                    {
                        _projectionProcessingPhase.SetProjectionState(PhaseState.Running);
                    }
                    break;

                case State.Faulted:
                case State.FaultedStopping:
                    if (wasRunning)
                    {
                        _projectionProcessingPhase.SetProjectionState(PhaseState.Stopped);
                    }
                    break;

                case State.Stopped:
                case State.Stopping:
                case State.CompletingPhase:
                case State.PhaseCompleted:
                    if (wasRunning)
                    {
                        _projectionProcessingPhase.SetProjectionState(PhaseState.Stopped);
                    }
                    break;

                default:
                    _projectionProcessingPhase.SetProjectionState(PhaseState.Unknown);
                    break;
                }
            }
            switch (state)
            {
            case State.Initial:
                EnterInitial();
                break;

            case State.LoadStateRequested:
                EnterLoadStateRequested();
                break;

            case State.StateLoaded:
                EnterStateLoaded();
                break;

            case State.Subscribed:
                EnterSubscribed();
                break;

            case State.Running:
                EnterRunning();
                break;

            case State.Stopping:
                EnterStopping();
                break;

            case State.Stopped:
                EnterStopped();
                break;

            case State.FaultedStopping:
                EnterFaultedStopping();
                break;

            case State.Faulted:
                EnterFaulted();
                break;

            case State.CompletingPhase:
                EnterCompletingPhase();
                break;

            case State.PhaseCompleted:
                EnterPhaseCompleted();
                break;

            case State.Suspended:
                EnterSuspended();
                break;

            default:
                throw new Exception();
            }

            if (stateChanged)
            {
                UpdateStatistics();
            }
        }