Search in sources :

Example 1 with BucketProfile

use of org.apache.geode.internal.cache.BucketAdvisor.BucketProfile 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 2 with BucketProfile

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

the class RegionAdvisor method getAllClientBucketProfiles.

/**
   * Returns an unmodifiable map of bucket IDs to locations hosting the bucket.
   */
public Map<Integer, List<BucketServerLocation66>> getAllClientBucketProfiles() {
    Map<Integer, List<BucketServerLocation66>> bucketToServerLocations = new HashMap<Integer, List<BucketServerLocation66>>();
    for (Integer bucketId : this.clientBucketProfilesMap.keySet()) {
        ArrayList<BucketServerLocation66> clientBucketProfiles = new ArrayList<BucketServerLocation66>();
        for (BucketProfile profile : this.clientBucketProfilesMap.get(bucketId)) {
            if (profile.isHosting) {
                ServerBucketProfile cProfile = (ServerBucketProfile) profile;
                Set<BucketServerLocation66> bucketServerLocations = cProfile.getBucketServerLocations();
                // Either we can make BucketServeLocation having ServerLocation with them
                // Or we can create bucketServerLocation as it is by iterating over the set of servers
                clientBucketProfiles.addAll(bucketServerLocations);
            }
        }
        bucketToServerLocations.put(bucketId, clientBucketProfiles);
    }
    if (getPartitionedRegion().isDataStore()) {
        for (Integer bucketId : getPartitionedRegion().getDataStore().getAllLocalBucketIds()) {
            BucketProfile profile = getBucketAdvisor(bucketId).getLocalProfile();
            if (logger.isDebugEnabled()) {
                logger.debug("The local profile is : {}", profile);
            }
            if (profile != null) {
                List<BucketServerLocation66> clientBucketProfiles = bucketToServerLocations.get(bucketId);
                if (clientBucketProfiles == null) {
                    clientBucketProfiles = new ArrayList<BucketServerLocation66>();
                    bucketToServerLocations.put(bucketId, clientBucketProfiles);
                }
                if ((profile instanceof ServerBucketProfile) && profile.isHosting) {
                    ServerBucketProfile cProfile = (ServerBucketProfile) profile;
                    Set<BucketServerLocation66> bucketServerLocations = cProfile.getBucketServerLocations();
                    // Either we can make BucketServeLocation having ServerLocation with
                    // them
                    // Or we can create bucketServerLocation as it is by iterating over
                    // the set of servers
                    clientBucketProfiles.removeAll(bucketServerLocations);
                    clientBucketProfiles.addAll(bucketServerLocations);
                }
            }
        }
    }
    return bucketToServerLocations;
}
Also used : ServerBucketProfile(org.apache.geode.internal.cache.BucketAdvisor.ServerBucketProfile) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BucketProfile(org.apache.geode.internal.cache.BucketAdvisor.BucketProfile) ServerBucketProfile(org.apache.geode.internal.cache.BucketAdvisor.ServerBucketProfile)

Example 3 with BucketProfile

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

the class RegionAdvisor method getAllClientBucketProfilesTest.

public ConcurrentHashMap<Integer, Set<ServerBucketProfile>> getAllClientBucketProfilesTest() {
    ConcurrentHashMap<Integer, Set<ServerBucketProfile>> map = new ConcurrentHashMap<Integer, Set<ServerBucketProfile>>();
    Map<Integer, List<BucketServerLocation66>> testMap = new HashMap<>(this.getAllClientBucketProfiles());
    for (Integer bucketId : testMap.keySet()) {
        Set<ServerBucketProfile> parr = new HashSet<>(this.clientBucketProfilesMap.get(bucketId));
        map.put(bucketId, parr);
    }
    if (getPartitionedRegion().isDataStore()) {
        for (Integer bucketId : getPartitionedRegion().getDataStore().getAllLocalBucketIds()) {
            BucketProfile profile = getBucketAdvisor(bucketId).getLocalProfile();
            if ((profile instanceof ServerBucketProfile) && profile.isHosting) {
                map.get(bucketId).add((ServerBucketProfile) profile);
            }
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("This maps is sksk {} and size is {}", map, map.keySet().size());
    }
    return map;
}
Also used : ServerBucketProfile(org.apache.geode.internal.cache.BucketAdvisor.ServerBucketProfile) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BucketProfile(org.apache.geode.internal.cache.BucketAdvisor.BucketProfile) ServerBucketProfile(org.apache.geode.internal.cache.BucketAdvisor.ServerBucketProfile) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 4 with BucketProfile

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

the class BucketRegion method fillInProfile.

@Override
public void fillInProfile(Profile profile) {
    super.fillInProfile(profile);
    BucketProfile bp = (BucketProfile) profile;
    bp.isInitializing = this.initializationLatchAfterGetInitialImage.getCount() > 0;
}
Also used : BucketProfile(org.apache.geode.internal.cache.BucketAdvisor.BucketProfile)

Example 5 with BucketProfile

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

the class AcceptorImpl method notifyCacheMembersOfClose.

private void notifyCacheMembersOfClose() {
    if (!this.cache.forcedDisconnect()) {
        for (PartitionedRegion pr : this.cache.getPartitionedRegions()) {
            Map<Integer, BucketAdvisor.BucketProfile> profiles = new HashMap<>();
            // 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();
                BucketProfile bp = (BucketProfile) advisor.createProfile();
                advisor.updateServerBucketProfile(bp);
                profiles.put(entry.getKey(), bp);
            }
            Set recipients = pr.getRegionAdvisor().adviseAllPRNodes();
            // send it to all in one message
            ReplyProcessor21 reply = AllBucketProfilesUpdateMessage.send(recipients, pr.getDistributionManager(), pr.getPRId(), profiles, true);
            if (reply != null) {
                reply.waitForRepliesUninterruptibly();
            }
            if (logger.isDebugEnabled()) {
                logger.debug("sending messages to all peers for removing this server..");
            }
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) BucketProfile(org.apache.geode.internal.cache.BucketAdvisor.BucketProfile) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) BucketAdvisor(org.apache.geode.internal.cache.BucketAdvisor) Map(java.util.Map) HashMap(java.util.HashMap) ReplyProcessor21(org.apache.geode.distributed.internal.ReplyProcessor21)

Aggregations

BucketProfile (org.apache.geode.internal.cache.BucketAdvisor.BucketProfile)6 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Set (java.util.Set)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ReplyProcessor21 (org.apache.geode.distributed.internal.ReplyProcessor21)2 BucketAdvisor (org.apache.geode.internal.cache.BucketAdvisor)2 ServerBucketProfile (org.apache.geode.internal.cache.BucketAdvisor.ServerBucketProfile)2 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)2 Random (java.util.Random)1 RegionAdvisor (org.apache.geode.internal.cache.partitioned.RegionAdvisor)1 LoggingThreadGroup (org.apache.geode.internal.logging.LoggingThreadGroup)1