private void checkIfConcurrentMapOpsAllowed() { // This check allows NORMAL with local scope to fix bug 44856 if (this.serverRegionProxy == null && (this.getDataPolicy() == DataPolicy.NORMAL && this.scope.isDistributed() || this.getDataPolicy() == DataPolicy.EMPTY)) { // the functional spec says these data policies do not support concurrent map // operations throw new UnsupportedOperationException(); } }
/** * Return false if it will never store entry ekys and values locally; otherwise return true. */ protected boolean hasStorage() { return this.getDataPolicy().withStorage(); }
public boolean canStoreDataLocally() { return this.getDataPolicy().withStorage(); }
/** * This method determines whether this region should synchronize with peer replicated regions when * the given member has crashed. * * @param id the crashed member * @return true if synchronization should be attempted */ public boolean shouldSyncForCrashedMember(InternalDistributedMember id) { return this.getConcurrencyChecksEnabled() && this.getDataPolicy().withReplication() && !this.isUsedForPartitionedRegionAdmin && !this.isUsedForMetaRegion && !this.isUsedForSerialGatewaySenderQueue; }
/** * whether concurrency checks should be disabled for this region */ @Override public boolean supportsConcurrencyChecks() { return !isSecret() || this.getDataPolicy().withPersistence(); }
/** local regions do not perform versioning */ protected boolean shouldGenerateVersionTag(RegionEntry entry, EntryEventImpl event) { if (this.getDataPolicy().withPersistence()) { return true; } else { return this.getConcurrencyChecksEnabled() && (entry.getVersionStamp().hasValidVersion() || this.getDataPolicy().withReplication()); } }
@Override public void writeToDisk() { if (this.diskRegion == null) { DataPolicy dp = getDataPolicy(); if (dp.isEmpty()) { throw new IllegalStateException( String.format("Cannot write a region with data-policy %s to disk.", dp)); } else if (!dp.withPersistence() && !isOverflowEnabled()) { throw new IllegalStateException( "Cannot write a region that is not configured to access disks."); } } else { this.diskRegion.asynchForceFlush(); } }
protected void checkIfReplicatedAndLocalDestroy(EntryEventImpl event) { // disallow local invalidation for replicated regions if (getScope().isDistributed() && getDataPolicy().withReplication() && !event.isDistributed() && !isUsedForSerialGatewaySenderQueue()) { throw new IllegalStateException( "Not allowed to do a local destroy on a replicated region"); } }
private static LocalRegion createOwner(boolean withConcurrencyChecks) { LocalRegion owner = mock(LocalRegion.class); CachePerfStats cachePerfStats = mock(CachePerfStats.class); when(owner.getCachePerfStats()).thenReturn(cachePerfStats); when(owner.getEvictionAttributes()).thenReturn(evictionAttributes); when(owner.getConcurrencyChecksEnabled()).thenReturn(withConcurrencyChecks); when(owner.getDataPolicy()).thenReturn(DataPolicy.REPLICATE); doThrow(EntryNotFoundException.class).when(owner).checkEntryNotFound(any()); return owner; }
void cmnClearRegion(RegionEventImpl regionEvent, boolean cacheWrite, boolean useRVV) { RegionVersionVector rvv = null; if (useRVV && this.getDataPolicy().withReplication() && this.getConcurrencyChecksEnabled()) { rvv = this.versionVector.getCloneForTransmission(); } clearRegionLocally(regionEvent, cacheWrite, rvv); }
private TombstoneSweeper getSweeper(LocalRegion r) { if (r.getScope().isDistributed() && r.getServerProxy() == null && r.getDataPolicy().withReplication()) { return this.replicatedTombstoneSweeper; } else { return this.nonReplicatedTombstoneSweeper; } }
@Override public void loadSnapshot(InputStream inputStream) throws CacheWriterException, TimeoutException, ClassNotFoundException, IOException { if (isProxy()) { throw new UnsupportedOperationException( String.format("Regions with DataPolicy %s do not support loadSnapshot.", getDataPolicy())); } if (inputStream == null) { throw new NullPointerException( "InputStream must not be null."); } checkReadiness(); checkForLimitedOrNoAccess(); RegionEventImpl event = new RegionEventImpl(this, Operation.REGION_LOAD_SNAPSHOT, null, false, getMyId(), generateEventID()/* generate EventID */); reinitialize(inputStream, event); }
@Override public VersionSource getVersionMember() { if (this.getDataPolicy().withPersistence()) { return getDiskStore().getDiskStoreID(); } else { return this.cache.getInternalDistributedSystem().getDistributedMember(); } }
@Override public Object put(Object key, Object value, byte[] deltaBytes, EntryEventImpl event, Operation op, boolean requireOldValue, Object expectedOldValue, Object callbackArg, boolean isCreate) { recordTXOperation(ServerRegionOperation.PUT, key, value, deltaBytes, event.getEventId(), op, Boolean.valueOf(requireOldValue), expectedOldValue, callbackArg, Boolean.valueOf(isCreate)); Operation operation = op; if (!isCreate && this.region.getDataPolicy() == DataPolicy.EMPTY && op.isCreate() && op != Operation.PUT_IF_ABSENT) { operation = Operation.UPDATE; } if (this.region == null) { return PutOp.execute(this.pool, this.regionName, key, value, deltaBytes, event, operation, requireOldValue, expectedOldValue, callbackArg, this.pool.getPRSingleHopEnabled()); } else { return PutOp.execute(this.pool, this.region, key, value, deltaBytes, event, operation, requireOldValue, expectedOldValue, callbackArg, this.pool.getPRSingleHopEnabled()); } }
private void unlockRVVForBulkOp() { ARMLockTestHook testHook = getRegionMap().getARMLockTestHook(); if (testHook != null) { testHook.beforeBulkRelease(this); } if (this.versionVector != null && this.getDataPolicy().withReplication()) { this.versionVector.releaseCacheModificationLock(this); } if (testHook != null) { testHook.afterBulkRelease(this); } }
/** * bug #46924 - putAll can be partially applied when a clear() occurs, leaving the cache in an * inconsistent state. Set the RVV to "cache op in progress" so clear() will block until the * putAll completes. This won't work for non-replicate regions though since they uses one-hop * during basicPutPart2 to get a valid version tag. */ private void lockRVVForBulkOp() { ARMLockTestHook testHook = getRegionMap().getARMLockTestHook(); if (testHook != null) { testHook.beforeBulkLock(this); } if (this.versionVector != null && this.getDataPolicy().withReplication()) { this.versionVector.lockForCacheModification(this); } if (testHook != null) { testHook.afterBulkLock(this); } }
@Override protected void initMessagePart() { int size = keys.size(); int flags = 0; if (region.getDataPolicy() == DataPolicy.EMPTY) { flags |= FLAG_EMPTY; } if (region.getConcurrencyChecksEnabled()) { flags |= FLAG_CONCURRENCY_CHECKS; } getMessage().addIntPart(flags); getMessage().addObjPart(this.callbackArg); getMessage().addIntPart(size); for (Object key : this.keys) { getMessage().addStringOrObjPart(key); } }
protected void enableConcurrencyChecks() { this.setConcurrencyChecksEnabled(true); if (this.getDataPolicy().withStorage()) { RegionEntryFactory versionedEntryFactory = this.entries.getEntryFactory().makeVersioned(); Assert.assertTrue(this.entries.isEmpty(), "RegionMap should be empty but was of size:" + this.entries.size()); this.entries.setEntryFactory(versionedEntryFactory); } }
@Test public void recordVersionIntoLocalMemberShouldFailIfRegionIsPersistent() { LocalRegion mockRegion = mock(LocalRegion.class); when(mockRegion.isInitialized()).thenReturn(true); when(mockRegion.getDataPolicy()).thenReturn(DataPolicy.PERSISTENT_REPLICATE); final String local = getIPLiteral(); DiskStoreID ownerId = new DiskStoreID(); DiskRegionVersionVector rvv = new DiskRegionVersionVector(ownerId, mockRegion); DiskVersionTag tag = new DiskVersionTag(); tag.setRegionVersion(1L); tag.setMemberID(ownerId); expectedException.expect(InternalGemFireError.class); rvv.recordVersion(ownerId, tag); }
@Test public void recordVersionIntoLocalMemberShouldPassfRegionIsNonPersistent() { LocalRegion mockRegion = mock(LocalRegion.class); when(mockRegion.isInitialized()).thenReturn(true); when(mockRegion.getDataPolicy()).thenReturn(DataPolicy.REPLICATE); final String local = getIPLiteral(); InternalDistributedMember ownerId = new InternalDistributedMember(local, 101); RegionVersionVector rvv = createRegionVersionVector(ownerId, mockRegion); VMVersionTag tag = new VMVersionTag(); tag.setRegionVersion(1); tag.setMemberID(ownerId); rvv.recordVersion(ownerId, tag); assertEquals(1, rvv.getLocalExceptions().version); assertEquals(2, rvv.getNextVersion()); }