Пример #1
0
  /**
   * recalculate interval if total number of partitions greater than maximum number of allowed
   * partitions
   *
   * @param low watermark value
   * @param high watermark value
   * @param partition interval
   * @param Maximum number of allowed partitions
   * @return calculated interval
   */
  private long getInterval(
      long lowWatermarkValue, long highWatermarkValue, long partitionInterval, int maxIntervals) {
    if (lowWatermarkValue > highWatermarkValue) {
      LOG.info(
          "lowWatermarkValue: "
              + lowWatermarkValue
              + " is greater than highWatermarkValue: "
              + highWatermarkValue);

      return 0;
    }
    long outputInterval = partitionInterval;
    boolean longOverflow = false;
    long totalIntervals = Long.MAX_VALUE;
    try {
      totalIntervals =
          DoubleMath.roundToLong(
              (double) highWatermarkValue / partitionInterval
                  - (double) lowWatermarkValue / partitionInterval,
              RoundingMode.CEILING);
    } catch (java.lang.ArithmeticException e) {
      longOverflow = true;
    }
    if (longOverflow || totalIntervals > maxIntervals) {
      outputInterval =
          DoubleMath.roundToLong(
              (double) highWatermarkValue / maxIntervals
                  - (double) lowWatermarkValue / maxIntervals,
              RoundingMode.CEILING);
    }
    return outputInterval;
  }
Пример #2
0
 @ScalarOperator(SATURATED_FLOOR_CAST)
 @SqlType(StandardTypes.BIGINT)
 public static long saturatedFloorCastToBigint(@SqlType(StandardTypes.DOUBLE) double value) {
   if (value <= MIN_LONG_AS_DOUBLE) {
     return Long.MIN_VALUE;
   }
   if (MAX_LONG_AS_DOUBLE_PLUS_ONE - value <= 1) {
     return Long.MAX_VALUE;
   }
   return DoubleMath.roundToLong(value, FLOOR);
 }
Пример #3
0
  synchronized void startPublishingTimer() {
    if (state.get() == State.Closed) return;

    lifetimeCounter--;

    if (lifetimeCounter < 1) {
      logger.debug("[id={}] lifetime expired.", subscriptionId);

      setState(State.Closing);
    } else {
      long interval = DoubleMath.roundToLong(publishingInterval, RoundingMode.UP);

      subscriptionManager
          .getServer()
          .getScheduledExecutorService()
          .schedule(this::onPublishingTimer, interval, TimeUnit.MILLISECONDS);
    }
  }