use of org.apache.geode.cache.DiskAccessException in project geode by apache.
the class DiskRegionJUnitTest method testBridgeServerStoppingInSynchPersistOnlyForIOExceptionCase.
/**
* If IOException occurs while updating an entry in an already initialized DiskRegion ,then the
* bridge servers should not be stopped , if any running as they are no clients connected to it.
*/
@Test
public void testBridgeServerStoppingInSynchPersistOnlyForIOExceptionCase() throws Exception {
DiskRegionProperties props = new DiskRegionProperties();
props.setRegionName("IGNORE_EXCEPTION_testBridgeServerStoppingInSynchPersistOnlyForIOExceptionCase");
props.setOverflow(true);
props.setRolling(true);
props.setDiskDirs(dirs);
props.setPersistBackup(true);
region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, props, Scope.LOCAL);
CacheServer bs1 = cache.addCacheServer();
bs1.setPort(0);
bs1.start();
region.create("key1", new byte[16]);
region.create("key2", new byte[16]);
// Get the oplog handle & hence the underlying file & close it
UninterruptibleFileChannel oplogFileChannel = ((LocalRegion) region).getDiskRegion().testHook_getChild().getFileChannel();
oplogFileChannel.close();
try {
region.put("key2", new byte[16]);
} catch (DiskAccessException dae) {
// OK expected
}
((LocalRegion) region).getDiskStore().waitForClose();
assertTrue(cache.isClosed());
region = null;
List bsRunning = cache.getCacheServers();
// [anil & bruce] the following assertion was changed to true because
// a disk access exception in a server should always stop the server
assertTrue(bsRunning.isEmpty());
}
use of org.apache.geode.cache.DiskAccessException in project geode by apache.
the class DiskRegionJUnitTest method testBridgeServerRunningInSynchPersistOnlyForIOExceptionCase.
/**
* If IOException occurs while initializing a region ,then the bridge servers should not be
* stopped
*/
@Test
public void testBridgeServerRunningInSynchPersistOnlyForIOExceptionCase() throws Exception {
DiskRegionProperties props = new DiskRegionProperties();
props.setRegionName("IGNORE_EXCEPTION_testBridgeServerStoppingInSynchPersistOnlyForIOExceptionCase");
props.setOverflow(true);
props.setRolling(true);
props.setDiskDirs(dirs);
props.setPersistBackup(true);
// just needs to be bigger than 65550
props.setMaxOplogSize(100000);
region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, props, Scope.LOCAL);
CacheServer bs1 = cache.addCacheServer();
bs1.setPort(0);
bs1.start();
region.create("key1", new byte[16]);
region.create("key2", new byte[16]);
// Get the oplog file path
UninterruptibleFileChannel oplogFileChnl = ((LocalRegion) region).getDiskRegion().testHook_getChild().getFileChannel();
// corrupt the opfile
oplogFileChnl.position(2);
ByteBuffer bf = ByteBuffer.allocate(416);
for (int i = 0; i < 5; ++i) {
bf.putInt(i);
}
bf.flip();
// Corrupt the oplogFile
oplogFileChnl.write(bf);
// Close the region
region.close();
assertTrue(region.isDestroyed());
try {
region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, props, Scope.LOCAL);
fail("expected DiskAccessException");
} catch (DiskAccessException dae) {
// OK expected
}
assertTrue(region.isDestroyed());
region = null;
List bsRunning = cache.getCacheServers();
assertTrue(!bsRunning.isEmpty());
}
use of org.apache.geode.cache.DiskAccessException in project geode by apache.
the class PersistentPartitionedRegionDUnitTest method testBadSerializationInAsyncThread.
/**
* Test for bug #49972 - handle a serialization error in the async writer thread.
*/
@Ignore("Bug 50376")
@Test
public void testBadSerializationInAsyncThread() throws Throwable {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
final int numBuckets = 50;
vm0.invoke(new SerializableRunnable() {
@Override
public void run() {
FAIL_IN_THIS_VM = true;
}
});
IgnoredException expected1 = IgnoredException.addIgnoredException("Fatal error from asynch");
IgnoredException expected2 = IgnoredException.addIgnoredException("ToDataException");
try {
int redundancy = 1;
createPR(vm0, redundancy, -1, 113, false);
createPR(vm2, redundancy, -1, 113, false);
// Trigger bucket creation
createData(vm0, 0, numBuckets, "a");
createPR(vm1, redundancy, -1, 113, false);
// write objects which will fail serialization in async writer thread.
vm0.invoke(new SerializableRunnable() {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion(PR_REGION_NAME);
try {
for (int i = 0; i < numBuckets; i++) {
region.put(i, new BadSerializer());
// this will trigger a deserialiation (could have also done this put with a function I
// guess.
region.get(i);
}
} catch (DiskAccessException ex) {
if (ex.getMessage().contains("the flusher thread had been terminated")) {
// expected
} else {
throw ex;
}
}
}
});
// Wait for the thread to get hosed.
Thread.sleep(2000);
createData(vm1, 0, numBuckets, "b");
// Try to do puts from vm1, which doesn't have any buckets
createData(vm1, numBuckets, numBuckets * 2, "b");
createData(vm1, numBuckets, numBuckets * 2, "c");
// make sure everything has settle out (these VM's I suppose may be terminated)
checkData(vm2, 0, numBuckets, "b");
checkData(vm2, numBuckets, numBuckets * 2, "c");
} finally {
expected1.remove();
expected2.remove();
}
}
use of org.apache.geode.cache.DiskAccessException in project geode by apache.
the class Bug39079DUnitTest method validateRunningBridgeServerList.
private void validateRunningBridgeServerList() throws IOException {
Region region = getCache().getRegion(REGION_NAME_testBridgeServerStoppingInSynchPersistOnlyForIOExceptionCase);
try {
region.create("key1", new byte[16]);
region.create("key2", new byte[16]);
// Get the oplog handle & hence the underlying file & close it
UninterruptibleFileChannel oplogFileChannel = ((LocalRegion) region).getDiskRegion().testHook_getChild().getFileChannel();
try {
oplogFileChannel.close();
region.put("key2", new byte[16]);
fail("Expected DiskAccessException");
} catch (DiskAccessException expected) {
}
((LocalRegion) region).getDiskStore().waitForClose();
assertTrue(region.getRegionService().isClosed());
region = null;
List bsRunning = getCache().getCacheServers();
assertTrue(bsRunning.isEmpty());
} finally {
if (region != null) {
region.destroyRegion();
}
}
}
use of org.apache.geode.cache.DiskAccessException in project geode by apache.
the class DiskStoreImpl method createLockFile.
private void createLockFile(String name) throws DiskAccessException {
File f = new File(getInfoFileDir().getDir(), "DRLK_IF" + name + LOCK_FILE_EXT);
if (logger.isDebugEnabled()) {
logger.debug("Creating lock file {}", f);
}
FileOutputStream fs = null;
// 41734: A known NFS issue on Redhat. The thread created the directory,
// but when it try to lock, it will fail with permission denied or
// input/output
// error. To workarround it, introduce 5 times retries.
int cnt = 0;
DiskAccessException dae = null;
do {
try {
fs = new FileOutputStream(f);
this.lockFile = f;
this.fl = fs.getChannel().tryLock();
if (fl == null) {
try {
fs.close();
} catch (IOException ignore) {
}
throw new IOException(LocalizedStrings.Oplog_THE_FILE_0_IS_BEING_USED_BY_ANOTHER_PROCESS.toLocalizedString(f));
}
f.deleteOnExit();
dae = null;
break;
} catch (IOException | IllegalStateException ex) {
if (fs != null) {
try {
fs.close();
} catch (IOException ignore) {
}
}
dae = new DiskAccessException(LocalizedStrings.Oplog_COULD_NOT_LOCK_0.toLocalizedString(f.getPath()), ex, this);
}
cnt++;
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
} while (cnt < 100);
if (dae != null) {
throw dae;
}
if (logger.isDebugEnabled()) {
logger.debug("Locked disk store {} for exclusive access in directory: {}", name, getInfoFileDir().getDir());
}
}
Aggregations