Skip to content

Commit 4790ecf

Browse files
dougqhclaude
andcommitted
Reach State only through the statics in AggregateTable
Addresses the review comments on #12312, with the API additions made in #12101 and percolated here: state.sizeManager.size() -> Hashtable.size(state) ... == 0 -> Hashtable.isEmpty(state) bucketFor(state.buckets, hash) -> bucketFor(state, hash) insertHeadEntryFor(state.buckets, ...) -> insertReserved(state, ...) forEach(state.buckets, ...) -> forEach(state, ...) No reference to state.buckets or state.sizeManager remains -- what State holds is now its own business. Also drops the field comment that re-documented the eviction cursor living inside it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent d140558 commit 4790ecf

1 file changed

Lines changed: 6 additions & 11 deletions

File tree

‎dd-trace-core/src/main/java/datadog/trace/common/metrics/AggregateTable.java‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ final class AggregateTable {
3131
*/
3232
private static final Predicate<AggregateEntry> STALE = AggregateEntry::isStale;
3333

34-
/**
35-
* Bucket spine plus the manager that keeps it within {@code maxAggregates} -- the manager also
36-
* owns the resumable eviction scan, so consecutive evictions don't re-walk the same hot entries
37-
* clustered near bucket 0.
38-
*/
3934
private final Hashtable.State<AggregateEntry> state;
4035

4136
private final AggregateEntry.Canonical canonical;
@@ -59,11 +54,11 @@ void resetCoreHandlers(HealthMetrics healthMetrics, CardinalityLimitReporter rep
5954
}
6055

6156
int size() {
62-
return state.sizeManager.size();
57+
return Hashtable.size(state);
6358
}
6459

6560
boolean isEmpty() {
66-
return state.sizeManager.size() == 0;
61+
return Hashtable.isEmpty(state);
6762
}
6863

6964
/**
@@ -74,7 +69,7 @@ boolean isEmpty() {
7469
AggregateEntry findOrInsert(SpanSnapshot snapshot) {
7570
canonical.populateFrom(snapshot);
7671
long keyHash = canonical.keyHash;
77-
for (AggregateEntry candidate = Hashtable.bucketFor(state.buckets, keyHash);
72+
for (AggregateEntry candidate = Hashtable.bucketFor(state, keyHash);
7873
candidate != null;
7974
candidate = candidate.next()) {
8075
if (candidate.keyHash == keyHash && canonical.matches(candidate)) {
@@ -87,7 +82,7 @@ AggregateEntry findOrInsert(SpanSnapshot snapshot) {
8782
return null;
8883
}
8984
AggregateEntry entry = canonical.createEntry();
90-
Hashtable.insertHeadEntryFor(state.buckets, keyHash, entry);
85+
Hashtable.insertReserved(state, keyHash, entry);
9186
return entry;
9287
}
9388

@@ -109,7 +104,7 @@ AggregateEntry findOrInsert(SpanSnapshot snapshot) {
109104
* backstop.
110105
*/
111106
void forEach(Consumer<AggregateEntry> consumer) {
112-
Hashtable.forEach(state.buckets, consumer);
107+
Hashtable.forEach(state, consumer);
113108
}
114109

115110
/**
@@ -118,7 +113,7 @@ void forEach(Consumer<AggregateEntry> consumer) {
118113
* plus whatever side-band state it needs as {@code context}.
119114
*/
120115
<C> void forEach(C context, BiConsumer<C, AggregateEntry> consumer) {
121-
Hashtable.forEach(state.buckets, context, consumer);
116+
Hashtable.forEach(state, context, consumer);
122117
}
123118

124119
/** Removes entries whose {@code getHitCount() == 0}. */

0 commit comments

Comments
 (0)