コード例 #1
0
        private IList <Endpoint> ReadEndpoints(CoreTopology coreTopology, ReadReplicaTopology rrTopology, Policy policy)
        {
//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
            ISet <ServerInfo> possibleReaders = rrTopology.Members().SetOfKeyValuePairs().Select(entry => new ServerInfo(entry.Value.connectors().boltAddress(), entry.Key, entry.Value.groups())).collect(Collectors.toSet());

            if (_allowReadsOnFollowers || possibleReaders.Count == 0)
            {
                ISet <MemberId> validCores = coreTopology.Members().Keys;
                try
                {
                    MemberId leader = _leaderLocator.Leader;
//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
                    validCores = validCores.Where(memberId => !memberId.Equals(leader)).collect(Collectors.toSet());
                }
                catch (NoLeaderFoundException)
                {
                    // we might end up using the leader for reading during this ttl, should be fine in general
                }

                foreach (MemberId validCore in validCores)
                {
                    Optional <CoreServerInfo> coreServerInfo = coreTopology.find(validCore);
                    coreServerInfo.ifPresent(coreServerInfo1 => possibleReaders.Add(new ServerInfo(coreServerInfo1.connectors().boltAddress(), validCore, coreServerInfo1.groups())));
                }
            }

            ISet <ServerInfo> readers = policy.Apply(possibleReaders);

            return(readers.Select(r => Endpoint.read(r.boltAddress())).ToList());
        }
コード例 #2
0
        private IList <Endpoint> WriteEndpoints(CoreTopology cores)
        {
            MemberId leader;

            try
            {
                leader = _leaderLocator.Leader;
            }
            catch (NoLeaderFoundException)
            {
                return(emptyList());
            }

            Optional <Endpoint> endPoint = cores.find(leader).map(extractBoltAddress()).map(Endpoint.write);

            return(new IList <Endpoint> {
                endPoint
            });
        }
コード例 #3
0
        public override RawIterator <object[], ProcedureException> Apply(Context ctx, object[] input, ResourceTracker resourceTracker)
        {
            IDictionary <MemberId, RoleInfo> roleMap   = _topologyService.allCoreRoles();
            IList <ReadWriteEndPoint>        endpoints = new List <ReadWriteEndPoint>();

            CoreTopology    coreTopology = _topologyService.allCoreServers();
            ISet <MemberId> coreMembers  = coreTopology.Members().Keys;

            foreach (MemberId memberId in coreMembers)
            {
                Optional <CoreServerInfo> coreServerInfo = coreTopology.find(memberId);
                if (coreServerInfo.Present)
                {
                    CoreServerInfo info = coreServerInfo.get();
                    RoleInfo       role = roleMap.getOrDefault(memberId, RoleInfo.UNKNOWN);
                    endpoints.Add(new ReadWriteEndPoint(info.Connectors(), role, memberId.Uuid, new IList <string> {
                        info.Groups()
                    }, info.DatabaseName));
                }
                else
                {
                    _log.debug("No Address found for " + memberId);
                }
            }

            foreach (KeyValuePair <MemberId, ReadReplicaInfo> readReplica in _topologyService.allReadReplicas().members().SetOfKeyValuePairs())
            {
                ReadReplicaInfo readReplicaInfo = readReplica.Value;
                endpoints.Add(new ReadWriteEndPoint(readReplicaInfo.Connectors(), RoleInfo.READ_REPLICA, readReplica.Key.Uuid, new IList <string> {
                    readReplicaInfo.Groups()
                }, readReplicaInfo.DatabaseName));
            }

            endpoints.sort(comparing(o => o.addresses().ToString()));

            return(map(endpoint => new object[] { endpoint.memberId().ToString(), endpoint.addresses().uriList().Select(URI.toString).ToList(), endpoint.role().name(), endpoint.groups(), endpoint.dbName() }, asRawIterator(endpoints.GetEnumerator())));
        }