You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "michaelsembwever (via GitHub)" <gi...@apache.org> on 2025/11/08 14:02:37 UTC
Re: [PR] [CASSANDRA-20226][trunk] Reduce contention in NativeAllocator.allocate [cassandra]
michaelsembwever commented on code in PR #4415:
URL: https://github.com/apache/cassandra/pull/4415#discussion_r2506934896
##########
src/java/org/apache/cassandra/utils/memory/NativeAllocator.java:
##########
@@ -104,30 +104,98 @@ public DecoratedKey clone(DecoratedKey key, OpOrder.Group writeOp)
@Override
public Cloner cloner(Group opGroup)
{
- return new Cloner()
- {
-
- @Override
- public DecoratedKey clone(DecoratedKey key)
- {
- return NativeAllocator.this.clone(key, opGroup);
- }
-
- @Override
- public Clustering<?> clone(Clustering<?> clustering)
- {
- if (clustering != Clustering.STATIC_CLUSTERING)
- return new NativeClustering(NativeAllocator.this, opGroup, clustering);
-
- return Clustering.STATIC_CLUSTERING;
- }
-
- @Override
- public Cell<?> clone(Cell<?> cell)
- {
- return new NativeCell(NativeAllocator.this, opGroup, cell);
- }
- };
+ return new NativeCloner(this, opGroup);
+ }
+
+ private static class NativeCloner implements Cloner, AddressBasedAllocator
+ {
+ private final NativeAllocator allocator;
+ private final Group opGroup;
+
+ private final long address;
+ private final int limit;
+ private int offset = 0;
+
+ private NativeCloner(NativeAllocator allocator, Group opGroup)
+ {
+ this(allocator, opGroup, 0);
+ }
+
+ private NativeCloner(NativeAllocator allocator, Group opGroup, int size)
+ {
+ this.allocator = allocator;
+ this.opGroup = opGroup;
+ this.limit = size;
+ this.address = size > 0 ? allocator.allocate(size, opGroup) : -1;
+ }
+
+ @Override
+ public DecoratedKey clone(DecoratedKey key)
+ {
+ return allocator.clone(key, opGroup);
+ }
+
+ @Override
+ public Clustering<?> clone(Clustering<?> clustering)
+ {
+ if (clustering != Clustering.STATIC_CLUSTERING)
+ return new NativeClustering(this, opGroup, clustering);
+
+ return Clustering.STATIC_CLUSTERING;
Review Comment:
nit: style
```
return (Clustering.STATIC_CLUSTERING == clustering) ? clustering : new NativeClustering(this, opGroup, clustering);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org