- @GuardedBy("lock")
- private void startCapture() {
- Verify.verify(capture == null, "Service group {} is already capturing events {}", identifier, capture);
- capture = new ArrayList<>(0);
- LOG.debug("Service group {} started capturing events", identifier);
- }
-
- private List<C> endCapture() {
- final List<C> ret = Verify.verifyNotNull(capture, "Service group {} is not currently capturing", identifier);
- capture = null;
- LOG.debug("Service group {} finished capturing events, {} events to process", identifier, ret.size());
- return ret;
- }
-
- @GuardedBy("lock")
- private void lockedClose(final SettableFuture<Void> future) {
- if (serviceEntityReg != null) {
- // We are still holding the service registration, close it now...
- LOG.debug("Service group {} unregistering service entity {}", identifier, serviceEntity);
- startCapture();
- serviceEntityReg.close();
- serviceEntityReg = null;
-
- // This can potentially mutate our state, so all previous checks need to be re-validated.
- endCapture().forEach(this::lockedOwnershipChanged);
- }
-
- // Now check service entity state: if it is still owned, we need to wait until it is acknowledged as
- // unregistered.
- switch (serviceEntityState) {
- case REGISTERED:
- case UNOWNED:
- case UNREGISTERED:
- // We have either successfully shut down, or have never started up, proceed with termination
- break;
- case OWNED:
- // We have unregistered, but EOS has not reported our loss of ownership. We will continue with shutdown
- // when that loss is reported.
- LOG.debug("Service group {} is still owned, postponing termination", identifier);
- return;
- case OWNED_JEOPARDY:
- // This is a significant event, as it relates to cluster split/join operations, operators need to know
- // we are waiting for cluster join event.
- LOG.info("Service group {} is still owned with split cluster, postponing termination", identifier);
- return;
- default:
- throw new IllegalStateException("Unhandled service entity state " + serviceEntityState);
- }
-
- // We do not own service entity state: we need to ensure services are stopped.
- if (stopServices()) {
- LOG.debug("Service group {} started shutting down services, postponing termination", identifier);
- return;
- }
-
- // Local cleanup completed, release cleanup entity if needed
- if (cleanupEntityReg != null) {
- LOG.debug("Service group {} unregistering cleanup entity {}", identifier, cleanupEntity);
- startCapture();
- cleanupEntityReg.close();
- cleanupEntityReg = null;
-
- // This can potentially mutate our state, so all previous checks need to be re-validated.
- endCapture().forEach(this::lockedOwnershipChanged);
- }
-
- switch (cleanupEntityState) {
- case REGISTERED:
- case UNOWNED:
- case UNREGISTERED:
- // We have either successfully shut down, or have never started up, proceed with termination
- break;
- case OWNED:
- // We have unregistered, but EOS has not reported our loss of ownership. We will continue with shutdown
- // when that loss is reported.
- LOG.debug("Service group {} is still owns cleanup, postponing termination", identifier);
- return;
- case OWNED_JEOPARDY:
- // This is a significant event, as it relates to cluster split/join operations, operators need to know
- // we are waiting for cluster join event.
- LOG.info("Service group {} is still owns cleanup with split cluster, postponing termination",
- identifier);
- return;
- default:
- throw new IllegalStateException("Unhandled cleanup entity state " + serviceEntityState);
- }
-
- // No registrations left and no service operations pending, we are done
- LOG.debug("Service group {} completing termination", identifier);
- future.set(null);
- }
-