1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.regionserver;
20
21 import java.util.concurrent.ConcurrentMap;
22 import java.util.concurrent.ConcurrentSkipListMap;
23 import java.util.concurrent.atomic.AtomicLong;
24
25 import org.apache.hadoop.hbase.classification.InterfaceAudience;
26 import org.apache.hadoop.hbase.util.Bytes;
27
28
29
30
31
32 @InterfaceAudience.Private
33 public class RegionServerAccounting {
34
35 private final AtomicLong atomicGlobalMemstoreSize = new AtomicLong(0);
36
37
38
39 private final ConcurrentMap<byte[], AtomicLong> replayEditsPerRegion =
40 new ConcurrentSkipListMap<byte[], AtomicLong>(Bytes.BYTES_COMPARATOR);
41
42
43
44
45 public long getGlobalMemstoreSize() {
46 return atomicGlobalMemstoreSize.get();
47 }
48
49
50
51
52
53
54 public long addAndGetGlobalMemstoreSize(long memStoreSize) {
55 return atomicGlobalMemstoreSize.addAndGet(memStoreSize);
56 }
57
58
59
60
61
62
63
64
65 public long addAndGetRegionReplayEditsSize(byte[] regionName, long memStoreSize) {
66 AtomicLong replayEdistsSize = replayEditsPerRegion.get(regionName);
67 if (replayEdistsSize == null) {
68 replayEdistsSize = new AtomicLong(0);
69 replayEditsPerRegion.put(regionName, replayEdistsSize);
70 }
71 return replayEdistsSize.addAndGet(memStoreSize);
72 }
73
74
75
76
77
78
79
80
81 public long rollbackRegionReplayEditsSize(byte[] regionName) {
82 AtomicLong replayEditsSize = replayEditsPerRegion.get(regionName);
83 long editsSizeLong = 0L;
84 if (replayEditsSize != null) {
85 editsSizeLong = -replayEditsSize.get();
86 clearRegionReplayEditsSize(regionName);
87 }
88 return addAndGetGlobalMemstoreSize(editsSizeLong);
89 }
90
91
92
93
94
95
96 public void clearRegionReplayEditsSize(byte[] regionName) {
97 replayEditsPerRegion.remove(regionName);
98 }
99
100 }