use of org.apache.geode.cache.DiskStore in project geode by apache.
the class ShutdownAllDUnitTest method getCreatePRRunnable.
private SerializableRunnable getCreatePRRunnable(final String regionName, final String diskStoreName, final int redundancy) {
return new SerializableRunnable("create pr") {
@Override
public void run() {
final CountDownLatch recoveryDone;
if (redundancy > 0) {
recoveryDone = new CountDownLatch(1);
ResourceObserver observer = new InternalResourceManager.ResourceObserverAdapter() {
@Override
public void recoveryFinished(Region region) {
recoveryDone.countDown();
}
};
InternalResourceManager.setResourceObserver(observer);
} else {
recoveryDone = null;
}
Cache cache = ShutdownAllDUnitTest.this.getCache();
if (diskStoreName != null) {
DiskStore ds = cache.findDiskStore(diskStoreName);
if (ds == null) {
ds = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create(diskStoreName);
}
}
AttributesFactory af = new AttributesFactory();
// use async to trigger flush
af.setDiskSynchronous(false);
af.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(100, EvictionAction.OVERFLOW_TO_DISK));
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(redundancy);
af.setPartitionAttributes(paf.create());
if (diskStoreName != null) {
af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
af.setDiskStoreName(diskStoreName);
} else {
af.setDataPolicy(DataPolicy.PARTITION);
}
cache.createRegion(regionName, af.create());
if (recoveryDone != null) {
try {
recoveryDone.await();
} catch (InterruptedException e) {
Assert.fail("Interrupted", e);
}
}
}
};
}
use of org.apache.geode.cache.DiskStore in project geode by apache.
the class PersistentPartitionedRegionTestBase method getPersistentPRAttributes.
protected RegionAttributes getPersistentPRAttributes(final int redundancy, final int recoveryDelay, Cache cache, int numBuckets, boolean synchronous) {
DiskStore ds = cache.findDiskStore("disk");
if (ds == null) {
ds = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create("disk");
}
AttributesFactory af = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(redundancy);
paf.setRecoveryDelay(recoveryDelay);
paf.setTotalNumBuckets(numBuckets);
// Make sure all vms end up with the same local max memory
paf.setLocalMaxMemory(500);
af.setPartitionAttributes(paf.create());
af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
af.setDiskStoreName("disk");
af.setDiskSynchronous(synchronous);
RegionAttributes attr = af.create();
return attr;
}
use of org.apache.geode.cache.DiskStore in project geode by apache.
the class MyGatewayEventSubstitutionFilter method createSender.
public static void createSender(String dsName, int remoteDsId, boolean isParallel, Integer maxMemory, Integer batchSize, boolean isConflation, boolean isPersistent, GatewayEventFilter filter, boolean isManulaStart) {
final IgnoredException exln = IgnoredException.addIgnoredException("Could not connect");
try {
File persistentDirectory = new File(dsName + "_disk_" + System.currentTimeMillis() + "_" + VM.getCurrentVMNum());
persistentDirectory.mkdir();
DiskStoreFactory dsf = cache.createDiskStoreFactory();
File[] dirs1 = new File[] { persistentDirectory };
if (isParallel) {
GatewaySenderFactory gateway = cache.createGatewaySenderFactory();
gateway.setParallel(true);
gateway.setMaximumQueueMemory(maxMemory);
gateway.setBatchSize(batchSize);
gateway.setManualStart(isManulaStart);
// set dispatcher threads
gateway.setDispatcherThreads(numDispatcherThreadsForTheRun);
((InternalGatewaySenderFactory) gateway).setLocatorDiscoveryCallback(new MyLocatorCallback());
if (filter != null) {
eventFilter = filter;
gateway.addGatewayEventFilter(filter);
}
if (isPersistent) {
gateway.setPersistenceEnabled(true);
gateway.setDiskStoreName(dsf.setDiskDirs(dirs1).create(dsName).getName());
} else {
DiskStore store = dsf.setDiskDirs(dirs1).create(dsName);
gateway.setDiskStoreName(store.getName());
}
gateway.setBatchConflationEnabled(isConflation);
gateway.create(dsName, remoteDsId);
} else {
GatewaySenderFactory gateway = cache.createGatewaySenderFactory();
gateway.setMaximumQueueMemory(maxMemory);
gateway.setBatchSize(batchSize);
gateway.setManualStart(isManulaStart);
// set dispatcher threads
gateway.setDispatcherThreads(numDispatcherThreadsForTheRun);
((InternalGatewaySenderFactory) gateway).setLocatorDiscoveryCallback(new MyLocatorCallback());
if (filter != null) {
eventFilter = filter;
gateway.addGatewayEventFilter(filter);
}
gateway.setBatchConflationEnabled(isConflation);
if (isPersistent) {
gateway.setPersistenceEnabled(true);
gateway.setDiskStoreName(dsf.setDiskDirs(dirs1).create(dsName).getName());
} else {
DiskStore store = dsf.setDiskDirs(dirs1).create(dsName);
gateway.setDiskStoreName(store.getName());
}
gateway.create(dsName, remoteDsId);
}
} finally {
exln.remove();
}
}
use of org.apache.geode.cache.DiskStore in project geode by apache.
the class DiskStoreCommandsDUnitTest method testOfflineDiskStorePdxCommands.
@Test
public void testOfflineDiskStorePdxCommands() {
final Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(START_LOCATOR, "localhost[" + AvailablePortHelper.getRandomAvailableTCPPort() + "]");
final File diskStoreDir = new File(new File(".").getAbsolutePath(), "DiskStoreCommandDUnitDiskStores");
diskStoreDir.mkdir();
this.filesToBeDeleted.add(diskStoreDir.getAbsolutePath());
final String diskStoreName1 = "DiskStore1";
final String region1 = "Region1";
final VM vm1 = Host.getHost(0).getVM(1);
vm1.invoke(new SerializableRunnable() {
public void run() {
final Cache cache = new CacheFactory(props).setPdxPersistent(true).setPdxDiskStore(diskStoreName1).create();
DiskStoreFactory diskStoreFactory = cache.createDiskStoreFactory();
diskStoreFactory.setDiskDirs(new File[] { diskStoreDir });
final DiskStore diskStore1 = diskStoreFactory.create(diskStoreName1);
assertNotNull(diskStore1);
RegionFactory regionFactory = cache.createRegionFactory(RegionShortcut.REPLICATE_PERSISTENT);
regionFactory.setDiskStoreName(diskStoreName1);
regionFactory.setDiskSynchronous(true);
Region r1 = regionFactory.create(region1);
r1.put("key-1", new PortfolioPdx(1));
cache.close();
assertTrue(new File(diskStoreDir, "BACKUP" + diskStoreName1 + ".if").exists());
}
});
CommandResult cmdResult = executeCommand("describe offline-disk-store --name=" + diskStoreName1 + " --disk-dirs=" + diskStoreDir.getAbsolutePath() + " --pdx=true");
String stringResult = commandResultToString(cmdResult);
assertTrue(stringContainsLine(stringResult, ".*PDX Types.*"));
assertTrue(stringContainsLine(stringResult, ".*org\\.apache\\.geode\\.cache\\.query\\.data\\.PortfolioPdx.*"));
assertTrue(stringContainsLine(stringResult, ".*org\\.apache\\.geode\\.cache\\.query\\.data\\.PositionPdx.*"));
assertTrue(stringContainsLine(stringResult, ".*PDX Enums.*"));
assertTrue(stringContainsLine(stringResult, ".*org\\.apache\\.geode\\.cache\\.query\\.data\\.PortfolioPdx\\$Day.*"));
}
use of org.apache.geode.cache.DiskStore in project geode by apache.
the class DiskStoreCommandsDUnitTest method testExportOfflineDiskStore.
@Test
public void testExportOfflineDiskStore() throws Exception {
setUpJmxManagerOnVm0ThenConnect(null);
final File diskStoreDir = new File(new File(".").getAbsolutePath(), "DiskStoreCommandDUnitDiskStores");
diskStoreDir.mkdir();
this.filesToBeDeleted.add(diskStoreDir.getAbsolutePath());
final File exportDir = new File(new File(".").getAbsolutePath(), "DiskStoreCommandDUnitExport");
exportDir.mkdir();
this.filesToBeDeleted.add(exportDir.getAbsolutePath());
final String diskStoreName1 = "DiskStore1";
final String region1 = "Region1";
final String region2 = "Region2";
final Map<String, String> entries = new HashMap<String, String>();
entries.put("key1", "value1");
entries.put("key2", "value2");
final VM vm1 = Host.getHost(0).getVM(1);
vm1.invoke(new SerializableRunnable() {
public void run() {
final Cache cache = getCache();
DiskStoreFactory diskStoreFactory = cache.createDiskStoreFactory();
diskStoreFactory.setDiskDirs(new File[] { diskStoreDir });
final DiskStore diskStore1 = diskStoreFactory.create(diskStoreName1);
assertNotNull(diskStore1);
RegionFactory regionFactory = cache.createRegionFactory(RegionShortcut.REPLICATE_PERSISTENT);
regionFactory.setDiskStoreName(diskStoreName1);
regionFactory.setDiskSynchronous(true);
Region r1 = regionFactory.create(region1);
r1.putAll(entries);
Region r2 = regionFactory.create(region2);
r2.putAll(entries);
cache.close();
assertTrue(new File(diskStoreDir, "BACKUP" + diskStoreName1 + ".if").exists());
}
});
String command = "export offline-disk-store --name=" + diskStoreName1 + " --disk-dirs=" + diskStoreDir.getAbsolutePath() + " --dir=" + exportDir;
getLogWriter().info("testExportDiskStore command" + command);
CommandResult cmdResult = executeCommand(command);
if (cmdResult != null) {
assertEquals(Result.Status.OK, cmdResult.getStatus());
String stringResult = commandResultToString(cmdResult);
SnapshotTestUtil.checkSnapshotEntries(exportDir, entries, diskStoreName1, region1);
SnapshotTestUtil.checkSnapshotEntries(exportDir, entries, diskStoreName1, region2);
} else {
getLogWriter().info("testExportOfflineDiskStore cmdResult is null");
fail("Did not get CommandResult in testExportOfflineDiskStore");
}
}
Aggregations