Skip to content

Commit 3e09b91

Browse files
authored
Merge pull request #8879 from knutwalker/2.6-arrow-authentication-issue
Avoid invalidation of user login state in Arrow server
2 parents ba0a67e + f7f1a03 commit 3e09b91

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

core-utils/src/main/java/org/neo4j/gds/core/utils/ClockService.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,31 @@
2020
package org.neo4j.gds.core.utils;
2121

2222
import java.time.Clock;
23+
import java.util.concurrent.atomic.AtomicReference;
24+
import java.util.function.Consumer;
2325

2426
public final class ClockService {
2527

2628
private static final Clock SYSTEM_CLOCK = Clock.systemUTC();
2729

28-
private static Clock CLOCK = SYSTEM_CLOCK;
30+
private static final AtomicReference<Clock> CLOCK = new AtomicReference<>(SYSTEM_CLOCK);
2931

3032
public static void setClock(Clock clock) {
31-
CLOCK = clock;
33+
CLOCK.set(clock);
3234
}
3335

3436
public static Clock clock() {
35-
return CLOCK;
37+
return CLOCK.get();
3638
}
3739

3840
private ClockService() {}
41+
42+
public static <T extends Clock> void runWithClock(T clock, Consumer<T> runnable) {
43+
Clock previousClock = CLOCK.getAndSet(clock);
44+
try {
45+
runnable.accept(clock);
46+
} finally {
47+
CLOCK.set(previousClock);
48+
}
49+
}
3950
}

core/src/main/java/org/neo4j/gds/core/concurrency/ExecutorServiceUtil.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.concurrent.ForkJoinPool;
3030
import java.util.concurrent.FutureTask;
3131
import java.util.concurrent.RejectedExecutionHandler;
32+
import java.util.concurrent.ScheduledExecutorService;
3233
import java.util.concurrent.ThreadFactory;
3334
import java.util.concurrent.ThreadPoolExecutor;
3435
import java.util.concurrent.TimeUnit;
@@ -49,6 +50,10 @@ public static ExecutorService createSingleThreadPool(String threadPrefix) {
4950
return Executors.newSingleThreadExecutor(NamedThreadFactory.daemon(threadPrefix));
5051
}
5152

53+
public static ScheduledExecutorService createSingleThreadScheduler(String threadPrefix) {
54+
return Executors.newSingleThreadScheduledExecutor(NamedThreadFactory.daemon(threadPrefix));
55+
}
56+
5257
static ExecutorService createThreadPool(int corePoolSize, int maxPoolSize) {
5358
return createThreadPool(THREAD_NAME_PREFIX, corePoolSize, maxPoolSize);
5459
}

0 commit comments

Comments
 (0)