コード例 #1
0
 private void waitForOutstandingRequests(
     TimeValue timeOut, Semaphore requestsOutstanding, int maxRequests, String name) {
   long start = System.currentTimeMillis();
   do {
     long msRemaining = timeOut.getMillis() - (System.currentTimeMillis() - start);
     logger.info(
         "[{}] going to try and aquire [{}] in [{}]ms [{}] available to aquire right now",
         name,
         maxRequests,
         msRemaining,
         requestsOutstanding.availablePermits());
     try {
       requestsOutstanding.tryAcquire(maxRequests, msRemaining, TimeUnit.MILLISECONDS);
       return;
     } catch (InterruptedException ie) {
       // Just keep swimming
     }
   } while ((System.currentTimeMillis() - start) < timeOut.getMillis());
   throw new ElasticsearchTimeoutException(
       "Requests were still outstanding after the timeout ["
           + timeOut
           + "] for type ["
           + name
           + "]");
 }
コード例 #2
0
 private void warnAboutSlowTaskIfNeeded(TimeValue executionTime, String source) {
   if (executionTime.getMillis() > slowTaskLoggingThreshold.getMillis()) {
     logger.warn(
         "cluster state update task [{}] took [{}] above the warn threshold of {}",
         source,
         executionTime,
         slowTaskLoggingThreshold);
   }
 }
コード例 #3
0
  private AbstractDistanceScoreFunction parseDateVariable(
      XContentParser parser,
      QueryShardContext context,
      DateFieldMapper.DateFieldType dateFieldType,
      MultiValueMode mode)
      throws IOException {
    XContentParser.Token token;
    String parameterName = null;
    String scaleString = null;
    String originString = null;
    String offsetString = "0d";
    double decay = 0.5;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
      if (token == XContentParser.Token.FIELD_NAME) {
        parameterName = parser.currentName();
      } else if (DecayFunctionBuilder.SCALE.equals(parameterName)) {
        scaleString = parser.text();
      } else if (DecayFunctionBuilder.ORIGIN.equals(parameterName)) {
        originString = parser.text();
      } else if (DecayFunctionBuilder.DECAY.equals(parameterName)) {
        decay = parser.doubleValue();
      } else if (DecayFunctionBuilder.OFFSET.equals(parameterName)) {
        offsetString = parser.text();
      } else {
        throw new ElasticsearchParseException("parameter [{}] not supported!", parameterName);
      }
    }
    long origin;
    if (originString == null) {
      origin = context.nowInMillis();
    } else {
      origin = dateFieldType.parseToMilliseconds(originString, false, null, null);
    }

    if (scaleString == null) {
      throw new ElasticsearchParseException(
          "[{}] must be set for date fields.", DecayFunctionBuilder.SCALE);
    }
    TimeValue val =
        TimeValue.parseTimeValue(
            scaleString,
            TimeValue.timeValueHours(24),
            DecayFunctionParser.class.getSimpleName() + ".scale");
    double scale = val.getMillis();
    val =
        TimeValue.parseTimeValue(
            offsetString,
            TimeValue.timeValueHours(24),
            DecayFunctionParser.class.getSimpleName() + ".offset");
    double offset = val.getMillis();
    IndexNumericFieldData numericFieldData = context.getForField(dateFieldType);
    return new NumericFieldDataScoreFunction(
        origin, scale, decay, offset, getDecayFunction(), numericFieldData, mode);
  }