Skip to content

Commit 7365414

Browse files
Workaround for https://bugs.openjdk.org/browse/JDK-8323659 regression, introduced in JDK-21.0.2 (#11968) (#11988)
(cherry picked from commit 48fdb4f) Signed-off-by: Andriy Redko <andriy.redko@aiven.io> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 12fb0e5 commit 7365414

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
118118
- Use slice_size == shard_size heuristic in terms aggs for concurrent segment search and properly calculate the doc_count_error ([#11732](https://github.com/opensearch-project/OpenSearch/pull/11732))
119119
- Ensure Jackson default maximums introduced in 2.16.0 do not conflict with OpenSearch settings ([#11890](https://github.com/opensearch-project/OpenSearch/pull/11890))
120120
- Extract cluster management for integration tests into JUnit test rule out of OpenSearchIntegTestCase ([#11877](https://github.com/opensearch-project/OpenSearch/pull/11877))
121+
- Workaround for https://bugs.openjdk.org/browse/JDK-8323659 regression, introduced in JDK-21.0.2 ([#11968](https://github.com/opensearch-project/OpenSearch/pull/11968))
121122

122123
### Deprecated
123124

server/src/main/java/org/opensearch/common/util/concurrent/OpenSearchExecutors.java

+24
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,30 @@ public boolean offer(E e) {
449449
}
450450
}
451451

452+
/**
453+
* Workaround for https://bugs.openjdk.org/browse/JDK-8323659 regression, introduced in JDK-21.0.2.
454+
*/
455+
@Override
456+
public void put(E e) {
457+
super.offer(e);
458+
}
459+
460+
/**
461+
* Workaround for https://bugs.openjdk.org/browse/JDK-8323659 regression, introduced in JDK-21.0.2.
462+
*/
463+
@Override
464+
public boolean offer(E e, long timeout, TimeUnit unit) {
465+
return super.offer(e);
466+
}
467+
468+
/**
469+
* Workaround for https://bugs.openjdk.org/browse/JDK-8323659 regression, introduced in JDK-21.0.2.
470+
*/
471+
@Override
472+
public boolean add(E e) {
473+
return super.offer(e);
474+
}
475+
452476
}
453477

454478
/**

server/src/test/java/org/opensearch/common/util/concurrent/OpenSearchExecutorsTests.java

+36
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import static org.hamcrest.Matchers.containsString;
5050
import static org.hamcrest.Matchers.equalTo;
5151
import static org.hamcrest.Matchers.lessThan;
52+
import static org.hamcrest.Matchers.lessThanOrEqualTo;
5253

5354
/**
5455
* Tests for OpenSearchExecutors and its components like OpenSearchAbortPolicy.
@@ -279,6 +280,41 @@ public void testScaleDown() throws Exception {
279280
terminate(pool);
280281
}
281282

283+
/**
284+
* The test case is adapted from https://bugs.openjdk.org/browse/JDK-8323659 reproducer.
285+
*/
286+
public void testScaleUpWithSpawningTask() throws Exception {
287+
ThreadPoolExecutor pool = OpenSearchExecutors.newScaling(
288+
getClass().getName() + "/" + getTestName(),
289+
0,
290+
1,
291+
between(1, 100),
292+
randomTimeUnit(),
293+
OpenSearchExecutors.daemonThreadFactory("test"),
294+
threadContext
295+
);
296+
assertThat("Min property", pool.getCorePoolSize(), equalTo(0));
297+
assertThat("Max property", pool.getMaximumPoolSize(), equalTo(1));
298+
299+
final CountDownLatch latch = new CountDownLatch(10);
300+
class TestTask implements Runnable {
301+
@Override
302+
public void run() {
303+
latch.countDown();
304+
if (latch.getCount() > 0) {
305+
pool.execute(TestTask.this);
306+
}
307+
}
308+
}
309+
pool.execute(new TestTask());
310+
latch.await();
311+
312+
assertThat("wrong pool size", pool.getPoolSize(), lessThanOrEqualTo(1));
313+
assertThat("wrong active size", pool.getActiveCount(), lessThanOrEqualTo(1));
314+
315+
terminate(pool);
316+
}
317+
282318
public void testRejectionMessageAndShuttingDownFlag() throws InterruptedException {
283319
int pool = between(1, 10);
284320
int queue = between(0, 100);

0 commit comments

Comments
 (0)