Skip to content

Commit 34c5114

Browse files
authored
Merge branch 'main' into flush_with_sorting
2 parents bada5b6 + 139bc58 commit 34c5114

80 files changed

Lines changed: 3672 additions & 437 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,14 @@ public void close() {
179179
}
180180
});
181181
pools.clear();
182+
// Close any remaining child allocators (e.g., ad-hoc children created via ArrowAllocatorService)
183+
for (BufferAllocator child : new ArrayList<>(root.getChildAllocators())) {
184+
try {
185+
child.close();
186+
} catch (Exception e) {
187+
// best-effort — log but don't block shutdown
188+
}
189+
}
182190
root.close();
183191
INSTANCE = null;
184192
}

plugins/cache-ehcache/src/test/java/org/opensearch/cache/store/disk/EhCacheDiskCacheTests.java

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

1111
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
1212

13+
import org.apache.lucene.tests.util.LuceneTestCase.AwaitsFix;
1314
import org.opensearch.cache.EhcacheDiskCacheSettings;
1415
import org.opensearch.common.Randomness;
1516
import org.opensearch.common.cache.CacheType;
@@ -354,6 +355,7 @@ public void testEvictions() throws Exception {
354355
}
355356
}
356357

358+
@AwaitsFix(bugUrl = "Flaky test - fix before enabling")
357359
public void testComputeIfAbsentConcurrently() throws Exception {
358360
Settings settings = Settings.builder().build();
359361
MockRemovalListener<String, String> removalListener = new MockRemovalListener<>();
@@ -558,6 +560,7 @@ public String load(ICacheKey<String> key) throws Exception {
558560
}
559561
}
560562

563+
@AwaitsFix(bugUrl = "Flaky test - fix before enabling")
561564
public void testComputeIfAbsentWithNullValueLoading() throws Exception {
562565
Settings settings = Settings.builder().build();
563566
MockRemovalListener<String, String> removalListener = new MockRemovalListener<>();

sandbox/libs/dataformat-native/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ description = 'Shared native bridge utilities for OpenSearch sandbox plugins'
1313
dependencies {
1414
api project(':libs:opensearch-core')
1515
api project(':libs:opensearch-common')
16+
compileOnly project(':server')
1617
implementation "org.apache.logging.log4j:log4j-api:${versions.log4j}"
1718
compileOnly "org.apache.arrow:arrow-c-data:${versions.arrow}"
1819

sandbox/libs/dataformat-native/licenses/log4j-api-2.25.4.jar.sha1

Lines changed: 0 additions & 1 deletion
This file was deleted.

sandbox/libs/dataformat-native/licenses/log4j-api-LICENSE.txt

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

sandbox/libs/dataformat-native/licenses/log4j-api-NOTICE.txt

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

sandbox/libs/dataformat-native/rust/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ async-trait = "=0.1.89"
7272
bytes = "=1.11.1"
7373
criterion = { version = "=0.5.1", features = ["async_tokio"] }
7474
tokio-metrics = { version = "=0.5.0", features = ["rt"] }
75+
proptest = "=1.4.0"
7576

7677
# Internal
7778
native-bridge-common = { path = "common" }

sandbox/libs/dataformat-native/src/main/java/org/opensearch/nativebridge/spi/NativeLibraryLoader.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,19 @@ public static SymbolLookup symbolLookup() {
7373
return Holder.LOOKUP;
7474
}
7575

76+
/**
77+
* Returns {@code true} if the native library has been (or can be) successfully loaded.
78+
* This method does not throw — it returns {@code false} if loading fails.
79+
*/
80+
public static boolean isLoaded() {
81+
try {
82+
symbolLookup();
83+
return true;
84+
} catch (Throwable t) {
85+
return false;
86+
}
87+
}
88+
7689
// ---- Error handling ----
7790

7891
/**
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.nativebridge.spi;
10+
11+
import org.apache.logging.log4j.LogManager;
12+
import org.apache.logging.log4j.Logger;
13+
import org.opensearch.plugin.stats.AnalyticsBackendNativeMemoryStats;
14+
15+
import java.lang.foreign.FunctionDescriptor;
16+
import java.lang.foreign.Linker;
17+
import java.lang.foreign.SymbolLookup;
18+
import java.lang.foreign.ValueLayout;
19+
import java.lang.invoke.MethodHandle;
20+
21+
/**
22+
* Stateless FFM fetcher for jemalloc memory metrics.
23+
* No caching, no server dependencies — just raw downcalls.
24+
*/
25+
public class NativeMemoryFetcher {
26+
27+
private static final Logger logger = LogManager.getLogger(NativeMemoryFetcher.class);
28+
29+
private static final MethodHandle ALLOCATED;
30+
private static final MethodHandle RESIDENT;
31+
32+
static {
33+
SymbolLookup lookup = NativeLibraryLoader.symbolLookup();
34+
Linker linker = Linker.nativeLinker();
35+
FunctionDescriptor desc = FunctionDescriptor.of(ValueLayout.JAVA_LONG);
36+
ALLOCATED = linker.downcallHandle(lookup.find("native_jemalloc_allocated_bytes").orElseThrow(), desc);
37+
RESIDENT = linker.downcallHandle(lookup.find("native_jemalloc_resident_bytes").orElseThrow(), desc);
38+
}
39+
40+
private NativeMemoryFetcher() {}
41+
42+
/**
43+
* Performs FFM downcalls and returns a fresh AnalyticsBackendNativeMemoryStats snapshot.
44+
* Returns AnalyticsBackendNativeMemoryStats(-1, -1) on error or negative values.
45+
*/
46+
public static AnalyticsBackendNativeMemoryStats fetch() {
47+
try {
48+
long allocated = (long) ALLOCATED.invokeExact();
49+
long resident = (long) RESIDENT.invokeExact();
50+
if (allocated < 0 || resident < 0) {
51+
logger.warn("Native memory stats returned error: allocated={}, resident={}", allocated, resident);
52+
return new AnalyticsBackendNativeMemoryStats(-1, -1);
53+
}
54+
return new AnalyticsBackendNativeMemoryStats(allocated, resident);
55+
} catch (Throwable t) {
56+
logger.warn("Error fetching native memory stats", t);
57+
return new AnalyticsBackendNativeMemoryStats(-1, -1);
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)