예제 #1
0
  /**
   * Called from the {@link Receiver} thread to processing any pending loss of packets.
   *
   * @return number of work items processed.
   */
  int processPendingLoss() {
    int workCount = 0;
    final long changeNumber = endLossChange;

    if (changeNumber != lastLossChangeNumber) {
      final int termId = lossTermId;
      final int termOffset = lossTermOffset;
      final int length = lossLength;

      UNSAFE
          .loadFence(); // LoadLoad required so previous loads don't move past version check below.

      if (changeNumber == beginLossChange) {
        if (isReliable) {
          channelEndpoint.sendNakMessage(
              controlAddress, sessionId, streamId, termId, termOffset, length);
          nakMessagesSent.orderedIncrement();
        } else {
          final UnsafeBuffer termBuffer = termBuffers[indexByTerm(initialTermId, termId)];
          if (tryFillGap(rawLog.logMetaData(), termBuffer, termId, termOffset, length)) {
            lossGapFills.orderedIncrement();
          }
        }

        lastLossChangeNumber = changeNumber;
        workCount = 1;
      }
    }

    return workCount;
  }
예제 #2
0
  /** {@inheritDoc} */
  public void close() {
    hwmPosition.close();
    rebuildPosition.close();
    for (final ReadablePosition position : subscriberPositions) {
      position.close();
    }

    congestionControl.close();
    rawLog.close();
  }
예제 #3
0
  public PublicationImage(
      final long correlationId,
      final long imageLivenessTimeoutNs,
      final ReceiveChannelEndpoint channelEndpoint,
      final InetSocketAddress controlAddress,
      final int sessionId,
      final int streamId,
      final int initialTermId,
      final int activeTermId,
      final int initialTermOffset,
      final RawLog rawLog,
      final FeedbackDelayGenerator lossFeedbackDelayGenerator,
      final List<ReadablePosition> subscriberPositions,
      final Position hwmPosition,
      final Position rebuildPosition,
      final NanoClock nanoClock,
      final EpochClock epochClock,
      final SystemCounters systemCounters,
      final InetSocketAddress sourceAddress,
      final CongestionControl congestionControl,
      final LossReport lossReport,
      final boolean isReliable) {
    this.correlationId = correlationId;
    this.imageLivenessTimeoutNs = imageLivenessTimeoutNs;
    this.channelEndpoint = channelEndpoint;
    this.controlAddress = controlAddress;
    this.sessionId = sessionId;
    this.streamId = streamId;
    this.rawLog = rawLog;
    this.subscriberPositions = subscriberPositions.toArray(new ReadablePosition[0]);
    this.hwmPosition = hwmPosition;
    this.rebuildPosition = rebuildPosition;
    this.sourceAddress = sourceAddress;
    this.initialTermId = initialTermId;
    this.congestionControl = congestionControl;
    this.lossReport = lossReport;
    this.isReliable = isReliable;

    heartbeatsReceived = systemCounters.get(HEARTBEATS_RECEIVED);
    statusMessagesSent = systemCounters.get(STATUS_MESSAGES_SENT);
    nakMessagesSent = systemCounters.get(NAK_MESSAGES_SENT);
    flowControlUnderRuns = systemCounters.get(FLOW_CONTROL_UNDER_RUNS);
    flowControlOverRuns = systemCounters.get(FLOW_CONTROL_OVER_RUNS);
    lossGapFills = systemCounters.get(LOSS_GAP_FILLS);

    this.nanoClock = nanoClock;
    this.epochClock = epochClock;
    final long time = nanoClock.nanoTime();
    timeOfLastStatusChange = time;
    lastPacketTimestamp = time;

    termBuffers = rawLog.termBuffers();
    lossDetector = new LossDetector(lossFeedbackDelayGenerator, this);

    final int termLength = rawLog.termLength();
    termLengthMask = termLength - 1;
    positionBitsToShift = Integer.numberOfTrailingZeros(termLength);

    final long initialPosition =
        computePosition(activeTermId, initialTermOffset, positionBitsToShift, initialTermId);
    nextSmPosition = initialPosition;
    nextSmReceiverWindowLength = congestionControl.initialWindowLength();
    cleanPosition = initialPosition;

    hwmPosition.setOrdered(initialPosition);
    rebuildPosition.setOrdered(initialPosition);
  }