@Override public EvictionAttributes getEvictionAttributes() { return this.ra.getEvictionAttributes(); }
protected boolean isOverflowToDisk(final Region region) { return (region.getAttributes().getEvictionAttributes() != null && EvictionAction.OVERFLOW_TO_DISK .equals(region.getAttributes().getEvictionAttributes().getAction())); }
private boolean isOverflowEnabled() { EvictionAttributes ea = getAttributes().getEvictionAttributes(); return ea != null && ea.getAction().isOverflowToDisk(); }
private boolean isMemoryEvictionConfigured() { boolean result = false; EvictionAttributes ea = region.getAttributes().getEvictionAttributes(); if (ea != null && ea.getAlgorithm().isLRUMemory()) { result = true; } return result; }
public static EvictionAttributesData getEvictionAttributesData(RegionAttributes regAttrs) { String algorithm = ""; Integer maximum = null; if (regAttrs.getEvictionAttributes().getAlgorithm() != null) { algorithm = regAttrs.getEvictionAttributes().getAlgorithm().toString(); if (algorithm.equals(EvictionAlgorithm.NONE.toString())) { EvictionAttributesData evictionAttributesData = new EvictionAttributesData(algorithm, null, EvictionAlgorithm.NONE.toString()); return evictionAttributesData; } if (!regAttrs.getEvictionAttributes().getAlgorithm().isLRUHeap()) { maximum = regAttrs.getEvictionAttributes().getMaximum(); } } String action = regAttrs.getEvictionAttributes().getAction().toString(); EvictionAttributesData evictionAttributesData = new EvictionAttributesData(algorithm, maximum, action); return evictionAttributesData; }
static void validateRegionAttributes(RegionAttributes attrs) { if (!attrs.getDataPolicy().withPartitioning()) { // replicated region throw new UnsupportedOperationException( "Lucene indexes on replicated regions are not supported"); } // For now we cannot support eviction with local destroy. // Eviction with overflow to disk still needs to be supported EvictionAttributes evictionAttributes = attrs.getEvictionAttributes(); EvictionAlgorithm evictionAlgorithm = evictionAttributes.getAlgorithm(); if (evictionAlgorithm != EvictionAlgorithm.NONE && evictionAttributes.getAction().isLocalDestroy()) { throw new UnsupportedOperationException( "Lucene indexes on regions with eviction and action local destroy are not supported"); } }
@Test public void testIsRegionOverflowToDiskWhenEvictionActionIsOverflowToDisk() { final Region mockRegion = mock(Region.class, "Region"); final RegionAttributes mockRegionAttributes = mock(RegionAttributes.class, "RegionAttributes"); final EvictionAttributes mockEvictionAttributes = mock(EvictionAttributes.class, "EvictionAttributes"); when(mockRegion.getAttributes()).thenReturn(mockRegionAttributes); when(mockRegionAttributes.getEvictionAttributes()).thenReturn(mockEvictionAttributes); when(mockEvictionAttributes.getAction()).thenReturn(EvictionAction.OVERFLOW_TO_DISK); final DescribeDiskStoreFunction function = new DescribeDiskStoreFunction(); assertThat(function.isOverflowToDisk(mockRegion)).isTrue(); verify(mockRegion, times(2)).getAttributes(); verify(mockRegionAttributes, times(2)).getEvictionAttributes(); }
@Test public void testIsRegionOverflowToDiskWithNullEvictionAttributes() { final Region mockRegion = mock(Region.class, "Region"); final RegionAttributes mockRegionAttributes = mock(RegionAttributes.class, "RegionAttributes"); when(mockRegion.getAttributes()).thenReturn(mockRegionAttributes); when(mockRegionAttributes.getEvictionAttributes()).thenReturn(null); final DescribeDiskStoreFunction function = new DescribeDiskStoreFunction(); assertThat(function.isOverflowToDisk(mockRegion)).isFalse(); }
@Test public void testIsRegionOverflowToDiskWhenEvictionActionIsLocalDestroy() { final Region mockRegion = mock(Region.class, "Region"); final RegionAttributes mockRegionAttributes = mock(RegionAttributes.class, "RegionAttributes"); final EvictionAttributes mockEvictionAttributes = mock(EvictionAttributes.class, "EvictionAttributes"); when(mockRegion.getAttributes()).thenReturn(mockRegionAttributes); when(mockRegionAttributes.getEvictionAttributes()).thenReturn(mockEvictionAttributes); when(mockEvictionAttributes.getAction()).thenReturn(EvictionAction.LOCAL_DESTROY); final DescribeDiskStoreFunction function = new DescribeDiskStoreFunction(); assertThat(function.isOverflowToDisk(mockRegion)).isFalse(); verify(mockRegion, times(2)).getAttributes(); verify(mockRegionAttributes, times(2)).getEvictionAttributes(); }
/** * Note: hydra invokes this with setRefid=false. */ public void setAttributes(RegionAttributes attrs, boolean setRefid) { this.hasAttributes = true; if (attrs instanceof RegionAttributesCreation) { this.attrs = (RegionAttributesCreation) attrs; } else { this.attrs = new RegionAttributesCreation(this.cache, attrs, false); } if ((setRefid && (this.attrs.getRefid() == null))) { this.attrs.setRefid(getRefid()); } if (attrs.getPartitionAttributes() != null && attrs.getEvictionAttributes() != null && attrs.getEvictionAttributes().getAlgorithm().isLRUMemory() && attrs.getPartitionAttributes().getLocalMaxMemory() != 0 && attrs.getEvictionAttributes() .getMaximum() != attrs.getPartitionAttributes().getLocalMaxMemory()) { getCache().getLogger().warning(String.format( "For region %s with data policy PARTITION, memory LRU eviction attribute maximum has been reset from %sMB to local-max-memory %sMB", new Object[] {this.getName(), attrs.getEvictionAttributes().getMaximum(), attrs.getPartitionAttributes().getLocalMaxMemory()})); this.attrs.setEvictionAttributes(attrs.getEvictionAttributes().createLRUMemoryAttributes( attrs.getPartitionAttributes().getLocalMaxMemory(), attrs.getEvictionAttributes().getObjectSizer(), attrs.getEvictionAttributes().getAction())); } }
@Test public void testIsRegionUsingDiskStoreWhenOverflowing() { final String diskStoreName = "testDiskStore"; final Region mockRegion = mock(Region.class, "Region"); final DiskStore mockDiskStore = mock(DiskStore.class, "DiskStore"); final RegionAttributes mockRegionAttributes = mock(RegionAttributes.class, "RegionAttributes"); final EvictionAttributes mockEvictionAttributes = mock(EvictionAttributes.class, "EvictionAttributes"); when(mockRegion.getAttributes()).thenReturn(mockRegionAttributes); when(mockRegionAttributes.getDataPolicy()).thenReturn(DataPolicy.PARTITION); when(mockRegionAttributes.getDiskStoreName()).thenReturn(diskStoreName); when(mockRegionAttributes.getEvictionAttributes()).thenReturn(mockEvictionAttributes); when(mockEvictionAttributes.getAction()).thenReturn(EvictionAction.OVERFLOW_TO_DISK); when(mockDiskStore.getName()).thenReturn(diskStoreName); final DescribeDiskStoreFunction function = new DescribeDiskStoreFunction(); assertThat(function.isUsingDiskStore(mockRegion, mockDiskStore)).isTrue(); verify(mockRegion, times(4)).getAttributes(); verify(mockRegionAttributes, times(2)).getEvictionAttributes(); }
@Test public void userRegionShouldNotBeSetBeforeIndexInitialized() throws Exception { TestLuceneServiceImpl testService = new TestLuceneServiceImpl(); Field f = LuceneServiceImpl.class.getDeclaredField("cache"); f.setAccessible(true); f.set(testService, cache); AsyncEventQueueFactoryImpl aeqFactory = mock(AsyncEventQueueFactoryImpl.class); when(cache.createAsyncEventQueueFactory()).thenReturn(aeqFactory); DistributedSystem ds = mock(DistributedSystem.class); Statistics luceneIndexStats = mock(Statistics.class); when(cache.getDistributedSystem()).thenReturn(ds); when(((StatisticsFactory) ds).createAtomicStatistics(any(), anyString())) .thenReturn(luceneIndexStats); when(cache.getRegion(anyString())).thenReturn(region); when(cache.getDistributionManager()).thenReturn(mock(DistributionManager.class)); when(cache.getDistributionManager().getWaitingThreadPool()) .thenReturn(Executors.newSingleThreadExecutor()); RegionAttributes ratts = mock(RegionAttributes.class); when(region.getAttributes()).thenReturn(ratts); when(ratts.getDataPolicy()).thenReturn(DataPolicy.PARTITION); EvictionAttributes evictionAttrs = mock(EvictionAttributes.class); when(ratts.getEvictionAttributes()).thenReturn(evictionAttrs); when(evictionAttrs.getAlgorithm()).thenReturn(EvictionAlgorithm.NONE); Map<String, Analyzer> fieldMap = new HashMap<String, Analyzer>(); fieldMap.put("field1", null); fieldMap.put("field2", null); testService.createIndex("index", "region", fieldMap, null, true); }
operation = mock(Operation.class); when(regionAttributes.getEvictionAttributes()).thenReturn(evictionAttributes); when(regionAttributes.getRegionTimeToLive()).thenReturn(expirationAttributes); when(regionAttributes.getRegionIdleTimeout()).thenReturn(expirationAttributes);
@Test public void beforeDataRegionCreatedShouldHaveSerializer() { String name = "indexName"; String regionPath = "regionName"; String[] fields = {"field1", "field2"}; String aeqId = LuceneServiceImpl.getUniqueIndexName(name, regionPath); InternalCache cache = Fakes.cache(); final Region region = Fakes.region(regionPath, cache); RegionAttributes attributes = region.getAttributes(); DataPolicy policy = attributes.getDataPolicy(); when(policy.withPartitioning()).thenReturn(true); EvictionAttributes evictionAttributes = mock(EvictionAttributes.class); when(attributes.getEvictionAttributes()).thenReturn(evictionAttributes); CopyOnWriteArraySet set = new CopyOnWriteArraySet(); set.add(aeqId); when(attributes.getAsyncEventQueueIds()).thenReturn(set); when(evictionAttributes.getAlgorithm()).thenReturn(EvictionAlgorithm.NONE); LuceneServiceImpl service = mock(LuceneServiceImpl.class); Analyzer analyzer = mock(Analyzer.class); LuceneSerializer serializer = mock(LuceneSerializer.class); InternalRegionArguments internalRegionArgs = mock(InternalRegionArguments.class); when(internalRegionArgs.addCacheServiceProfile(any())).thenReturn(internalRegionArgs); LuceneRegionListener listener = new LuceneRegionListener(service, cache, name, "/" + regionPath, fields, analyzer, null, serializer); listener.beforeCreate(null, regionPath, attributes, internalRegionArgs); verify(service).beforeDataRegionCreated(eq(name), eq("/" + regionPath), eq(attributes), eq(analyzer), any(), eq(aeqId), eq(serializer), any()); } }
when(mockUserRegionAttributes.getDataPolicy()).thenReturn(DataPolicy.PERSISTENT_PARTITION); when(mockUserRegionAttributes.getDiskStoreName()).thenReturn(diskStoreName); when(mockUserRegionAttributes.getEvictionAttributes()).thenReturn(mockUserEvictionAttributes); when(mockUserEvictionAttributes.getAction()).thenReturn(EvictionAction.LOCAL_DESTROY); when(mockSessionRegion.getAttributes()).thenReturn(mockSessionRegionAttributes); when(mockSessionRegionAttributes.getDataPolicy()).thenReturn(DataPolicy.REPLICATE); when(mockSessionRegionAttributes.getDiskStoreName()).thenReturn(diskStoreName); when(mockSessionRegionAttributes.getEvictionAttributes()) .thenReturn(mockSessionEvictionAttributes); when(mockSessionEvictionAttributes.getAction()).thenReturn(EvictionAction.OVERFLOW_TO_DISK); when(mockGuestRegionAttributes.getDiskStoreName()) .thenReturn(DiskStoreDetails.DEFAULT_DISK_STORE_NAME); when(mockGuestRegionAttributes.getEvictionAttributes()).thenReturn(mockGuestEvictionAttributes); when(mockGuestEvictionAttributes.getAction()).thenReturn(EvictionAction.OVERFLOW_TO_DISK);
private void initialize(Region region) { setNumberOfEntries(region.size()); EvictionAttributes ea = region.getAttributes().getEvictionAttributes(); if (ea != null && ea.getAlgorithm().isLRUMemory()) { setHeapSize(((InternalRegion) region).getEvictionCounter()); } else { setHeapSize(-1); } }
public int getSizeForEviction() { EvictionAttributes ea = this.getAttributes().getEvictionAttributes(); if (ea == null) return 0; EvictionAlgorithm algo = ea.getAlgorithm(); if (!algo.isLRUHeap()) return 0; EvictionAction action = ea.getAction(); int size = action.isLocalDestroy() ? this.getRegionMap().sizeInVM() : (int) this.getNumEntriesInVM(); return size; }
final EvictionAttributes ea = pr.getAttributes().getEvictionAttributes();
|| !pr.getAttributes().getEvictionAttributes().getAlgorithm().isNone()) { return ClusterDistributionManager.PARTITIONED_REGION_EXECUTOR;
public IndexManager(InternalCache cache, Region region) { this.cache = cache; this.region = region; // must be a SortedMap to ensure the indexes are iterated over in fixed // order // to avoid deadlocks when acquiring locks // indexes = Collections.synchronizedSortedMap(new TreeMap()); indexMaintenanceSynchronous = region.getAttributes().getIndexMaintenanceSynchronous(); isOverFlowToDisk = region.getAttributes().getEvictionAttributes().getAction().isOverflowToDisk(); this.offHeap = region.getAttributes().getOffHeap(); if (!indexMaintenanceSynchronous) { updater = new IndexUpdaterThread(this.INDEX_MAINTENANCE_BUFFER, "OqlIndexUpdater:" + region.getFullPath()); updater.start(); } }