Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions src/Orleans.BroadcastChannel/BroadcastChannelWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Orleans.BroadcastChannel.SubscriberTable;
using Orleans.Runtime;

namespace Orleans.BroadcastChannel
{
Expand All @@ -21,7 +22,7 @@ public interface IBroadcastChannelWriter<T>
}

/// <inheritdoc />
internal class BroadcastChannelWriter<T> : IBroadcastChannelWriter<T>
internal partial class BroadcastChannelWriter<T> : IBroadcastChannelWriter<T>
{
private static readonly string LoggingCategory = typeof(BroadcastChannelWriter<>).FullName;

Expand Down Expand Up @@ -52,11 +53,11 @@ public async Task Publish(T item)

if (subscribers.Count == 0)
{
if (_logger.IsEnabled(LogLevel.Debug)) _logger.LogDebug("No consumer found for {Item}", item);
LogDebugNoConsumerFound(_logger, item);
return;
}

if (_logger.IsEnabled(LogLevel.Debug)) _logger.LogDebug("Publishing item {Item} to {ConsumerCount} consumers", item, subscribers.Count);
LogDebugPublishingItem(_logger, item, subscribers.Count);

if (_fireAndForgetDelivery)
{
Expand Down Expand Up @@ -91,13 +92,31 @@ private async Task PublishToSubscriber(IBroadcastChannelConsumerExtension consum
}
catch (Exception ex)
{
_logger.LogError(ex, "Exception when sending item to {GrainId}", consumer.GetGrainId());
LogErrorExceptionWhenSendingItem(_logger, ex, consumer.GetGrainId());
if (!_fireAndForgetDelivery)
{
throw;
}
}
}

[LoggerMessage(
Level = LogLevel.Debug,
Message = "No consumer found for {Item}"
)]
private static partial void LogDebugNoConsumerFound(ILogger logger, T item);

[LoggerMessage(
Level = LogLevel.Debug,
Message = "Publishing item {Item} to {ConsumerCount} consumers"
)]
private static partial void LogDebugPublishingItem(ILogger logger, T item, int consumerCount);

[LoggerMessage(
Level = LogLevel.Error,
Message = "Exception when sending item to {GrainId}"
)]
private static partial void LogErrorExceptionWhenSendingItem(ILogger logger, Exception exception, GrainId grainId);
}
}

4 changes: 2 additions & 2 deletions src/Orleans.Core/Messaging/ClientMessageCenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,11 @@ public void RejectMessage(Message msg, string reason, Exception exc = null)

if (msg.Direction != Message.Directions.Request)
{
if (logger.IsEnabled(LogLevel.Debug)) LogDroppingMessage(msg, reason);
LogDroppingMessage(msg, reason);
}
else
{
if (logger.IsEnabled(LogLevel.Debug)) LogRejectingMessage(msg, reason);
LogRejectingMessage(msg, reason);
MessagingInstruments.OnRejectedMessage(msg);
var error = this.messageFactory.CreateRejectionResponse(msg, Message.RejectionTypes.Unrecoverable, reason, exc);
DispatchLocalMessage(error);
Expand Down
42 changes: 14 additions & 28 deletions src/Orleans.Runtime/Catalog/ActivationData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1535,18 +1535,15 @@ private async Task ActivateAsync(Dictionary<string, object>? requestContextData,

success = false;
CatalogInstruments.ActivationConcurrentRegistrationAttempts.Add(1);
if (_shared.Logger.IsEnabled(LogLevel.Debug))
{
// If this was a duplicate, it's not an error, just a race.
// Forward on all of the pending messages, and then forget about this activation.
LogDuplicateActivation(
_shared.Logger,
Address,
ForwardingAddress,
GrainInstance?.GetType(),
Address.ToFullString(),
WaitingCount);
}
// If this was a duplicate, it's not an error, just a race.
// Forward on all of the pending messages, and then forget about this activation.
LogDuplicateActivation(
_shared.Logger,
Address,
ForwardingAddress,
GrainInstance?.GetType(),
Address.ToFullString(),
WaitingCount);
}

break;
Expand Down Expand Up @@ -1579,10 +1576,7 @@ private async Task ActivateAsync(Dictionary<string, object>? requestContextData,
SetState(ActivationState.Activating);
}

if (_shared.Logger.IsEnabled(LogLevel.Debug))
{
LogActivatingGrain(_shared.Logger, this);
}
LogActivatingGrain(_shared.Logger, this);

// Start grain lifecycle within try-catch wrapper to safely capture any exceptions thrown from called function
try
Expand Down Expand Up @@ -1623,10 +1617,7 @@ private async Task ActivateAsync(Dictionary<string, object>? requestContextData,
}
}

if (_shared.Logger.IsEnabled(LogLevel.Debug))
{
LogFinishedActivatingGrain(_shared.Logger, this);
}
LogFinishedActivatingGrain(_shared.Logger, this);
}
catch (Exception exception)
{
Expand Down Expand Up @@ -1676,10 +1667,7 @@ private async Task FinishDeactivating(ActivationState previousState, Cancellatio
var encounteredError = false;
try
{
if (_shared.Logger.IsEnabled(LogLevel.Trace))
{
LogCompletingDeactivation(_shared.Logger, this);
}
LogCompletingDeactivation(_shared.Logger, this);

// Stop timers from firing.
DisposeTimers();
Expand All @@ -1691,13 +1679,11 @@ private async Task FinishDeactivating(ActivationState previousState, Cancellatio
{
try
{
if (_shared.Logger.IsEnabled(LogLevel.Debug))
LogBeforeOnDeactivateAsync(_shared.Logger, this);
LogBeforeOnDeactivateAsync(_shared.Logger, this);

await grainBase.OnDeactivateAsync(DeactivationReason, cancellationToken).WaitAsync(cancellationToken);

if (_shared.Logger.IsEnabled(LogLevel.Debug))
LogAfterOnDeactivateAsync(_shared.Logger, this);
LogAfterOnDeactivateAsync(_shared.Logger, this);
}
catch (Exception exception)
{
Expand Down
5 changes: 1 addition & 4 deletions src/Orleans.Runtime/Catalog/ActivationMigrationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,7 @@ private void RemoveWorker(SiloAddress targetSilo)
{
if (_workers.TryRemove(targetSilo, out var entry))
{
if (_logger.IsEnabled(LogLevel.Debug))
{
LogDebugTargetSilo(targetSilo);
}
LogDebugTargetSilo(targetSilo);

entry.WorkItemChannel.Writer.TryComplete();

Expand Down
Loading