use of org.apache.geode.cache.RegionShortcut in project geode by apache.
the class LuceneIndexForPartitionedRegion method createLuceneListenersAndFileChunkRegions.
protected void createLuceneListenersAndFileChunkRegions(AbstractPartitionedRepositoryManager partitionedRepositoryManager) {
partitionedRepositoryManager.setUserRegionForRepositoryManager();
RegionShortcut regionShortCut;
final boolean withPersistence = withPersistence();
RegionAttributes regionAttributes = dataRegion.getAttributes();
final boolean withStorage = regionAttributes.getPartitionAttributes().getLocalMaxMemory() > 0;
// 4) Offheap to Offheap
if (!withStorage) {
regionShortCut = RegionShortcut.PARTITION_PROXY;
} else if (withPersistence) {
// TODO: add PartitionedRegionAttributes instead
regionShortCut = RegionShortcut.PARTITION_PERSISTENT;
} else {
regionShortCut = RegionShortcut.PARTITION;
}
// create PR fileAndChunkRegion, but not to create its buckets for now
final String fileRegionName = createFileRegionName();
PartitionAttributes partitionAttributes = dataRegion.getPartitionAttributes();
DM dm = this.cache.getInternalDistributedSystem().getDistributionManager();
LuceneBucketListener lucenePrimaryBucketListener = new LuceneBucketListener(partitionedRepositoryManager, dm);
if (!fileRegionExists(fileRegionName)) {
fileAndChunkRegion = createFileRegion(regionShortCut, fileRegionName, partitionAttributes, regionAttributes, lucenePrimaryBucketListener);
}
fileSystemStats.setBytesSupplier(() -> getFileAndChunkRegion().getPrStats().getDataStoreBytesInUse());
}
use of org.apache.geode.cache.RegionShortcut in project geode by apache.
the class CreateAlterDestroyRegionCommands method validateRegionFunctionArgs.
private void validateRegionFunctionArgs(InternalCache cache, RegionFunctionArgs regionFunctionArgs) {
if (regionFunctionArgs.getRegionPath() == null) {
throw new IllegalArgumentException(CliStrings.CREATE_REGION__MSG__SPECIFY_VALID_REGION_PATH);
}
ManagementService managementService = ManagementService.getExistingManagementService(cache);
DistributedSystemMXBean dsMBean = managementService.getDistributedSystemMXBean();
String useAttributesFrom = regionFunctionArgs.getUseAttributesFrom();
if (useAttributesFrom != null && !useAttributesFrom.isEmpty() && regionExists(cache, useAttributesFrom)) {
if (!regionExists(cache, useAttributesFrom)) {
// check already done in createRegion !!!
throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__SPECIFY_VALID_REGION_PATH_FOR_0_REGIONPATH_1_NOT_FOUND, new Object[] { CliStrings.CREATE_REGION__USEATTRIBUTESFROM, useAttributesFrom }));
}
if (!regionFunctionArgs.isSetUseAttributesFrom() || regionFunctionArgs.getRegionAttributes() == null) {
throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__COULD_NOT_RETRIEVE_REGION_ATTRS_FOR_PATH_0_VERIFY_REGION_EXISTS, useAttributesFrom));
}
}
if (regionFunctionArgs.hasPartitionAttributes()) {
RegionFunctionArgs.PartitionArgs partitionArgs = regionFunctionArgs.getPartitionArgs();
String colocatedWith = partitionArgs.getPrColocatedWith();
if (colocatedWith != null && !colocatedWith.isEmpty()) {
String[] listAllRegionPaths = dsMBean.listAllRegionPaths();
String foundRegionPath = null;
for (String regionPath : listAllRegionPaths) {
if (regionPath.equals(colocatedWith)) {
foundRegionPath = regionPath;
break;
}
}
if (foundRegionPath == null) {
throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__SPECIFY_VALID_REGION_PATH_FOR_0_REGIONPATH_1_NOT_FOUND, new Object[] { CliStrings.CREATE_REGION__COLOCATEDWITH, colocatedWith }));
}
ManagementService mgmtService = ManagementService.getExistingManagementService(cache);
DistributedRegionMXBean distributedRegionMXBean = mgmtService.getDistributedRegionMXBean(foundRegionPath);
String regionType = distributedRegionMXBean.getRegionType();
if (!(DataPolicy.PARTITION.toString().equals(regionType) || DataPolicy.PERSISTENT_PARTITION.toString().equals(regionType))) {
throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__COLOCATEDWITH_REGION_0_IS_NOT_PARTITIONEDREGION, new Object[] { colocatedWith }));
}
}
if (partitionArgs.isSetPRLocalMaxMemory()) {
int prLocalMaxMemory = partitionArgs.getPrLocalMaxMemory();
if (prLocalMaxMemory < 0) {
throw new IllegalArgumentException(LocalizedStrings.AttributesFactory_PARTITIONATTRIBUTES_LOCALMAXMEMORY_MUST_NOT_BE_NEGATIVE.toLocalizedString());
}
}
if (partitionArgs.isSetPRTotalMaxMemory()) {
long prTotalMaxMemory = partitionArgs.getPrTotalMaxMemory();
if (prTotalMaxMemory <= 0) {
throw new IllegalArgumentException(LocalizedStrings.AttributesFactory_TOTAL_SIZE_OF_PARTITION_REGION_MUST_BE_0.toLocalizedString());
}
}
if (partitionArgs.isSetPRRedundantCopies()) {
int prRedundantCopies = partitionArgs.getPrRedundantCopies();
switch(prRedundantCopies) {
case 0:
case 1:
case 2:
case 3:
break;
default:
throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__REDUNDANT_COPIES_SHOULD_BE_ONE_OF_0123, new Object[] { prRedundantCopies }));
}
}
}
String keyConstraint = regionFunctionArgs.getKeyConstraint();
if (keyConstraint != null && !isClassNameValid(keyConstraint)) {
throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__SPECIFY_VALID_CLASSNAME_FOR_KEYCONSTRAINT_0_IS_INVALID, new Object[] { keyConstraint }));
}
String valueConstraint = regionFunctionArgs.getValueConstraint();
if (valueConstraint != null && !isClassNameValid(valueConstraint)) {
throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__SPECIFY_VALID_CLASSNAME_FOR_VALUECONSTRAINT_0_IS_INVALID, new Object[] { valueConstraint }));
}
Set<String> cacheListeners = regionFunctionArgs.getCacheListeners();
if (cacheListeners != null && !cacheListeners.isEmpty()) {
for (String cacheListener : cacheListeners) {
if (!isClassNameValid(cacheListener)) {
throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__SPECIFY_VALID_CLASSNAME_FOR_CACHELISTENER_0_IS_INVALID, new Object[] { cacheListener }));
}
}
}
String cacheLoader = regionFunctionArgs.getCacheLoader();
if (cacheLoader != null && !isClassNameValid(cacheLoader)) {
throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__SPECIFY_VALID_CLASSNAME_FOR_CACHELOADER_0_IS_INVALID, new Object[] { cacheLoader }));
}
String cacheWriter = regionFunctionArgs.getCacheWriter();
if (cacheWriter != null && !isClassNameValid(cacheWriter)) {
throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__SPECIFY_VALID_CLASSNAME_FOR_CACHEWRITER_0_IS_INVALID, new Object[] { cacheWriter }));
}
Set<String> gatewaySenderIds = regionFunctionArgs.getGatewaySenderIds();
if (gatewaySenderIds != null && !gatewaySenderIds.isEmpty()) {
String[] gatewaySenders = dsMBean.listGatewaySenders();
if (gatewaySenders.length == 0) {
throw new IllegalArgumentException(CliStrings.CREATE_REGION__MSG__NO_GATEWAYSENDERS_IN_THE_SYSTEM);
} else {
List<String> gatewaySendersList = new ArrayList<>(Arrays.asList(gatewaySenders));
gatewaySenderIds = new HashSet<>(gatewaySenderIds);
gatewaySenderIds.removeAll(gatewaySendersList);
if (!gatewaySenderIds.isEmpty()) {
throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__SPECIFY_VALID_GATEWAYSENDER_ID_UNKNOWN_0, new Object[] { gatewaySenderIds }));
}
}
}
if (regionFunctionArgs.isSetConcurrencyLevel()) {
int concurrencyLevel = regionFunctionArgs.getConcurrencyLevel();
if (concurrencyLevel < 0) {
throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__SPECIFY_POSITIVE_INT_FOR_CONCURRENCYLEVEL_0_IS_NOT_VALID, new Object[] { concurrencyLevel }));
}
}
String diskStore = regionFunctionArgs.getDiskStore();
if (diskStore != null) {
RegionShortcut regionShortcut = regionFunctionArgs.getRegionShortcut();
if (regionShortcut != null && !PERSISTENT_OVERFLOW_SHORTCUTS.contains(regionShortcut)) {
String subMessage = LocalizedStrings.DiskStore_IS_USED_IN_NONPERSISTENT_REGION.toLocalizedString();
String message = subMessage + ". " + CliStrings.format(CliStrings.CREATE_REGION__MSG__USE_ONE_OF_THESE_SHORTCUTS_0, new Object[] { String.valueOf(PERSISTENT_OVERFLOW_SHORTCUTS) });
throw new IllegalArgumentException(message);
}
RegionAttributes<?, ?> regionAttributes = regionFunctionArgs.getRegionAttributes();
if (regionAttributes != null && !regionAttributes.getDataPolicy().withPersistence()) {
String subMessage = LocalizedStrings.DiskStore_IS_USED_IN_NONPERSISTENT_REGION.toLocalizedString();
String message = subMessage + ". " + CliStrings.format(CliStrings.CREATE_REGION__MSG__USE_ATTRIBUTES_FROM_REGION_0_IS_NOT_WITH_PERSISTENCE, new Object[] { String.valueOf(regionFunctionArgs.getUseAttributesFrom()) });
throw new IllegalArgumentException(message);
}
if (!diskStoreExists(cache, diskStore)) {
throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__SPECIFY_VALID_DISKSTORE_UNKNOWN_DISKSTORE_0, new Object[] { diskStore }));
}
}
RegionFunctionArgs.ExpirationAttrs entryExpirationIdleTime = regionFunctionArgs.getEntryExpirationIdleTime();
RegionFunctionArgs.ExpirationAttrs entryExpirationTTL = regionFunctionArgs.getEntryExpirationTTL();
RegionFunctionArgs.ExpirationAttrs regionExpirationIdleTime = regionFunctionArgs.getRegionExpirationIdleTime();
RegionFunctionArgs.ExpirationAttrs regionExpirationTTL = regionFunctionArgs.getRegionExpirationTTL();
if ((!regionFunctionArgs.isSetStatisticsEnabled() || !regionFunctionArgs.isStatisticsEnabled()) && (entryExpirationIdleTime != null || entryExpirationTTL != null || regionExpirationIdleTime != null || regionExpirationTTL != null)) {
String message = LocalizedStrings.AttributesFactory_STATISTICS_MUST_BE_ENABLED_FOR_EXPIRATION.toLocalizedString();
throw new IllegalArgumentException(message + ".");
}
boolean compressorFailure = false;
if (regionFunctionArgs.isSetCompressor()) {
String compressorClassName = regionFunctionArgs.getCompressor();
Object compressor = null;
try {
Class<?> compressorClass = ClassPathLoader.getLatest().forName(compressorClassName);
compressor = compressorClass.newInstance();
} catch (InstantiationException | ClassNotFoundException | IllegalAccessException e) {
compressorFailure = true;
}
if (compressorFailure || !(compressor instanceof Compressor)) {
throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__INVALID_COMPRESSOR, new Object[] { regionFunctionArgs.getCompressor() }));
}
}
if (regionFunctionArgs.hasPartitionAttributes()) {
if (regionFunctionArgs.isPartitionResolverSet()) {
String partitionResolverClassName = regionFunctionArgs.getPartitionResolver();
try {
Class<PartitionResolver> resolverClass = (Class<PartitionResolver>) ClassPathLoader.getLatest().forName(partitionResolverClassName);
PartitionResolver partitionResolver = resolverClass.newInstance();
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__INVALID_PARTITION_RESOLVER, new Object[] { regionFunctionArgs.getCompressor() }), e);
}
}
}
}
use of org.apache.geode.cache.RegionShortcut in project geode by apache.
the class CacheXml66DUnitTest method testNormalCache.
@Test
public void testNormalCache() throws Exception {
CacheCreation cache = new CacheCreation();
cache.setCopyOnRead(true);
testXml(cache);
GemFireCacheImpl c = (GemFireCacheImpl) getCache();
assertEquals(true, c.getCopyOnRead());
assertEquals(false, c.isClient());
for (RegionShortcut pra : RegionShortcut.values()) {
assertNotNull(c.getRegionAttributes(pra.name()));
}
assertEquals(RegionShortcut.values().length, c.listRegionAttributes().size());
}
use of org.apache.geode.cache.RegionShortcut in project geode by apache.
the class RollingUpgrade2DUnitTest method doTestConcurrent.
public void doTestConcurrent(boolean partitioned, String oldVersion) throws Exception {
Host host = Host.getHost(0);
VM locator = host.getVM(oldVersion, 1);
VM server1 = host.getVM(oldVersion, 2);
VM server2 = host.getVM(oldVersion, 3);
final String objectType = "strings";
final String regionName = "aRegion";
RegionShortcut shortcut = RegionShortcut.REPLICATE;
if (partitioned) {
shortcut = RegionShortcut.PARTITION_REDUNDANT;
}
int[] locatorPorts = AvailablePortHelper.getRandomAvailableTCPPorts(1);
String hostName = NetworkUtils.getServerHostName(host);
String locatorString = getLocatorString(locatorPorts);
DistributedTestUtils.deleteLocatorStateFile(locatorPorts);
try {
locator.invoke(invokeStartLocator(hostName, locatorPorts[0], getTestMethodName(), getLocatorPropertiesPre91(locatorString)));
invokeRunnableInVMs(invokeCreateCache(getSystemProperties(locatorPorts)), server1, server2);
// invokeRunnableInVMs(invokeAssertVersion(oldOrdinal), server1, server2);
// create region
invokeRunnableInVMs(invokeCreateRegion(regionName, shortcut), server1, server2);
// async puts through server 2
AsyncInvocation asyncPutsThroughOld = server2.invokeAsync(new CacheSerializableRunnable("async puts") {
public void run2() {
try {
for (int i = 0; i < 500; i++) {
put(RollingUpgrade2DUnitTest.cache, regionName, "" + i, "VALUE(" + i + ")");
}
} catch (Exception e) {
fail("error putting");
}
}
});
locator = rollLocatorToCurrent(locator, hostName, locatorPorts[0], getTestMethodName(), locatorString);
server1 = rollServerToCurrentAndCreateRegion(server1, shortcut, regionName, locatorPorts);
ThreadUtils.join(asyncPutsThroughOld, 30000);
// verifyValues in server1
verifyValues(objectType, regionName, 0, 500, server1);
// aync puts through server 1
AsyncInvocation asyncPutsThroughNew = server1.invokeAsync(new CacheSerializableRunnable("async puts") {
public void run2() {
try {
for (int i = 250; i < 750; i++) {
put(RollingUpgrade2DUnitTest.cache, regionName, "" + i, "VALUE(" + i + ")");
}
} catch (Exception e) {
fail("error putting");
}
}
});
server2 = rollServerToCurrentAndCreateRegion(server2, shortcut, regionName, locatorPorts);
ThreadUtils.join(asyncPutsThroughNew, 30000);
// verifyValues in server2
verifyValues(objectType, regionName, 250, 750, server2);
} finally {
invokeRunnableInVMs(true, invokeStopLocator(), locator);
invokeRunnableInVMs(true, invokeCloseCache(), server1, server2);
}
}
use of org.apache.geode.cache.RegionShortcut in project geode by apache.
the class RollingUpgrade2DUnitTest method doTestTracePRQuery.
public void doTestTracePRQuery(boolean partitioned, String oldVersion) throws Exception {
final Host host = Host.getHost(0);
VM currentServer1 = host.getVM(0);
VM oldServer = host.getVM(oldVersion, 1);
VM currentServer2 = host.getVM(2);
VM oldServerAndLocator = host.getVM(oldVersion, 3);
String regionName = "cqs";
RegionShortcut shortcut = RegionShortcut.REPLICATE;
if (partitioned) {
shortcut = RegionShortcut.PARTITION;
}
String serverHostName = NetworkUtils.getServerHostName(Host.getHost(0));
int port = AvailablePortHelper.getRandomAvailableTCPPort();
try {
Properties props = getSystemProperties();
props.remove(DistributionConfig.LOCATORS_NAME);
invokeRunnableInVMs(invokeStartLocatorAndServer(serverHostName, port, props), oldServerAndLocator);
props.put(DistributionConfig.LOCATORS_NAME, serverHostName + "[" + port + "]");
invokeRunnableInVMs(invokeCreateCache(props), currentServer1, currentServer2, oldServer);
currentServer1.invoke(invokeAssertVersion(Version.CURRENT_ORDINAL));
currentServer2.invoke(invokeAssertVersion(Version.CURRENT_ORDINAL));
// oldServer.invoke(invokeAssertVersion(oldOrdinal));
// oldServerAndLocator.invoke(invokeAssertVersion(oldOrdinal));
// create region
invokeRunnableInVMs(invokeCreateRegion(regionName, shortcut), currentServer1, currentServer2, oldServer, oldServerAndLocator);
putDataSerializableAndVerify(currentServer1, regionName, 0, 100, currentServer2, oldServer, oldServerAndLocator);
query("<trace> Select * from /" + regionName + " p where p.timeout > 0L", 99, currentServer1, currentServer2, oldServer, oldServerAndLocator);
} finally {
invokeRunnableInVMs(invokeCloseCache(), currentServer1, currentServer2, oldServer, oldServerAndLocator);
}
}
Aggregations