`GatewayService` implements logic for delaying state recovery in the cluster until enough data nodes have joined and/or some timeout has occurred. The implementation is pretty old and doesn't make use of much modern infrastructure for doing this kind of thing, making it pretty hard to follow and to improve (see e.g. #86588). We should clean it up and simplify it.
test/framework/src/main/java/org/elasticsearch/common/util/concurrent/DeterministicTaskQueue.java
final Runnable contextPreservingRunnable = getThreadContext().preserveContext(command);
                scheduleAt(currentTimeMillis + delay.millis(), runnableWrapper.apply(new Runnable() {
                    @Override
                    public void run() {
                        if (taskState.compareAndSet(NOT_STARTED, STARTED)) {
                            contextPreservingRunnable.run();
                        }
                    }
                    @Override
                    public String toString() {
                        return command.toString();
                    }
                }));
                return new ScheduledCancellable() {
                    @Override
                    public long getDelay(TimeUnit unit) {
                        throw new UnsupportedOperationException();
                    }
                    @Override
                    public int compareTo(Delayed o) {
                        throw new UnsupportedOperationException();
                    }
                    @Override
                    public boolean cancel() {
                        return taskState.compareAndSet(NOT_STARTED, CANCELLED);
                    }
                    @Override
                    public boolean isCancelled() {
                        return taskState.get() == CANCELLED;
                    }