Example #1
0
  /**
   * For each segment-set in the instanceToSegmentMap, we select one (or more speculative) servers
   *
   * @param requestContext
   */
  private void selectServicesPerPartitionGroup(ScatterGatherRequestContext requestContext) {
    Map<ServerInstance, SegmentIdSet> selectedServers = new HashMap<ServerInstance, SegmentIdSet>();
    ScatterGatherRequest request = requestContext.getRequest();
    Map<List<ServerInstance>, SegmentIdSet> instanceToSegmentMap = requestContext.getInvertedMap();
    // int numDuplicateRequests = request.getNumSpeculativeRequests();
    ReplicaSelection selection = request.getReplicaSelection();
    for (Entry<List<ServerInstance>, SegmentIdSet> e : instanceToSegmentMap.entrySet()) {
      ServerInstance s =
          selection.selectServer(e.getValue().getOneSegment(), e.getKey(), request.getHashKey());
      mergePartitionGroup(selectedServers, s, e.getValue());

      /**
       * TODO: We can easily add speculative execution here. The below code will pick a distinct
       * server for the segmentId, This entry needs to be maintained in a separate container in
       * ScatterGatherRequestContext Then in sndRequest, we need to construct SelectingFuture for
       * the pairs of Future corresponding to original and speculative(duplicate) request.
       *
       * <p>int numServers = e.getKey().size();
       *
       * <p>// Pick Unique servers for speculative request int numIterations = Math.min(numServers -
       * 1, numDuplicateRequests); for (int i = 0, c = 0; i < numIterations; i++, c++) {
       * ServerInstance s1 = e.getKey().get(c); if ( s.equals(s1)) { c++; s1 = e.getKey().get(c); }
       * mergePartitionGroup(selectedServers, s1, e.getValue()); //TODO: speculative servers need to
       * be maintained in a separate entry in ScatterGatherRequestContext }
       */
    }
    requestContext.setSelectedServers(selectedServers);
  }
Example #2
0
  /**
   * For each segmentId in the instanceToSegmentMap, we select one (or more speculative) servers
   *
   * @param requestContext
   */
  private void selectServicesPerPartition(ScatterGatherRequestContext requestContext) {
    Map<ServerInstance, SegmentIdSet> selectedServers = new HashMap<ServerInstance, SegmentIdSet>();
    ScatterGatherRequest request = requestContext.getRequest();
    Map<List<ServerInstance>, SegmentIdSet> instanceToSegmentMap = requestContext.getInvertedMap();
    ReplicaSelection selection = request.getReplicaSelection();
    for (Entry<List<ServerInstance>, SegmentIdSet> e : instanceToSegmentMap.entrySet()) {
      SegmentId firstPartition = null;
      for (SegmentId p : e.getValue().getSegments()) {
        /**
         * For selecting the server, we always use first segmentId in the group. This will provide
         * more chance for fanning out the query
         */
        if (null == firstPartition) {
          firstPartition = p;
        }
        ServerInstance s = selection.selectServer(firstPartition, e.getKey(), request.getHashKey());

        mergePartitionGroup(selectedServers, s, p);
      }
    }

    requestContext.setSelectedServers(selectedServers);
  }