zstan commented on code in PR #13874:
URL: https://github.com/apache/ignite/pull/13874#discussion_r4739186141
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/ssl/SslFactoryRegistry.java:
##########
@@ -128,146 +123,202 @@ private long consecutiveHotReloadFailures() {
return sum;
}
- /** Runs the hourly check of the factories with hot reload enabled. */
- private void checkFactories() {
- if (log.isDebugEnabled())
- log.debug("TLS hot reload check started");
-
- for (RegisteredFactory registered : factories) {
- if (registered.hotReloadFactory() != null)
- registered.check();
- }
- }
-
/** {@inheritDoc} */
@Override public void onKernalStop(boolean cancel) {
if (executor != null)
executor.shutdownNow();
}
/**
- * Reloads a registered factory. For a factory with hot reload enabled,
waits for its running check and resets its failure
- * count.
+ * Reloads a registered factory. If the factory has automatic checks,
waits for its running check, resets its failure
+ * count and schedules its next check for the loaded certificates. If they
are already due, the next check comes after
+ * {@link #CHECK_PERIOD}, because an automatic reload right away would
load the same certificates from the source. If the
+ * factory cannot give the automatic reload time of the loaded
certificates, the reload still succeeds, and the next check
+ * comes after {@link #CHECK_PERIOD}. The node start schedules the first
check of each factory with automatic reload
+ * enabled, so a reload before the start only loads the factory.
*
* @param factory Registered factory to reload.
*/
- public void reload(AbstractSslContextFactory factory) {
+ public void reload(ReloadableSslFactory factory) {
for (RegisteredFactory registered : factories) {
if (registered.factory == factory)
registered.reload();
}
}
- /** Registered factory with its transports and hot reload state. The
hourly check and manual reload hold its monitor. */
+ /** Registered factory with its transports and automatic reload state. Its
checks and manual reload hold its monitor. */
private class RegisteredFactory {
/** */
private final Factory<SSLContext> factory;
+ /** The factory if the registry can reload it, {@code null} otherwise.
*/
+ @Nullable private final ReloadableSslFactory reloadable;
+
/** */
private final String transports;
/** */
private final AtomicInteger failures = new AtomicInteger();
+ /** Next automatic check, or {@code null} if the factory has no
automatic checks. */
+ @Nullable private ScheduledFuture<?> nextCheck;
+
+ /** Automatic reload time that the registry logged last, or {@code -1}
before the first log. */
+ private long loggedAutoReloadTime = -1;
+
/** */
private RegisteredFactory(Factory<SSLContext> factory, String
transports) {
this.factory = factory;
this.transports = transports;
- }
- /** @return The factory if hot reload is enabled for it, {@code null}
otherwise. */
- @Nullable private AbstractSslContextFactory hotReloadFactory() {
- return factory instanceof AbstractSslContextFactory sslFactory &&
sslFactory.isHotReloadEnabled() ? sslFactory : null;
+ reloadable = factory instanceof ReloadableSslFactory sslFactory ?
sslFactory : null;
}
/**
- * Checks the factory unless the registry has stopped. Counts and logs
a failed check, so it does not stop
- * the other factories or the schedule. A check that fails while the
registry stops is logged at debug level
- * and not counted.
+ * Checks the factory unless the registry has stopped, and schedules
its next check. Counts and logs a failed
+ * check and retries it after {@link #CHECK_PERIOD}, so a failure does
not stop the checks. A check that fails
+ * while the registry stops is logged at debug level and not counted.
*/
private synchronized void check() {
if (executor.isShutdown())
return;
+ if (log.isDebugEnabled())
+ log.debug("TLS automatic reload check started [transports=" +
transports + ']');
+
+ long nextCheckDelay = CHECK_PERIOD;
+
try {
- reloadIfDue();
+ nextCheckDelay = reloadIfDue();
}
catch (Throwable e) {
if (!executor.isShutdown()) {
failures.incrementAndGet();
- log.warning("TLS hot reload failed [transports=" +
transports + ", nextAttempt="
+ log.warning("TLS automatic reload failed [transports=" +
transports + ", nextAttempt="
+ new Date(System.currentTimeMillis() + CHECK_PERIOD)
+ ']', e);
}
else if (log.isDebugEnabled())
- log.debug("TLS hot reload failed during node stop
[transports=" + transports + ", err=" + e + ']');
+ log.debug("TLS automatic reload failed during node stop
[transports=" + transports + ", err=" + e + ']');
}
+
+ scheduleCheck(nextCheckDelay);
}
/**
- * Reloads the factory if its hot reload time has come, and ends the
failure streak if it has not.
+ * Reloads the factory if its automatic reload time has come, and ends
the failure streak if it has not.
*
+ * @return Delay of the next check.
* @throws IgniteException If the reload fails or leaves certificates
that are still due.
*/
- private void reloadIfDue() {
- AbstractSslContextFactory sslFactory =
(AbstractSslContextFactory)factory;
+ private long reloadIfDue() {
+ long autoReloadTime = reloadable.autoReloadTime();
Review Comment:
Do we need a defence from NPE here ? reloadable is @Nullable
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]