/** * Returns the local BucketRegion given the key and value. Returns null if no BucketRegion exists. */ public BucketRegion getBucketRegion(Object key, Object value) { if (this.dataStore == null) { return null; } final Integer bucketId = PartitionedRegionHelper.getHashKey(this, null, key, value, null); return this.dataStore.getLocalBucketById(bucketId); }
public BucketRegion getLocalBucketByKey(Object key) { Integer bucketId = Integer .valueOf(PartitionedRegionHelper.getHashKey(this.partitionedRegion, null, key, null, null)); return getLocalBucketById(bucketId); }
/** * Returns the local BucketRegion given the key. Returns null if no BucketRegion exists. * * @since GemFire 6.1.2.9 */ public BucketRegion getBucketRegion(Object key) { if (this.dataStore == null) return null; Integer bucketId = PartitionedRegionHelper.getHashKey(this, null, key, null, null); return this.dataStore.getLocalBucketById(bucketId); }
protected BucketRegionQueue getBucketRegionQueueByBucketId(final PartitionedRegion prQ, final int bucketId) { return (BucketRegionQueue) prQ.getDataStore().getLocalBucketById(bucketId); }
@Override public int size() { int size = 0; for (Integer bId : buckets) { BucketRegion br = proxy.getDataStore().getLocalBucketById(bId); size += br.size(); } return size; }
/** * Find the bucket in region2 that matches the bucket id from region1. */ protected BucketRegion getMatchingBucket(PartitionedRegion region, Integer bucketId) { // Force the bucket to be created if it is not already region.getOrCreateNodeForBucketWrite(bucketId, null); return region.getDataStore().getLocalBucketById(bucketId); } }
@Override public Object answer(InvocationOnMock invocation) throws Throwable { when(fileDataStore.getLocalBucketById(eq(0))).thenReturn(fileAndChunkBuckets.get(0)); return null; } });
public boolean hasSeenEvent(EntryEventImpl event) { BucketRegion bucket = getLocalBucketById(event.getKeyInfo().getBucketId()); if (bucket == null) { return false; } else { return bucket.hasSeenEvent(event); } }
@Override protected BucketRegion setUpMockBucket(int id) throws BucketNotFoundException { BucketRegion mockBucket = Mockito.mock(BucketRegion.class); when(mockBucket.getId()).thenReturn(id); when(userRegion.getBucketRegion(eq(id), eq(null))).thenReturn(mockBucket); when(userDataStore.getLocalBucketById(eq(id))).thenReturn(mockBucket); when(userRegion.getBucketRegion(eq(id + 113), eq(null))).thenReturn(mockBucket); when(userDataStore.getLocalBucketById(eq(id + 113))).thenReturn(mockBucket); dataBuckets.put(id, mockBucket); repoManager.computeRepository(mockBucket.getId()); return mockBucket; }
/** * Return all of the user PR buckets for this bucket region queue. */ public Collection<BucketRegion> getCorrespondingUserPRBuckets() { List<BucketRegion> userPRBuckets = new ArrayList<BucketRegion>(4); Map<String, PartitionedRegion> colocatedPRs = ColocationHelper.getAllColocationRegions(getPartitionedRegion()); for (PartitionedRegion colocatedPR : colocatedPRs.values()) { if (!colocatedPR.isShadowPR() && isThisSenderAttached(colocatedPR)) { BucketRegion parentBucket = colocatedPR.getDataStore().getLocalBucketById(getId()); if (parentBucket != null) userPRBuckets.add(parentBucket); } } return userPRBuckets; }
@Test public void createLuceneIndexOnExistingRegionShouldNotThrowNPEIfBucketMovedDuringReindexing() { LuceneIndexImpl index = mock(LuceneIndexImpl.class); PartitionedRegionDataStore dataStore = mock(PartitionedRegionDataStore.class); when(region.getDataStore()).thenReturn(dataStore); Integer bucketIds[] = {1, 2, 3, 4, 5}; Set<Integer> primaryBucketIds = new HashSet(Arrays.asList(bucketIds)); when(dataStore.getAllLocalPrimaryBucketIds()).thenReturn(primaryBucketIds); when(dataStore.getLocalBucketById(3)).thenReturn(null); boolean result = service.createLuceneIndexOnDataRegion(region, index); assertTrue(result); }
protected BucketRegion setUpMockBucket(int id) throws BucketNotFoundException { BucketRegion mockBucket = Mockito.mock(BucketRegion.class); BucketRegion fileAndChunkBucket = Mockito.mock(BucketRegion.class); // Allowing the fileAndChunkBucket to behave like a map so that the IndexWriter operations don't // fail Fakes.addMapBehavior(fileAndChunkBucket); when(fileAndChunkBucket.getFullPath()).thenReturn("File" + id); when(mockBucket.getId()).thenReturn(id); when(userRegion.getBucketRegion(eq(id), eq(null))).thenReturn(mockBucket); when(userDataStore.getLocalBucketById(eq(id))).thenReturn(mockBucket); when(userRegion.getBucketRegion(eq(id + 113), eq(null))).thenReturn(mockBucket); when(userDataStore.getLocalBucketById(eq(id + 113))).thenReturn(mockBucket); when(fileDataStore.getLocalBucketById(eq(id))).thenReturn(fileAndChunkBucket); fileAndChunkBuckets.put(id, fileAndChunkBucket); dataBuckets.put(id, mockBucket); BucketAdvisor mockBucketAdvisor = Mockito.mock(BucketAdvisor.class); when(fileAndChunkBucket.getBucketAdvisor()).thenReturn(mockBucketAdvisor); when(mockBucketAdvisor.isPrimary()).thenReturn(true); return mockBucket; } }
@Test public void createMissingBucket() throws BucketNotFoundException { setUpMockBucket(0); when(fileDataStore.getLocalBucketById(eq(0))).thenReturn(null); when(fileAndChunkRegion.getOrCreateNodeForBucketWrite(eq(0), (RetryTimeKeeper) any())) .then(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { when(fileDataStore.getLocalBucketById(eq(0))).thenReturn(fileAndChunkBuckets.get(0)); return null; } }); assertNotNull(repoManager.getRepository(userRegion, 0, null)); }
@Override public Collection<IndexRepository> getRepositories(RegionFunctionContext ctx, boolean waitForRepository) throws BucketNotFoundException { Region<Object, Object> region = ctx.getDataSet(); Set<Integer> buckets = ((InternalRegionFunctionContext) ctx).getLocalBucketSet(region); ArrayList<IndexRepository> repos = new ArrayList<IndexRepository>(buckets.size()); for (Integer bucketId : buckets) { BucketRegion userBucket = userRegion.getDataStore().getLocalBucketById(bucketId); if (userBucket == null) { throw new BucketNotFoundException( "User bucket was not found for region " + region + "bucket id " + bucketId); } else { if (index.isIndexAvailable(userBucket.getId()) || userBucket.isEmpty() || waitForRepository) { repos.add(getRepository(userBucket.getId())); } else { waitingThreadPoolFromDM.execute(() -> { try { getRepository(userBucket.getId()); } catch (Exception e) { logger.debug("Lucene Index creation in progress.", e); } }); throw new LuceneIndexCreationInProgressException( "Lucene Index creation in progress for bucket: " + userBucket.getId()); } } } return repos; }
private void setEventSeqNum() { if (this.partitionedRegion.isShadowPR() && this.partitionedRegion.getColocatedWith() != null) { PartitionedRegion parentPR = ColocationHelper.getLeaderRegion(this.partitionedRegion); BucketRegion parentBucket = parentPR.getDataStore().getLocalBucketById(getId()); // needs to be set only once. if (parentBucket.eventSeqNum == null) { parentBucket.eventSeqNum = new AtomicLong5(getId()); } } if (this.partitionedRegion.getColocatedWith() == null) { this.eventSeqNum = new AtomicLong5(getId()); } else { PartitionedRegion parentPR = ColocationHelper.getLeaderRegion(this.partitionedRegion); BucketRegion parentBucket = parentPR.getDataStore().getLocalBucketById(getId()); if (parentBucket == null && logger.isDebugEnabled()) { logger.debug("The parentBucket of region {} bucketId {} is NULL", this.partitionedRegion.getFullPath(), getId()); } Assert.assertTrue(parentBucket != null); this.eventSeqNum = parentBucket.eventSeqNum; } }
@Override public boolean isIndexingInProgress() { PartitionedRegion userRegion = (PartitionedRegion) cache.getRegion(this.getRegionPath()); Set<Integer> fileRegionPrimaryBucketIds = this.getFileAndChunkRegion().getDataStore().getAllLocalPrimaryBucketIds(); for (Integer bucketId : fileRegionPrimaryBucketIds) { BucketRegion userBucket = userRegion.getDataStore().getLocalBucketById(bucketId); if (!userBucket.isEmpty() && !this.isIndexAvailable(bucketId)) { return true; } } return false; }
@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; }
rgn = prLocal.getDataStore().getLocalBucketById(bucketID);
/** * Returns the index for the bucket. */ public static AbstractIndex getBucketIndex(PartitionedRegion pr, String indexName, Integer bId) throws QueryInvocationTargetException { try { pr.checkReadiness(); } catch (Exception ex) { throw new QueryInvocationTargetException(ex.getMessage()); } PartitionedRegionDataStore prds = pr.getDataStore(); BucketRegion bukRegion; bukRegion = (BucketRegion) prds.getLocalBucketById(bId); if (bukRegion == null) { throw new BucketMovedException("Bucket not found for the id :" + bId); } AbstractIndex index = null; if (bukRegion.getIndexManager() != null) { index = (AbstractIndex) (bukRegion.getIndexManager().getIndex(indexName)); } else { if (pr.getCache().getLogger().fineEnabled()) { pr.getCache().getLogger().fine("Index Manager not found for the bucket region " + bukRegion.getFullPath() + " unable to fetch the index " + indexName); } throw new QueryInvocationTargetException( "Index Manager not found, " + " unable to fetch the index " + indexName); } return index; }
BucketRegion bukRegion = (BucketRegion) prds.getLocalBucketById((Integer) bId); if (bukRegion == null) { throw new QueryInvocationTargetException("Bucket not found for the id :" + bId);