use of org.apache.geode.cache.DiskStore in project geode by apache.
the class PRQueryDUnitHelper method getCacheSerializableRunnableForColocatedChildCreate.
/**
* This function creates the parent region of colocated pair of PR's given the scope & the
* redundancy parameters for the parent *
*
* @param regionName
* @param redundancy
* @param constraint
* @param isPersistent
* @return cacheSerializable object
*/
public CacheSerializableRunnable getCacheSerializableRunnableForColocatedChildCreate(final String regionName, final int redundancy, final Class constraint, boolean isPersistent) {
final String childRegionName = regionName + "Child";
final String diskName = "disk";
SerializableRunnable createPrRegion;
createPrRegion = new CacheSerializableRunnable(regionName + "-ChildRegion") {
@Override
public void run2() throws CacheException {
Cache cache = getCache();
Region partitionedregion = null;
Region childRegion = null;
AttributesFactory attr = new AttributesFactory();
attr.setValueConstraint(constraint);
if (isPersistent) {
DiskStore ds = cache.findDiskStore(diskName);
if (ds == null) {
// ds = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs())
ds = cache.createDiskStoreFactory().setDiskDirs(org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase.getDiskDirs()).create(diskName);
}
attr.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
attr.setDiskStoreName(diskName);
} else {
attr.setDataPolicy(DataPolicy.PARTITION);
attr.setDiskStoreName(null);
}
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(redundancy);
attr.setPartitionAttributes(paf.create());
// skip parent region creation
// partitionedregion = cache.createRegion(regionName, attr.create());
// child region
attr.setValueConstraint(constraint);
paf.setColocatedWith(regionName);
attr.setPartitionAttributes(paf.create());
childRegion = cache.createRegion(childRegionName, attr.create());
}
};
return (CacheSerializableRunnable) createPrRegion;
}
use of org.apache.geode.cache.DiskStore in project geode by apache.
the class DiskStoreFactoryImpl method create.
public DiskStore create(String name) {
this.attrs.name = name;
// As a simple fix for 41290, only allow one DiskStore to be created
// at a time per cache by syncing on the cache.
DiskStore result;
synchronized (this.cache) {
result = findExisting(name);
if (result == null) {
if (this.cache instanceof GemFireCacheImpl) {
TypeRegistry registry = this.cache.getPdxRegistry();
DiskStoreImpl dsi = new DiskStoreImpl(this.cache, this.attrs);
result = dsi;
// Added for M&M
this.cache.getInternalDistributedSystem().handleResourceEvent(ResourceEvent.DISKSTORE_CREATE, dsi);
dsi.doInitialRecovery();
this.cache.addDiskStore(dsi);
if (registry != null) {
registry.creatingDiskStore(dsi);
}
} else if (this.cache instanceof CacheCreation) {
CacheCreation creation = (CacheCreation) this.cache;
result = new DiskStoreAttributesCreation(this.attrs);
creation.addDiskStore(result);
}
}
}
// that isn't backed up.
if (this.cache instanceof GemFireCacheImpl) {
BackupManager backup = this.cache.getBackupManager();
if (backup != null) {
backup.waitForBackup();
}
}
return result;
}
use of org.apache.geode.cache.DiskStore in project geode by apache.
the class CacheXmlGenerator method parse.
/**
* Called by the transformer to parse the "input source". We ignore the input source and, instead,
* generate SAX events to the {@link #setContentHandler ContentHandler}.
*/
public void parse(InputSource input) throws SAXException {
Assert.assertTrue(this.handler != null);
boolean isClientCache = this.creation instanceof ClientCacheCreation;
handler.startDocument();
AttributesImpl atts = new AttributesImpl();
if (this.useSchema) {
if (null == version.getSchemaLocation()) {
// TODO jbarrett - localize
throw new IllegalStateException("No schema for version " + version.getVersion());
}
// add schema location for cache schema.
handler.startPrefixMapping(W3C_XML_SCHEMA_INSTANCE_PREFIX, W3C_XML_SCHEMA_INSTANCE_NS_URI);
addAttribute(atts, W3C_XML_SCHEMA_INSTANCE_PREFIX, W3C_XML_SCHEMA_INSTANCE_ATTRIBUTE_SCHEMA_LOCATION, version.getNamespace() + " " + version.getSchemaLocation());
// add cache schema to default prefix.
handler.startPrefixMapping(XmlConstants.DEFAULT_PREFIX, version.getNamespace());
addAttribute(atts, VERSION, this.version.getVersion());
}
if (creation.hasLockLease()) {
atts.addAttribute("", "", LOCK_LEASE, "", String.valueOf(creation.getLockLease()));
}
if (creation.hasLockTimeout()) {
atts.addAttribute("", "", LOCK_TIMEOUT, "", String.valueOf(creation.getLockTimeout()));
}
if (creation.hasSearchTimeout()) {
atts.addAttribute("", "", SEARCH_TIMEOUT, "", String.valueOf(creation.getSearchTimeout()));
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_5) >= 0) {
// TODO
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_7) >= 0) {
// TODO
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_8) >= 0) {
// TODO
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_0) >= 0) {
// TODO
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_5) >= 0) {
// TODO
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) {
// TODO
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) {
// TODO
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_1) >= 0) {
if (creation.hasMessageSyncInterval()) {
atts.addAttribute("", "", MESSAGE_SYNC_INTERVAL, "", String.valueOf(creation.getMessageSyncInterval()));
}
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_4_0) >= 0) {
if (creation.hasServer()) {
atts.addAttribute("", "", IS_SERVER, "", String.valueOf(creation.isServer()));
}
if (creation.hasCopyOnRead()) {
atts.addAttribute("", "", COPY_ON_READ, "", String.valueOf(creation.getCopyOnRead()));
}
}
if (isClientCache) {
handler.startElement("", CLIENT_CACHE, CLIENT_CACHE, atts);
} else {
handler.startElement("", CACHE, CACHE, atts);
}
if (this.cache != null) {
if (!isClientCache) {
generate(this.cache.getCacheTransactionManager());
} else if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_6) >= 0) {
generate(this.cache.getCacheTransactionManager());
}
generateDynamicRegionFactory(this.cache);
if (!isClientCache) {
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) {
Set<GatewaySender> senderSet = cache.getGatewaySenders();
for (GatewaySender sender : senderSet) {
generateGatewaySender(sender);
}
generateGatewayReceiver(this.cache);
generateAsyncEventQueue(this.cache);
}
}
if (!isClientCache && this.version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) {
if (this.cache.getGatewayConflictResolver() != null) {
generate(GATEWAY_CONFLICT_RESOLVER, this.cache.getGatewayConflictResolver());
}
}
if (!isClientCache) {
for (Iterator iter = this.cache.getCacheServers().iterator(); iter.hasNext(); ) {
CacheServer bridge = (CacheServer) iter.next();
generate(bridge);
}
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_7) >= 0) {
Iterator pools;
if (this.cache instanceof GemFireCacheImpl) {
pools = PoolManager.getAll().values().iterator();
} else {
pools = this.creation.getPools().values().iterator();
}
while (pools.hasNext()) {
Pool cp = (Pool) pools.next();
generate(cp);
}
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_5) >= 0) {
if (this.cache instanceof GemFireCacheImpl) {
InternalCache gfc = (InternalCache) this.cache;
for (DiskStore ds : gfc.listDiskStores()) {
generate(ds);
}
} else {
for (DiskStore ds : this.creation.listDiskStores()) {
generate(ds);
}
}
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_6) >= 0) {
generatePdx();
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_4_1) >= 0) {
Map namedAttributes = this.cache.listRegionAttributes();
for (Iterator iter = namedAttributes.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry entry = (Map.Entry) iter.next();
String id = (String) entry.getKey();
RegionAttributes attrs = (RegionAttributes) entry.getValue();
// Since CacheCreation predefines these even in later versions
// we need to exclude them in all versions.
// It would be better if CacheCreation could only predefine them
// for versions 6.5 and later but that is not easy to do
{
if (this.creation instanceof ClientCacheCreation) {
try {
ClientRegionShortcut.valueOf(id);
// skip this guy since id mapped to one of the enum types
continue;
} catch (IllegalArgumentException ignore) {
// id is not a shortcut so go ahead and call generate
}
} else {
try {
RegionShortcut.valueOf(id);
// skip this guy since id mapped to one of the enum types
continue;
} catch (IllegalArgumentException ignore) {
// id is not a shortcut so go ahead and call generate
}
}
}
generate(id, attrs);
}
}
if (cache instanceof GemFireCacheImpl) {
generateRegions();
} else {
TreeSet rSet = new TreeSet(new RegionComparator());
rSet.addAll(this.cache.rootRegions());
Iterator it = rSet.iterator();
while (it.hasNext()) {
Region root = (Region) it.next();
generateRegion(root);
}
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_8) >= 0) {
generateFunctionService();
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_0) >= 0) {
generateResourceManager();
generateSerializerRegistration();
}
if (!isClientCache) {
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_5) >= 0) {
if (this.cache instanceof GemFireCacheImpl) {
InternalCache internalCache = (InternalCache) this.cache;
for (File file : internalCache.getBackupFiles()) {
generateBackupFile(file);
}
} else {
for (File file : this.creation.getBackupFiles()) {
generateBackupFile(file);
}
}
}
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_6) >= 0) {
generateInitializer();
}
}
if (cache instanceof Extensible) {
@SuppressWarnings("unchecked") final Extensible<Cache> extensible = (Extensible<Cache>) cache;
generate(extensible);
}
if (isClientCache) {
handler.endElement("", CLIENT_CACHE, CLIENT_CACHE);
} else {
handler.endElement("", CACHE, CACHE);
}
handler.endDocument();
}
use of org.apache.geode.cache.DiskStore in project geode by apache.
the class CacheCreation method create.
/**
* Fills in the contents of a {@link Cache} based on this creation object's state.
*/
void create(InternalCache cache) throws TimeoutException, CacheWriterException, GatewayException, RegionExistsException {
this.extensionPoint.beforeCreate(cache);
cache.setDeclarativeCacheConfig(this.cacheConfig);
if (cache.isClient()) {
throw new IllegalStateException("You must use client-cache in the cache.xml when ClientCacheFactory is used.");
}
if (this.hasLockLease()) {
cache.setLockLease(this.lockLease);
}
if (this.hasLockTimeout()) {
cache.setLockTimeout(this.lockTimeout);
}
if (this.hasSearchTimeout()) {
cache.setSearchTimeout(this.searchTimeout);
}
if (this.hasMessageSyncInterval()) {
cache.setMessageSyncInterval(this.getMessageSyncInterval());
}
if (this.gatewayConflictResolver != null) {
cache.setGatewayConflictResolver(this.gatewayConflictResolver);
}
// create connection pools
Map<String, Pool> pools = getPools();
if (!pools.isEmpty()) {
for (Pool pool : pools.values()) {
PoolFactoryImpl poolFactory = (PoolFactoryImpl) PoolManager.createFactory();
poolFactory.init(pool);
poolFactory.create(pool.getName());
}
}
if (hasResourceManager()) {
// moved this up to fix bug 42128
getResourceManager().configure(cache.getResourceManager());
}
DiskStoreAttributesCreation pdxRegDSC = initializePdxDiskStore(cache);
cache.initializePdxRegistry();
for (DiskStore diskStore : this.diskStores.values()) {
DiskStoreAttributesCreation creation = (DiskStoreAttributesCreation) diskStore;
if (creation != pdxRegDSC) {
createDiskStore(creation, cache);
}
}
if (this.hasDynamicRegionFactory()) {
DynamicRegionFactory.get().open(this.getDynamicRegionFactoryConfig());
}
if (this.hasServer()) {
cache.setIsServer(this.isServer);
}
if (this.hasCopyOnRead()) {
cache.setCopyOnRead(this.copyOnRead);
}
if (this.txMgrCreation != null && this.txMgrCreation.getListeners().length > 0 && cache.getCacheTransactionManager() != null) {
cache.getCacheTransactionManager().initListeners(this.txMgrCreation.getListeners());
}
if (this.txMgrCreation != null && cache.getCacheTransactionManager() != null) {
cache.getCacheTransactionManager().setWriter(this.txMgrCreation.getWriter());
}
for (GatewaySender senderCreation : this.getGatewaySenders()) {
GatewaySenderFactory factory = cache.createGatewaySenderFactory();
((InternalGatewaySenderFactory) factory).configureGatewaySender(senderCreation);
GatewaySender gatewaySender = factory.create(senderCreation.getId(), senderCreation.getRemoteDSId());
// Start the sender if it is not set to manually start
if (gatewaySender.isManualStart()) {
cache.getLoggerI18n().info(LocalizedStrings.CacheCreation_0_IS_NOT_BEING_STARTED_SINCE_IT_IS_CONFIGURED_FOR_MANUAL_START, gatewaySender);
}
}
for (AsyncEventQueue asyncEventQueueCreation : this.getAsyncEventQueues()) {
AsyncEventQueueFactoryImpl asyncQueueFactory = (AsyncEventQueueFactoryImpl) cache.createAsyncEventQueueFactory();
asyncQueueFactory.configureAsyncEventQueue(asyncEventQueueCreation);
AsyncEventQueue asyncEventQueue = cache.getAsyncEventQueue(asyncEventQueueCreation.getId());
if (asyncEventQueue == null) {
asyncQueueFactory.create(asyncEventQueueCreation.getId(), asyncEventQueueCreation.getAsyncEventListener());
}
}
cache.initializePdxRegistry();
for (String id : this.regionAttributesNames) {
RegionAttributesCreation creation = (RegionAttributesCreation) getRegionAttributes(id);
creation.inheritAttributes(cache, false);
// Don't let the RegionAttributesCreation escape to the user
AttributesFactory<?, ?> factory = new AttributesFactory<>(creation);
RegionAttributes<?, ?> attrs = factory.create();
cache.setRegionAttributes(id, attrs);
}
initializeRegions(this.roots, cache);
cache.readyDynamicRegionFactory();
// Create and start the BridgeServers. This code was moved from
// before region initialization to after it to fix bug 33587.
// Create and start the CacheServers after the gateways have been initialized
// to fix bug 39736.
Integer serverPort = CacheServerLauncher.getServerPort();
String serverBindAdd = CacheServerLauncher.getServerBindAddress();
Boolean disableDefaultServer = CacheServerLauncher.getDisableDefaultServer();
startCacheServers(getCacheServers(), cache, serverPort, serverBindAdd, disableDefaultServer);
for (GatewayReceiver receiverCreation : this.getGatewayReceivers()) {
GatewayReceiverFactory factory = cache.createGatewayReceiverFactory();
factory.setBindAddress(receiverCreation.getBindAddress());
factory.setMaximumTimeBetweenPings(receiverCreation.getMaximumTimeBetweenPings());
factory.setStartPort(receiverCreation.getStartPort());
factory.setEndPort(receiverCreation.getEndPort());
factory.setSocketBufferSize(receiverCreation.getSocketBufferSize());
factory.setManualStart(receiverCreation.isManualStart());
for (GatewayTransportFilter filter : receiverCreation.getGatewayTransportFilters()) {
factory.addGatewayTransportFilter(filter);
}
factory.setHostnameForSenders(receiverCreation.getHost());
GatewayReceiver receiver = factory.create();
if (receiver.isManualStart()) {
cache.getLoggerI18n().info(LocalizedStrings.CacheCreation_0_IS_NOT_BEING_STARTED_SINCE_IT_IS_CONFIGURED_FOR_MANUAL_START, receiver);
}
}
cache.setBackupFiles(this.backups);
cache.addDeclarableProperties(this.declarablePropertiesMap);
runInitializer();
cache.setInitializer(getInitializer(), getInitializerProps());
// Create all extensions
this.extensionPoint.fireCreate(cache);
}
use of org.apache.geode.cache.DiskStore in project geode by apache.
the class MemberMBeanBridge method backupMember.
/**
* backs up all the disk to the targeted directory
*
* @param targetDirPath path of the directory where back up is to be taken
* @return array of DiskBackup results which might get aggregated at Managing node Check the
* validity of this mbean call. When does it make sense to backup a single member of a
* gemfire system in isolation of the other members?
*/
public DiskBackupResult[] backupMember(String targetDirPath) {
if (cache != null) {
Collection<DiskStore> diskStores = cache.listDiskStoresIncludingRegionOwned();
for (DiskStore store : diskStores) {
store.flush();
}
}
DiskBackupResult[] diskBackUpResult = null;
File targetDir = new File(targetDirPath);
if (cache == null) {
return null;
} else {
try {
BackupManager manager = cache.startBackup(cache.getInternalDistributedSystem().getDistributedMember());
boolean abort = true;
Set<PersistentID> existingDataStores;
Set<PersistentID> successfulDataStores;
try {
existingDataStores = manager.prepareBackup();
abort = false;
} finally {
successfulDataStores = manager.finishBackup(targetDir, null, /* TODO rishi */
abort);
}
diskBackUpResult = new DiskBackupResult[existingDataStores.size()];
int j = 0;
for (PersistentID id : existingDataStores) {
if (successfulDataStores.contains(id)) {
diskBackUpResult[j] = new DiskBackupResult(id.getDirectory(), false);
} else {
diskBackUpResult[j] = new DiskBackupResult(id.getDirectory(), true);
}
j++;
}
} catch (IOException e) {
throw new ManagementException(e);
}
}
return diskBackUpResult;
}
Aggregations