Ejemplo n.º 1
0
 boolean hasCheckpointThresholdBeenExceeded() {
   // account for cases where control events are sent ; without windows being removed
   long maxWindowSizeInBytes =
       (long)
           (_dataEventsBuffer.getAllocatedSize()
               * (_connConfig.getCheckpointThresholdPct())
               / 100.00);
   boolean exceeded = getCurrentWindowSizeInBytes() > maxWindowSizeInBytes;
   if (_log.isDebugEnabled()) {
     _log.debug(
         "Threshold check : CurrentWindowSize="
             + getCurrentWindowSizeInBytes()
             + " MaxWindowSize="
             + maxWindowSizeInBytes
             + " bufferFreeSpace="
             + _dataEventsBuffer.getBufferFreeSpace());
   }
   if (exceeded) {
     _log.info(
         "The checkpoint threshold has exceeded. The CurrentWindowSize="
             + getCurrentWindowSizeInBytes()
             + " MaxWindowSize="
             + maxWindowSizeInBytes
             + " bufferFreeSpace="
             + _dataEventsBuffer.getBufferFreeSpace());
   }
   return exceeded;
 }
Ejemplo n.º 2
0
  public void resetIterators() {
    if (null != _lastSuccessfulIterator) {
      setLastSuccessfulIterator(null);
      _lastSuccessfulScn = null;
      _lastSuccessfulCheckpoint = null;
    }

    if (null != _eventsIterator) {
      DbusEventBuffer eventBuffer = _eventsIterator.getEventBuffer();
      String iteratorName = _eventsIterator.getIdentifier();
      _eventsIterator.close();
      _eventsIterator = eventBuffer.acquireIterator(iteratorName);
      if (LOG.isDebugEnabled()) {
        String msg = "Reset event iterator to: " + _eventsIterator;
        DbusLogAccumulator.addLog(msg, LOG);
      }
      resetSourceInfo();
    }
  }
Ejemplo n.º 3
0
 private void createEventsIterator(String iteratorName) {
   if (null == _eventsIterator) {
     _stateId = StateId.START_DISPATCH_EVENTS;
     _lastSuccessfulCheckpoint = null;
     _lastSuccessfulScn = null;
     resetSourceInfo();
     _eventsIterator = _buffer.acquireIterator(iteratorName);
     LOG.info("start dispatch from: " + _eventsIterator);
     setLastSuccessfulIterator(_eventsIterator);
   }
 }
  @Override
  public synchronized boolean start() throws IllegalStateException, DatabusClientException {
    _log.info("Starting registration (" + toString() + ") !!");

    if (_state.isRunning()) {
      _log.info("Registration (" + _id + ") already started !!");
      return false;
    }

    if (_state != RegistrationState.REGISTERED)
      throw new IllegalStateException(
          "Registration (" + _id + ") not in startable state !! Current State is :" + _state);

    if ((null == _sources) || (_sources.isEmpty()))
      throw new DatabusClientException(
          "Registration (" + _id + ") does not have any sources to start !!");

    if ((null == _consumers) || (_consumers.isEmpty()))
      throw new DatabusClientException(
          "Registration (" + _id + ") does not have any consumers to start !!");

    List<ServerInfo> relays = _client.getRelays();
    List<ServerInfo> bootstrapServers = _client.getBootstrapServices();

    List<DatabusCombinedConsumer> streamConsumers = new ArrayList<DatabusCombinedConsumer>();
    List<DatabusCombinedConsumer> bootstrapConsumers = new ArrayList<DatabusCombinedConsumer>();

    if ((null == relays) || (relays.isEmpty()))
      throw new DatabusClientException("No configured relays in the client to start");

    Set<ServerInfo> candidateRelays = new HashSet<ServerInfo>();

    for (ServerInfo s : relays) {
      if (canServe(s, _sources)) candidateRelays.add(s);
    }

    if (candidateRelays.isEmpty())
      throw new DatabusClientException("No candidate relays for source : " + _sources);

    streamConsumers.addAll(_consumers);

    boolean canConsumerBootstrap = false;
    _streamConsumerRawRegistrations = new ArrayList<DatabusV2ConsumerRegistration>();
    _streamConsumerRawRegistrations.add(
        new DatabusV2ConsumerRegistration(streamConsumers, _sources, _filterConfig));

    for (DatabusCombinedConsumer c : _consumers) {
      if (c.canBootstrap()) {
        canConsumerBootstrap = true;
        bootstrapConsumers.add(c);
      }
    }

    boolean enableBootstrap =
        _client.getClientStaticConfig().getRuntime().getBootstrap().isEnabled();
    Set<ServerInfo> candidateBootstrapServers = new HashSet<ServerInfo>();

    if (enableBootstrap && canConsumerBootstrap) {
      if ((null == bootstrapServers) || (bootstrapServers.isEmpty()))
        throw new DatabusClientException("No configured bootstrap servers in the client to start");

      for (ServerInfo s : bootstrapServers) {
        if (canServe(s, _sources)) candidateBootstrapServers.add(s);
      }

      if (candidateBootstrapServers.isEmpty())
        throw new DatabusClientException("No candidate bootstrap servers for source : " + _sources);

      _bootstrapConsumerRawRegistrations = new ArrayList<DatabusV2ConsumerRegistration>();
      ;
      _bootstrapConsumerRawRegistrations.add(
          new DatabusV2ConsumerRegistration(bootstrapConsumers, _sources, _filterConfig));
    }

    // All validations done. Setup and start
    initializeStatsCollectors();

    DatabusSourcesConnection.StaticConfig connConfig =
        _client.getClientStaticConfig().getConnection(_sources);

    if (null == connConfig) connConfig = _client.getClientStaticConfig().getConnectionDefaults();

    DbusEventBuffer eventBuffer = null;
    {
      DbusEventBuffer.StaticConfig cfg = connConfig.getEventBuffer();
      eventBuffer =
          new DbusEventBuffer(
              cfg.getMaxSize(),
              cfg.getMaxIndividualBufferSize(),
              cfg.getScnIndexSize(),
              cfg.getReadBufferSize(),
              cfg.getMaxEventSize(),
              cfg.getAllocationPolicy(),
              new File(cfg.getMmapDirectory().getAbsolutePath() + "_stream_" + _id),
              cfg.getQueuePolicy(),
              cfg.getTrace(),
              null,
              cfg.getAssertLevel(),
              cfg.getBufferRemoveWaitPeriod(),
              cfg.getRestoreMMappedBuffers(),
              cfg.getRestoreMMappedBuffersValidateEvents(),
              cfg.isEnableScnIndex(),
              _client.getEventFactory());
      eventBuffer.setDropOldEvents(true);
      eventBuffer.start(0);
    }

    DbusEventBuffer bootstrapBuffer = null;
    if (enableBootstrap && canConsumerBootstrap) {
      DbusEventBuffer.StaticConfig bstCfg = connConfig.getBstEventBuffer();
      bootstrapBuffer =
          new DbusEventBuffer(
              bstCfg.getMaxSize(),
              bstCfg.getMaxIndividualBufferSize(),
              bstCfg.getScnIndexSize(),
              bstCfg.getReadBufferSize(),
              bstCfg.getMaxEventSize(),
              bstCfg.getAllocationPolicy(),
              new File(bstCfg.getMmapDirectory().getAbsolutePath() + "_bootstrap_" + _id),
              bstCfg.getQueuePolicy(),
              bstCfg.getTrace(),
              null,
              bstCfg.getAssertLevel(),
              bstCfg.getBufferRemoveWaitPeriod(),
              bstCfg.getRestoreMMappedBuffers(),
              bstCfg.getRestoreMMappedBuffersValidateEvents(),
              bstCfg.isEnableScnIndex(),
              _client.getEventFactory());
      bootstrapBuffer.setDropOldEvents(false);
      bootstrapBuffer.start(0);
    }

    List<DatabusSubscription> subs = createSubscriptions(_sources);

    if (null != _checkpointPersistenceProvider
        && _client.getClientStaticConfig().getCheckpointPersistence().isClearBeforeUse()) {
      _log.info("Clearing checkpoint for sources :" + _sources + " with regId :" + _id);
      _checkpointPersistenceProvider.removeCheckpoint(_sources);
    }

    _sourcesConnection =
        createConnection(
            connConfig,
            subs,
            candidateRelays,
            candidateBootstrapServers,
            eventBuffer,
            bootstrapBuffer);
    _sourcesConnection.start();
    _state = RegistrationState.STARTED;
    _status.start();

    _state = RegistrationState.STARTED;
    return true;
  }