Skip to content

Commit 6105940

Browse files
authored
Move native_allocator under native_memory; replace PluginNodeStats SPI with typed NodeStats field (opensearch-project#21820)
* Move native_allocator under native_memory; replace PluginNodeStats SPI Consolidates Arrow native allocator stats under nodes.<id>.native_memory.native_allocator (was a top-level sibling at nodes.<id>.native_allocator) and replaces the experimental PluginNodeStats SPI with a typed NativeAllocatorPoolStats field on NodeStats. Strips peak_bytes, child_count, and humanReadableField byte-string duplicates from the allocator JSON. Pool and root blocks now expose only allocated_bytes and limit_bytes. Adds new metric: GET /_nodes/stats/native_allocator Removes metric: GET /_nodes/stats/plugin_stats (no production consumer) PluginNodeStats and Plugin.nodeStats() were @experimentalapi with one production consumer (arrow-base) and an unreleased wire format (Version.V_3_7_0). Replaced with a small ArrowAllocatorPlugin SPI in libs/arrow-spi so server can inject the allocator into NodeService without depending on the arrow-base plugin. Signed-off-by: Gaurav Singh <snghsvn@amazon.com>
1 parent 1878f4a commit 6105940

25 files changed

Lines changed: 543 additions & 593 deletions

File tree

libs/arrow-spi/src/main/java/org/opensearch/arrow/spi/NativeAllocator.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ public interface NativeAllocator extends Closeable {
5252
*/
5353
void setRootLimit(long limit);
5454

55-
/**
56-
* Collects a point-in-time stats snapshot across all pools.
57-
*/
58-
NativeAllocatorPoolStats stats();
59-
6055
/**
6156
* Opaque handle to a memory pool. Plugins downcast to the concrete type
6257
* (e.g., Arrow's {@code BufferAllocator}) in the implementation layer.

plugins/arrow-base/src/main/java/org/opensearch/arrow/allocator/ArrowBasePlugin.java

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
import org.opensearch.env.Environment;
2121
import org.opensearch.env.NodeEnvironment;
2222
import org.opensearch.node.resource.tracker.ResourceTrackerSettings;
23+
import org.opensearch.plugin.stats.NativeAllocatorPoolStats;
24+
import org.opensearch.plugin.stats.NativeAllocatorStatsRegistry;
2325
import org.opensearch.plugins.ExtensiblePlugin;
2426
import org.opensearch.plugins.Plugin;
25-
import org.opensearch.plugins.PluginNodeStats;
2627
import org.opensearch.repositories.RepositoriesService;
2728
import org.opensearch.script.ScriptService;
2829
import org.opensearch.threadpool.ThreadPool;
@@ -252,7 +253,15 @@ public Collection<Object> createComponents(
252253
ClusterSettings cs = clusterService.getClusterSettings();
253254
ArrowNativeAllocator built = buildAllocator(settings, cs);
254255
this.allocator = built;
255-
return List.of(built);
256+
// Publish a NativeAllocatorStatsRegistry alongside the allocator so the server-side
257+
// NodeService can discover the supplier via pluginComponents (instanceof filter) without
258+
// taking a compile-time dependency on this plugin. The lambda re-reads `this.allocator`
259+
// each invocation, so after close() nulls the field, the supplier returns null cleanly.
260+
Supplier<NativeAllocatorPoolStats> statsSupplier = () -> {
261+
ArrowNativeAllocator a = this.allocator;
262+
return a != null ? a.stats() : null;
263+
};
264+
return List.of(built, new NativeAllocatorStatsRegistry(statsSupplier));
256265
}
257266

258267
/**
@@ -347,21 +356,6 @@ public List<Setting<?>> getSettings() {
347356
);
348357
}
349358

350-
@Override
351-
public List<PluginNodeStats> nodeStats() {
352-
if (allocator == null) {
353-
return List.of();
354-
}
355-
return List.of(new NativeAllocatorPluginStats(allocator.stats()));
356-
}
357-
358-
@Override
359-
public List<NamedWriteableRegistry.Entry> getNamedWriteables() {
360-
return List.of(
361-
new NamedWriteableRegistry.Entry(PluginNodeStats.class, NativeAllocatorPluginStats.NAME, NativeAllocatorPluginStats::new)
362-
);
363-
}
364-
365359
private static void validateMinMax(String poolName, long min, long max) {
366360
if (min > max) {
367361
throw new IllegalArgumentException("Pool '" + poolName + "' min (" + min + ") exceeds max (" + max + ")");

plugins/arrow-base/src/main/java/org/opensearch/arrow/allocator/ArrowNativeAllocator.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import org.apache.arrow.memory.BufferAllocator;
1212
import org.apache.arrow.memory.RootAllocator;
1313
import org.opensearch.arrow.spi.NativeAllocator;
14-
import org.opensearch.arrow.spi.NativeAllocatorPoolStats;
14+
import org.opensearch.plugin.stats.NativeAllocatorPoolStats;
1515

1616
import java.util.ArrayList;
1717
import java.util.Collections;
@@ -176,7 +176,12 @@ public void setRootLimit(long limit) {
176176
root.setLimit(limit);
177177
}
178178

179-
@Override
179+
/**
180+
* Returns a point-in-time stats snapshot across all pools. Used by the
181+
* {@code NativeAllocatorStatsRegistry} component published from
182+
* {@code ArrowBasePlugin.createComponents()} and wired into {@code NodeService} to
183+
* render allocator state under {@code _nodes/stats[/native_allocator]}.
184+
*/
180185
public NativeAllocatorPoolStats stats() {
181186
List<NativeAllocatorPoolStats.PoolStats> poolStats = new ArrayList<>();
182187
for (var entry : pools.entrySet()) {
@@ -186,8 +191,7 @@ public NativeAllocatorPoolStats stats() {
186191
entry.getKey(),
187192
alloc.getAllocatedMemory(),
188193
alloc.getPeakMemoryAllocation(),
189-
alloc.getLimit(),
190-
alloc.getChildAllocators().size()
194+
alloc.getLimit()
191195
)
192196
);
193197
}

plugins/arrow-base/src/main/java/org/opensearch/arrow/allocator/NativeAllocatorPluginStats.java

Lines changed: 0 additions & 93 deletions
This file was deleted.

plugins/arrow-base/src/test/java/org/opensearch/arrow/allocator/ArrowNativeAllocatorTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import org.apache.arrow.memory.BufferAllocator;
1212
import org.opensearch.arrow.spi.NativeAllocator;
13-
import org.opensearch.arrow.spi.NativeAllocatorPoolStats;
13+
import org.opensearch.plugin.stats.NativeAllocatorPoolStats;
1414
import org.opensearch.test.OpenSearchTestCase;
1515

1616
public class ArrowNativeAllocatorTests extends OpenSearchTestCase {
@@ -86,7 +86,8 @@ public void testStats() {
8686
assertEquals("stats-pool", poolStats.getName());
8787
assertEquals(64 * 1024 * 1024, poolStats.getLimitBytes());
8888
assertEquals(0, poolStats.getAllocatedBytes());
89-
assertEquals(0, poolStats.getChildCount());
89+
// child_count is no longer rendered in stats; getPoolAllocator(...).getChildAllocators()
90+
// is the runtime accessor for that detail if needed.
9091
}
9192

9293
public void testStatsMultiplePools() {

plugins/arrow-base/src/test/java/org/opensearch/arrow/allocator/NativeAllocatorPluginStatsTests.java

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)