@@ -14,6 +14,7 @@ internal sealed partial class AdaptiveDirectoryCacheMaintainer
14
14
{
15
15
private static readonly TimeSpan SLEEP_TIME_BETWEEN_REFRESHES = Debugger . IsAttached ? TimeSpan . FromMinutes ( 5 ) : TimeSpan . FromMinutes ( 1 ) ; // this should be something like minTTL/4
16
16
17
+ private readonly ILogger < AdaptiveDirectoryCacheMaintainer > _log ;
17
18
private readonly AdaptiveGrainDirectoryCache cache ;
18
19
private readonly LocalGrainDirectory router ;
19
20
private readonly IInternalGrainFactory grainFactory ;
@@ -29,7 +30,7 @@ internal AdaptiveDirectoryCacheMaintainer(
29
30
IInternalGrainFactory grainFactory ,
30
31
ILoggerFactory loggerFactory )
31
32
{
32
- Log = loggerFactory . CreateLogger < AdaptiveDirectoryCacheMaintainer > ( ) ;
33
+ _log = loggerFactory . CreateLogger < AdaptiveDirectoryCacheMaintainer > ( ) ;
33
34
this . grainFactory = grainFactory ;
34
35
this . router = router ;
35
36
this . cache = cache ;
@@ -38,8 +39,6 @@ internal AdaptiveDirectoryCacheMaintainer(
38
39
lastNumHits = 0 ;
39
40
}
40
41
41
- private ILogger < AdaptiveDirectoryCacheMaintainer > Log { get ; }
42
-
43
42
public void Start ( )
44
43
{
45
44
_runTask = Run ( ) ;
@@ -135,7 +134,7 @@ private async Task Run()
135
134
}
136
135
}
137
136
138
- LogTraceSelfOwnedAndRemoved ( Log , router . MyAddress , ownedAndRemovedCount , keptCount , removedCount , refreshedCount ) ;
137
+ LogTraceSelfOwnedAndRemoved ( _log , router . MyAddress , ownedAndRemovedCount , keptCount , removedCount , refreshedCount ) ;
139
138
140
139
// Send batch requests
141
140
SendBatchCacheRefreshRequests ( fetchInBatchList ) ;
@@ -144,7 +143,7 @@ private async Task Run()
144
143
}
145
144
catch ( Exception ex ) when ( ! cancellationToken . IsCancellationRequested )
146
145
{
147
- Log . LogError ( ex , $ "Error in { nameof ( AdaptiveDirectoryCacheMaintainer ) } ." ) ;
146
+ LogErrorAdaptiveDirectoryCacheMaintainer ( ex ) ;
148
147
}
149
148
}
150
149
}
@@ -167,15 +166,15 @@ private void SendBatchCacheRefreshRequests(Dictionary<SiloAddress, List<GrainId>
167
166
ProcessCacheRefreshResponse ( silo , response ) ;
168
167
} ) . Ignore ( ) ;
169
168
170
- LogTraceSendingRequest ( Log , router . MyAddress , silo , cachedGrainAndETagList . Count ) ;
169
+ LogTraceSendingRequest ( _log , router . MyAddress , silo , cachedGrainAndETagList . Count ) ;
171
170
}
172
171
}
173
172
174
173
private void ProcessCacheRefreshResponse (
175
174
SiloAddress silo ,
176
175
List < AddressAndTag > refreshResponse )
177
176
{
178
- LogTraceReceivedProcessCacheRefreshResponse ( Log , router . MyAddress , refreshResponse . Count ) ;
177
+ LogTraceReceivedProcessCacheRefreshResponse ( _log , router . MyAddress , refreshResponse . Count ) ;
179
178
180
179
int otherSiloCount = 0 , updatedCount = 0 , unchangedCount = 0 ;
181
180
@@ -211,7 +210,7 @@ private void ProcessCacheRefreshResponse(
211
210
}
212
211
}
213
212
214
- LogTraceProcessedRefreshResponse ( Log , router . MyAddress , silo , otherSiloCount , updatedCount , unchangedCount ) ;
213
+ LogTraceProcessedRefreshResponse ( _log , router . MyAddress , silo , otherSiloCount , updatedCount , unchangedCount ) ;
215
214
}
216
215
217
216
/// <summary>
@@ -237,10 +236,7 @@ private void ProcessCacheRefreshResponse(
237
236
{
238
237
// this may happen only if the LRU cache is full and decided to drop this grain
239
238
// while we try to refresh it
240
- Log . LogWarning (
241
- ( int ) ErrorCode . Runtime_Error_100199 ,
242
- "Grain {GrainId} disappeared from the cache during maintenance" ,
243
- grain ) ;
239
+ LogWarningGrainDisappearedFromCache ( grain ) ;
244
240
}
245
241
}
246
242
@@ -258,12 +254,25 @@ private void ProduceStats()
258
254
long numAccesses = curNumAccesses - lastNumAccesses ;
259
255
long numHits = curNumHits - lastNumHits ;
260
256
261
- if ( Log . IsEnabled ( LogLevel . Trace ) ) Log . LogTrace ( "#accesses: {AccessCount}, hit-ratio: {HitRatio}%" , numAccesses , ( numHits / Math . Max ( numAccesses , 0.00001 ) ) * 100 ) ;
257
+ if ( _log . IsEnabled ( LogLevel . Trace ) ) _log . LogTrace ( "#accesses: {AccessCount}, hit-ratio: {HitRatio}%" , numAccesses , ( numHits / Math . Max ( numAccesses , 0.00001 ) ) * 100 ) ;
262
258
263
259
lastNumAccesses = curNumAccesses ;
264
260
lastNumHits = curNumHits ;
265
261
}
266
262
263
+ [ LoggerMessage (
264
+ Level = LogLevel . Error ,
265
+ Message = $ "Error in { nameof ( AdaptiveDirectoryCacheMaintainer ) } ."
266
+ ) ]
267
+ private partial void LogErrorAdaptiveDirectoryCacheMaintainer ( Exception ex ) ;
268
+
269
+ [ LoggerMessage (
270
+ EventId = ( int ) ErrorCode . Runtime_Error_100199 ,
271
+ Level = LogLevel . Warning ,
272
+ Message = "Grain {GrainId} disappeared from the cache during maintenance"
273
+ ) ]
274
+ private partial void LogWarningGrainDisappearedFromCache ( GrainId grainId ) ;
275
+
267
276
[ LoggerMessage (
268
277
Level = LogLevel . Trace ,
269
278
Message = "Silo {SiloAddress} self-owned (and removed) {OwnedAndRemovedCount}, kept {KeptCount}, removed {RemovedCount} and tried to refresh {RefreshedCount} grains"
0 commit comments