protected void removeFiles(DiskStore diskStore) { final String diskStoreName = diskStore.getName(); File[] dirs = diskStore.getDiskDirs(); for(File dir : dirs) { File[] files = dir.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.startsWith("BACKUP" + diskStoreName); } }); for(File file : files) { file.delete(); } } }
/** * Returns the disk store as a string. Serves calling methods for both * factory attributes and actual disk store. */ private static synchronized String diskStoreToString(String diskStoreName, DiskStore d) { StringBuffer buf = new StringBuffer(); buf.append("\n diskStoreName: " + diskStoreName); buf.append("\n allowForceCompaction: " + d.getAllowForceCompaction()); buf.append("\n autoCompact: " + d.getAutoCompact()); buf.append("\n compactionThreshold: " + d.getCompactionThreshold()); buf.append("\n diskDirSizes: " + asList(d.getDiskDirSizes())); buf.append("\n diskDirs: " + Arrays.asList(d.getDiskDirs())); buf.append("\n maxOplogSize: " + d.getMaxOplogSize()); buf.append("\n queueSize: " + d.getQueueSize()); buf.append("\n timeInterval: " + d.getTimeInterval()); buf.append("\n writeBufferSize: " + d.getWriteBufferSize()); return buf.toString(); }
private void setDiskDirDetails(final DiskStore diskStore, final DiskStoreDetails diskStoreDetails) { File[] diskDirs = diskStore.getDiskDirs(); Integer[] diskDirSizes = ArrayUtils.toIntegerArray(diskStore.getDiskDirSizes()); assertState(diskDirs.length == diskDirSizes.length, "The number of disk directories with a specified size (%1$d) does not match the number of disk directories (%2$d)!", diskDirSizes.length, diskDirs.length); for (int index = 0; index < diskDirs.length; index++) { diskStoreDetails.add(new DiskStoreDetails.DiskDirDetails(diskDirs[index].getAbsolutePath(), ArrayUtils.getElementAtIndex(diskDirSizes, index, 0))); } }
private void setDiskDirDetails(final DiskStore diskStore, final DiskStoreDetails diskStoreDetails) { final File[] diskDirs = diskStore.getDiskDirs(); final Integer[] diskDirSizes = ArrayUtils.toIntegerArray(diskStore.getDiskDirSizes()); // TODO decide whether to use an assertion or guard against ArrayIndexOutOfBoundsExceptions with // ArrayUtils.getElementAtIndex, demonstrated below... assertState(diskDirs.length == diskDirSizes.length, "The number of disk directories with a specified size (%1$d) does not match the number of disk directories (%2$d)!", diskDirSizes.length, diskDirs.length); for (int index = 0; index < diskDirs.length; index++) { diskStoreDetails.add(new DiskStoreDetails.DiskDirDetails(diskDirs[index].getAbsolutePath(), ArrayUtils.getElementAtIndex(diskDirSizes, index, 0))); } }
if (da.getDiskDirs().length != d.getDiskDirs().length) { return false; for (int i = 0; i < da.getDiskDirs().length; i++) { if (!da.getDiskDirs()[i].equals(d.getDiskDirs()[i])) { return false;
public void testGetDefaultInstance() { DiskStoreFactory dsf = cache.createDiskStoreFactory(); String name = "testGetDefaultInstance"; assertEquals(null, cache.findDiskStore(name)); DiskStore ds = dsf.create(name); assertEquals(ds, cache.findDiskStore(name)); assertEquals(name, ds.getName()); assertEquals(DiskStoreFactory.DEFAULT_AUTO_COMPACT, ds.getAutoCompact()); assertEquals(DiskStoreFactory.DEFAULT_COMPACTION_THRESHOLD, ds.getCompactionThreshold()); assertEquals(DiskStoreFactory.DEFAULT_ALLOW_FORCE_COMPACTION, ds.getAllowForceCompaction()); assertEquals(DiskStoreFactory.DEFAULT_MAX_OPLOG_SIZE, ds.getMaxOplogSize()); assertEquals(DiskStoreFactory.DEFAULT_TIME_INTERVAL, ds.getTimeInterval()); assertEquals(DiskStoreFactory.DEFAULT_WRITE_BUFFER_SIZE, ds.getWriteBufferSize()); assertEquals(DiskStoreFactory.DEFAULT_QUEUE_SIZE, ds.getQueueSize()); if (!Arrays.equals(DiskStoreFactory.DEFAULT_DISK_DIRS, ds.getDiskDirs())) { fail("expected=" + Arrays.toString(DiskStoreFactory.DEFAULT_DISK_DIRS) + " had=" + Arrays.toString(ds.getDiskDirs())); } if (!Arrays.equals(DiskStoreFactory.DEFAULT_DISK_DIR_SIZES, ds.getDiskDirSizes())) { fail("expected=" + Arrays.toString(DiskStoreFactory.DEFAULT_DISK_DIR_SIZES) + " had=" + Arrays.toString(ds.getDiskDirSizes())); } }
public void testMissingInitFile() { DiskStoreFactory dsf = cache.createDiskStoreFactory(); String name = "testMissingInitFile"; DiskStore diskStore = dsf.create(name); File ifFile = new File(diskStore.getDiskDirs()[0], "BACKUP" + name + DiskInitFile.IF_FILE_EXT); assertTrue(ifFile.exists()); AttributesFactory af = new AttributesFactory(); af.setDiskStoreName(name); af.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE); cache.createRegion("r", af.create()); cache.close(); assertTrue(ifFile.exists()); assertTrue(ifFile.delete()); assertFalse(ifFile.exists()); cache = createCache(); dsf = cache.createDiskStoreFactory(); assertEquals(null, ((GemFireCacheImpl)cache).findDiskStore(name)); try { dsf.create(name); fail("expected IllegalStateException"); } catch (IllegalStateException expected) { } // if test passed clean up files removeFiles(diskStore); }
String name = "testTwoEntriesNoCompact"; DiskStore diskStore = dsf.create(name); File crfFile = new File(diskStore.getDiskDirs()[0], "BACKUP" + name + "_1.crf"); File drfFile = new File(diskStore.getDiskDirs()[0], "BACKUP" + name + "_1.drf"); File ifFile = new File(diskStore.getDiskDirs()[0], "BACKUP" + name + ".if"); AttributesFactory af = new AttributesFactory(); af.setDiskStoreName(name); System.out.println("1 member rvv size = "+getRVVSize(1, new int[] {1}, false)); System.out.println("2 member rvv size = "+getRVVSize(2, new int[] {1, 1}, false)); DiskStoreImpl.validate(name, diskStore.getDiskDirs()); int crfsize = Oplog.OPLOG_DISK_STORE_REC_SIZE + Oplog.OPLOG_GEMFIRE_VERSION_REC_SIZE + getRVVSize(0, null, false) + Oplog.OPLOG_NEW_ENTRY_BASE_REC_SIZE; long originalIfLength = ifFile.length(); DiskStoreImpl dsi = DiskStoreImpl.offlineCompact(name, diskStore.getDiskDirs(), false, -1); assertEquals(0, dsi.getDeadRecordCount()); assertEquals(2, dsi.getLiveEntryCount());
public void testMissingDrfFile() { DiskStoreFactory dsf = cache.createDiskStoreFactory(); String name = "testMissingDrfFile"; DiskStore diskStore = dsf.create(name); File drfFile = new File(diskStore.getDiskDirs()[0], "BACKUP" + name + "_1.drf"); AttributesFactory af = new AttributesFactory(); af.setDiskStoreName(name); af.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE); Region r = cache.createRegion("r", af.create()); r.put("key", "value"); assertTrue(drfFile.exists()); cache.close(); assertTrue(drfFile.exists()); assertTrue(drfFile.delete()); assertFalse(drfFile.exists()); cache = createCache(); dsf = cache.createDiskStoreFactory(); assertEquals(null, ((GemFireCacheImpl)cache).findDiskStore(name)); try { dsf.create(name); fail("expected IllegalStateException"); } catch (IllegalStateException expected) { } // if test passed clean up files removeFiles(diskStore); }
public void testMissingCrfFile() { DiskStoreFactory dsf = cache.createDiskStoreFactory(); String name = "testMissingCrfFile"; DiskStore diskStore = dsf.create(name); File crfFile = new File(diskStore.getDiskDirs()[0], "BACKUP" + name + "_1.crf"); AttributesFactory af = new AttributesFactory(); af.setDiskStoreName(name); af.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE); Region r = cache.createRegion("r", af.create()); r.put("key", "value"); assertTrue(crfFile.exists()); cache.close(); assertTrue(crfFile.exists()); assertTrue(crfFile.delete()); assertFalse(crfFile.exists()); cache = createCache(); dsf = cache.createDiskStoreFactory(); assertEquals(null, ((GemFireCacheImpl)cache).findDiskStore(name)); try { dsf.create(name); fail("expected IllegalStateException"); } catch (IllegalStateException expected) { } // if test passed clean up files removeFiles(diskStore); }
throw new RuntimeException(LocalizedStrings.DiskStoreAttributesCreation_QUEUESIZE_OF_0_IS_NOT_THE_SAME_THIS_1_OTHER_2.toLocalizedString(new Object[] {name, this.queueSize, other.getQueueSize()})); if (! equal(this.diskDirs, other.getDiskDirs())) { throw new RuntimeException(LocalizedStrings.DiskStoreAttributesCreation_DISK_DIRS_OF_0_ARE_NOT_THE_SAME.toLocalizedString(name));
throw new RuntimeException(LocalizedStrings.DiskStoreAttributesCreation_QUEUESIZE_OF_0_IS_NOT_THE_SAME_THIS_1_OTHER_2.toLocalizedString(new Object[] {name, this.queueSize, other.getQueueSize()})); if (! equal(this.diskDirs, other.getDiskDirs())) { throw new RuntimeException(LocalizedStrings.DiskStoreAttributesCreation_DISK_DIRS_OF_0_ARE_NOT_THE_SAME.toLocalizedString(name));
/** Create the DiskStore if the RegionAttributes specifies it. * * @param attr The RegionAttributes that could specify a DiskStore. * @return A String description of the DiskStore, useful for logging. */ public static String createDiskStore(RegionAttributes attr) { String diskDirsStr = ""; Log.getLogWriter().info("DiskStore name in attributes is " + attr.getDiskStoreName()); if ((attr.getDiskStoreName() != null) && (!attr.getDiskStoreName().equals("notUsed"))) { Log.getLogWriter().info("Creating diskStore " + attr.getDiskStoreName()); DiskStoreFactory dsFactory = DiskStoreHelper.getDiskStoreFactory(attr.getDiskStoreName()); dsFactory.create(attr.getDiskStoreName()); File[] diskDirs = CacheHelper.getCache().findDiskStore(attr.getDiskStoreName()).getDiskDirs(); for (File diskDir: diskDirs) { diskDirsStr = diskDirsStr + diskDir.getName() + " "; } diskDirsStr = " with disk dirs " + diskDirsStr; } return "disk store name is " + attr.getDiskStoreName() + " " + diskDirsStr; }
File[] diskDirs = dStore.getDiskDirs(); List diskDirNameList = new ArrayList(); for (File aFile: diskDirs) {
protected static String getDiskAttributes(Region r) { String dsn = r.getAttributes().getDiskStoreName(); if (dsn == null) { throw new HydraConfigException("Persistence is not configured"); } DiskStore ds = DiskStoreHelper.getDiskStore(dsn); return "the DiskStore is" + ds + ", the allow force compaction is " + ds.getAllowForceCompaction() + ", the auto compact is " + ds.getAutoCompact() + ", the compaction threshold is " + ds.getCompactionThreshold() + ", the disk dir num is " + ds.getDiskDirs().length + ", the max oplog size is " + ds.getMaxOplogSize() + ", the queue size is " + ds.getQueueSize() + ", the synchronous (from the region) is " + r.getAttributes().isDiskSynchronous() ; } protected static String getResourceManager(Cache c) {
diskDir = getCache().findDiskStore(attrs.getDiskStoreName()).getDiskDirs()[0];
assertNotNull(ds); assertEquals(500, ds.getQueueSize()); File[] dirs = ds.getDiskDirs(); assertEquals("west", dirs[0].getPath()); assertNotNull(ds); assertEquals(500, ds.getQueueSize()); dirs = ds.getDiskDirs(); assertEquals("east", dirs[0].getPath());
assertEquals(501, chaqf.getCapacity()); DiskStore dsi = cache.findDiskStore(chaqf.getDiskStoreName()); assertEquals("overFlow", dsi.getDiskDirs()[0].toString());
protected void verify(LocalRegion lr, DiskRegionProperties drp) { DiskStore ds = cache.findDiskStore(lr.getDiskStoreName()); assertTrue(ds != null); assertTrue(lr.getAttributes().isDiskSynchronous() == drp.isSynchronous()); assertTrue(ds.getAutoCompact() == drp.isRolling()); assertEquals(drp.getMaxOplogSize()/(1024*1024), ds.getMaxOplogSize()); if (drp.getTimeInterval() != -1) { assertEquals(drp.getTimeInterval(), ds.getTimeInterval()); } else { assertEquals(DiskStoreFactory.DEFAULT_TIME_INTERVAL, ds.getTimeInterval()); } assertEquals((int)drp.getBytesThreshold(), ds.getQueueSize()); int dirnum = drp.getDiskDirs().length; int dirnum2 = ds.getDiskDirs().length; int[] diskSizes = drp.getDiskDirSizes(); int[] ds_diskSizes = ds.getDiskDirSizes(); assertEquals(dirnum, dirnum2); if (diskSizes == null) { diskSizes = new int[dirnum]; java.util.Arrays.fill(diskSizes, Integer.MAX_VALUE); } for (int i=0; i<dirnum; i++) { assertTrue("diskSizes not matching", diskSizes[i] == ds_diskSizes[i]); } }
oneOf(mockDiskStore).getWriteBufferSize(); will(returnValue(writeBufferSize)); allowing(mockDiskStore).getDiskDirs(); will(returnValue(diskDirs)); allowing(mockDiskStore).getDiskDirSizes();