-
Notifications
You must be signed in to change notification settings - Fork 102
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
IGNITE-23634 Make hardcoded REBALANCE_RETRY_DELAY_MS configurable #4951
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b90f19c
prepare general mechanism to read distributed properties
kgusakov b784b01
propagate configuration to listener
kgusakov 2801e6d
added integration test for configuration
kgusakov 51ed725
fix initialization
kgusakov 2723bb5
Merge branch 'main' into ignite-23634
kgusakov 776353f
fix checkstyle
kgusakov d4bf87f
fix checkstyle
kgusakov 9811983
fix PR comments
kgusakov 1b68666
fix checkstyle
kgusakov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
...che/ignite/internal/configuration/utils/SystemDistributedConfigurationPropertyHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* 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.configuration.utils; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
import java.util.function.BiConsumer; | ||
import java.util.function.Function; | ||
import org.apache.ignite.internal.configuration.SystemDistributedConfiguration; | ||
import org.apache.ignite.internal.configuration.SystemDistributedView; | ||
import org.apache.ignite.internal.configuration.SystemPropertyView; | ||
|
||
/** Holder of system distributed configuration property with auto-update and support of external listener. */ | ||
public class SystemDistributedConfigurationPropertyHolder<T> { | ||
/** Configuration property name. */ | ||
private final String propertyName; | ||
|
||
/** Default value. */ | ||
private final T defaultValue; | ||
|
||
/** System distributed configuration. */ | ||
private final SystemDistributedConfiguration systemDistributedConfig; | ||
|
||
/** Current value of target system distributed configuration property. */ | ||
private final AtomicReference<T> currentValue = new AtomicReference<>(); | ||
|
||
/** Listener, which receives (newValue, revision) on every configuration update. */ | ||
private final BiConsumer<T, Long> valueListener; | ||
|
||
/** Converter to translate {@link String} representation of property value to target type. */ | ||
private final Function<String, T> propertyConverter; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param systemDistributedConfig System distributed configuration. | ||
* @param valueListener Listener, which receives (newValue, revision) on every configuration update. | ||
* @param propertyName Configuration property name. | ||
* @param defaultValue Default value. | ||
* @param propertyConverter Converter to translate {@link String} representation of property value to target type. | ||
*/ | ||
public SystemDistributedConfigurationPropertyHolder( | ||
SystemDistributedConfiguration systemDistributedConfig, | ||
BiConsumer<T, Long> valueListener, | ||
String propertyName, | ||
T defaultValue, | ||
Function<String, T> propertyConverter | ||
) { | ||
this.systemDistributedConfig = systemDistributedConfig; | ||
this.valueListener = valueListener; | ||
this.propertyName = propertyName; | ||
this.defaultValue = defaultValue; | ||
this.propertyConverter = propertyConverter; | ||
|
||
systemDistributedConfig.listen(ctx -> { | ||
updateSystemProperties(ctx.newValue(), ctx.storageRevision()); | ||
|
||
return CompletableFuture.completedFuture(null); | ||
}); | ||
} | ||
|
||
/** | ||
* Init property value, but doesn't call the listener. | ||
* | ||
* <p>If this method's call or first configuration update will not occur before holder usage, it will produce a {@code null} value. | ||
*/ | ||
public void init() { | ||
updateSystemProperties(systemDistributedConfig.value(), -1); | ||
} | ||
|
||
/** | ||
* Returns current value of configuration property. | ||
* | ||
* @return Current value. | ||
*/ | ||
public T currentValue() { | ||
return currentValue.get(); | ||
} | ||
|
||
/** | ||
* Update current value and call listener (if revision != -1). | ||
* | ||
* @param view System distributed view. | ||
* @param revision Metastorage revision. | ||
*/ | ||
private void updateSystemProperties(SystemDistributedView view, long revision) { | ||
SystemPropertyView systemPropertyView = view.properties().get(propertyName); | ||
|
||
T value = (systemPropertyView == null) ? defaultValue : propertyConverter.apply(systemPropertyView.propertyValue()); | ||
|
||
currentValue.set(value); | ||
|
||
if (revision != -1) { | ||
valueListener.accept(value, revision); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a bit more details why we need this init and when it must be called
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.