Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FISH-8794 Fix PayaraInstanceImpl Desync on Restart of Hazelcast #6804

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2016-2021 Payara Foundation and/or its affiliates. All rights reserved.
* Copyright (c) 2016-2024 Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
Expand Down Expand Up @@ -141,10 +141,7 @@ public class PayaraInstanceImpl implements EventListener, MessageReceiver, Payar

private UUID myCurrentID;

private String instanceName;
private String instanceGroup;

private final LazyHolder<InstanceDescriptorImpl> descriptor = lazyHolder(this::initialiseInstanceDescriptor);
private LazyHolder<InstanceDescriptorImpl> descriptor = lazyHolder(this::initialiseInstanceDescriptor);

@Inject
private ServerEnvironment environment;
Expand All @@ -161,12 +158,11 @@ public class PayaraInstanceImpl implements EventListener, MessageReceiver, Payar

@Override
public String getInstanceName() {
return instanceName;
return descriptor.get().getInstanceName();
}

@Override
public void setInstanceName(String instanceName) {
this.instanceName = instanceName;
descriptor.get().setInstanceName(instanceName);
}

Expand Down Expand Up @@ -295,10 +291,14 @@ else if (event.is(Deployment.APPLICATION_UNLOADED)) {
cluster.getClusteredStore().set(INSTANCE_STORE_NAME, myCurrentID, descriptor.get());
}
} else if (event.is(HazelcastEvents.HAZELCAST_SHUTDOWN_STARTED)) {
// Set to null to help prevent the scheduled heartbeat task re-adding the descriptor we're removing here.
myCurrentID = null;
PayaraInternalEvent pie = new PayaraInternalEvent(PayaraInternalEvent.MESSAGE.REMOVED, descriptor.get());
ClusterMessage<PayaraInternalEvent> message = new ClusterMessage<>(pie);
this.cluster.getClusteredStore().remove(INSTANCE_STORE_NAME, myCurrentID);
this.cluster.getEventBus().publish(INTERNAL_EVENTS_NAME, message);
// Create a new lazy initialiser
descriptor = lazyHolder(this::initialiseInstanceDescriptor);
}

// When Hazelcast is bootstrapped, update the instance descriptor with any new information
Expand Down Expand Up @@ -375,6 +375,8 @@ public InstanceDescriptorImpl getDescriptor(UUID member) {
}

private InstanceDescriptorImpl initialiseInstanceDescriptor() {
String instanceName = "payara-micro";
String instanceGroup = "no-cluster";
boolean liteMember = false;
int hazelcastPort = 5900;
InetAddress hostname = null;
Expand All @@ -387,9 +389,6 @@ private InstanceDescriptorImpl initialiseInstanceDescriptor() {
liteMember = hazelcast.isLite();
hazelcastPort = hazelcast.getPort();
hostname = hazelcast.getInstance().getCluster().getLocalMember().getSocketAddress().getAddress();
} else {
instanceName = "payara-micro";
instanceGroup = "no-cluster";
}

// Get this instance's runtime type
Expand Down