Skip to content
Merged
Show file tree
Hide file tree
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
Expand Up @@ -330,6 +330,11 @@ public class AttributesFactory<K, V> {
*/
public static final boolean DEFAULT_DISK_SYNCHRONOUS = true;

/**
* The default concurrency level for updates to region values
*/
public static final int DEFAULT_CONCURRENCY_LEVEL = 16;

/**
* Creates a new instance of AttributesFactory ready to create a {@code RegionAttributes} with
* default settings.
Expand Down Expand Up @@ -1559,7 +1564,7 @@ private static class RegionAttributesImpl<K, V> extends UserSpecifiedRegionAttri
Class<V> valueConstraint = null;
int initialCapacity = 16;
float loadFactor = 0.75f;
int concurrencyLevel = 16;
int concurrencyLevel = DEFAULT_CONCURRENCY_LEVEL;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why only define symbolic constant for concurrencyLevel? For consistency I'd either define constants for all the unexplained hardcoded numbers (initialCapacity & loadFactor ?) or none of them. DEFAULT_CONCURRENCY is only used the once so I don't see a reason for singling it out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to be able to reference this value outside of this class. I guess the other values aren't being used/referenced anywhere outside of this class.

Also, the AttributesFactory class is deprecated, so making larger changes is less important I think.

boolean concurrencyChecksEnabled = true;
boolean earlyAck = false;
boolean publisher = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,22 @@ public ExpirationAttributes(int expirationTime) {
/**
* Constructs an <code>ExpirationAttributes</code> with the specified expiration time and
* expiration action.
*
* @param expirationTime The number of seconds for a value to live before it expires
*
* @param expirationTime The number of seconds for a value to live before it expires. If this
* parameter is negative, the expiration time will be set to 0, indicating no expiration.
* @param expirationAction the action to take when the value expires
* @throws IllegalArgumentException if expirationTime is nonpositive
*/
public ExpirationAttributes(int expirationTime, ExpirationAction expirationAction) {
this.timeout = expirationTime;
this.action = expirationAction;
if (expirationTime < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that the javadoc says this method should throw an IllegalArgumentException if the expirationTime is nonpositive. We should either update the javadoc or throw the exception in that case.

this.timeout = 0;
} else {
this.timeout = expirationTime;
}
if (expirationAction == null) {
this.action = ExpirationAction.INVALIDATE;
} else {
this.action = expirationAction;
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,16 @@
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;

import org.apache.commons.lang.StringUtils;
import org.springframework.shell.core.annotation.CliCommand;
import org.springframework.shell.core.annotation.CliOption;

import org.apache.geode.cache.ExpirationAttributes;
import org.apache.geode.cache.execute.ResultCollector;
import org.apache.geode.distributed.DistributedMember;
import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.management.cli.CliMetaData;
import org.apache.geode.management.cli.ConverterHint;
import org.apache.geode.management.cli.Result;
import org.apache.geode.management.internal.cli.CliUtil;
import org.apache.geode.management.internal.cli.LogWrapper;
import org.apache.geode.management.internal.cli.functions.CliFunctionResult;
import org.apache.geode.management.internal.cli.functions.RegionAlterFunction;
import org.apache.geode.management.internal.cli.functions.RegionFunctionArgs;
Expand All @@ -51,24 +48,21 @@ public Result alterRegion(
optionContext = ConverterHint.MEMBERGROUP,
help = CliStrings.ALTER_REGION__GROUP__HELP) String[] groups,
@CliOption(key = CliStrings.ALTER_REGION__ENTRYEXPIRATIONIDLETIME,
specifiedDefaultValue = "-1",
help = CliStrings.ALTER_REGION__ENTRYEXPIRATIONIDLETIME__HELP) Integer entryExpirationIdleTime,
@CliOption(key = CliStrings.ALTER_REGION__ENTRYEXPIRATIONIDLETIMEACTION,
specifiedDefaultValue = "INVALIDATE",
help = CliStrings.ALTER_REGION__ENTRYEXPIRATIONIDLETIMEACTION__HELP) String entryExpirationIdleTimeAction,
@CliOption(key = CliStrings.ALTER_REGION__ENTRYEXPIRATIONTIMETOLIVE,
specifiedDefaultValue = "-1",
help = CliStrings.ALTER_REGION__ENTRYEXPIRATIONTIMETOLIVE__HELP) Integer entryExpirationTTL,
@CliOption(key = CliStrings.ALTER_REGION__ENTRYEXPIRATIONTTLACTION,
specifiedDefaultValue = "INVALIDATE",
help = CliStrings.ALTER_REGION__ENTRYEXPIRATIONTTLACTION__HELP) String entryExpirationTTLAction,
@CliOption(key = CliStrings.ALTER_REGION__REGIONEXPIRATIONIDLETIME,
specifiedDefaultValue = "-1",
help = CliStrings.ALTER_REGION__REGIONEXPIRATIONIDLETIME__HELP) Integer regionExpirationIdleTime,
@CliOption(key = CliStrings.ALTER_REGION__REGIONEXPIRATIONIDLETIMEACTION,
specifiedDefaultValue = "INVALIDATE",
help = CliStrings.ALTER_REGION__REGIONEXPIRATIONIDLETIMEACTION__HELP) String regionExpirationIdleTimeAction,
@CliOption(key = CliStrings.ALTER_REGION__REGIONEXPIRATIONTTL, specifiedDefaultValue = "-1",
@CliOption(key = CliStrings.ALTER_REGION__REGIONEXPIRATIONTTL,
help = CliStrings.ALTER_REGION__REGIONEXPIRATIONTTL__HELP) Integer regionExpirationTTL,
@CliOption(key = CliStrings.ALTER_REGION__REGIONEXPIRATIONTTLACTION,
specifiedDefaultValue = "INVALIDATE",
Expand All @@ -83,141 +77,93 @@ public Result alterRegion(
help = CliStrings.ALTER_REGION__ASYNCEVENTQUEUEID__HELP) String[] asyncEventQueueIds,
@CliOption(key = CliStrings.ALTER_REGION__GATEWAYSENDERID, specifiedDefaultValue = "",
help = CliStrings.ALTER_REGION__GATEWAYSENDERID__HELP) String[] gatewaySenderIds,
@CliOption(key = CliStrings.ALTER_REGION__CLONINGENABLED, specifiedDefaultValue = "false",
help = CliStrings.ALTER_REGION__CLONINGENABLED__HELP) Boolean cloningEnabled,
@CliOption(key = CliStrings.ALTER_REGION__CLONINGENABLED, specifiedDefaultValue = "true",
unspecifiedDefaultValue = "false",
help = CliStrings.ALTER_REGION__CLONINGENABLED__HELP) boolean cloningEnabled,
@CliOption(key = CliStrings.ALTER_REGION__EVICTIONMAX, specifiedDefaultValue = "0",
help = CliStrings.ALTER_REGION__EVICTIONMAX__HELP) Integer evictionMax) {
Result result;
AtomicReference<XmlEntity> xmlEntity = new AtomicReference<>();

getSecurityService().authorize(Resource.DATA, Operation.MANAGE, regionPath);

try {
InternalCache cache = getCache();
InternalCache cache = getCache();

if (groups != null) {
RegionCommandsUtils.validateGroups(cache, groups);
}

RegionFunctionArgs.ExpirationAttrs entryIdle = null;
if (entryExpirationIdleTime != null || entryExpirationIdleTimeAction != null) {
if (entryExpirationIdleTime != null && entryExpirationIdleTime == -1) {
entryExpirationIdleTime = ExpirationAttributes.DEFAULT.getTimeout();
}
if (CliMetaData.ANNOTATION_DEFAULT_VALUE.equals(entryExpirationIdleTimeAction)) {
entryExpirationIdleTimeAction = ExpirationAttributes.DEFAULT.getAction().toString();
}
entryIdle = new RegionFunctionArgs.ExpirationAttrs(
RegionFunctionArgs.ExpirationAttrs.ExpirationFor.ENTRY_IDLE, entryExpirationIdleTime,
entryExpirationIdleTimeAction);
}
RegionFunctionArgs.ExpirationAttrs entryTTL = null;
if (entryExpirationTTL != null || entryExpirationTTLAction != null) {
if (entryExpirationTTL != null && entryExpirationTTL == -1) {
entryExpirationTTL = ExpirationAttributes.DEFAULT.getTimeout();
}
if (CliMetaData.ANNOTATION_DEFAULT_VALUE.equals(entryExpirationTTLAction)) {
entryExpirationTTLAction = ExpirationAttributes.DEFAULT.getAction().toString();
}
entryTTL = new RegionFunctionArgs.ExpirationAttrs(
RegionFunctionArgs.ExpirationAttrs.ExpirationFor.ENTRY_TTL, entryExpirationTTL,
entryExpirationTTLAction);
}
RegionFunctionArgs.ExpirationAttrs regionIdle = null;
if (regionExpirationIdleTime != null || regionExpirationIdleTimeAction != null) {
if (regionExpirationIdleTime != null && regionExpirationIdleTime == -1) {
regionExpirationIdleTime = ExpirationAttributes.DEFAULT.getTimeout();
}
if (CliMetaData.ANNOTATION_DEFAULT_VALUE.equals(regionExpirationIdleTimeAction)) {
regionExpirationIdleTimeAction = ExpirationAttributes.DEFAULT.getAction().toString();
}
regionIdle = new RegionFunctionArgs.ExpirationAttrs(
RegionFunctionArgs.ExpirationAttrs.ExpirationFor.REGION_IDLE, regionExpirationIdleTime,
regionExpirationIdleTimeAction);
}
RegionFunctionArgs.ExpirationAttrs regionTTL = null;
if (regionExpirationTTL != null || regionExpirationTTLAction != null) {
if (regionExpirationTTL != null && regionExpirationTTL == -1) {
regionExpirationTTL = ExpirationAttributes.DEFAULT.getTimeout();
}
if (CliMetaData.ANNOTATION_DEFAULT_VALUE.equals(regionExpirationTTLAction)) {
regionExpirationTTLAction = ExpirationAttributes.DEFAULT.getAction().toString();
}
regionTTL = new RegionFunctionArgs.ExpirationAttrs(
RegionFunctionArgs.ExpirationAttrs.ExpirationFor.REGION_TTL, regionExpirationTTL,
regionExpirationTTLAction);
}
if (groups != null) {
RegionCommandsUtils.validateGroups(cache, groups);
}

cacheLoader = convertDefaultValue(cacheLoader, StringUtils.EMPTY);
cacheWriter = convertDefaultValue(cacheWriter, StringUtils.EMPTY);

RegionFunctionArgs regionFunctionArgs;
regionFunctionArgs = new RegionFunctionArgs(regionPath, null, null, false, null, null, null,
entryIdle, entryTTL, regionIdle, regionTTL, null, null, null, null, cacheListeners,
cacheLoader, cacheWriter, asyncEventQueueIds, gatewaySenderIds, null, cloningEnabled,
null, null, null, null, null, null, null, null, evictionMax, null, null, null, null);

Set<String> cacheListenersSet = regionFunctionArgs.getCacheListeners();
if (cacheListenersSet != null && !cacheListenersSet.isEmpty()) {
for (String cacheListener : cacheListenersSet) {
if (!RegionCommandsUtils.isClassNameValid(cacheListener)) {
throw new IllegalArgumentException(CliStrings.format(
CliStrings.ALTER_REGION__MSG__SPECIFY_VALID_CLASSNAME_FOR_CACHELISTENER_0_IS_INVALID,
new Object[] {cacheListener}));
}
RegionFunctionArgs regionFunctionArgs = new RegionFunctionArgs();
regionFunctionArgs.setRegionPath(regionPath);
regionFunctionArgs.setEntryExpirationIdleTime(entryExpirationIdleTime,
entryExpirationIdleTimeAction);
regionFunctionArgs.setEntryExpirationTTL(entryExpirationTTL, entryExpirationTTLAction);
regionFunctionArgs.setRegionExpirationIdleTime(regionExpirationIdleTime,
regionExpirationIdleTimeAction);
regionFunctionArgs.setRegionExpirationTTL(regionExpirationTTL, regionExpirationTTLAction);
regionFunctionArgs.setCacheListeners(cacheListeners);
regionFunctionArgs.setCacheLoader(cacheLoader);
regionFunctionArgs.setCacheWriter(cacheWriter);
regionFunctionArgs.setAsyncEventQueueIds(asyncEventQueueIds);
regionFunctionArgs.setGatewaySenderIds(gatewaySenderIds);
regionFunctionArgs.setCloningEnabled(cloningEnabled);
regionFunctionArgs.setEvictionMax(evictionMax);


Set<String> cacheListenersSet = regionFunctionArgs.getCacheListeners();
if (cacheListenersSet != null && !cacheListenersSet.isEmpty()) {
for (String cacheListener : cacheListenersSet) {
if (!RegionCommandsUtils.isClassNameValid(cacheListener)) {
throw new IllegalArgumentException(CliStrings.format(
CliStrings.ALTER_REGION__MSG__SPECIFY_VALID_CLASSNAME_FOR_CACHELISTENER_0_IS_INVALID,
new Object[] {cacheListener}));
}
}
}

if (cacheLoader != null && !RegionCommandsUtils.isClassNameValid(cacheLoader)) {
throw new IllegalArgumentException(CliStrings.format(
CliStrings.ALTER_REGION__MSG__SPECIFY_VALID_CLASSNAME_FOR_CACHELOADER_0_IS_INVALID,
new Object[] {cacheLoader}));
}
if (cacheLoader != null && !RegionCommandsUtils.isClassNameValid(cacheLoader)) {
throw new IllegalArgumentException(CliStrings.format(
CliStrings.ALTER_REGION__MSG__SPECIFY_VALID_CLASSNAME_FOR_CACHELOADER_0_IS_INVALID,
new Object[] {cacheLoader}));
}

if (cacheWriter != null && !RegionCommandsUtils.isClassNameValid(cacheWriter)) {
throw new IllegalArgumentException(CliStrings.format(
CliStrings.ALTER_REGION__MSG__SPECIFY_VALID_CLASSNAME_FOR_CACHEWRITER_0_IS_INVALID,
new Object[] {cacheWriter}));
}
if (cacheWriter != null && !RegionCommandsUtils.isClassNameValid(cacheWriter)) {
throw new IllegalArgumentException(CliStrings.format(
CliStrings.ALTER_REGION__MSG__SPECIFY_VALID_CLASSNAME_FOR_CACHEWRITER_0_IS_INVALID,
new Object[] {cacheWriter}));
}

if (evictionMax != null && evictionMax < 0) {
throw new IllegalArgumentException(CliStrings.format(
CliStrings.ALTER_REGION__MSG__SPECIFY_POSITIVE_INT_FOR_EVICTIONMAX_0_IS_NOT_VALID,
new Object[] {evictionMax}));
}
if (evictionMax != null && evictionMax < 0) {
throw new IllegalArgumentException(CliStrings.format(
CliStrings.ALTER_REGION__MSG__SPECIFY_POSITIVE_INT_FOR_EVICTIONMAX_0_IS_NOT_VALID,
new Object[] {evictionMax}));
}

Set<DistributedMember> targetMembers = CliUtil.findMembers(groups, null);
Set<DistributedMember> targetMembers = CliUtil.findMembers(groups, null);

if (targetMembers.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}
if (targetMembers.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}

ResultCollector<?, ?> resultCollector =
CliUtil.executeFunction(new RegionAlterFunction(), regionFunctionArgs, targetMembers);
List<CliFunctionResult> regionAlterResults =
(List<CliFunctionResult>) resultCollector.getResult();

TabularResultData tabularResultData = ResultBuilder.createTabularResultData();
final String errorPrefix = "ERROR: ";
for (CliFunctionResult regionAlterResult : regionAlterResults) {
boolean success = regionAlterResult.isSuccessful();
tabularResultData.accumulate("Member", regionAlterResult.getMemberIdOrName());
if (success) {
tabularResultData.accumulate("Status", regionAlterResult.getMessage());
xmlEntity.set(regionAlterResult.getXmlEntity());
} else {
tabularResultData.accumulate("Status", errorPrefix + regionAlterResult.getMessage());
tabularResultData.setStatus(Result.Status.ERROR);
}
ResultCollector<?, ?> resultCollector =
CliUtil.executeFunction(new RegionAlterFunction(), regionFunctionArgs, targetMembers);
List<CliFunctionResult> regionAlterResults =
(List<CliFunctionResult>) resultCollector.getResult();

TabularResultData tabularResultData = ResultBuilder.createTabularResultData();
final String errorPrefix = "ERROR: ";
for (CliFunctionResult regionAlterResult : regionAlterResults) {
boolean success = regionAlterResult.isSuccessful();
tabularResultData.accumulate("Member", regionAlterResult.getMemberIdOrName());
if (success) {
tabularResultData.accumulate("Status", regionAlterResult.getMessage());
xmlEntity.set(regionAlterResult.getXmlEntity());
} else {
tabularResultData.accumulate("Status", errorPrefix + regionAlterResult.getMessage());
tabularResultData.setStatus(Result.Status.ERROR);
}
result = ResultBuilder.buildResult(tabularResultData);
} catch (IllegalArgumentException | IllegalStateException e) {
LogWrapper.getInstance().info(e.getMessage());
result = ResultBuilder.createUserErrorResult(e.getMessage());
} catch (RuntimeException e) {
LogWrapper.getInstance().info(e.getMessage(), e);
result = ResultBuilder.createGemFireErrorResult(e.getMessage());
}
result = ResultBuilder.buildResult(tabularResultData);

if (xmlEntity.get() != null) {
persistClusterConfiguration(result,
Expand Down
Loading