/** * Creates PartitionedRegionDataStore for dataStorage of PR and starts a PartitionService to * handle remote operations on this DataStore from other participating nodes. * * @param pr PartitionedRegion associated with this DataStore. */ PartitionedRegionDataStore(final PartitionedRegion pr) { final int bucketCount = pr.getTotalNumberOfBuckets(); this.localBucket2RegionMap = new ConcurrentHashMap<Integer, BucketRegion>(bucketCount); this.partitionedRegion = pr; this.bucketCreationLock = new StoppableReentrantReadWriteLock(pr.getCancelCriterion()); if (pr.getAttributes().getCacheLoader() != null) { this.loader = pr.getAttributes().getCacheLoader(); if (logger.isDebugEnabled()) { logger.debug("Installing cache loader from partitioned region attributes: {}", loader); } } // this.maximumLocalBytes = (long) (pr.getLocalMaxMemory() * // PartitionedRegionHelper.BYTES_PER_MB // * this.partitionedRegion.rebalanceThreshold); this.maximumLocalBytes = (pr.getLocalMaxMemory() * PartitionedRegionHelper.BYTES_PER_MB); // this.bucketStats = new CachePerfStats(pr.getSystem(), "partition-" + pr.getName()); this.bucketStats = new RegionPerfStats(pr.getCache(), pr.getCachePerfStats(), "partition-" + pr.getName()); this.keysOfInterest = new ConcurrentHashMap(); }
@Override public Object getSerializedValue(LocalRegion localRegion, KeyInfo keyInfo, boolean doNotLockEntry, ClientProxyMembershipID requestingClient, EntryEventImpl clientEvent, boolean returnTombstones) throws DataLocationException { PartitionedRegion pr = (PartitionedRegion) localRegion; return pr.getDataStore().getSerializedLocally(keyInfo, doNotLockEntry, requestingClient, clientEvent, returnTombstones); }
@Override public String toString() { return new StringBuffer().append("Partitioned Region ").append("@") .append(Integer.toHexString(hashCode())).append(" [").append("path='").append(getFullPath()) .append("'; dataPolicy=").append(this.getDataPolicy()).append("; prId=") .append(this.partitionedRegionId).append("; isDestroyed=").append(this.isDestroyed) .append("; isClosed=").append(this.isClosed).append("; retryTimeout=") .append(this.retryTimeout).append("; serialNumber=").append(getSerialNumber()) .append("; partition attributes=").append(getPartitionAttributes().toString()) .append("; on VM ").append(getMyId()).append("]").toString(); }
protected RecoveryLock() { super(PartitionedRegion.this.getRegionIdentifier() + "-RecoveryLock", getCache(), false); }
public RegionLock getRegionLock() { return getRegionLock(getRegionIdentifier(), getGemFireCache()); }
@Override public int compare(PartitionedRegion o1, PartitionedRegion o2) { if (o1.isShadowPR() == o2.isShadowPR()) { return o1.getFullPath().compareTo(o2.getFullPath()); } if (o1.isShadowPR()) { return 1; } return -1; } });
protected void createIndexAndRepoManager() throws Exception { fileAndChunkRegion = Mockito.mock(PartitionedRegion.class); fileDataStore = Mockito.mock(PartitionedRegionDataStore.class); when(fileAndChunkRegion.getDataStore()).thenReturn(fileDataStore); when(fileAndChunkRegion.getTotalNumberOfBuckets()).thenReturn(113); when(fileAndChunkRegion.getFullPath()).thenReturn("FileRegion"); when(fileAndChunkRegion.getCache()).thenReturn(cache); when(fileAndChunkRegion.getRegionIdentifier()).thenReturn("rid"); indexStats = Mockito.mock(LuceneIndexStats.class); fileSystemStats = Mockito.mock(FileSystemStats.class);
void validateColocation() { final PartitionAttributesImpl userPA = (PartitionAttributesImpl) pr.getAttributes().getPartitionAttributes(); userPA.validateColocation(pr.getCache()); // do this here to fix bug 47197 if (colocatedPR.getPartitionAttributes().getTotalNumBuckets() != userPA .getTotalNumBuckets()) { throw new IllegalStateException( "Colocated regions should have same number of total-num-buckets"); if (colocatedPR.getPartitionAttributes().getRedundantCopies() != userPA .getRedundantCopies()) { throw new IllegalStateException( "Colocated regions should have same number of redundant-copies"); if ((colocatedPR.getPartitionAttributes().getLocalMaxMemory() == 0) && (userPA.getLocalMaxMemory() != 0)) { throw new IllegalStateException("Colocated regions should have accessors at the same node"); if ((colocatedPR.getLocalMaxMemory() != 0) && (userPA.getLocalMaxMemory() == 0)) { throw new IllegalStateException("Colocated regions should have accessors at the same node"); if (!pr.isShadowPR()) { if (pr.getAttributes().getDataPolicy().withPersistence()) { if (!colocatedPR.getDataPolicy().withPersistence()) { throw new IllegalStateException( "Cannot colocate a persistent region with a non persistent region");
public static DumpB2NResponse send(Set recipients, PartitionedRegion r, int bId, boolean justPrimaryInfo) { DumpB2NResponse p = new DumpB2NResponse(r.getSystem(), recipients); DumpB2NRegion m = new DumpB2NRegion(recipients, r.getPRId(), p, bId, justPrimaryInfo); m.setTransactionDistributed(r.getCache().getTxManager().isDistributed()); r.getDistributionManager().putOutgoing(m); return p; }
@Override public void localDestroyRegion(Object aCallbackArgument) { getDataView().checkSupportsRegionDestroy(); String prName = this.getColocatedWith(); List<PartitionedRegion> listOfChildRegions = ColocationHelper.getColocatedChildRegions(this); List<String> childRegionsWithoutSendersList = new ArrayList<String>(); if (listOfChildRegions.size() != 0) { for (PartitionedRegion childRegion : listOfChildRegions) { if (!childRegion.getName().contains(ParallelGatewaySenderQueue.QSTRING)) { childRegionsWithoutSendersList.add(childRegion.getFullPath()); } } } if ((prName != null) || (!childRegionsWithoutSendersList.isEmpty())) { throw new UnsupportedOperationException( "Any Region in colocation chain cannot be destroyed locally."); } RegionEventImpl event = new RegionEventImpl(this, Operation.REGION_LOCAL_DESTROY, aCallbackArgument, false, getMyId(), generateEventID()/* generate EventID */); try { basicDestroyRegion(event, false); } catch (CacheWriterException e) { // not possible with local operation, CacheWriter not called throw new Error("CacheWriterException should not be thrown in localDestroyRegion", e); } catch (TimeoutException e) { // not possible with local operation, no distributed locks possible throw new Error("TimeoutException should not be thrown in localDestroyRegion", e); } }
@Before public void setup() throws Exception { localNode = new InternalDistributedMember("localhost", 8888); remoteNodeA = new InternalDistributedMember("localhost", 8889); remoteNodeB = new InternalDistributedMember("localhost", 8890); cache = Fakes.cache(); system = (InternalDistributedSystem) cache.getDistributedSystem(); allNodes.add(localNode); allNodes.add(remoteNodeA); allNodes.add(remoteNodeB); pr = mock(PartitionedRegion.class); dataStore = new ExtendedPartitionedRegionDataStore(); CompiledSelect select = mock(CompiledSelect.class); when(select.getType()).thenReturn(CompiledValue.COMPARISON); when(select.getElementTypeForOrderByQueries()).thenReturn(new ObjectTypeImpl(String.class)); query = mock(DefaultQuery.class); when(query.getSimpleSelect()).thenReturn(select); when(query.getLimit(any())).thenReturn(-1); when(pr.getCachePerfStats()).thenReturn(mock(CachePerfStats.class)); when(pr.getMyId()).thenReturn(localNode); when(pr.getDataStore()).thenReturn(dataStore); when(pr.getCache()).thenReturn(cache); }
PartitionedRegionDataStore ds = pr.getDataStore(); if (ds == null) { return null; InternalDistributedMember localMember = (InternalDistributedMember) pr.getMyId(); int configuredBucketCount = pr.getTotalNumberOfBuckets(); long[] bucketSizes = new long[configuredBucketCount]; new PartitionMemberInfoImpl(localMember, pr.getLocalMaxMemory() * (1024L * 1024L), size, ds.getBucketsManaged(), ds.getNumberOfPrimaryBucketsManaged(), prLoad, bucketSizes); } else { localDetails = new PartitionMemberInfoImpl(localMember, pr.getLocalMaxMemory() * (1024L * 1024L), size, ds.getBucketsManaged(), ds.getNumberOfPrimaryBucketsManaged());
@Override public boolean equals(Object other) { if (!(other instanceof PartitionRebalanceDetailsImpl)) { return false; } PartitionRebalanceDetailsImpl o = (PartitionRebalanceDetailsImpl) other; return this.region.getFullPath().equals(o.region.getFullPath()); }
private void setNetworkHopType(final Integer bucketId, final InternalDistributedMember targetNode) { if (this.isDataStore() && !getMyId().equals(targetNode)) { Set<ServerBucketProfile> profiles = this.getRegionAdvisor().getClientBucketProfiles(bucketId); if (profiles != null) { for (ServerBucketProfile profile : profiles) { if (profile.getDistributedMember().equals(targetNode)) { if (isProfileFromSameGroup(profile)) { if (this.getNetworkHopType() != NETWORK_HOP_TO_SAME_GROUP && logger.isDebugEnabled()) { logger.debug( "one-hop: cache op meta data staleness observed. Message is in same server group (byte 1)"); } this.setNetworkHopType((byte) NETWORK_HOP_TO_SAME_GROUP); } else { if (this.getNetworkHopType() != NETWORK_HOP_TO_DIFFERENT_GROUP && logger.isDebugEnabled()) { logger.debug( "one-hop: cache op meta data staleness observed. Message is to different server group (byte 2)"); } this.setNetworkHopType((byte) NETWORK_HOP_TO_DIFFERENT_GROUP); } this.setMetadataVersion((byte) profile.getVersion()); break; } } } } }
@Override protected boolean includePartitionedRegion(PartitionedRegion region) { return region.getEvictionAttributes().getAlgorithm().isLRUHeap() && region.getDataStore() != null && region.getAttributes().getOffHeap(); }
/** * Utility method to print warning when nodeList in b2n region is found empty. This will signify * potential data loss scenario. * * @param bucketId Id of Bucket whose nodeList in b2n is empty. * @param callingMethod methodName of the calling method. */ public static void logForDataLoss(PartitionedRegion partitionedRegion, int bucketId, String callingMethod) { if (!Boolean.getBoolean(DistributionConfig.GEMFIRE_PREFIX + "PRDebug")) { return; } Region root = PartitionedRegionHelper.getPRRoot(partitionedRegion.getCache()); // Region allPartitionedRegions = PartitionedRegionHelper.getPRConfigRegion( // root, partitionedRegion.getCache()); PartitionRegionConfig prConfig = (PartitionRegionConfig) root.get(partitionedRegion.getRegionIdentifier()); if (prConfig == null) return; Set members = partitionedRegion.getDistributionManager().getDistributionManagerIds(); logger.warn( "DATALOSS ( {} ) :: Size of nodeList After verifyBucketNodes for bucket ID, {} is 0", callingMethod, bucketId); logger.warn("DATALOSS ( {} ) :: NodeList from prConfig, {}", callingMethod, printCollection(prConfig.getNodes())); logger.warn("DATALOSS ( {} ) :: Current Membership List, {}", callingMethod, printCollection(members)); }
private Set<InternalDistributedMember> getAllStores(String partitionName) { if (partitionName != null) { return getFixedPartitionStores(partitionName); } final Set<InternalDistributedMember> allStores = this.prRegion.getRegionAdvisor().adviseDataStore(true); PartitionedRegionDataStore myDS = this.prRegion.getDataStore(); if (myDS != null) { allStores.add(this.prRegion.getDistributionManager().getId()); } return allStores; }
/** * A utility to check to see if a region has been created on all of the VMs that host the regions * this region is colocated with. */ public static boolean isColocationComplete(PartitionedRegion region) { Region prRoot = PartitionedRegionHelper.getPRRoot(region.getCache()); PartitionRegionConfig config = (PartitionRegionConfig) prRoot.get(region.getRegionIdentifier()); // Fix for bug 40075. There is race between this call and the region being concurrently // destroyed. if (config == null) { Assert.assertTrue(region.isDestroyed() || region.isClosed, "Region is not destroyed, but there is no entry in the prRoot for region " + region); return false; } return config.isColocationComplete(); }
@Override public void destroyRegion(Object aCallbackArgument) throws CacheWriterException, TimeoutException { this.cache.invokeBeforeDestroyed(this); checkForColocatedChildren(); getDataView().checkSupportsRegionDestroy(); checkForLimitedOrNoAccess(); RegionEventImpl event = new RegionEventImpl(this, Operation.REGION_DESTROY, aCallbackArgument, false, getMyId(), generateEventID()); basicDestroyRegion(event, true); }
public IndexRepository computeIndexRepository(final Integer bucketId, LuceneSerializer serializer, InternalLuceneIndex index, PartitionedRegion userRegion, final IndexRepository oldRepository, PartitionedRepositoryManager partitionedRepositoryManager) throws IOException { LuceneIndexForPartitionedRegion indexForPR = (LuceneIndexForPartitionedRegion) index; final PartitionedRegion fileRegion = indexForPR.getFileAndChunkRegion(); // We need to ensure that all members have created the fileAndChunk region before continuing Region prRoot = PartitionedRegionHelper.getPRRoot(fileRegion.getCache()); PartitionRegionConfig prConfig = (PartitionRegionConfig) prRoot.get(fileRegion.getRegionIdentifier()); LuceneFileRegionColocationListener luceneFileRegionColocationCompleteListener = new LuceneFileRegionColocationListener(partitionedRepositoryManager, bucketId); fileRegion.addColocationListener(luceneFileRegionColocationCompleteListener); IndexRepository repo = null; if (prConfig.isColocationComplete()) { repo = finishComputingRepository(bucketId, serializer, userRegion, oldRepository, index); } return repo; }