@Override public String toString() { if (this.partitionedRegion != null) { String rName = this.partitionedRegion.getFullPath(); return this.partitionedRegion.getMyId() + "@" + getClass().getName() + "@" + System.identityHashCode(this) + " name: " + rName + " bucket count: " + this.localBucket2RegionMap.size(); } return null; }
@Override public String toString() { if (this.partitionedRegion != null) { String rName = this.partitionedRegion.getFullPath(); return this.partitionedRegion.getMyId() + "@" + getClass().getName() + "@" + System.identityHashCode(this) + " name: " + rName + " bucket count: " + this.localBucket2RegionMap.size(); } return null; }
@Override protected StringBuilder getStringBuilder() { return super.getStringBuilder() .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("; hdfsStoreName=").append(getHDFSStoreName()) .append("; hdfsWriteOnly=").append(getHDFSWriteOnly()) .append("; partition attributes=").append(getPartitionAttributes()) .append("; on VM ").append(getMyId()); }
@Override public String toString() { return new StringBuffer() .append("Partitioned Region ") .append("@").append(Integer.toHexString(hashCode())) .append(" [") .append("path='").append(getFullPath()) .append("'; dataPolicy=").append(this.dataPolicy) .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("; hdfsStoreName=").append(getHDFSStoreName()) .append("; hdfsWriteOnly=").append(getHDFSWriteOnly()) .append("; partition attributes=").append(getPartitionAttributes().toString()) .append("; on VM ").append(getMyId()) .append("]") .toString(); }
public boolean isPersistentRecoveryComplete() { if(!ColocationHelper.checkMembersColocation(this.prRegion, this.prRegion.getMyId())) { return false; } if(allBucketsRecoveredFromDisk != null && allBucketsRecoveredFromDisk.getCount() > 0) { return false; } Map<String, PartitionedRegion> colocatedRegions = ColocationHelper.getAllColocationRegions(this.prRegion); for(PartitionedRegion region : colocatedRegions.values()) { PRHARedundancyProvider redundancyProvider = region.getRedundancyProvider(); if(redundancyProvider.allBucketsRecoveredFromDisk != null && redundancyProvider.allBucketsRecoveredFromDisk.getCount() > 0) { return false; } } return true; }
public boolean isPersistentRecoveryComplete() { if(!ColocationHelper.checkMembersColocation(this.prRegion, this.prRegion.getMyId())) { return false; } if(allBucketsRecoveredFromDisk != null && allBucketsRecoveredFromDisk.getCount() > 0) { return false; } Map<String, PartitionedRegion> colocatedRegions = ColocationHelper.getAllColocationRegions(this.prRegion); for(PartitionedRegion region : colocatedRegions.values()) { PRHARedundancyProvider redundancyProvider = region.getRedundancyProvider(); if(redundancyProvider.allBucketsRecoveredFromDisk != null && redundancyProvider.allBucketsRecoveredFromDisk.getCount() > 0) { return false; } } return true; }
public Object call() throws Exception { int containsNode = 0; Cache cache = getCache(); PartitionedRegion pr = (PartitionedRegion)cache .getRegion(Region.SEPARATOR + PR_PREFIX + ri.intValue()); Iterator it = pr.getRegionAdvisor().getBucketSet().iterator(); Set nodeList; try { while (it.hasNext()) { Integer bucketId = (Integer) it.next(); nodeList = pr.getRegionAdvisor().getBucketOwners(bucketId.intValue()); if ((nodeList != null) && (nodeList.contains(pr.getMyId()))) { containsNode++; } else { getCache().getLogger().fine("I don't contain member " + pr.getMyId()); } } } catch (NoSuchElementException done) { } return new Integer(containsNode); } };
/** * This is for FPR, for given partition, we have to return the set of * datastores on which the given partition is defined * * @param partitionName * name of the partition for which datastores need to be found out */ private Set<InternalDistributedMember> getFixedPartitionStores( String partitionName) { Set<InternalDistributedMember> members = this.prRegion.getRegionAdvisor() .adviseFixedPartitionDataStores(partitionName); List<FixedPartitionAttributesImpl> FPAs = this.prRegion .getFixedPartitionAttributesImpl(); if (FPAs != null) { for (FixedPartitionAttributesImpl fpa : FPAs) { if (fpa.getPartitionName().equals(partitionName)) { members.add((InternalDistributedMember)this.prRegion.getMyId()); } } } return members; }
/** * This is for FPR, for given partition, we have to return the set of * datastores on which the given partition is defined * * @param partitionName * name of the partition for which datastores need to be found out */ private Set<InternalDistributedMember> getFixedPartitionStores( String partitionName) { Set<InternalDistributedMember> members = this.prRegion.getRegionAdvisor() .adviseFixedPartitionDataStores(partitionName); List<FixedPartitionAttributesImpl> FPAs = this.prRegion .getFixedPartitionAttributesImpl(); if (FPAs != null) { for (FixedPartitionAttributesImpl fpa : FPAs) { if (fpa.getPartitionName().equals(partitionName)) { members.add(this.prRegion.getMyId()); } } } return members; }
/** * If a bucket is local, try to fetch the value * from it * */ public Object getFromLocalBucket(int bucketId, final Object key, final Object aCallbackArgument, boolean disableCopyOnRead, boolean preferCD, ClientProxyMembershipID requestingClient, EntryEventImpl clientEvent, boolean returnTombstones, boolean allowReadFromHDFS) throws ForceReattemptException, PRLocallyDestroyedException { Object obj; // try reading locally. InternalDistributedMember readNode = getNodeForBucketRead(bucketId); if (readNode == null) { return null; // fixes 51657 } if (readNode.equals(getMyId()) && null != ( obj = this.dataStore.getLocally(bucketId, key, aCallbackArgument, disableCopyOnRead, preferCD, requestingClient, clientEvent, returnTombstones, true, allowReadFromHDFS))) { if (logger.isTraceEnabled()) { logger.trace("getFromBucket: Getting key {} ({}) locally - success", key, key.hashCode()); } return obj; } return null; }
/** * Fetch a BucketRegion, but do not return until it is initialized * @param key optional for error reporting; if none, no key available. * @param bucketId the bucket to fetch * @return the region * @throws ForceReattemptException */ public BucketRegion getInitializedBucketForId(Object key, Integer bucketId) throws ForceReattemptException { final BucketRegion bucketRegion = this.localBucket2RegionMap.get(bucketId); if (null == bucketRegion) { this.partitionedRegion.checkReadiness(); if (logger.isDebugEnabled()) { logger.debug("Got null bucket region for bucketId={}{}{} for PartitionedRegion = {}", this.partitionedRegion.getPRId(), PartitionedRegion.BUCKET_ID_SEPARATOR, bucketId, this.partitionedRegion); } ForceReattemptException fre = new BucketNotFoundException(LocalizedStrings.PartitionedRegionDataStore_BUCKET_ID_0_NOT_FOUND_ON_VM_1.toLocalizedString(new Object[] {this.partitionedRegion.bucketStringForLogs(bucketId.intValue()), this.partitionedRegion.getMyId()})); if (key != null) { fre.setHash(key.hashCode()); } throw fre; } bucketRegion.waitForData(); return bucketRegion; }
private PutAllPRMessage.PutAllResponse tryToSendOnePutAllMessage( PutAllPRMessage prMsg, final Set currentTargets, final TXStateProxy txProxy) throws DataLocationException { PutAllPRMessage.PutAllResponse response = null; prMsg.setRemoteResponse(null); final InternalDistributedMember self = getMyId(); final boolean isLocalAlso = (this.localMaxMemory != 0) && currentTargets.contains(self); final boolean hasRemote = !isLocalAlso || currentTargets.size() > 1; // first do remote sends if required if (hasRemote) { if (isLocalAlso) { currentTargets.remove(self); } response = (PutAllPRMessage.PutAllResponse)prMsg.send(currentTargets, this); } if (isLocalAlso) { // local // It might throw retry exception when one key failed // InternalDS has to be set for each msg prMsg.initMessage(this, null, false, null); prMsg.doLocalPutAll(this, self, 0L); if (response != null) { prMsg.setRemoteResponse(response); } response = new PutAllPRMessage.PutAllResponseFromLocal(prMsg); } return response; }
/** * @throws ForceReattemptException if it detects that the given bucket moved * @throws RegionDestroyedException if the given pr was destroyed */ private static void checkForBucketMoved(Integer bId, BucketRegion br, PartitionedRegion pr) throws ForceReattemptException, RegionDestroyedException { if (br.isBucketDestroyed()) { // see if the pr is destroyed if (pr.isLocallyDestroyed || pr.isClosed) { throw new RegionDestroyedException("PR destroyed during query", pr.getFullPath()); } pr.checkReadiness(); throw new ForceReattemptException("Bucket id " + pr.bucketStringForLogs(bId.intValue()) + " not found on VM " + pr.getMyId()); } }
/** * Fetch a BucketRegion, but do not return until it is initialized * @param key optional for error reporting; if none, no key available. * @param bucketId the bucket to fetch * @return the region * @throws ForceReattemptException */ public BucketRegion getInitializedBucketForId(Object key, Integer bucketId) throws ForceReattemptException { final BucketRegion bucketRegion = this.localBucket2RegionMap.get(bucketId); if (null == bucketRegion) { this.partitionedRegion.checkReadiness(); if (this.logger.fineEnabled()) { this.logger.fine("Got null bucket region for bucketId=" + partitionedRegion.bucketStringForLogs(bucketId.intValue()) + " for PartitionedRegion = " + this.partitionedRegion); } ForceReattemptException fre = new BucketNotFoundException(LocalizedStrings.PartitionedRegionDataStore_BUCKET_ID_0_NOT_FOUND_ON_VM_1.toLocalizedString(new Object[] {this.partitionedRegion.bucketStringForLogs(bucketId.intValue()), this.partitionedRegion.getMyId()})); if (key != null) { fre.setHash(key.hashCode()); } throw fre; } bucketRegion.waitForData(); return bucketRegion; }
/** * @throws ForceReattemptException if it detects that the given bucket moved * @throws RegionDestroyedException if the given pr was destroyed */ private static void checkForBucketMoved(Integer bId, BucketRegion br, PartitionedRegion pr) throws ForceReattemptException, RegionDestroyedException { if (br.isBucketDestroyed()) { // see if the pr is destroyed if (pr.isLocallyDestroyed || pr.isClosed) { throw new RegionDestroyedException("PR destroyed during query", pr.getFullPath()); } pr.checkReadiness(); throw new ForceReattemptException("Bucket id " + pr.bucketStringForLogs(bId.intValue()) + " not found on VM " + pr.getMyId()); } }
/** * Now only used for tests. TODO: method should be removed. */ public DistributedMember getOwnerForKey(KeyInfo keyInfo) { if (keyInfo == null) { return getMyId(); } int bucketId = keyInfo.getBucketId(); if (bucketId == KeyInfo.UNKNOWN_BUCKET) { bucketId = PartitionedRegionHelper.getHashKey(this, null, keyInfo.getKey(), keyInfo.getValue(), keyInfo.getCallbackArg()); keyInfo.setBucketId(bucketId); } return createBucket(bucketId, 0, null); }
public Object call() throws Exception { TXManagerImpl mgr = getGemfireCache().getTxManager(); PartitionedRegion pr = (PartitionedRegion)getCache().getRegion(CUSTOMER); CustId keyOnDs = getKeyOnMember(pr.getMyId(), pr); mgr.begin(); pr.get(keyOnDs); Set filter = new HashSet(); filter.add(keyOnDs); FunctionService.onRegion(pr).withFilter(filter).execute(TXFunction.id).getResult(); assertEquals(expectedCustomer, pr.get(expectedCustId)); TXStateInterface tx = mgr.internalSuspend(); assertNull(pr.get(expectedCustId)); mgr.resume(tx); return null; } };
@Override public void destroyRegion(Object aCallbackArgument) throws CacheWriterException, TimeoutException { //For HDFS regions, we need a data store //to do the global destroy so that it can delete //the data from HDFS as well. if(!isDataStore()) { if(destroyOnDataStore(aCallbackArgument)) { //If we were able to find a data store to do the destroy, //stop here. //otherwise go ahead and destroy the region from this member return; } } checkForColocatedChildren(false); getDataView().checkSupportsRegionDestroy(); checkForLimitedOrNoAccess(); RegionEventImpl event = new RegionEventImpl(this, Operation.REGION_DESTROY, aCallbackArgument, false, getMyId(), generateEventID()); basicDestroyRegion(event, true); }
@Override public void destroyRegion(Object aCallbackArgument) throws CacheWriterException, TimeoutException { //For HDFS regions, we need a data store //to do the global destroy so that it can delete //the data from HDFS as well. if(!isDataStore() && this.dataPolicy.withHDFS()) { if(destroyOnDataStore(aCallbackArgument)) { //If we were able to find a data store to do the destroy, //stop here. //otherwise go ahead and destroy the region from this member return; } } checkForColocatedChildren(); getDataView().checkSupportsRegionDestroy(); checkForLimitedOrNoAccess(); RegionEventImpl event = new RegionEventImpl(this, Operation.REGION_DESTROY, aCallbackArgument, false, getMyId(), generateEventID()); basicDestroyRegion(event, true); }
@Override protected RegionEntry basicGetTXEntry(KeyInfo keyInfo) { int bucketId = keyInfo.getBucketId(); if (bucketId == KeyInfo.UNKNOWN_BUCKET) { bucketId = PartitionedRegionHelper.getHashKey(this, null, keyInfo.getKey(), keyInfo.getValue(), keyInfo.getCallbackArg()); keyInfo.setBucketId(bucketId); } if (keyInfo.isCheckPrimary()) { DistributedMember primary = getRegionAdvisor().getPrimaryMemberForBucket( bucketId); if (!primary.equals(getMyId())) { throw new PrimaryBucketException("Bucket " + bucketId + " is not primary. Current primary holder is " + primary); } } BucketRegion br = this.dataStore.getLocalBucketById(bucketId); RegionEntry re = br.basicGetEntry(keyInfo.getKey()); if (re != null && re.isRemoved()) { re = null; } return re; }