You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "alex-plekhanov (via GitHub)" <gi...@apache.org> on 2024/10/23 14:15:58 UTC
[PR] IGNITE-23518 Add configuration for distributed properties default values [ignite]
alex-plekhanov opened a new pull request, #11616:
URL: https://github.com/apache/ignite/pull/11616
Thank you for submitting the pull request to the Apache Ignite.
In order to streamline the review of the contribution
we ask you to ensure the following steps have been taken:
### The Contribution Checklist
- [ ] There is a single JIRA ticket related to the pull request.
- [ ] The web-link to the pull request is attached to the JIRA ticket.
- [ ] The JIRA ticket has the _Patch Available_ state.
- [ ] The pull request body describes changes that have been made.
The description explains _WHAT_ and _WHY_ was made instead of _HOW_.
- [ ] The pull request title is treated as the final commit message.
The following pattern must be used: `IGNITE-XXXX Change summary` where `XXXX` - number of JIRA issue.
- [ ] A reviewer has been mentioned through the JIRA comments
(see [the Maintainers list](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute#HowtoContribute-ReviewProcessandMaintainers))
- [ ] The pull request has been checked by the Teamcity Bot and
the `green visa` attached to the JIRA ticket (see [TC.Bot: Check PR](https://mtcga.gridgain.com/prs.html))
### Notes
- [How to Contribute](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute)
- [Coding abbreviation rules](https://cwiki.apache.org/confluence/display/IGNITE/Abbreviation+Rules)
- [Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Coding+Guidelines)
- [Apache Ignite Teamcity Bot](https://cwiki.apache.org/confluence/display/IGNITE/Apache+Ignite+Teamcity+Bot)
If you need any help, please email dev@ignite.apache.org or ask anу advice on http://asf.slack.com _#ignite_ channel.
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-23518 Add configuration for distributed properties default values [ignite]
Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #11616:
URL: https://github.com/apache/ignite/pull/11616#issuecomment-2437696962
## [](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11616) **Quality Gate passed**
Issues
 [1 New issue](https://sonarcloud.io/project/issues?id=apache_ignite&pullRequest=11616&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_ignite&pullRequest=11616&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_ignite&pullRequest=11616&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_ignite&pullRequest=11616&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_ignite&pullRequest=11616&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11616)
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-23518 Add configuration for distributed properties default values [ignite]
Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #11616:
URL: https://github.com/apache/ignite/pull/11616#issuecomment-2437565718
## [](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11616) **Quality Gate failed**
Failed conditions
 [2 New Code Smells](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11616) (required ≤ 1)
[See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11616)
##
 Catch issues before they fail your Quality Gate with our IDE extension  [SonarLint](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-23518 Add configuration for distributed properties default values [ignite]
Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #11616:
URL: https://github.com/apache/ignite/pull/11616#issuecomment-2432488899
## [](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11616) **Quality Gate failed**
Failed conditions
 [3 New Code Smells](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11616) (required ≤ 1)
[See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11616)
##
 Catch issues before they fail your Quality Gate with our IDE extension  [SonarLint](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-23518 Add configuration for distributed properties default values [ignite]
Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #11616:
URL: https://github.com/apache/ignite/pull/11616#issuecomment-2437669847
## [](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11616) **Quality Gate passed**
Issues
 [1 New issue](https://sonarcloud.io/project/issues?id=apache_ignite&pullRequest=11616&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_ignite&pullRequest=11616&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_ignite&pullRequest=11616&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_ignite&pullRequest=11616&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_ignite&pullRequest=11616&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11616)
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-23518 Add configuration for distributed properties default values [ignite]
Posted by "alex-plekhanov (via GitHub)" <gi...@apache.org>.
alex-plekhanov commented on code in PR #11616:
URL: https://github.com/apache/ignite/pull/11616#discussion_r1816489585
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/configuration/distributed/DistributedConfigurationProcessor.java:
##########
@@ -94,12 +98,64 @@ public DistributedConfigurationProcessor(GridKernalContext ctx) {
//Switch to cluster wide update action and do it on already registered properties.
switchCurrentActionTo(CLUSTER_WIDE_UPDATE);
- isp.getDistributedConfigurationListeners()
- .forEach(DistributedConfigurationLifecycleListener::onReadyToWrite);
+ IgniteInternalFuture<Void> initFut = initDefaultPropertiesValues();
+
+ // Notify registered listeners only after propagation of default values.
+ // Can't wait for initFut in the current thread, since it can block discovery and deadlock is possible.
+ initFut.listen(fut -> isp.getDistributedConfigurationListeners()
+ .forEach(DistributedConfigurationLifecycleListener::onReadyToWrite));
}
});
}
+ /** Init default values for distributed properties. */
+ private IgniteInternalFuture<Void> initDefaultPropertiesValues() {
+ Map<String, ?> dfltVals = ctx.config().getDistributedPropertiesDefaultValues();
+
+ if (F.isEmpty(dfltVals))
+ return new GridFinishedFuture<>();
+
+ GridCompoundFuture<Void, Void> compFut = new GridCompoundFuture<>() {
+ @Override protected boolean ignoreFailure(Throwable err) {
+ // Do not complete the entire compound future if any property failed.
+ return true;
+ }
+ };
+
+ for (Map.Entry<String, ?> entry : dfltVals.entrySet()) {
+ DistributedChangeableProperty<Serializable> prop = props.get(entry.getKey());
+
+ if (prop == null) {
+ log.warning("Cannot set default value for distributed property '" + entry.getKey() +
+ "', property is not registered");
+
+ continue;
+ }
+
+ if (prop.get() != null)
+ continue;
+
+ try {
+ Serializable val = entry.getValue() instanceof String ? prop.parse((String)entry.getValue()) :
+ (Serializable)entry.getValue();
+
+ IgniteInternalFuture<?> fut = prop.propagateAsync(null, val);
+
+ fut.listen(f -> {
+ if (f.error() != null)
+ log.error("Cannot set default value for distributed property '" + prop.getName() + '\'', f.error());
+ });
+
+ compFut.add((IgniteInternalFuture<Void>)fut);
+ }
+ catch (Exception e) {
+ log.error("Cannot initiate setting default value for distributed property '" + prop.getName() + '\'', e);
Review Comment:
It's a current behaviour for `DistributedConfigurationUtils#setDefaultValue`, which is used by some subsystems to set default values in `onReadyToWrite`.
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-23518 Add configuration for distributed properties default values [ignite]
Posted by "nizhikov (via GitHub)" <gi...@apache.org>.
nizhikov commented on code in PR #11616:
URL: https://github.com/apache/ignite/pull/11616#discussion_r1816389862
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/configuration/distributed/DistributedConfigurationProcessor.java:
##########
@@ -94,12 +98,64 @@ public DistributedConfigurationProcessor(GridKernalContext ctx) {
//Switch to cluster wide update action and do it on already registered properties.
switchCurrentActionTo(CLUSTER_WIDE_UPDATE);
- isp.getDistributedConfigurationListeners()
- .forEach(DistributedConfigurationLifecycleListener::onReadyToWrite);
+ IgniteInternalFuture<Void> initFut = initDefaultPropertiesValues();
+
+ // Notify registered listeners only after propagation of default values.
+ // Can't wait for initFut in the current thread, since it can block discovery and deadlock is possible.
+ initFut.listen(fut -> isp.getDistributedConfigurationListeners()
+ .forEach(DistributedConfigurationLifecycleListener::onReadyToWrite));
}
});
}
+ /** Init default values for distributed properties. */
+ private IgniteInternalFuture<Void> initDefaultPropertiesValues() {
+ Map<String, ?> dfltVals = ctx.config().getDistributedPropertiesDefaultValues();
+
+ if (F.isEmpty(dfltVals))
+ return new GridFinishedFuture<>();
+
+ GridCompoundFuture<Void, Void> compFut = new GridCompoundFuture<>() {
+ @Override protected boolean ignoreFailure(Throwable err) {
+ // Do not complete the entire compound future if any property failed.
+ return true;
+ }
+ };
+
+ for (Map.Entry<String, ?> entry : dfltVals.entrySet()) {
+ DistributedChangeableProperty<Serializable> prop = props.get(entry.getKey());
+
+ if (prop == null) {
+ log.warning("Cannot set default value for distributed property '" + entry.getKey() +
+ "', property is not registered");
+
+ continue;
+ }
+
+ if (prop.get() != null)
Review Comment:
Let's add som debug logging here to provide ablility to overcome any issues:
```
if (prop.get() != null) {
log.debug("Skip set default value for porperty[name=" + entry.getKey() + ", clusterValue=" + prop.get() + ", configValue=" + entry.getValue() + ']');
}
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-23518 Add configuration for distributed properties default values [ignite]
Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #11616:
URL: https://github.com/apache/ignite/pull/11616#issuecomment-2437596761
## [](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11616) **Quality Gate passed**
Issues
 [1 New issue](https://sonarcloud.io/project/issues?id=apache_ignite&pullRequest=11616&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_ignite&pullRequest=11616&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_ignite&pullRequest=11616&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_ignite&pullRequest=11616&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_ignite&pullRequest=11616&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11616)
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-23518 Add configuration for distributed properties default values [ignite]
Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #11616:
URL: https://github.com/apache/ignite/pull/11616#issuecomment-2437736488
## [](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11616) **Quality Gate passed**
Issues
 [0 New issues](https://sonarcloud.io/project/issues?id=apache_ignite&pullRequest=11616&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_ignite&pullRequest=11616&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_ignite&pullRequest=11616&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_ignite&pullRequest=11616&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_ignite&pullRequest=11616&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11616)
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-23518 Add configuration for distributed properties default values [ignite]
Posted by "nizhikov (via GitHub)" <gi...@apache.org>.
nizhikov commented on code in PR #11616:
URL: https://github.com/apache/ignite/pull/11616#discussion_r1816395567
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/configuration/distributed/DistributedConfigurationProcessor.java:
##########
@@ -94,12 +98,64 @@ public DistributedConfigurationProcessor(GridKernalContext ctx) {
//Switch to cluster wide update action and do it on already registered properties.
switchCurrentActionTo(CLUSTER_WIDE_UPDATE);
- isp.getDistributedConfigurationListeners()
- .forEach(DistributedConfigurationLifecycleListener::onReadyToWrite);
+ IgniteInternalFuture<Void> initFut = initDefaultPropertiesValues();
+
+ // Notify registered listeners only after propagation of default values.
+ // Can't wait for initFut in the current thread, since it can block discovery and deadlock is possible.
+ initFut.listen(fut -> isp.getDistributedConfigurationListeners()
+ .forEach(DistributedConfigurationLifecycleListener::onReadyToWrite));
}
});
}
+ /** Init default values for distributed properties. */
+ private IgniteInternalFuture<Void> initDefaultPropertiesValues() {
+ Map<String, ?> dfltVals = ctx.config().getDistributedPropertiesDefaultValues();
+
+ if (F.isEmpty(dfltVals))
+ return new GridFinishedFuture<>();
+
+ GridCompoundFuture<Void, Void> compFut = new GridCompoundFuture<>() {
+ @Override protected boolean ignoreFailure(Throwable err) {
+ // Do not complete the entire compound future if any property failed.
+ return true;
+ }
+ };
+
+ for (Map.Entry<String, ?> entry : dfltVals.entrySet()) {
+ DistributedChangeableProperty<Serializable> prop = props.get(entry.getKey());
+
+ if (prop == null) {
+ log.warning("Cannot set default value for distributed property '" + entry.getKey() +
+ "', property is not registered");
+
+ continue;
+ }
+
+ if (prop.get() != null)
+ continue;
+
+ try {
+ Serializable val = entry.getValue() instanceof String ? prop.parse((String)entry.getValue()) :
+ (Serializable)entry.getValue();
+
+ IgniteInternalFuture<?> fut = prop.propagateAsync(null, val);
+
+ fut.listen(f -> {
+ if (f.error() != null)
+ log.error("Cannot set default value for distributed property '" + prop.getName() + '\'', f.error());
+ });
+
+ compFut.add((IgniteInternalFuture<Void>)fut);
+ }
+ catch (Exception e) {
+ log.error("Cannot initiate setting default value for distributed property '" + prop.getName() + '\'', e);
Review Comment:
Why do we want to ignore exception?
Error while setting user provided property is a critical error IMHO.
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-23518 Add configuration for distributed properties default values [ignite]
Posted by "alex-plekhanov (via GitHub)" <gi...@apache.org>.
alex-plekhanov commented on code in PR #11616:
URL: https://github.com/apache/ignite/pull/11616#discussion_r1816496263
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/configuration/distributed/DistributedConfigurationProcessor.java:
##########
@@ -160,15 +216,12 @@ private static String toPropertyKey(String metaStorageKey) {
* @return Public properties.
*/
public List<DistributedChangeableProperty<Serializable>> properties() {
- return props.values().stream()
- .filter(p -> p instanceof DistributedChangeableProperty)
- .map(p -> (DistributedChangeableProperty<Serializable>)p)
- .collect(Collectors.toList());
+ return U.sealList(props.values());
Review Comment:
Currently, it's used only by control.sh to show list of properties, so overhead is very small. Also, `sealList` and `Collections.unmodifiable*` methods are used for internal code too, you can search for references of this method to ensure.
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-23518 Add configuration for distributed properties default values [ignite]
Posted by "nizhikov (via GitHub)" <gi...@apache.org>.
nizhikov commented on code in PR #11616:
URL: https://github.com/apache/ignite/pull/11616#discussion_r1816393017
##########
modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java:
##########
@@ -605,6 +605,9 @@ public class IgniteConfiguration {
/** Shutdown policy for cluster. */
public ShutdownPolicy shutdown = DFLT_SHUTDOWN_POLICY;
+ /** Default values for distributed properties. */
+ private Map<String, ?> distrProps;
Review Comment:
Let's have Map<String, String> here as we support setting properties from String and this will simplify API.
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-23518 Add configuration for distributed properties default values [ignite]
Posted by "alex-plekhanov (via GitHub)" <gi...@apache.org>.
alex-plekhanov commented on code in PR #11616:
URL: https://github.com/apache/ignite/pull/11616#discussion_r1816517977
##########
modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java:
##########
@@ -605,6 +605,9 @@ public class IgniteConfiguration {
/** Shutdown policy for cluster. */
public ShutdownPolicy shutdown = DFLT_SHUTDOWN_POLICY;
+ /** Default values for distributed properties. */
+ private Map<String, ?> distrProps;
Review Comment:
Fixed
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-23518 Add configuration for distributed properties default values [ignite]
Posted by "asfgit (via GitHub)" <gi...@apache.org>.
asfgit closed pull request #11616: IGNITE-23518 Add configuration for distributed properties default values
URL: https://github.com/apache/ignite/pull/11616
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-23518 Add configuration for distributed properties default values [ignite]
Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #11616:
URL: https://github.com/apache/ignite/pull/11616#issuecomment-2432403071
## [](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11616) **Quality Gate failed**
Failed conditions
 [6 New Code Smells](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11616) (required ≤ 1)
[See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11616)
##
 Catch issues before they fail your Quality Gate with our IDE extension  [SonarLint](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-23518 Add configuration for distributed properties default values [ignite]
Posted by "nizhikov (via GitHub)" <gi...@apache.org>.
nizhikov commented on code in PR #11616:
URL: https://github.com/apache/ignite/pull/11616#discussion_r1816399172
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/configuration/distributed/DistributedConfigurationProcessor.java:
##########
@@ -160,15 +216,12 @@ private static String toPropertyKey(String metaStorageKey) {
* @return Public properties.
*/
public List<DistributedChangeableProperty<Serializable>> properties() {
- return props.values().stream()
- .filter(p -> p instanceof DistributedChangeableProperty)
- .map(p -> (DistributedChangeableProperty<Serializable>)p)
- .collect(Collectors.toList());
+ return U.sealList(props.values());
Review Comment:
Do we really need to wrap in unmodifiable list here?
AFAIK we don't wrap for internal code.
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-23518 Add configuration for distributed properties default values [ignite]
Posted by "nizhikov (via GitHub)" <gi...@apache.org>.
nizhikov commented on code in PR #11616:
URL: https://github.com/apache/ignite/pull/11616#discussion_r1816589200
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/configuration/distributed/DistributedConfigurationProcessor.java:
##########
@@ -94,12 +98,69 @@ public DistributedConfigurationProcessor(GridKernalContext ctx) {
//Switch to cluster wide update action and do it on already registered properties.
switchCurrentActionTo(CLUSTER_WIDE_UPDATE);
- isp.getDistributedConfigurationListeners()
- .forEach(DistributedConfigurationLifecycleListener::onReadyToWrite);
+ IgniteInternalFuture<Void> initFut = initDefaultPropertiesValues();
+
+ // Notify registered listeners only after propagation of default values.
+ // Can't wait for initFut in the current thread, since it can block discovery and deadlock is possible.
+ initFut.listen(fut -> isp.getDistributedConfigurationListeners()
+ .forEach(DistributedConfigurationLifecycleListener::onReadyToWrite));
}
});
}
+ /** Init default values for distributed properties. */
+ private IgniteInternalFuture<Void> initDefaultPropertiesValues() {
+ Map<String, String> dfltVals = ctx.config().getDistributedPropertiesDefaultValues();
+
+ if (F.isEmpty(dfltVals))
+ return new GridFinishedFuture<>();
+
+ GridCompoundFuture<Void, Void> compFut = new GridCompoundFuture<>() {
+ @Override protected boolean ignoreFailure(Throwable err) {
+ // Do not complete the entire compound future if any property failed.
+ return true;
+ }
+ };
+
+ for (Map.Entry<String, String> entry : dfltVals.entrySet()) {
+ DistributedChangeableProperty<Serializable> prop = props.get(entry.getKey());
+
+ if (prop == null) {
+ log.warning("Cannot set default value for distributed property '" + entry.getKey() +
+ "', property is not registered");
+
+ continue;
+ }
+
+ if (prop.get() != null) {
+ if (log.isDebugEnabled()) {
+ log.debug("Skip set default value for distributed property [name=" + entry.getKey() +
+ ", clusterValue=" + prop.get() + ", configValue=" + entry.getValue() + ']');
+ }
+
+ continue;
+ }
+
+ try {
+ Serializable val = prop.parse(entry.getValue());
Review Comment:
val can be inlined.
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-23518 Add configuration for distributed properties default values [ignite]
Posted by "nizhikov (via GitHub)" <gi...@apache.org>.
nizhikov commented on code in PR #11616:
URL: https://github.com/apache/ignite/pull/11616#discussion_r1816592703
##########
modules/core/src/test/java/org/apache/ignite/internal/processors/configuration/distributed/DistributedConfigurationDefaultValuesTest.java:
##########
@@ -0,0 +1,299 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.configuration.distributed;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.plugin.AbstractTestPluginProvider;
+import org.apache.ignite.plugin.PluginContext;
+import org.apache.ignite.testframework.ListeningTestLogger;
+import org.apache.ignite.testframework.LogListener;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+/**
+ * Test default values configuration for distributed properties.
+ */
+public class DistributedConfigurationDefaultValuesTest extends GridCommonAbstractTest {
+ /** */
+ private Consumer<DistributedPropertyDispatcher> onReadyToRegister;
+
+ /** */
+ private Runnable onReadyToWrite;
+
+ /** */
+ Map<String, String> dfltPropVals;
+
+ /** */
+ private boolean pds;
+
+ /** */
+ private final ListeningTestLogger listeningLog = new ListeningTestLogger(log);
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ super.beforeTest();
+
+ stopAllGrids();
+
+ cleanPersistenceDir();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ stopAllGrids();
+
+ cleanPersistenceDir();
+
+ super.afterTest();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+ cfg.setGridLogger(listeningLog);
+
+ cfg.setConsistentId(igniteInstanceName);
+
+ cfg.setDataStorageConfiguration(new DataStorageConfiguration().setDefaultDataRegionConfiguration(
+ new DataRegionConfiguration().setPersistenceEnabled(pds)
+ ));
+
+ cfg.setDistributedPropertiesDefaultValues(dfltPropVals);
+
+ cfg.setPluginProviders(new AbstractTestPluginProvider() {
+ @Override public String name() {
+ return "Distributed property register";
+ }
+
+ @Override public void start(PluginContext ctx) {
+ ((IgniteEx)ctx.grid()).context().internalSubscriptionProcessor().getDistributedConfigurationListeners().add(
+ new DistributedConfigurationLifecycleListener() {
+ @Override public void onReadyToRegister(DistributedPropertyDispatcher dispatcher) {
+ if (onReadyToRegister != null)
+ onReadyToRegister.accept(dispatcher);
+ }
+
+ @Override public void onReadyToWrite() {
+ if (onReadyToWrite != null)
+ onReadyToWrite.run();
+ }
+ }
+ );
+ }
+ });
+
+ return cfg;
+ }
+
+ /** */
+ @Test
+ public void testDifferentPropertyTypes() throws Exception {
+ DistributedLongProperty longProp = DistributedLongProperty.detachedLongProperty("longProp", "");
+ DistributedBooleanProperty boolProp = DistributedBooleanProperty.detachedBooleanProperty("boolProp", "");
+ SimpleDistributedProperty<String> strProp = new SimpleDistributedProperty<>("stringProp", Function.identity(), "");
+ DistributedEnumProperty<ClusterState> enumProp = new DistributedEnumProperty<>(
+ "enumProp", "",
+ ordinal -> ordinal == null ? null : ClusterState.fromOrdinal(ordinal),
+ state -> state == null ? null : state.ordinal(),
+ ClusterState.class
+ );
+
+ dfltPropVals = Map.of(
+ "longProp", "1",
+ "boolProp", "true",
+ "stringProp", "val",
+ "enumProp", "ACTIVE"
+ );
+
+ onReadyToRegister = dispatcher -> dispatcher.registerProperties(longProp, boolProp, strProp, enumProp);
+
+ Map<String, String> lsnrProps = new HashMap<>();
+
+ DistributePropertyListener<Object> lsnr = (name, oldVal, newVal) -> {
+ if (newVal != null)
+ lsnrProps.put(name, newVal.toString());
+ };
+
+ longProp.addListener(lsnr);
+ boolProp.addListener(lsnr);
+ strProp.addListener(lsnr);
+ enumProp.addListener(lsnr);
+
+ // Properties values when distributed configuration is ready to write.
+ Map<String, String> lsnrProps0 = new HashMap<>();
+
+ onReadyToWrite = () -> lsnrProps0.putAll(lsnrProps);
+
+ startGrid(0);
+
+ assertEquals(dfltPropVals, lsnrProps0);
+
+ assertEquals((Long)1L, longProp.get());
+ assertEquals(Boolean.TRUE, boolProp.get());
+ assertEquals("val", strProp.get());
+ assertEquals(ClusterState.ACTIVE, enumProp.get());
+ }
+
+ /** */
+ @Test
+ public void testInMemoryCluster() throws Exception {
+ checkDistributedPropertiesClusterPropagation(false);
+ }
+
+ /** */
+ @Test
+ public void testPersistentCluster() throws Exception {
+ checkDistributedPropertiesClusterPropagation(true);
+ }
+
+ /** */
+ private void checkDistributedPropertiesClusterPropagation(boolean pds) throws Exception {
+ this.pds = pds;
+
+ String propName = "testProp";
+
+ // Properties with the same name, but on different nodes.
+ DistributedLongProperty prop0 = DistributedLongProperty.detachedLongProperty(propName, "");
+ DistributedLongProperty prop1 = DistributedLongProperty.detachedLongProperty(propName, "");
+ DistributedLongProperty prop2 = DistributedLongProperty.detachedLongProperty(propName, "");
+
+ dfltPropVals = F.asMap(propName, "1");
+
+ onReadyToRegister = dispatcher -> dispatcher.registerProperties(prop0);
+
+ startGrid(0).cluster().state(ClusterState.ACTIVE);
+
+ // Value from default configuration.
+ assertEquals((Long)1L, prop0.get());
+
+ dfltPropVals = null;
+
+ onReadyToRegister = dispatcher -> dispatcher.registerProperties(prop1);
+
+ startGrid(1);
+
+ // Value from cluster, when default configuration is empty.
+ assertEquals((Long)1L, prop1.get());
+
+ dfltPropVals = F.asMap(propName, "2");
+
+ onReadyToRegister = dispatcher -> dispatcher.registerProperties(prop2);
+
+ startGrid(2);
+
+ // Value from cluster, when default configuration is not empty.
+ assertEquals((Long)1L, prop2.get());
+
+ if (!pds) // Further checks for PDS after cluster restart.
+ return;
+
+ stopAllGrids();
+
+ // Properties for all nodes after restart.
+ DistributedLongProperty prop3 = DistributedLongProperty.detachedLongProperty(propName, "");
+ DistributedLongProperty prop4 = DistributedLongProperty.detachedLongProperty(propName, "");
+ DistributedLongProperty prop5 = DistributedLongProperty.detachedLongProperty(propName, "");
+
+ dfltPropVals = F.asMap(propName, "2");
+
+ onReadyToRegister = dispatcher -> dispatcher.registerProperties(prop3);
+
+ startGrid(0);
+
+ // Value from PDS, when default configuration is not empty and PDS is not empty.
+ assertEquals((Long)1L, prop3.get());
+
+ prop3.propagateAsync(2L).get();
+
+ dfltPropVals = null;
+
+ onReadyToRegister = dispatcher -> dispatcher.registerProperties(prop4);
+
+ startGrid(1);
+
+ // Value from cluster, when default configuration is empty and PDS is not empty.
+ assertEquals((Long)2L, prop4.get());
+
+ dfltPropVals = F.asMap(propName, "3");
+
+ onReadyToRegister = dispatcher -> dispatcher.registerProperties(prop5);
+
+ startGrid(2);
+
+ // Value from cluster, when default configuration is not empty and PDS is not empty.
+ assertEquals((Long)2L, prop5.get());
+ }
+
+ /** */
+ @Test
+ public void testPropertyInitBySecondNode() throws Exception {
+ String propName = "testProp";
+
+ DistributedLongProperty prop0 = DistributedLongProperty.detachedLongProperty(propName, "");
+ DistributedLongProperty prop1 = DistributedLongProperty.detachedLongProperty(propName, "");
+
+ onReadyToRegister = dispatcher -> dispatcher.registerProperties(prop0);
+
+ startGrid(0);
+
+ assertNull(prop0.get());
+
+ dfltPropVals = F.asMap(propName, "1");
+
+ onReadyToRegister = dispatcher -> dispatcher.registerProperties(prop1);
+
+ startGrid(1);
+
+ assertEquals((Long)1L, prop1.get());
+ assertEquals((Long)1L, prop0.get());
+ }
+
+ /** */
+ @Test
+ public void testNotRegisteredProperty() throws Exception {
+ String propName = "testProp";
+ String notExistingPropName = "notExistingProp";
+
+ DistributedLongProperty prop = DistributedLongProperty.detachedLongProperty(propName, "");
+
+ dfltPropVals = F.asMap(propName, "1", notExistingPropName, "2");
+
+ onReadyToRegister = dispatcher -> dispatcher.registerProperties(prop);
+
+ String warn = "Cannot set default value for distributed property 'notExistingProp', property is not registered";
Review Comment:
`warn` can be inlined.
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-23518 Add configuration for distributed properties default values [ignite]
Posted by "nizhikov (via GitHub)" <gi...@apache.org>.
nizhikov commented on code in PR #11616:
URL: https://github.com/apache/ignite/pull/11616#discussion_r1816389862
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/configuration/distributed/DistributedConfigurationProcessor.java:
##########
@@ -94,12 +98,64 @@ public DistributedConfigurationProcessor(GridKernalContext ctx) {
//Switch to cluster wide update action and do it on already registered properties.
switchCurrentActionTo(CLUSTER_WIDE_UPDATE);
- isp.getDistributedConfigurationListeners()
- .forEach(DistributedConfigurationLifecycleListener::onReadyToWrite);
+ IgniteInternalFuture<Void> initFut = initDefaultPropertiesValues();
+
+ // Notify registered listeners only after propagation of default values.
+ // Can't wait for initFut in the current thread, since it can block discovery and deadlock is possible.
+ initFut.listen(fut -> isp.getDistributedConfigurationListeners()
+ .forEach(DistributedConfigurationLifecycleListener::onReadyToWrite));
}
});
}
+ /** Init default values for distributed properties. */
+ private IgniteInternalFuture<Void> initDefaultPropertiesValues() {
+ Map<String, ?> dfltVals = ctx.config().getDistributedPropertiesDefaultValues();
+
+ if (F.isEmpty(dfltVals))
+ return new GridFinishedFuture<>();
+
+ GridCompoundFuture<Void, Void> compFut = new GridCompoundFuture<>() {
+ @Override protected boolean ignoreFailure(Throwable err) {
+ // Do not complete the entire compound future if any property failed.
+ return true;
+ }
+ };
+
+ for (Map.Entry<String, ?> entry : dfltVals.entrySet()) {
+ DistributedChangeableProperty<Serializable> prop = props.get(entry.getKey());
+
+ if (prop == null) {
+ log.warning("Cannot set default value for distributed property '" + entry.getKey() +
+ "', property is not registered");
+
+ continue;
+ }
+
+ if (prop.get() != null)
Review Comment:
Let's add som debug logging here to provide ablility to overcome any issues:
```
if (prop.get() != null) {
log.debug("Skip set default value for porperty[name=" + entry.getKey() + ", clusterValue=" + prop.get() + ", configValue=" + entry.getValue() + ']');
continue;
}
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-23518 Add configuration for distributed properties default values [ignite]
Posted by "alex-plekhanov (via GitHub)" <gi...@apache.org>.
alex-plekhanov commented on code in PR #11616:
URL: https://github.com/apache/ignite/pull/11616#discussion_r1816517595
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/configuration/distributed/DistributedConfigurationProcessor.java:
##########
@@ -94,12 +98,64 @@ public DistributedConfigurationProcessor(GridKernalContext ctx) {
//Switch to cluster wide update action and do it on already registered properties.
switchCurrentActionTo(CLUSTER_WIDE_UPDATE);
- isp.getDistributedConfigurationListeners()
- .forEach(DistributedConfigurationLifecycleListener::onReadyToWrite);
+ IgniteInternalFuture<Void> initFut = initDefaultPropertiesValues();
+
+ // Notify registered listeners only after propagation of default values.
+ // Can't wait for initFut in the current thread, since it can block discovery and deadlock is possible.
+ initFut.listen(fut -> isp.getDistributedConfigurationListeners()
+ .forEach(DistributedConfigurationLifecycleListener::onReadyToWrite));
}
});
}
+ /** Init default values for distributed properties. */
+ private IgniteInternalFuture<Void> initDefaultPropertiesValues() {
+ Map<String, ?> dfltVals = ctx.config().getDistributedPropertiesDefaultValues();
+
+ if (F.isEmpty(dfltVals))
+ return new GridFinishedFuture<>();
+
+ GridCompoundFuture<Void, Void> compFut = new GridCompoundFuture<>() {
+ @Override protected boolean ignoreFailure(Throwable err) {
+ // Do not complete the entire compound future if any property failed.
+ return true;
+ }
+ };
+
+ for (Map.Entry<String, ?> entry : dfltVals.entrySet()) {
+ DistributedChangeableProperty<Serializable> prop = props.get(entry.getKey());
+
+ if (prop == null) {
+ log.warning("Cannot set default value for distributed property '" + entry.getKey() +
+ "', property is not registered");
+
+ continue;
+ }
+
+ if (prop.get() != null)
Review Comment:
Fixed
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-23518 Add configuration for distributed properties default values [ignite]
Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #11616:
URL: https://github.com/apache/ignite/pull/11616#issuecomment-2437635424
## [](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11616) **Quality Gate passed**
Issues
 [1 New issue](https://sonarcloud.io/project/issues?id=apache_ignite&pullRequest=11616&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_ignite&pullRequest=11616&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_ignite&pullRequest=11616&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_ignite&pullRequest=11616&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_ignite&pullRequest=11616&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11616)
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-23518 Add configuration for distributed properties default values [ignite]
Posted by "nizhikov (via GitHub)" <gi...@apache.org>.
nizhikov commented on code in PR #11616:
URL: https://github.com/apache/ignite/pull/11616#discussion_r1816590358
##########
modules/core/src/test/java/org/apache/ignite/internal/processors/configuration/distributed/DistributedConfigurationDefaultValuesTest.java:
##########
@@ -0,0 +1,299 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.configuration.distributed;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.plugin.AbstractTestPluginProvider;
+import org.apache.ignite.plugin.PluginContext;
+import org.apache.ignite.testframework.ListeningTestLogger;
+import org.apache.ignite.testframework.LogListener;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+/**
+ * Test default values configuration for distributed properties.
+ */
+public class DistributedConfigurationDefaultValuesTest extends GridCommonAbstractTest {
+ /** */
+ private Consumer<DistributedPropertyDispatcher> onReadyToRegister;
+
+ /** */
+ private Runnable onReadyToWrite;
+
+ /** */
+ Map<String, String> dfltPropVals;
+
+ /** */
+ private boolean pds;
+
+ /** */
+ private final ListeningTestLogger listeningLog = new ListeningTestLogger(log);
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ super.beforeTest();
+
+ stopAllGrids();
+
+ cleanPersistenceDir();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ stopAllGrids();
+
+ cleanPersistenceDir();
+
+ super.afterTest();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+ cfg.setGridLogger(listeningLog);
+
+ cfg.setConsistentId(igniteInstanceName);
+
+ cfg.setDataStorageConfiguration(new DataStorageConfiguration().setDefaultDataRegionConfiguration(
+ new DataRegionConfiguration().setPersistenceEnabled(pds)
+ ));
+
+ cfg.setDistributedPropertiesDefaultValues(dfltPropVals);
+
+ cfg.setPluginProviders(new AbstractTestPluginProvider() {
+ @Override public String name() {
+ return "Distributed property register";
+ }
+
+ @Override public void start(PluginContext ctx) {
+ ((IgniteEx)ctx.grid()).context().internalSubscriptionProcessor().getDistributedConfigurationListeners().add(
+ new DistributedConfigurationLifecycleListener() {
+ @Override public void onReadyToRegister(DistributedPropertyDispatcher dispatcher) {
+ if (onReadyToRegister != null)
+ onReadyToRegister.accept(dispatcher);
+ }
+
+ @Override public void onReadyToWrite() {
+ if (onReadyToWrite != null)
+ onReadyToWrite.run();
+ }
+ }
+ );
+ }
+ });
+
+ return cfg;
+ }
+
+ /** */
+ @Test
+ public void testDifferentPropertyTypes() throws Exception {
+ DistributedLongProperty longProp = DistributedLongProperty.detachedLongProperty("longProp", "");
+ DistributedBooleanProperty boolProp = DistributedBooleanProperty.detachedBooleanProperty("boolProp", "");
+ SimpleDistributedProperty<String> strProp = new SimpleDistributedProperty<>("stringProp", Function.identity(), "");
+ DistributedEnumProperty<ClusterState> enumProp = new DistributedEnumProperty<>(
+ "enumProp", "",
+ ordinal -> ordinal == null ? null : ClusterState.fromOrdinal(ordinal),
+ state -> state == null ? null : state.ordinal(),
+ ClusterState.class
+ );
+
+ dfltPropVals = Map.of(
+ "longProp", "1",
+ "boolProp", "true",
+ "stringProp", "val",
+ "enumProp", "ACTIVE"
+ );
+
+ onReadyToRegister = dispatcher -> dispatcher.registerProperties(longProp, boolProp, strProp, enumProp);
+
+ Map<String, String> lsnrProps = new HashMap<>();
+
+ DistributePropertyListener<Object> lsnr = (name, oldVal, newVal) -> {
+ if (newVal != null)
+ lsnrProps.put(name, newVal.toString());
+ };
+
+ longProp.addListener(lsnr);
+ boolProp.addListener(lsnr);
+ strProp.addListener(lsnr);
+ enumProp.addListener(lsnr);
+
+ // Properties values when distributed configuration is ready to write.
+ Map<String, String> lsnrProps0 = new HashMap<>();
+
+ onReadyToWrite = () -> lsnrProps0.putAll(lsnrProps);
+
+ startGrid(0);
+
+ assertEquals(dfltPropVals, lsnrProps0);
+
+ assertEquals((Long)1L, longProp.get());
+ assertEquals(Boolean.TRUE, boolProp.get());
+ assertEquals("val", strProp.get());
+ assertEquals(ClusterState.ACTIVE, enumProp.get());
+ }
+
+ /** */
+ @Test
+ public void testInMemoryCluster() throws Exception {
+ checkDistributedPropertiesClusterPropagation(false);
+ }
+
+ /** */
+ @Test
+ public void testPersistentCluster() throws Exception {
+ checkDistributedPropertiesClusterPropagation(true);
+ }
+
+ /** */
+ private void checkDistributedPropertiesClusterPropagation(boolean pds) throws Exception {
+ this.pds = pds;
+
+ String propName = "testProp";
+
+ // Properties with the same name, but on different nodes.
+ DistributedLongProperty prop0 = DistributedLongProperty.detachedLongProperty(propName, "");
+ DistributedLongProperty prop1 = DistributedLongProperty.detachedLongProperty(propName, "");
+ DistributedLongProperty prop2 = DistributedLongProperty.detachedLongProperty(propName, "");
+
+ dfltPropVals = F.asMap(propName, "1");
+
+ onReadyToRegister = dispatcher -> dispatcher.registerProperties(prop0);
+
+ startGrid(0).cluster().state(ClusterState.ACTIVE);
+
+ // Value from default configuration.
+ assertEquals((Long)1L, prop0.get());
Review Comment:
Let's move comment to the assert call here and below:
```
assertEquals("Expecting value from configuration", 1L, prop0.get());
```
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org