<pre>
Mechanism used to determine which version a request is sent to.
The traffic selection algorithm will
be stable for either type until allocations are changed.
</pre>

<code>.google.appengine.v1.TrafficSplit.ShardBy shard_by = 1;</code>
195570
public com.google.appengine.v1.TrafficSplit.ShardBy getShardBy() {
    com.google.appengine.v1.TrafficSplit.ShardBy result = com.google.appengine.v1.TrafficSplit.ShardBy.valueOf(shardBy_);
    return result == null ? com.google.appengine.v1.TrafficSplit.ShardBy.UNRECOGNIZED : result;
  }
12898
public SimpleOrderedMap<Object> createListOutput(boolean shardRequests, int maxNumber) {
    garbageCollect();
    SimpleOrderedMap<Object> output = new SimpleOrderedMap<>();
    output.add(NAME_ENABLED, enabled());
    output.add(NAME_ENABLED, true);
    int numberTotal = data.size();
    ListData listData = new ListData();

    synchronized (data) {
      ListIterator<MtasSolrStatus> iter = data.listIterator(data.size());
      MtasSolrStatus item;
      int number = 0;
      while (iter.hasPrevious() && number < maxNumber) {
        item = iter.previous();
        if (item.shardRequest()) {
          listData.addShardRequest();
          if (shardRequests) {
            listData.outputList.add(item.createItemOutput());
            number++;
          }
        } else {
          listData.addNormal();
          listData.outputList.add(item.createItemOutput());
          number++;
        }
      }
    }
    output.add(NAME_SIZE_TOTAL, numberTotal);
    output.add(NAME_SIZE_NORMAL, listData.numberNormal);
    output.add(NAME_SIZE_SHARDREQUESTS, listData.numberShardRequests);
    output.add(NAME_LIST, listData.outputList);
    return output;
  }
194100
int numShardsIOwn() {
        final boolean[] shards = iOwn.get();
        if (shards == null)
            return 0;
        return (int) IntStream.range(0, shards.length).mapToObj(i -> Boolean.valueOf(shards[i])).filter(b -> b.booleanValue()).count();
    }
706365
public com.google.protobuf.ByteString
      getVersionUrlBytes() {
    java.lang.Object ref = versionUrl_;
    if (ref instanceof java.lang.String) {
      com.google.protobuf.ByteString b = 
          com.google.protobuf.ByteString.copyFromUtf8(
              (java.lang.String) ref);
      versionUrl_ = b;
      return b;
    } else {
      return (com.google.protobuf.ByteString) ref;
    }
  }
1141985
@Override
    public java.util.concurrent.Future<SplitShardResult> splitShardAsync(String streamName, String shardToSplit, String newStartingHashKey,
            com.amazonaws.handlers.AsyncHandler<SplitShardRequest, SplitShardResult> asyncHandler) {

        return splitShardAsync(new SplitShardRequest().withStreamName(streamName).withShardToSplit(shardToSplit).withNewStartingHashKey(newStartingHashKey),
                asyncHandler);
    }
762361
private void cacheShardValue(TableDefinition tableDef,
                                 Integer         shardNumber,
                                 Date            shardStart) {
        // Get or create the app name -> table map
        String appName = tableDef.getAppDef().getAppName();
        Map<String, Map<Integer, Date>> tableShardNumberMap = m_appShardMap.get(appName);
        if (tableShardNumberMap == null) {
            tableShardNumberMap = new HashMap<String, Map<Integer,Date>>();
            m_appShardMap.put(appName, tableShardNumberMap);
        }
        
        // Get or create the table name -> shard number map
        String tableName = tableDef.getTableName();
        Map<Integer, Date> shardNumberMap = tableShardNumberMap.get(tableName);
        if (shardNumberMap == null) {
            shardNumberMap = new HashMap<Integer, Date>();
            tableShardNumberMap.put(tableName, shardNumberMap);
        }
        
        // Add the shard number -> start date
        shardNumberMap.put(shardNumber, shardStart);
        m_logger.debug("Sharding date for {}.{} shard #{} set to: {} ({})",
                       new Object[]{appName, tableName, shardNumber, shardStart.getTime(), Utils.formatDateUTC(shardStart)});
    }
238969
public static Map<DataSourceWrapper, List<ShardRouteInfo>> groupRouteInfosByDataSource(DDRDataSource ddrDataSource,
                                                                                           boolean readOnly,
                                                                                           List<ShardRouteInfo> routeInfos) {
        if (routeInfos == null || routeInfos.isEmpty()) {
            return Collections.EMPTY_MAP;
        }
        Map<DataSourceWrapper, List<ShardRouteInfo>> result = new LinkedHashMap<>();
        Map<String, DataSourceWrapper> dataSourceWrapperMap = new HashMap<>();
        for (ShardRouteInfo routeInfo : routeInfos) {
            DataSourceWrapper dataSourceWrapper = dataSourceWrapperMap.get(routeInfo.getScName());
            if (dataSourceWrapper == null) {
                DataSourceParam param = new DataSourceParam();
                Set<String> schemas = new HashSet<>();
                schemas.add(routeInfo.getScName());
                param.setScNames(schemas);
                param.setReadOnly(readOnly);
                dataSourceWrapper = ddrDataSource.getDataSource(param);
                for (String scName : dataSourceWrapper.getSchemas()) {
                    Object preValue = dataSourceWrapperMap.put(scName, dataSourceWrapper);
                    if (preValue != null) {
                        throw new IllegalStateException("Duplicate dataSource binding on schema: " + scName);
                    }
                }
            }
            List<ShardRouteInfo> list = result.get(dataSourceWrapper);
            if (list == null) {
                list = new ArrayList<>();
                result.put(dataSourceWrapper, list);
            }
            list.add(routeInfo);
        }
        return result;
    }
212373
int version()
  {
    if (_version > 0) {
      return _version;
    }

    CharSegment protocol = getProtocolBuffer();
    if (protocol.equals("HTTP/1.1")) {
      _version = HTTP_1_1;
      return HTTP_1_1;
    }
    else if (protocol.equals("HTTP/1.0")) {
      _version = HTTP_1_0;
      return _version;
    }
    else if (protocol.equals("HTTP/0.9")) {
      _version = HTTP_0_9;
      return HTTP_0_9;
    }
    else if (protocol.length() < 8) {
      _version = HTTP_0_9;
      return _version;
    }

    int i = protocol.indexOf('/');
    int len = protocol.length();
    int major = 0;
    for (i++; i < len; i++) {
      char ch = protocol.charAt(i);

      if ('0' <= ch && ch <= '9')
        major = 10 * major + ch - '0';
      else if (ch == '.')
        break;
      else {
        _version = HTTP_1_0;
        return _version;
      }
    }

    int minor = 0;
    for (i++; i < len; i++) {
      char ch = protocol.charAt(i);

      if ('0' <= ch && ch <= '9')
        minor = 10 * minor + ch - '0';
      else
        break;
    }

    _version = 256 * major + minor;

    return _version;
  }
657829
public VoltMessage poll()
    {
        if (m_mustDrain || m_replayEntries.isEmpty()) {
            return null;
        }
        if (m_replayEntries.firstEntry().getValue().isEmpty()) {
            m_replayEntries.pollFirstEntry();
        }
        // All the drain conditions depend on being blocked, which
        // we will only really know for sure when we try to poll().
        checkDrainCondition();
        if (m_mustDrain || m_replayEntries.isEmpty()) {
            return null;
        }

        VoltMessage m = m_replayEntries.firstEntry().getValue().poll();
        updateLastPolledUniqueId(m_replayEntries.firstEntry().getKey(), (TransactionInfoBaseMessage) m);
        return m;
    }
476473
public com.google.appengine.v1.Version getVersion() {
    return version_ == null ? com.google.appengine.v1.Version.getDefaultInstance() : version_;
  }
137014
def get_shard_id2num_examples(num_shards, total_num_examples):
  """"""
  # TODO(b/130353071): This has the strong assumption that the shards have
  # been written in a round-robin fashion. This assumption does not hold, for
  # instance, with Beam generation. The mapping shard_id=>num_examples
  # should be computed during generation.

  # Minimum number of example per shards
  num_example_in_shard = total_num_examples // num_shards
  shard_id2num_examples = [num_example_in_shard for _ in range(num_shards)]
  # If there are remaining examples, we add them to the first shards
  for shard_id in range(total_num_examples % num_shards):
    shard_id2num_examples[shard_id] += 1
  return shard_id2num_examples
505339
def shards(self, add_shard=False):
        
        url = self._service_url + 'shards/'
        if add_shard:
            response = requests.post(url, **self._instances._default_request_kwargs)
        else:
            response = requests.get(url, **self._instances._default_request_kwargs)

        return response.json()
714439
public com.google.appengine.v1.UrlDispatchRuleOrBuilder getDispatchRulesOrBuilder(
      int index) {
    return dispatchRules_.get(index);
  }
169550
@Override
    public java.util.concurrent.Future<DescribeInternetGatewaysResult> describeInternetGatewaysAsync(
            com.amazonaws.handlers.AsyncHandler<DescribeInternetGatewaysRequest, DescribeInternetGatewaysResult> asyncHandler) {

        return describeInternetGatewaysAsync(new DescribeInternetGatewaysRequest(), asyncHandler);
    }
151718
public static boolean checkIfClassVersionApplicable(Object cacheEntry, boolean useStructuredCache) {
        if (!useStructuredCache && cacheEntry instanceof CacheEntry) {
            return true;
        }

        if (useStructuredCache && cacheEntry instanceof Map) {
            return true;
        }
        return false;
    }
1127605
private boolean hasMessages(String shardName) throws MessageQueueException {
        UUID currentTime = TimeUUIDUtils.getUniqueTimeUUIDinMicros();

        try {
            ColumnList<MessageQueueEntry> result = keyspace.prepareQuery(queueColumnFamily)
                    .setConsistencyLevel(consistencyLevel)
                    .getKey(shardName)
                    .withColumnRange(new RangeBuilder()
                        .setLimit(1)   // Read extra messages because of the lock column
                    .setStart(entrySerializer
                                .makeEndpoint((byte)MessageQueueEntryType.Message.ordinal(), Equality.EQUAL)
                                .toBytes()
                                )
                    .setEnd(entrySerializer
                                .makeEndpoint((byte)MessageQueueEntryType.Message.ordinal(), Equality.EQUAL)
                                .append((byte)0, Equality.EQUAL)
                                .append(currentTime, Equality.LESS_THAN_EQUALS)
                                .toBytes()
                                )
                    .build())
                    .execute()
                    .getResult();
            return !result.isEmpty();
        } catch (ConnectionException e) {
            throw new MessageQueueException("Error checking shard for messages. " + shardName, e);
        }
    }
105979
public int serviceVersion()
    {
        if (tc.isEntryEnabled())
            Tr.entry(tc, "serviceVersion", this);
        if (tc.isEntryEnabled())
            Tr.exit(tc, "serviceVersion", new Integer(_serviceVersion));
        return _serviceVersion;
    }