Package com.linkedin.databus.bootstrap.common

Examples of com.linkedin.databus.bootstrap.common.BootstrapHttpStatsCollector


         throws IOException, InvalidConfigException, DatabusException
  {
    super(bootstrapServerConfig.getDb().getContainer(), byteOrder);
    _bootstrapServerConfig = bootstrapServerConfig;

    BootstrapHttpStatsCollector httpStatsColl = null;
    if (null == httpStatsColl)
    {

      httpStatsColl = new BootstrapHttpStatsCollector(getContainerStaticConfig().getId(),
                                                  "bootstrapHttpOutbound",
                                                  true,
                                                  //_bootstrapStaticConfig.getRuntime().getHttpStatsCollector().isEnabled(),
                                                  true,
                                                  getMbeanServer());
View Full Code Here


  @Override
  protected DatabusRequest doProcess(DatabusRequest request) throws IOException,
  RequestProcessingException
  {
    BootstrapProcessor processor = null;
    BootstrapHttpStatsCollector bootstrapStatsCollector = _bootstrapServer.getBootstrapStatsCollector();
    long startTime = System.currentTimeMillis();
    boolean isDebug = LOG.isDebugEnabled();

    try
    {
      try
      {
        String threadName = Thread.currentThread().getName();
        DbusEventsStatisticsCollector threadCollector = _bootstrapServer.getOutBoundStatsCollectors().getStatsCollector(threadName);
        if (null == threadCollector)
        {
            threadCollector = new DbusEventsStatisticsCollector(_bootstrapServer.getContainerStaticConfig().getId(),
                    threadName,
                    true,
                    false,
                    _bootstrapServer.getMbeanServer());
          StatsCollectors<DbusEventsStatisticsCollector> ds = _bootstrapServer.getOutBoundStatsCollectors();
            ds.addStatsCollector(threadName, threadCollector);
        }
        processor = new BootstrapProcessor(_config, threadCollector);
    }
      catch (Exception e)
      {
        if (null != bootstrapStatsCollector)
        {
          bootstrapStatsCollector.registerErrBootstrap();
        }

        throw new RequestProcessingException(e);
      }

      DatabusComponentStatus componentStatus = _componentStatus.getStatusSnapshot();
      if (!componentStatus.isRunningStatus())
      {
        if (null != bootstrapStatsCollector)
          bootstrapStatsCollector.registerErrBootstrap();

       throw new RequestProcessingException(componentStatus.getMessage());
      }

      String partitionInfoString = request.getParams().getProperty(PARTITION_INFO_PARAM);

      DbusKeyFilter keyFilter = null;
      if ( (null != partitionInfoString) && (!partitionInfoString.isEmpty()))
      {
        try
        {
          keyFilter = KeyFilterConfigJSONFactory.parseDbusKeyFilter(partitionInfoString);
          if ( isDebug) LOG.debug("ServerSideFilter is :" + keyFilter);
        } catch ( Exception ex) {
          String msg = "Unable to parse partitionInfo from request. PartitionInfo was :" + partitionInfoString;
          LOG.error(msg,ex);
          throw new RequestProcessingException(msg,ex);
        }
      }

      String outputFormat = request.getParams().getProperty(OUTPUT_PARAM);
      Encoding enc = Encoding.BINARY;

      if ( null != outputFormat)
      {
        try
        {
          enc = Encoding.valueOf(outputFormat.toUpperCase());
        } catch (Exception ex) {
          LOG.error("Unable to find the output format for bootstrap request for " + outputFormat + ". Using Binary!!", ex);
        }
      }

      processor.setKeyFilter(keyFilter);
      String checkpointString = request.getRequiredStringParam(CHECKPOINT_PARAM);

      int bufferMarginSpace = DEFAULT_BUFFER_MARGIN_SPACE;
      if ( null != _serverHostPort)
      {
        bufferMarginSpace = Math.max(bufferMarginSpace, (_serverHostPort.length() + Checkpoint.BOOTSTRAP_SERVER_INFO.length() + DEFAULT_JSON_OVERHEAD_BYTES));
      }

      int clientFreeBufferSize = request.getRequiredIntParam(BATCHSIZE_PARAM) - checkpointString.length() - bufferMarginSpace;

        BootstrapEventWriter writer = null;
        if(_config.getPredicatePushDown())
          writer = createEventWriter(request, clientFreeBufferSize, null, enc);
        else
          writer = createEventWriter(request, clientFreeBufferSize, keyFilter, enc);

        Checkpoint cp = new Checkpoint(checkpointString);


      DbusClientMode consumptionMode = cp.getConsumptionMode();

      LOG.info("Bootstrap request received: " +
          "fetchSize=" + clientFreeBufferSize +
          ", consumptionMode=" + consumptionMode +
          ", checkpoint=" + checkpointString +
          ", predicatePushDown=" + _config.getPredicatePushDown()
          );

      try
      {
        boolean phaseCompleted = false;
        switch (consumptionMode)
        {
        case BOOTSTRAP_SNAPSHOT:
          phaseCompleted = processor.streamSnapShotRows(new Checkpoint(
              checkpointString), writer);
          break;
        case BOOTSTRAP_CATCHUP:
          phaseCompleted = processor.streamCatchupRows(new Checkpoint(
              checkpointString), writer);
          break;
        default:
          if (null != bootstrapStatsCollector)
            bootstrapStatsCollector.registerErrBootstrap();

          throw new RequestProcessingException("Unexpected mode: "
              + consumptionMode);
        }

        if (null != bootstrapStatsCollector)
          bootstrapStatsCollector.registerBootStrapReq(cp, System.currentTimeMillis()-startTime, clientFreeBufferSize);

        if (writer.getNumRowsWritten() == 0 && writer.getSizeOfPendingEvent() > 0)
        {
          // Append a header to indicate to the client that we do have at least one event to
          // send, but it is too large to fit into client's offered buffer.
          request.getResponseContent().addMetadata(DatabusHttpHeaders.DATABUS_PENDING_EVENT_SIZE,
                                                   writer.getSizeOfPendingEvent());
          if (isDebug)
          {
            LOG.debug("Returning 0 events but have pending event of size " + writer.getSizeOfPendingEvent());
          }
        }
        if (phaseCompleted)
        {
          request.getResponseContent().setMetadata(BootstrapProcessor.PHASE_COMPLETED_HEADER_NAME, BootstrapProcessor.PHASE_COMPLETED_HEADER_TRUE);
        }

      }
      catch (BootstrapDatabaseTooOldException e)
      {
        if (null != bootstrapStatsCollector)
          bootstrapStatsCollector.registerErrDatabaseTooOld();

        LOG.error("Bootstrap database is too old!", e);
        throw new RequestProcessingException(e);
      }
      catch (BootstrapDBException e)
      {
        if (null != bootstrapStatsCollector)
          bootstrapStatsCollector.registerErrBootstrap();
        throw new RequestProcessingException(e);
      }
      catch (SQLException e)
      {
        if (null != bootstrapStatsCollector)
          bootstrapStatsCollector.registerErrSqlException();

        throw new RequestProcessingException(e);
      }
      catch (BootstrapProcessingException e)
      {
        if (null != bootstrapStatsCollector)
          bootstrapStatsCollector.registerErrBootstrap();

        throw new RequestProcessingException(e);
      }
    }
    finally
View Full Code Here

  @Override
  protected DatabusRequest doProcess(DatabusRequest request) throws IOException,
      RequestProcessingException
  {
    BootstrapHttpStatsCollector bootstrapStatsCollector = _bootstrapServer.getBootstrapStatsCollector();
    long startTime = System.currentTimeMillis();
    String sources = request.getRequiredStringParam(SOURCES_PARAM);
    List<String> srcList =  getSources(sources);

  Checkpoint ckpt = new Checkpoint(request.getRequiredStringParam(CHECKPOINT_PARAM));

    LOG.info("StartSCN requested for sources : (" + sources + "). CheckPoint is :" + ckpt);
    long sinceScn = ckpt.getBootstrapSinceScn();
    ObjectMapper mapper = new ObjectMapper();
    StringWriter out = new StringWriter(1024);
    long startSCN = -1;
    BootstrapSCNProcessor processor = null;

    try
    {
      processor = new BootstrapSCNProcessor(_config, _bootstrapServer.getInboundEventStatisticsCollector());
      List<SourceStatusInfo> srcStatusPairs = null;
      try
      {
        srcStatusPairs = processor.getSourceIdAndStatusFromName(srcList);
        startSCN = processor.getMinApplierWindowScn(sinceScn, srcStatusPairs);
        if (processor.shouldBypassSnapshot(sinceScn, startSCN, srcStatusPairs))
        {
          LOG.info("Bootstrap Snapshot phase will be bypassed for startScn request :" + request);
          LOG.info("Original startSCN is:" + startSCN + ", Setting startSCN to the sinceSCN:" + sinceScn);
          startSCN = sinceScn;
        }
        else
        {
          if (startSCN == BootstrapDBMetaDataDAO.DEFAULT_WINDOWSCN)
          {
            throw new RequestProcessingException("Bootstrap DB is being initialized! startSCN=" + startSCN);
          }

          if (_config.isEnableMinScnCheck())
          {
            //snapshot isn't bypassed. Check if snapshot is possible from sinceScn by checking minScn
            long minScn = processor.getBootstrapMetaDataDAO().getMinScnOfSnapshots(srcStatusPairs);
            LOG.info("Min scn for tab tables is: " + minScn);
            if (minScn == BootstrapDBMetaDataDAO.DEFAULT_WINDOWSCN)
            {
              throw new BootstrapDatabaseTooYoungException("BootstrapDB has no minScn for these sources, but minScn check is enabled! minScn=" + minScn);
            }

            //Note: The cleaner deletes rows less than or equal to scn: BootstrapDBCleaner::doClean
            //sinceSCN should be greater than minScn, unless sinceScn=minScn=0
            if ((sinceScn <= minScn) && !(sinceScn==0 && minScn==0))
            {
              LOG.error("Bootstrap Snapshot doesn't have requested data . sinceScn too old! sinceScn is " + sinceScn +  " but minScn available is " + minScn);
              throw new BootstrapDatabaseTooYoungException("Min scn=" + minScn + " Since scn=" + sinceScn);
            }
          }
          else
          {
            LOG.debug("Bypassing minScn check! ");
          }
        }
      }
      catch (BootstrapDatabaseTooOldException tooOldException)
      {
        if (bootstrapStatsCollector != null)
        {
          bootstrapStatsCollector.registerErrStartSCN();
          bootstrapStatsCollector.registerErrDatabaseTooOld();
        }

        LOG.error("The bootstrap database is too old!", tooOldException);
        throw new RequestProcessingException(tooOldException);
      }
      catch (BootstrapDatabaseTooYoungException e)
      {
        if (bootstrapStatsCollector != null)
        {
          bootstrapStatsCollector.registerErrStartSCN();
          bootstrapStatsCollector.registerErrBootstrap();
        }
        LOG.error("The bootstrap database is too young!", e);
        throw new RequestProcessingException(e);
      }
      catch (SQLException e)
      {
          if (bootstrapStatsCollector != null)
          {
            bootstrapStatsCollector.registerErrStartSCN();
              bootstrapStatsCollector.registerErrSqlException();
          }
        LOG.error("Error encountered while fetching startSCN from database.", e);
        throw new RequestProcessingException(e);
      }
      mapper.writeValue(out, String.valueOf(startSCN));
      byte[] resultBytes = out.toString().getBytes(Charset.defaultCharset());
      request.getResponseContent().write(ByteBuffer.wrap(resultBytes));
      LOG.info("startSCN: " + startSCN + " with server Info :" + _serverHostPort);

    } catch (RequestProcessingException ex) {
      LOG.error("Got exception while calculating startSCN", ex);
      throw ex;
    } catch (Exception ex) {
      LOG.error("Got exception while calculating startSCN", ex);
      throw new RequestProcessingException(ex);
    } finally {
      if ( null != processor)
        processor.shutdown();
    }

    if (bootstrapStatsCollector != null)
    {
        bootstrapStatsCollector.registerStartSCNReq(System.currentTimeMillis()-startTime);
    }
    return request;
  }
View Full Code Here

  @Override
  protected DatabusRequest doProcess(DatabusRequest request)
      throws IOException, RequestProcessingException
  {
    BootstrapHttpStatsCollector bootstrapStatsCollector = _bootstrapServer.getBootstrapStatsCollector();
    long startTime = System.currentTimeMillis();

    int srcId = -1;
    long targetScn = -1;
    String source = request.getRequiredStringParam(SOURCE_PARAM);
    BootstrapSCNProcessor processor = null;
    try
    {
      processor = new BootstrapSCNProcessor(_config, _bootstrapServer.getInboundEventStatisticsCollector());

      try
      {
        // get src id from db
        BootstrapDBMetaDataDAO.SourceStatusInfo srcIdStatus = processor.getSrcIdStatusFromDB(source, true);

        if ( !srcIdStatus.isValidSource())
            throw new BootstrapProcessingException("Bootstrap DB not servicing source :" + source);

        srcId = srcIdStatus.getSrcId();

        // select target scn
        targetScn = processor.getSourceTargetScn(srcId);
      }
      catch (BootstrapDatabaseTooOldException tooOldException)
      {
          if (bootstrapStatsCollector != null)
          {
            bootstrapStatsCollector.registerErrTargetSCN();
            bootstrapStatsCollector.registerErrDatabaseTooOld();
          }

        LOG.error("The bootstrap database is too old!", tooOldException);
        throw new RequestProcessingException(tooOldException);
      }
      catch (SQLException e)
      {
        if (bootstrapStatsCollector != null)
          {
            bootstrapStatsCollector.registerErrTargetSCN();
            bootstrapStatsCollector.registerErrSqlException();
          }

        LOG.error("Error encountered while fetching targetSCN from database.", e);
        throw new RequestProcessingException(e);
      }

      ObjectMapper mapper = new ObjectMapper();
      StringWriter out = new StringWriter(1024);
      mapper.writeValue(out, String.valueOf(targetScn));
      byte[] resultBytes = out.toString().getBytes(Charset.defaultCharset());
      request.getResponseContent().write(ByteBuffer.wrap(resultBytes));
      LOG.info("targetSCN: " + targetScn);
    } catch (Exception ex) {
      LOG.error("Got exception while calculating targetSCN", ex);
      throw new RequestProcessingException(ex);
    } finally {
      if ( null != processor)
        processor.shutdown();
    }

    if (bootstrapStatsCollector != null)
    {
      bootstrapStatsCollector.registerTargetSCNReq(System.currentTimeMillis()-startTime);
    }

    return request;
  }
View Full Code Here

TOP

Related Classes of com.linkedin.databus.bootstrap.common.BootstrapHttpStatsCollector

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.