public static boolean sameBucket(Host host1, Host host2, String bucketKey) { if (bucketKey == null) { return true; } return Objects.equals( host1.getEnvironmentFlags().get(bucketKey), host2.getEnvironmentFlags().get(bucketKey) ); }
private boolean isPreferredHost(Host host) { LOG.info("Environment flags for host "+host+": "+host.getEnvironmentFlags()); if (host.getEnvironmentFlags() != null && preferredHostEnvironment != null) { String clientValue = host.getEnvironmentFlags().get(preferredHostEnvironment.getKey()); if (clientValue != null && clientValue.equals(preferredHostEnvironment.getValue())) { return true; } } return false; }
private String getABForRing(Ring ring) { Set<String> buckets = Sets.newHashSet(); for (Host host : ring.getHosts()) { buckets.add(host.getEnvironmentFlags().get(status.getAvailabilityBucketKey())); } if (buckets.size() == 1) { return Accessors.only(buckets); } throw new RuntimeException("Unable to find a single AB for ring: " + ring); }
public static ThreeNestedMap<Domain, Integer, String, Long> domainToPartitionToHostsServingInBucket( Map<Domain, Map<Integer, Set<Host>>> domainToPartitionToHostsFullyServing, HostReplicaStatus status ) { ThreeNestedCountingMap<Domain, Integer, String> domainPartitionBucketHostCounts = new ThreeNestedCountingMap<>(0l); for (Map.Entry<Domain, Map<Integer, Set<Host>>> entry : domainToPartitionToHostsFullyServing.entrySet()) { Domain domain = entry.getKey(); for (Map.Entry<Integer, Set<Host>> partitionEntry : entry.getValue().entrySet()) { Integer partition = partitionEntry.getKey(); for (Host host : partitionEntry.getValue()) { domainPartitionBucketHostCounts.incrementAndGet( domain, partition, host.getEnvironmentFlags().get(status.getAvailabilityBucketKey()), 1l ); } } } return domainPartitionBucketHostCounts; }
protected Ring getUnderpopulatedRing(RingGroup group, String bucket) { for (Ring ring : group.getRings()) { Set<Host> hosts = ring.getHosts(); if (!hosts.isEmpty()) { // kinda iffy, but we don't assign multiple buckets within a ring String ringBucket = Accessors.first(hosts).getEnvironmentFlags().get(status.getAvailabilityBucketKey()); if ((ringBucket == null && bucket == null) || (ringBucket != null && ringBucket.equals(bucket))) { if (hosts.size() < targetHostsPerRing) { return ring; } } } } return null; }
String bucket = host.getEnvironmentFlags().get(status.getAvailabilityBucketKey()); Long count = domainPartitionBucketCounts.get(domain, partition.getPartitionNumber(), bucket);