public static async Task <List <RemoteTablet> > GetTabletsAsync( this IKuduConnectionFactory connectionFactory, string tableId, GetTableLocationsResponsePB locations) { // TODO: Need error handling here. var tsInfos = locations.TsInfos; var internedServers = new List <ServerInfo>(tsInfos.Count); var results = new List <RemoteTablet>(locations.TabletLocations.Count); foreach (var tsInfo in tsInfos) { var serverInfo = await GetServerInfoAsync(connectionFactory, tsInfo) .ConfigureAwait(false); if (serverInfo is not null) { internedServers.Add(serverInfo); } } foreach (var tabletInfo in locations.TabletLocations) { var tabletId = tabletInfo.TabletId.ToStringUtf8(); var partition = ProtobufHelper.ToPartition(tabletInfo.Partition); var numReplicas = Math.Max( tabletInfo.DEPRECATEDReplicas.Count, tabletInfo.InternedReplicas.Count); var servers = new List <ServerInfo>(numReplicas); var replicas = new List <KuduReplica>(numReplicas); int leaderIndex = -1; // Handle interned replicas. foreach (var replicaPb in tabletInfo.InternedReplicas) { var tsInfoIdx = (int)replicaPb.TsInfoIdx; var serverInfo = internedServers[tsInfoIdx]; var replica = new KuduReplica( serverInfo.HostPort, (ReplicaRole)replicaPb.Role, replicaPb.DimensionLabel); if (replica.Role == ReplicaRole.Leader) { leaderIndex = servers.Count; } servers.Add(serverInfo); replicas.Add(replica); } // Handle "old-style" non-interned replicas. // It's used for backward compatibility. foreach (var replicaPb in tabletInfo.DEPRECATEDReplicas) { var serverInfo = await connectionFactory.GetServerInfoAsync( replicaPb.TsInfo).ConfigureAwait(false); if (serverInfo != null) { var replica = new KuduReplica( serverInfo.HostPort, (ReplicaRole)replicaPb.Role, replicaPb.DimensionLabel); if (replica.Role == ReplicaRole.Leader) { leaderIndex = servers.Count; } servers.Add(serverInfo); replicas.Add(replica); } } var serverCache = new ServerInfoCache(servers, replicas, leaderIndex); var tablet = new RemoteTablet( tableId, tabletId, partition, serverCache); results.Add(tablet); } return(results); }