Search in sources :

Example 1 with BucketAdvisor

use of org.apache.geode.internal.cache.BucketAdvisor in project geode by apache.

the class PartitionedRepositoryManagerJUnitTest method setUpMockBucket.

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;
}
Also used : BucketRegion(org.apache.geode.internal.cache.BucketRegion) BucketAdvisor(org.apache.geode.internal.cache.BucketAdvisor)

Example 2 with BucketAdvisor

use of org.apache.geode.internal.cache.BucketAdvisor in project geode by apache.

the class IndexRepositoryImplJUnitTest method setUp.

@Before
public void setUp() throws IOException {
    ConcurrentHashMap fileAndChunkRegion = new ConcurrentHashMap();
    fileSystemStats = mock(FileSystemStats.class);
    RegionDirectory dir = new RegionDirectory(fileAndChunkRegion, fileSystemStats);
    IndexWriterConfig config = new IndexWriterConfig(analyzer);
    writer = new IndexWriter(dir, config);
    String[] indexedFields = new String[] { "s", "i", "l", "d", "f", "s2", "missing" };
    mapper = new HeterogeneousLuceneSerializer(indexedFields);
    region = Mockito.mock(Region.class);
    userRegion = Mockito.mock(BucketRegion.class);
    BucketAdvisor bucketAdvisor = Mockito.mock(BucketAdvisor.class);
    Mockito.when(bucketAdvisor.isPrimary()).thenReturn(true);
    Mockito.when(((BucketRegion) userRegion).getBucketAdvisor()).thenReturn(bucketAdvisor);
    Mockito.when(((BucketRegion) userRegion).getBucketAdvisor().isPrimary()).thenReturn(true);
    stats = Mockito.mock(LuceneIndexStats.class);
    Mockito.when(userRegion.isDestroyed()).thenReturn(false);
    repo = new IndexRepositoryImpl(region, writer, mapper, stats, userRegion, mock(DistributedLockService.class), "lockName");
}
Also used : LuceneIndexStats(org.apache.geode.cache.lucene.internal.LuceneIndexStats) HeterogeneousLuceneSerializer(org.apache.geode.cache.lucene.internal.repository.serializer.HeterogeneousLuceneSerializer) FileSystemStats(org.apache.geode.cache.lucene.internal.filesystem.FileSystemStats) BucketRegion(org.apache.geode.internal.cache.BucketRegion) IndexWriter(org.apache.lucene.index.IndexWriter) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Region(org.apache.geode.cache.Region) BucketAdvisor(org.apache.geode.internal.cache.BucketAdvisor) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) RegionDirectory(org.apache.geode.cache.lucene.internal.directory.RegionDirectory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Before(org.junit.Before)

Example 3 with BucketAdvisor

use of org.apache.geode.internal.cache.BucketAdvisor in project geode by apache.

the class ParallelQueueRemovalMessageJUnitTest method createBucketRegionQueue.

private void createBucketRegionQueue() {
    // Create InternalRegionArguments
    InternalRegionArguments ira = new InternalRegionArguments();
    ira.setPartitionedRegion(this.queueRegion);
    ira.setPartitionedRegionBucketRedundancy(1);
    BucketAdvisor ba = mock(BucketAdvisor.class);
    ira.setBucketAdvisor(ba);
    InternalRegionArguments pbrIra = new InternalRegionArguments();
    RegionAdvisor ra = mock(RegionAdvisor.class);
    when(ra.getPartitionedRegion()).thenReturn(this.queueRegion);
    pbrIra.setPartitionedRegionAdvisor(ra);
    PartitionAttributes pa = mock(PartitionAttributes.class);
    when(this.queueRegion.getPartitionAttributes()).thenReturn(pa);
    when(this.queueRegion.getBucketName(eq(BUCKET_ID))).thenAnswer(new Answer<String>() {

        @Override
        public String answer(final InvocationOnMock invocation) throws Throwable {
            return PartitionedRegionHelper.getBucketName(queueRegion.getFullPath(), BUCKET_ID);
        }
    });
    when(this.queueRegion.getDataPolicy()).thenReturn(DataPolicy.PARTITION);
    when(pa.getColocatedWith()).thenReturn(null);
    // classes cannot be mocked
    ProxyBucketRegion pbr = new ProxyBucketRegion(BUCKET_ID, this.queueRegion, pbrIra);
    when(ba.getProxyBucketRegion()).thenReturn(pbr);
    // Create RegionAttributes
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    factory.setDataPolicy(DataPolicy.REPLICATE);
    factory.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes(100, null, EvictionAction.OVERFLOW_TO_DISK));
    RegionAttributes attributes = factory.create();
    // Create BucketRegionQueue
    BucketRegionQueue realBucketRegionQueue = new BucketRegionQueue(this.queueRegion.getBucketName(BUCKET_ID), attributes, this.rootRegion, this.cache, ira);
    this.bucketRegionQueue = spy(realBucketRegionQueue);
    // (this.queueRegion.getBucketName(BUCKET_ID), attributes, this.rootRegion, this.cache, ira);
    EntryEventImpl entryEvent = EntryEventImpl.create(this.bucketRegionQueue, Operation.DESTROY, mock(EventID.class), "value", null, false, mock(DistributedMember.class));
    doReturn(entryEvent).when(this.bucketRegionQueue).newDestroyEntryEvent(any(), any());
    // when(this.bucketRegionQueue.newDestroyEntryEvent(any(), any())).thenReturn();
    this.bucketRegionQueueHelper = new BucketRegionQueueHelper(this.cache, this.queueRegion, this.bucketRegionQueue);
}
Also used : RegionAdvisor(org.apache.geode.internal.cache.partitioned.RegionAdvisor) RegionAttributes(org.apache.geode.cache.RegionAttributes) EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) InternalRegionArguments(org.apache.geode.internal.cache.InternalRegionArguments) BucketRegionQueueHelper(org.apache.geode.internal.cache.BucketRegionQueueHelper) AttributesFactory(org.apache.geode.cache.AttributesFactory) BucketRegionQueue(org.apache.geode.internal.cache.BucketRegionQueue) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ProxyBucketRegion(org.apache.geode.internal.cache.ProxyBucketRegion) DistributedMember(org.apache.geode.distributed.DistributedMember) EventID(org.apache.geode.internal.cache.EventID) BucketAdvisor(org.apache.geode.internal.cache.BucketAdvisor)

Example 4 with BucketAdvisor

use of org.apache.geode.internal.cache.BucketAdvisor in project geode by apache.

the class AcceptorImpl method start.

@Override
public void start() throws IOException {
    ThreadGroup tg = LoggingThreadGroup.createThreadGroup("Acceptor " + this.serverSock.getInetAddress() + ":" + this.localPort, logger);
    thread = new Thread(tg, this, "Cache Server Acceptor " + this.serverSock.getInetAddress() + ":" + this.localPort + " local port: " + this.serverSock.getLocalPort());
    this.acceptorId = thread.getId();
    // This thread should not be a daemon to keep BridgeServers created
    // in code from exiting immediately.
    thread.start();
    if (isSelector()) {
        Runnable r = new Runnable() {

            public void run() {
                AcceptorImpl.this.runSelectorLoop();
            }
        };
        this.selectorThread = new Thread(tg, r, "Cache Server Selector " + this.serverSock.getInetAddress() + ":" + this.localPort + " local port: " + this.serverSock.getLocalPort());
        this.selectorThread.start();
    }
    Set<PartitionedRegion> prs = this.cache.getPartitionedRegions();
    for (PartitionedRegion pr : prs) {
        Map<Integer, BucketAdvisor.BucketProfile> profiles = new HashMap<Integer, BucketAdvisor.BucketProfile>();
        // get all local real bucket advisors
        Map<Integer, BucketAdvisor> advisors = pr.getRegionAdvisor().getAllBucketAdvisors();
        for (Map.Entry<Integer, BucketAdvisor> entry : advisors.entrySet()) {
            BucketAdvisor advisor = entry.getValue();
            // addLocally
            BucketProfile bp = (BucketProfile) advisor.createProfile();
            advisor.updateServerBucketProfile(bp);
            // advisor.basicAddClientProfile(bp);
            profiles.put(entry.getKey(), bp);
        }
        Set receipients = new HashSet();
        receipients = pr.getRegionAdvisor().adviseAllPRNodes();
        // send it to all in one messgae
        ReplyProcessor21 reply = AllBucketProfilesUpdateMessage.send(receipients, pr.getDistributionManager(), pr.getPRId(), profiles, true);
        if (reply != null) {
            reply.waitForRepliesUninterruptibly();
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BucketProfile(org.apache.geode.internal.cache.BucketAdvisor.BucketProfile) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) LoggingThreadGroup(org.apache.geode.internal.logging.LoggingThreadGroup) BucketAdvisor(org.apache.geode.internal.cache.BucketAdvisor) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet) ReplyProcessor21(org.apache.geode.distributed.internal.ReplyProcessor21)

Example 5 with BucketAdvisor

use of org.apache.geode.internal.cache.BucketAdvisor in project geode by apache.

the class BucketCountLoadProbe method getLoad.

public PRLoad getLoad(PartitionedRegion pr) {
    PartitionedRegionDataStore ds = pr.getDataStore();
    int configuredBucketCount = pr.getTotalNumberOfBuckets();
    PRLoad prLoad = new PRLoad(configuredBucketCount, pr.getLocalMaxMemory());
    // key: bid, value: size
    for (Integer bidInt : ds.getAllLocalBucketIds()) {
        int bid = bidInt.intValue();
        BucketAdvisor bucketAdvisor = pr.getRegionAdvisor().getBucket(bid).getBucketAdvisor();
        // Wait for a primary to exist for this bucket, because
        // it might be this member.
        bucketAdvisor.getPrimary();
        boolean isPrimary = pr.getRegionAdvisor().getBucket(bid).getBucketAdvisor().isPrimary();
        prLoad.addBucket(bid, 1, isPrimary ? 1 : 0);
    }
    return prLoad;
}
Also used : PartitionedRegionDataStore(org.apache.geode.internal.cache.PartitionedRegionDataStore) BucketAdvisor(org.apache.geode.internal.cache.BucketAdvisor)

Aggregations

BucketAdvisor (org.apache.geode.internal.cache.BucketAdvisor)10 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Set (java.util.Set)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ReplyProcessor21 (org.apache.geode.distributed.internal.ReplyProcessor21)2 BucketProfile (org.apache.geode.internal.cache.BucketAdvisor.BucketProfile)2 BucketRegion (org.apache.geode.internal.cache.BucketRegion)2 PartitionedRegionDataStore (org.apache.geode.internal.cache.PartitionedRegionDataStore)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AttributesFactory (org.apache.geode.cache.AttributesFactory)1 PartitionAttributes (org.apache.geode.cache.PartitionAttributes)1 Region (org.apache.geode.cache.Region)1 RegionAttributes (org.apache.geode.cache.RegionAttributes)1 LuceneIndexStats (org.apache.geode.cache.lucene.internal.LuceneIndexStats)1 RegionDirectory (org.apache.geode.cache.lucene.internal.directory.RegionDirectory)1 FileSystemStats (org.apache.geode.cache.lucene.internal.filesystem.FileSystemStats)1 HeterogeneousLuceneSerializer (org.apache.geode.cache.lucene.internal.repository.serializer.HeterogeneousLuceneSerializer)1