use of org.apache.geode.cache.DiskStoreFactory in project geode by apache.
the class MyGatewayEventSubstitutionFilter method createAsyncEventQueueWithDiskStore.
public static String createAsyncEventQueueWithDiskStore(String asyncChannelId, boolean isParallel, Integer maxMemory, Integer batchSize, boolean isPersistent, String diskStoreName) {
AsyncEventListener asyncEventListener = new MyAsyncEventListener();
File persistentDirectory = null;
if (diskStoreName == null) {
persistentDirectory = new File(asyncChannelId + "_disk_" + System.currentTimeMillis() + "_" + VM.getCurrentVMNum());
} else {
persistentDirectory = new File(diskStoreName);
}
LogWriterUtils.getLogWriter().info("The ds is : " + persistentDirectory.getName());
persistentDirectory.mkdir();
DiskStoreFactory dsf = cache.createDiskStoreFactory();
File[] dirs1 = new File[] { persistentDirectory };
AsyncEventQueueFactory factory = cache.createAsyncEventQueueFactory();
factory.setBatchSize(batchSize);
factory.setParallel(isParallel);
if (isPersistent) {
factory.setPersistent(isPersistent);
factory.setDiskStoreName(dsf.setDiskDirs(dirs1).create(asyncChannelId).getName());
}
factory.setMaximumQueueMemory(maxMemory);
// set dispatcher threads
factory.setDispatcherThreads(numDispatcherThreadsForTheRun);
AsyncEventQueue asyncChannel = factory.create(asyncChannelId, asyncEventListener);
return persistentDirectory.getName();
}
use of org.apache.geode.cache.DiskStoreFactory 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.DiskStoreFactory 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.DiskStoreFactory 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");
}
}
use of org.apache.geode.cache.DiskStoreFactory in project geode by apache.
the class DiskStoreCommandsDUnitTest method createParRegWithPersistence.
private Region<?, ?> createParRegWithPersistence(String regionName, String diskStoreName, String diskDirName) {
Cache cache = getCache();
File diskStoreDirFile = new File(diskDirName);
if (!diskStoreDirFile.exists()) {
diskStoreDirFile.mkdirs();
}
DiskStoreFactory diskStoreFactory = cache.createDiskStoreFactory();
diskStoreFactory.setDiskDirs(new File[] { diskStoreDirFile });
diskStoreFactory.setMaxOplogSize(1);
diskStoreFactory.setAllowForceCompaction(true);
diskStoreFactory.setAutoCompact(false);
diskStoreFactory.create(diskStoreName);
/****
* Eviction Attributes
*/
EvictionAttributes ea = EvictionAttributes.createLRUEntryAttributes(1, EvictionAction.OVERFLOW_TO_DISK);
RegionFactory regionFactory = cache.createRegionFactory();
regionFactory.setDiskStoreName(diskStoreName);
regionFactory.setDiskSynchronous(true);
regionFactory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
regionFactory.setScope(Scope.DISTRIBUTED_ACK);
regionFactory.setEvictionAttributes(ea);
return regionFactory.create(regionName);
}
Aggregations