19
19
20
20
package org .elasticsearch .index .cache .request ;
21
21
22
+ import org .apache .lucene .util .Accountable ;
22
23
import org .elasticsearch .common .cache .RemovalListener ;
23
24
import org .elasticsearch .common .cache .RemovalNotification ;
24
25
import org .elasticsearch .common .metrics .CounterMetric ;
25
26
import org .elasticsearch .index .IndexSettings ;
26
27
import org .elasticsearch .index .shard .AbstractIndexShardComponent ;
27
28
import org .elasticsearch .index .shard .ShardId ;
28
- import org .elasticsearch .indices .cache . request . IndicesRequestCache ;
29
+ import org .elasticsearch .indices .IndicesRequestCache ;
29
30
30
31
/**
31
32
*/
32
- public class ShardRequestCache extends AbstractIndexShardComponent implements RemovalListener < IndicesRequestCache . Key , IndicesRequestCache . Value > {
33
+ public final class ShardRequestCache {
33
34
34
35
final CounterMetric evictionsMetric = new CounterMetric ();
35
36
final CounterMetric totalMetric = new CounterMetric ();
36
37
final CounterMetric hitCount = new CounterMetric ();
37
38
final CounterMetric missCount = new CounterMetric ();
38
39
39
- public ShardRequestCache (ShardId shardId , IndexSettings indexSettings ) {
40
- super (shardId , indexSettings );
41
- }
42
-
43
40
public RequestCacheStats stats () {
44
41
return new RequestCacheStats (totalMetric .count (), evictionsMetric .count (), hitCount .count (), missCount .count ());
45
42
}
@@ -52,21 +49,20 @@ public void onMiss() {
52
49
missCount .inc ();
53
50
}
54
51
55
- public void onCached (IndicesRequestCache . Key key , IndicesRequestCache . Value value ) {
52
+ public void onCached (Accountable key , Accountable value ) {
56
53
totalMetric .inc (key .ramBytesUsed () + value .ramBytesUsed ());
57
54
}
58
55
59
- @ Override
60
- public void onRemoval (RemovalNotification <IndicesRequestCache .Key , IndicesRequestCache .Value > removalNotification ) {
61
- if (removalNotification .getRemovalReason () == RemovalNotification .RemovalReason .EVICTED ) {
56
+ public void onRemoval (Accountable key , Accountable value , boolean evicted ) {
57
+ if (evicted ) {
62
58
evictionsMetric .inc ();
63
59
}
64
60
long dec = 0 ;
65
- if (removalNotification . getKey () != null ) {
66
- dec += removalNotification . getKey () .ramBytesUsed ();
61
+ if (key != null ) {
62
+ dec += key .ramBytesUsed ();
67
63
}
68
- if (removalNotification . getValue () != null ) {
69
- dec += removalNotification . getValue () .ramBytesUsed ();
64
+ if (value != null ) {
65
+ dec += value .ramBytesUsed ();
70
66
}
71
67
totalMetric .dec (dec );
72
68
}
0 commit comments