// This maps a list of keyranges to shard names. func resolveKeyRangeToShards(topoServer SrvTopoServer, cell, keyspace string, tabletType topo.TabletType, kr key.KeyRange) ([]string, error) { srvKeyspace, err := topoServer.GetSrvKeyspace(cell, keyspace) if err != nil { return nil, fmt.Errorf("Error in reading the keyspace %v", err) } tabletTypePartition, ok := srvKeyspace.Partitions[tabletType] if !ok { return nil, fmt.Errorf("No shards available for tablet type '%v' in keyspace '%v'", tabletType, keyspace) } topo.SrvShardArray(tabletTypePartition.Shards).Sort() shards := make([]string, 0, 1) if !kr.IsPartial() { for j := 0; j < len(tabletTypePartition.Shards); j++ { shards = append(shards, tabletTypePartition.Shards[j].ShardName()) } return shards, nil } for j := 0; j < len(tabletTypePartition.Shards); j++ { shard := tabletTypePartition.Shards[j] if key.KeyRangesIntersect(kr, shard.KeyRange) { shards = append(shards, shard.ShardName()) } if kr.End != key.MaxKey && kr.End < shard.KeyRange.Start { break } } return shards, nil }
// This maps a list of keyranges to shard names. func resolveKeyRangeToShards(allShards []topo.ShardReference, kr key.KeyRange) ([]string, error) { shards := make([]string, 0, 1) if !kr.IsPartial() { for j := 0; j < len(allShards); j++ { shards = append(shards, allShards[j].Name) } return shards, nil } for j := 0; j < len(allShards); j++ { shard := allShards[j] if key.KeyRangesIntersect(kr, shard.KeyRange) { shards = append(shards, shard.Name) } } return shards, nil }
// This maps a list of keyranges to shard names. func resolveKeyRangeToShards(allShards []topo.SrvShard, kr key.KeyRange) ([]string, error) { shards := make([]string, 0, 1) topo.SrvShardArray(allShards).Sort() if !kr.IsPartial() { for j := 0; j < len(allShards); j++ { shards = append(shards, allShards[j].ShardName()) } return shards, nil } for j := 0; j < len(allShards); j++ { shard := allShards[j] if key.KeyRangesIntersect(kr, shard.KeyRange) { shards = append(shards, shard.ShardName()) } if kr.End != key.MaxKey && kr.End < shard.KeyRange.Start { break } } return shards, nil }