Skip to content

Commit 0a6774d

Browse files
committed
Merge branch 'cassandra-6.0' into trunk
* cassandra-6.0: Replace LongAdder in metric-like logic with ThreadLocalCounter
2 parents d8de51c + 454f62d commit 0a6774d

6 files changed

Lines changed: 46 additions & 39 deletions

File tree

CHANGES.txt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,8 @@
22
* Avoid using ObjectUtils.getFirstNonNull in Schema (CASSANDRA-21394)
33
* Allow nodetool garbagecollect to take a user defined list of SSTables (CASSANDRA-16767)
44
* Add a guardrail for misprepared statements (CASSANDRA-21139)
5-
6.0-alpha2
6-
* Ensure schema created before 2.1 without tableId in folder name can be loaded in SnapshotLoader (CASSANDRA-21246)
7-
* Differentiate between legitimate cases where the first entry is the same as the last entry and empty bounds in SSTableCursorWriter#addIndexBlock() (CASSANDRA-21255)
8-
* Introduce minimum_threshold for data resurrection startup check (CASSANDRA-21293)
9-
Merged from 5.0:
10-
* Use estimated compressed size for tables to check if there is enough free space for a compaction (CASSANDRA-21245)
11-
* Fix failing select on system_views.settings for non-string keys (CASSANDRA-21348)
12-
13-
14-
6.0-alpha2
5+
Merged from 6.0:
6+
* Replace LongAdder in metric-like logic with ThreadLocalCounter (CASSANDRA-21400)
157
* BTreeRow#hasLiveData: Avoid Cell iteration if there are no tombstones in a row (CASSANDRA-21363)
168
* Reduce memory allocations in row merge logic (CASSANDRA-21359)
179
* Restore option to avoid hint transfer during decommission (CASSANDRA-21341)
@@ -24,7 +16,16 @@ Merged from 5.0:
2416
* Avoid unit conversion in DatabaseDescriptor.getMaxValueSize() for every deserializing Cell (CASSANDRA-21295)
2517
* Fix single token batch atomicity with Accord/non-Accord batches by using the batch log (CASSANDRA-20588)
2618
* Avoid CompactionOptions parsing for every read by WithoutPurgeableTombstones (CASSANDRA-21294)
19+
* Ensure schema created before 2.1 without tableId in folder name can be loaded in SnapshotLoader (CASSANDRA-21246)
20+
* Differentiate between legitimate cases where the first entry is the same as the last entry and empty bounds in SSTableCursorWriter#addIndexBlock() (CASSANDRA-21255)
21+
* Introduce minimum_threshold for data resurrection startup check (CASSANDRA-21293)
2722
* Synchronously publish changes to local gossip state following metadata updates (CASSANDRA-21239)
23+
Merged from 5.0:
24+
* Use estimated compressed size for tables to check if there is enough free space for a compaction (CASSANDRA-21245)
25+
* Fix failing select on system_views.settings for non-string keys (CASSANDRA-21348)
26+
27+
28+
6.0-alpha2
2829
* Change default for cassandra.set_sep_thread_name to false to reduce CPU usage (CASSANDRA-21089)
2930
* Avoid permission checks for masked columns when the table doesn't have any (CASSANDRA-21299)
3031
* Reduce allocations and array copies due to buffer resizing in LocalDataResponse during row serialization (CASSANDRA-21285)

src/java/org/apache/cassandra/io/sstable/filter/BloomFilterTracker.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,36 @@
1818
package org.apache.cassandra.io.sstable.filter;
1919

2020
import java.util.concurrent.atomic.AtomicLong;
21-
import java.util.concurrent.atomic.LongAdder;
21+
22+
import org.apache.cassandra.metrics.ThreadLocalCounter;
2223

2324
public class BloomFilterTracker
2425
{
25-
private final LongAdder falsePositiveCount = new LongAdder();
26-
private final LongAdder truePositiveCount = new LongAdder();
27-
private final LongAdder trueNegativeCount = new LongAdder();
26+
private final ThreadLocalCounter falsePositiveCount = new ThreadLocalCounter();
27+
private final ThreadLocalCounter truePositiveCount = new ThreadLocalCounter();
28+
private final ThreadLocalCounter trueNegativeCount = new ThreadLocalCounter();
2829
private final AtomicLong lastFalsePositiveCount = new AtomicLong();
2930
private final AtomicLong lastTruePositiveCount = new AtomicLong();
3031
private final AtomicLong lastTrueNegativeCount = new AtomicLong();
3132

3233
public void addFalsePositive()
3334
{
34-
falsePositiveCount.increment();
35+
falsePositiveCount.inc();
3536
}
3637

3738
public void addTruePositive()
3839
{
39-
truePositiveCount.increment();
40+
truePositiveCount.inc();
4041
}
4142

4243
public void addTrueNegative()
4344
{
44-
trueNegativeCount.increment();
45+
trueNegativeCount.inc();
4546
}
4647

4748
public long getFalsePositiveCount()
4849
{
49-
return falsePositiveCount.sum();
50+
return falsePositiveCount.getCount();
5051
}
5152

5253
public long getRecentFalsePositiveCount()
@@ -58,7 +59,7 @@ public long getRecentFalsePositiveCount()
5859

5960
public long getTruePositiveCount()
6061
{
61-
return truePositiveCount.sum();
62+
return truePositiveCount.getCount();
6263
}
6364

6465
public long getRecentTruePositiveCount()
@@ -70,7 +71,7 @@ public long getRecentTruePositiveCount()
7071

7172
public long getTrueNegativeCount()
7273
{
73-
return trueNegativeCount.sum();
74+
return trueNegativeCount.getCount();
7475
}
7576

7677
public long getRecentTrueNegativeCount()

src/java/org/apache/cassandra/io/sstable/keycache/KeyCache.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
package org.apache.cassandra.io.sstable.keycache;
2020

21-
import java.util.concurrent.atomic.LongAdder;
22-
2321
import javax.annotation.Nonnull;
2422
import javax.annotation.Nullable;
2523

@@ -29,6 +27,7 @@
2927
import org.apache.cassandra.cache.InstrumentingCache;
3028
import org.apache.cassandra.cache.KeyCacheKey;
3129
import org.apache.cassandra.io.sstable.AbstractRowIndexEntry;
30+
import org.apache.cassandra.metrics.ThreadLocalCounter;
3231

3332
/**
3433
* A simple wrapper of possibly global cache with local metrics.
@@ -40,8 +39,8 @@ public class KeyCache
4039
private final static Logger logger = LoggerFactory.getLogger(KeyCache.class);
4140

4241
private final InstrumentingCache<KeyCacheKey, AbstractRowIndexEntry> cache;
43-
private final LongAdder hits = new LongAdder();
44-
private final LongAdder requests = new LongAdder();
42+
private final ThreadLocalCounter hits = new ThreadLocalCounter();
43+
private final ThreadLocalCounter requests = new ThreadLocalCounter();
4544

4645
public KeyCache(@Nullable InstrumentingCache<KeyCacheKey, AbstractRowIndexEntry> cache)
4746
{
@@ -50,12 +49,12 @@ public KeyCache(@Nullable InstrumentingCache<KeyCacheKey, AbstractRowIndexEntry>
5049

5150
public long getHits()
5251
{
53-
return cache != null ? hits.sum() : 0;
52+
return cache != null ? hits.getCount() : 0;
5453
}
5554

5655
public long getRequests()
5756
{
58-
return cache != null ? requests.sum() : 0;
57+
return cache != null ? requests.getCount() : 0;
5958
}
6059

6160
public void put(@Nonnull KeyCacheKey cacheKey, @Nonnull AbstractRowIndexEntry info)
@@ -74,10 +73,10 @@ public void put(@Nonnull KeyCacheKey cacheKey, @Nonnull AbstractRowIndexEntry in
7473

7574
if (updateStats)
7675
{
77-
requests.increment();
76+
requests.inc();
7877
AbstractRowIndexEntry r = cache.get(key);
7978
if (r != null)
80-
hits.increment();
79+
hits.inc();
8180
return r;
8281
}
8382
else

src/java/org/apache/cassandra/metrics/ThreadLocalCounter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,9 @@ public long getCount()
7373
{
7474
return ThreadLocalMetrics.getCount(metricId);
7575
}
76+
77+
public void reset()
78+
{
79+
ThreadLocalMetrics.getCountAndReset(metricId);
80+
}
7681
}

src/java/org/apache/cassandra/transport/ServerConnection.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import org.apache.cassandra.auth.IAuthenticator;
3030
import org.apache.cassandra.config.DatabaseDescriptor;
31+
import org.apache.cassandra.metrics.ThreadLocalCounter;
3132
import org.apache.cassandra.service.ClientState;
3233
import org.apache.cassandra.service.QueryState;
3334

@@ -41,7 +42,7 @@ public class ServerConnection extends Connection
4142
private volatile IAuthenticator.SaslNegotiator saslNegotiator;
4243
private final ClientState clientState;
4344
private volatile ConnectionStage stage;
44-
public final Counter requests = new Counter();
45+
public final Counter requests = new ThreadLocalCounter();
4546

4647
ServerConnection(Channel channel, ProtocolVersion version, Connection.Tracker tracker)
4748
{

src/java/org/apache/cassandra/utils/memory/BufferPool.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import java.util.concurrent.atomic.AtomicLong;
3434
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
3535
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
36-
import java.util.concurrent.atomic.LongAdder;
3736
import java.util.function.BiPredicate;
3837
import java.util.function.Consumer;
3938
import java.util.function.Supplier;
@@ -48,6 +47,7 @@
4847
import org.apache.cassandra.concurrent.Shutdownable;
4948
import org.apache.cassandra.io.compress.BufferType;
5049
import org.apache.cassandra.metrics.BufferPoolMetrics;
50+
import org.apache.cassandra.metrics.ThreadLocalCounter;
5151
import org.apache.cassandra.utils.NoSpamLogger;
5252
import org.apache.cassandra.utils.Shared;
5353
import org.apache.cassandra.utils.concurrent.Ref;
@@ -150,12 +150,12 @@ public class BufferPool
150150
/**
151151
* Size of unpooled buffer being allocated outside of buffer pool in bytes.
152152
*/
153-
private final LongAdder overflowMemoryUsage = new LongAdder();
153+
private final ThreadLocalCounter overflowMemoryUsage = new ThreadLocalCounter();
154154

155155
/**
156156
* Size of buffer being used in bytes, including pooled buffer and unpooled buffer.
157157
*/
158-
private final LongAdder memoryInUse = new LongAdder();
158+
private final ThreadLocalCounter memoryInUse = new ThreadLocalCounter();
159159

160160
/**
161161
* Size of allocated buffer pool slabs in bytes
@@ -264,7 +264,7 @@ public void putUnusedPortion(ByteBuffer buffer)
264264

265265
private void updateOverflowMemoryUsage(int size)
266266
{
267-
overflowMemoryUsage.add(size);
267+
overflowMemoryUsage.inc(size);
268268
}
269269

270270
public void setRecycleWhenFreeForCurrentThread(boolean recycleWhenFree)
@@ -277,23 +277,23 @@ public void setRecycleWhenFreeForCurrentThread(boolean recycleWhenFree)
277277
*/
278278
public long sizeInBytes()
279279
{
280-
return memoryAllocated.get() + overflowMemoryUsage.longValue();
280+
return memoryAllocated.get() + overflowMemoryUsage.getCount();
281281
}
282282

283283
/**
284284
* @return buffer size being used, including used pooled buffers and unpooled buffers
285285
*/
286286
public long usedSizeInBytes()
287287
{
288-
return memoryInUse.longValue() + overflowMemoryUsage.longValue();
288+
return memoryInUse.getCount() + overflowMemoryUsage.getCount();
289289
}
290290

291291
/**
292292
* @return unpooled buffer size being allocated outside of buffer pool.
293293
*/
294294
public long overflowMemoryInBytes()
295295
{
296-
return overflowMemoryUsage.longValue();
296+
return overflowMemoryUsage.getCount();
297297
}
298298

299299
/**
@@ -825,7 +825,7 @@ public void put(ByteBuffer buffer)
825825
else
826826
{
827827
put(buffer, chunk);
828-
memoryInUse.add(-size);
828+
memoryInUse.dec(size);
829829
}
830830
}
831831

@@ -892,7 +892,7 @@ public void putUnusedPortion(ByteBuffer buffer)
892892

893893
chunk.freeUnusedPortion(buffer);
894894
// Calculate the actual freed bytes which may be different from `size` when pooling is involved
895-
memoryInUse.add(buffer.capacity() - originalCapacity);
895+
memoryInUse.inc(buffer.capacity() - originalCapacity);
896896
}
897897

898898
public ByteBuffer get(int size)
@@ -951,7 +951,7 @@ else if (size > NORMAL_CHUNK_SIZE)
951951
if (ret != null)
952952
{
953953
metrics.hits.mark();
954-
memoryInUse.add(ret.capacity());
954+
memoryInUse.inc(ret.capacity());
955955
}
956956
else
957957
{

0 commit comments

Comments
 (0)