LicensesService: make sure that there are no race conditions on cluster state metaData
Original commit: elastic/x-pack-elasticsearch@095e7263b8
This commit is contained in:
parent
feeae1956f
commit
cc2859d22f
|
@ -361,15 +361,14 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
|
||||||
* {@link org.elasticsearch.gateway.GatewayService#STATE_NOT_RECOVERED_BLOCK}, calls
|
* {@link org.elasticsearch.gateway.GatewayService#STATE_NOT_RECOVERED_BLOCK}, calls
|
||||||
* {@link #notifyFeaturesAndScheduleNotification(LicensesMetaData)}
|
* {@link #notifyFeaturesAndScheduleNotification(LicensesMetaData)}
|
||||||
* - else calls {@link #notifyFeaturesAndScheduleNotificationIfNeeded(LicensesMetaData)}
|
* - else calls {@link #notifyFeaturesAndScheduleNotificationIfNeeded(LicensesMetaData)}
|
||||||
*
|
|
||||||
* clears up any finished notifications on every call
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void clusterChanged(ClusterChangedEvent event) {
|
public void clusterChanged(ClusterChangedEvent event) {
|
||||||
clearFinishedNotifications();
|
final ClusterState currentClusterState = event.state();
|
||||||
if (!event.state().blocks().hasGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK)) {
|
final ClusterState previousClusterState = event.previousState();
|
||||||
LicensesMetaData oldLicensesMetaData = event.previousState().getMetaData().custom(LicensesMetaData.TYPE);
|
if (!currentClusterState.blocks().hasGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK)) {
|
||||||
LicensesMetaData currentLicensesMetaData = event.state().getMetaData().custom(LicensesMetaData.TYPE);
|
LicensesMetaData oldLicensesMetaData = previousClusterState.getMetaData().custom(LicensesMetaData.TYPE);
|
||||||
|
LicensesMetaData currentLicensesMetaData = currentClusterState.getMetaData().custom(LicensesMetaData.TYPE);
|
||||||
logLicenseMetaDataStats("old", oldLicensesMetaData);
|
logLicenseMetaDataStats("old", oldLicensesMetaData);
|
||||||
logLicenseMetaDataStats("new", currentLicensesMetaData);
|
logLicenseMetaDataStats("new", currentLicensesMetaData);
|
||||||
|
|
||||||
|
@ -396,7 +395,7 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
|
||||||
|
|
||||||
// notify all interested plugins
|
// notify all interested plugins
|
||||||
// Change to debug
|
// Change to debug
|
||||||
if (event.previousState().blocks().hasGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK) || addedNewRegisteredListener) {
|
if (previousClusterState.blocks().hasGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK) || addedNewRegisteredListener) {
|
||||||
logger.info("calling notifyFeaturesAndScheduleNotification from clusterChanged");
|
logger.info("calling notifyFeaturesAndScheduleNotification from clusterChanged");
|
||||||
notifyFeaturesAndScheduleNotification(currentLicensesMetaData);
|
notifyFeaturesAndScheduleNotification(currentLicensesMetaData);
|
||||||
} else {
|
} else {
|
||||||
|
@ -536,12 +535,13 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
|
||||||
*/
|
*/
|
||||||
private boolean registerListener(final ListenerHolder listenerHolder) {
|
private boolean registerListener(final ListenerHolder listenerHolder) {
|
||||||
logger.info("Registering listener for " + listenerHolder.feature);
|
logger.info("Registering listener for " + listenerHolder.feature);
|
||||||
if (clusterService.state().blocks().hasGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK)) {
|
ClusterState currentState = clusterService.state();
|
||||||
|
if (currentState.blocks().hasGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK)) {
|
||||||
logger.info("Store as pendingRegistration [cluster has NOT_RECOVERED_BLOCK]");
|
logger.info("Store as pendingRegistration [cluster has NOT_RECOVERED_BLOCK]");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
LicensesMetaData currentMetaData = clusterService.state().metaData().custom(LicensesMetaData.TYPE);
|
LicensesMetaData currentMetaData = currentState.metaData().custom(LicensesMetaData.TYPE);
|
||||||
if (expiryDateForFeature(listenerHolder.feature, currentMetaData) == -1l) {
|
if (expiryDateForFeature(listenerHolder.feature, currentMetaData) == -1l) {
|
||||||
// does not have any license so generate a trial license
|
// does not have any license so generate a trial license
|
||||||
TrialLicenseOptions options = listenerHolder.trialLicenseOptions;
|
TrialLicenseOptions options = listenerHolder.trialLicenseOptions;
|
||||||
|
@ -549,11 +549,11 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
|
||||||
// Trial license option is provided
|
// Trial license option is provided
|
||||||
RegisterTrialLicenseRequest request = new RegisterTrialLicenseRequest(listenerHolder.feature,
|
RegisterTrialLicenseRequest request = new RegisterTrialLicenseRequest(listenerHolder.feature,
|
||||||
options.duration, options.maxNodes);
|
options.duration, options.maxNodes);
|
||||||
if (clusterService.state().nodes().localNodeMaster()) {
|
if (currentState.nodes().localNodeMaster()) {
|
||||||
logger.info("Executing trial license request");
|
logger.info("Executing trial license request");
|
||||||
registerTrialLicense(request);
|
registerTrialLicense(request);
|
||||||
} else {
|
} else {
|
||||||
DiscoveryNode masterNode = clusterService.state().nodes().masterNode();
|
DiscoveryNode masterNode = currentState.nodes().masterNode();
|
||||||
if (masterNode != null) {
|
if (masterNode != null) {
|
||||||
logger.info("Sending trial license request to master");
|
logger.info("Sending trial license request to master");
|
||||||
transportService.sendRequest(masterNode,
|
transportService.sendRequest(masterNode,
|
||||||
|
@ -654,10 +654,10 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
|
||||||
public void run() {
|
public void run() {
|
||||||
logger.info("Performing LicensingClientNotificationJob");
|
logger.info("Performing LicensingClientNotificationJob");
|
||||||
|
|
||||||
|
|
||||||
// next clusterChanged event will deal with the missed notifications
|
// next clusterChanged event will deal with the missed notifications
|
||||||
if (!clusterService.state().blocks().hasGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK)) {
|
ClusterState currentClusterState = clusterService.state();
|
||||||
LicensesMetaData currentLicensesMetaData = clusterService.state().metaData().custom(LicensesMetaData.TYPE);
|
if (!currentClusterState.blocks().hasGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK)) {
|
||||||
|
LicensesMetaData currentLicensesMetaData = currentClusterState.metaData().custom(LicensesMetaData.TYPE);
|
||||||
long nextScheduleDelay = notifyFeatures(currentLicensesMetaData);
|
long nextScheduleDelay = notifyFeatures(currentLicensesMetaData);
|
||||||
if (nextScheduleDelay != -1l) {
|
if (nextScheduleDelay != -1l) {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue