diff options
author | Harald Musum <musum@oath.com> | 2017-11-18 10:02:21 +0100 |
---|---|---|
committer | Harald Musum <musum@oath.com> | 2017-11-18 10:02:21 +0100 |
commit | 33b2792d14e80e9bdab47b4186d1ba32ffa27c5e (patch) | |
tree | 02413a9d5edaf1f46bc3f6ca825900e8ea35cd53 /configserver | |
parent | 37526af13ac63b77ccc72f1c162b6a6871fd48d4 (diff) |
Periodically check for removed applications
Diffstat (limited to 'configserver')
-rw-r--r-- | configserver/src/main/java/com/yahoo/vespa/config/server/application/ZKTenantApplications.java | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/application/ZKTenantApplications.java b/configserver/src/main/java/com/yahoo/vespa/config/server/application/ZKTenantApplications.java index c425dc9f22d..bb482d71374 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/application/ZKTenantApplications.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/application/ZKTenantApplications.java @@ -18,11 +18,15 @@ import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent; import org.apache.curator.framework.recipes.cache.PathChildrenCacheListener; +import java.time.Duration; import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.TimeUnit; import java.util.logging.Logger; /** @@ -36,10 +40,13 @@ import java.util.logging.Logger; public class ZKTenantApplications implements TenantApplications, PathChildrenCacheListener { private static final Logger log = Logger.getLogger(ZKTenantApplications.class.getName()); + private static final Duration checkForRemovedApplicationsInterval = Duration.ofMinutes(1); + private final Curator curator; private final Path applicationsPath; private final ExecutorService pathChildrenExecutor = Executors.newFixedThreadPool(1, ThreadFactoryFactory.getThreadFactory(ZKTenantApplications.class.getName())); + private final ScheduledExecutorService checkForRemovedApplicationsService = new ScheduledThreadPoolExecutor(1); private final Curator.DirectoryCache directoryCache; private final ReloadHandler reloadHandler; private final TenantName tenant; @@ -53,6 +60,8 @@ public class ZKTenantApplications implements TenantApplications, PathChildrenCac this.directoryCache = curator.createDirectoryCache(applicationsPath.getAbsolute(), false, false, pathChildrenExecutor); this.directoryCache.start(); this.directoryCache.addListener(this); + checkForRemovedApplicationsService.scheduleAtFixedRate(this::removeApplications, checkForRemovedApplicationsInterval.getSeconds(), + checkForRemovedApplicationsInterval.getSeconds(), TimeUnit.SECONDS); } public static TenantApplications create(Curator curator, ReloadHandler reloadHandler, TenantName tenant) { @@ -119,6 +128,7 @@ public class ZKTenantApplications implements TenantApplications, PathChildrenCac public void close() { directoryCache.close(); pathChildrenExecutor.shutdown(); + checkForRemovedApplicationsService.shutdown(); } @Override @@ -139,7 +149,7 @@ public class ZKTenantApplications implements TenantApplications, PathChildrenCac } // We might have lost events and might need to remove applications (new applications are // not added by listening for events here, they are added when session is added, see RemoteSessionRepo) - removeApplications(event.getType()); + removeApplications(); } private void applicationRemoved(ApplicationId applicationId) { @@ -151,10 +161,10 @@ public class ZKTenantApplications implements TenantApplications, PathChildrenCac log.log(LogLevel.DEBUG, Tenants.logPre(applicationId) + "Application added: " + applicationId); } - private void removeApplications(PathChildrenCacheEvent.Type eventType) { + private void removeApplications() { ImmutableSet<ApplicationId> activeApplications = ImmutableSet.copyOf(listApplications()); - log.log(LogLevel.DEBUG, "Got " + eventType + " event for tenant '" + tenant + - "', removing applications except these active applications: " + activeApplications); + log.log(LogLevel.INFO, "Removing stale applications for tenant '" + tenant + + "', not removing these active applications: " + activeApplications); reloadHandler.removeApplicationsExcept(activeApplications); } |