Package com.linkedin.databus.monitoring.mbean

Examples of com.linkedin.databus.monitoring.mbean.EventSourceStatistics


    PartitionFunction partitionFunction = buildPartitionFunction(sourceConfig);
    EventFactory factory = createEventFactory(eventViewSchema, eventView, sourceConfig, pConfig,
                                              schema, partitionFunction);

    EventSourceStatistics statisticsBean = new EventSourceStatistics(sourceConfig.getName());


    OracleTriggerMonitoredSourceInfo sourceInfo = new OracleTriggerMonitoredSourceInfo(sourceConfig.getId(),
                                                             sourceConfig.getName(),
                                                             eventViewSchema,
View Full Code Here


  {
    // udpate partition mapping
    PartitionFunction partitionFunction = GGEventGenerationFactory.buildPartitionFunction(sourceConfig);
    _partitionFunctionHashMap.put((int)sourceConfig.getId(), partitionFunction);

    EventSourceStatistics statisticsBean = new EventSourceStatistics(sourceConfig.getName());

    GGMonitoredSourceInfo sourceInfo =
        new GGMonitoredSourceInfo(sourceConfig.getId(), sourceConfig.getName(), statisticsBean);

    registerMbeans(sourceInfo);
View Full Code Here

    if(dbUpdates.size() == 0)
      throw new DatabusException("Cannot handle empty dbUpdates");

    long scn = ti.getScn();
    long timestamp = ti.getTransactionTimeStampNs();
    EventSourceStatistics globalStats = getSource(GLOBAL_SOURCE_ID).getStatisticsBean();

    /**
     * We skip the start scn of the relay, we have already added a EOP for this SCN in the buffer.
     * Why is this not a problem ?
     * There are two cases:
     * 1. When we use the earliest/latest scn if there is no maxScn (We don't really have a start point). So it's really OK to miss the first event.
     * 2. If it's the maxSCN, then event was already seen by the relay.
     */
    if(scn == _startPrevScn.get())
    {
      _log.info("Skipping this transaction, EOP already send for this event");
      return;
    }

    getEventBuffer().startEvents();

    int eventsInTransactionCount = 0;

    List<EventReaderSummary> summaries = new ArrayList<EventReaderSummary>();

    for (int i = 0; i < dbUpdates.size(); ++i)
    {
      GenericRecord record = null;
      TransactionState.PerSourceTransactionalUpdate perSourceUpdate = dbUpdates.get(i);
      short sourceId = (short)perSourceUpdate.getSourceId();
      // prepare stats collection per source
      EventSourceStatistics perSourceStats = getSource(sourceId).getStatisticsBean();

      Iterator<DbUpdateState.DBUpdateImage> dbUpdateIterator = perSourceUpdate.getDbUpdatesSet().iterator();
      int eventsInDbUpdate = 0;
      long dbUpdatesEventsSize = 0;
      long startDbUpdatesMs = System.currentTimeMillis();

      while(dbUpdateIterator.hasNext())  //TODO verify if there is any case where we need to rollback.
      {
        DbUpdateState.DBUpdateImage dbUpdate =  dbUpdateIterator.next();

        //Construct the Databus Event key, determine the key type and construct the key
        Object keyObj = obtainKey(dbUpdate);
        DbusEventKey eventKey = new DbusEventKey(keyObj);

        //Get the logicalparition id
        PartitionFunction partitionFunction = _partitionFunctionHashMap.get((int)sourceId);
        short lPartitionId = partitionFunction.getPartition(eventKey);

        record = dbUpdate.getGenericRecord();
        //Write the event to the buffer
        if (record == null)
          throw new DatabusException("Cannot write event to buffer because record = " + record);

        if(record.getSchema() == null)
          throw new DatabusException("The record does not have a schema (null schema)");

        try
        {
          //Collect stats on number of dbUpdates for one source
          eventsInDbUpdate++;

          //Count of all the events in the current transaction
          eventsInTransactionCount++;
          // Serialize the row
          ByteArrayOutputStream bos = new ByteArrayOutputStream();
          Encoder encoder = new BinaryEncoder(bos);
          GenericDatumWriter<GenericRecord> writer = new GenericDatumWriter<GenericRecord>(
              record.getSchema());
          writer.write(record, encoder);
          byte[] serializedValue = bos.toByteArray();

          //Get the md5 for the schema
          SchemaId schemaId = SchemaId.createWithMd5(dbUpdate.getSchema());

          //Determine the operation type and convert to dbus opcode
          DbusOpcode opCode;
          if(dbUpdate.getOpType() == DbUpdateState.DBUpdateImage.OpType.INSERT || dbUpdate.getOpType() == DbUpdateState.DBUpdateImage.OpType.UPDATE)
          {
            opCode = DbusOpcode.UPSERT;
            if(_log.isDebugEnabled())
              _log.debug("The event with scn "+ scn +" is INSERT/UPDATE");
          }
          else if(dbUpdate.getOpType() == DbUpdateState.DBUpdateImage.OpType.DELETE)
          {
            opCode = DbusOpcode.DELETE;
            if(_log.isDebugEnabled())
              _log.debug("The event with scn "+ scn +" is DELETE");
          }
          else
          {
            throw new DatabusException("Unknown opcode from dbUpdate for event with scn:" + scn);
          }


          //Construct the dbusEvent info
          DbusEventInfo dbusEventInfo = new DbusEventInfo(opCode,
                                                          scn,
                                                          (short)_pConfig.getId(),
                                                          lPartitionId,
                                                          timestamp,
                                                          sourceId,
                                                          schemaId.getByteArray(),
                                                          serializedValue,
                                                          false,
                                                          false);
          dbusEventInfo.setReplicated(dbUpdate.isReplicated());

          perSourceStats.addEventCycle(1, ti.getTransactionTimeRead(), serializedValue.length, scn);
          globalStats.addEventCycle(1, ti.getTransactionTimeRead(), serializedValue.length, scn);

          long tsEnd = System.currentTimeMillis();
          perSourceStats.addTimeOfLastDBAccess(tsEnd);
          globalStats.addTimeOfLastDBAccess(tsEnd);

          //Append to the event buffer
          getEventBuffer().appendEvent(eventKey, dbusEventInfo, _statsCollector);
          _rc.incrementEventCount();
          dbUpdatesEventsSize += serializedValue.length;
        }
        catch (IOException io)
        {
          perSourceStats.addError();
          globalStats.addEmptyEventCycle();
          _log.error("Cannot create byte stream payload: " + dbUpdates.get(i).getSourceId());
        }
      }
      long endDbUpdatesMs = System.currentTimeMillis();
View Full Code Here

  private ORMonitoredSourceInfo buildORMonitoredSourceInfo( LogicalSourceStaticConfig sourceConfig,
                                                           PhysicalSourceStaticConfig pConfig)
         throws DatabusException, InvalidConfigException
  {
    EventSourceStatistics statisticsBean = new EventSourceStatistics(sourceConfig.getName());

    ORMonitoredSourceInfo sourceInfo =
        new ORMonitoredSourceInfo(sourceConfig.getId(), sourceConfig.getName(), statisticsBean);

    registerMbeans(sourceInfo);
View Full Code Here

        _log.info("Skipping this transaction, EOP already send for this event. Txn SCN =" + txn.getScn()
                                    + ", _startPrevScn=" + _startPrevScn.get());
        return;
      }

      EventSourceStatistics globalStats = getSource(GLOBAL_SOURCE_ID).getStatisticsBean();

      _eventBuffer.startEvents();

      long scn = txn.getScn();
      long timestamp = txn.getTxnNanoTimestamp();
      List<EventReaderSummary> summaries = new ArrayList<EventReaderSummary>();

      for (PerSourceTransaction t: txn.getOrderedPerSourceTransactions() )
      {
        long startDbUpdatesMs = System.currentTimeMillis();
        short sourceId = (short)t.getSrcId();
        EventSourceStatistics perSourceStats = getSource(sourceId).getStatisticsBean();
        long dbUpdatesEventsSize = 0;

        for (DbChangeEntry c : t.getDbChangeEntrySet())
        {
          int length = 0;

          try
          {
            length = _eventFactoryMap.get(t.getSrcId()).createAndAppendEvent(
                                                                  c,
                                                                  _eventBuffer,
                                                                  false,
                                                                  _relayInboundStatsCollector);
            if ( length < 0)
            {
              _log.error("Unable to append DBChangeEntry (" + c + ") to event buffer !! EVB State : " + _eventBuffer);
              throw new DatabusException("Unable to append DBChangeEntry (" + c + ") to event buffer !!");
            }
            dbUpdatesEventsSize += length;
          } catch (DatabusException e) {
            _log.error("Got databus exception :", e);
            perSourceStats.addError();
            globalStats.addEmptyEventCycle();
            throw e;
          } catch (UnsupportedKeyException e) {
            perSourceStats.addError();
            globalStats.addEmptyEventCycle();
            _log.error("Got UnsupportedKeyException :", e);
            throw e;
          } catch (EventCreationException e) {
            perSourceStats.addError();
            globalStats.addEmptyEventCycle();
            _log.error("Got EventCreationException :", e);
            throw e;
          }
          perSourceStats.addEventCycle(1, txn.getTxnReadLatencyNanos(), length, scn);
          globalStats.addEventCycle(1, txn.getTxnReadLatencyNanos(), length, scn);
        }

        long endDbUpdatesMs = System.currentTimeMillis();
        long dbUpdatesElapsedTimeMs = endDbUpdatesMs - startDbUpdatesMs;

        // Log Event Summary at logical source level
        EventReaderSummary summary = new EventReaderSummary(sourceId, _monitoredSources.get(sourceId).getSourceName(),
                                                            scn, t.getDbChangeEntrySet().size(), dbUpdatesEventsSize,-1L /* Not supported */,
                                                            dbUpdatesElapsedTimeMs,  timestamp, timestamp, -1L /* Not supported */);
        if (_eventsLog.isInfoEnabled())
        {
          _eventsLog.info(summary.toString());
        }
        summaries.add(summary);

        long tsEnd = System.currentTimeMillis();
        perSourceStats.addTimeOfLastDBAccess(tsEnd);
        globalStats.addTimeOfLastDBAccess(tsEnd);
      }
      _eventBuffer.endEvents(scn, _relayInboundStatsCollector);
      // Log Event Summary at Physical source level
      ReadEventCycleSummary summary = new ReadEventCycleSummary(_physicalSourceStaticConfig.getName(),
View Full Code Here

      eventStatsValuesMap.put(e.getSrcId(), e);
    }

    for (EventSourceStatisticsIface si : gg.getSources())
    {
      EventSourceStatistics ss = si.getStatisticsBean();
      LOG.info(si.getSourceName() + ": scn=" + ss.getMaxScn() + ",averageSize="
          + ss.getAvgEventSerializedSize() + ",numErrors=" + ss.getNumErrors()
          + ",totalEvents=" + ss.getNumTotalEvents() + ",averageFactTime="
          + ss.getAvgEventFactoryTimeMillisPerEvent() + ",timeSinceDb="
          + ss.getTimeSinceLastDBAccess());
      EventStatsValues e = eventStatsValuesMap.get(si.getSourceId());

      Assert.assertEquals(e.getAvgEventSize(), ss.getAvgEventSerializedSize());
      Assert.assertEquals(e.getNumErrors(), ss.getNumErrors());
      Assert.assertEquals(e.getNumTotalEvents(), ss.getNumTotalEvents());
      Assert.assertEquals(e.getAvgEventFactoryTimeMillisPerEvent(),
                          ss.getAvgEventFactoryTimeMillisPerEvent());
      Assert.assertEquals(e.getMaxScn(), ss.getMaxScn());

    }
  }
View Full Code Here

    method.invoke(handleXmlCallbackObject, new Object[] { dbUpdates2,
        new TransactionInfo(0, 0, timestamp + 1, scn + 2) });

    for (EventSourceStatisticsIface si : gg.getSources())
    {
      EventSourceStatistics ss = si.getStatisticsBean();
      LOG.info(si.getSourceName() + ": scn=" + ss.getMaxScn() + ",averageSize="
          + ss.getAvgEventSerializedSize() + ",numErrors=" + ss.getNumErrors()
          + ",totalEvents=" + ss.getNumTotalEvents() + ",averageFactTime="
          + ss.getAvgEventFactoryTimeMillisPerEvent() + ",timeSinceDb="
          + ss.getTimeSinceLastDBAccess());

      if (si.getSourceId() == 505)
      {
        Assert.assertEquals(6, ss.getAvgEventSerializedSize());
        Assert.assertEquals(0, ss.getNumErrors());
        Assert.assertEquals(1, ss.getNumTotalEvents());
        Assert.assertEquals(0, ss.getAvgEventFactoryTimeMillisPerEvent());
        Assert.assertEquals(0, ss.getAvgEventFactoryTimeMillisPerEvent()); // we are not
                                                                           // really
                                                                           // reading
        Assert.assertEquals(10, ss.getMaxScn());
      }
      if (si.getSourceId() == 506)
      {
        Assert.assertEquals(6, ss.getAvgEventSerializedSize());
        Assert.assertEquals(0, ss.getNumErrors());
        Assert.assertEquals(1, ss.getNumTotalEvents());
        Assert.assertEquals(0, ss.getAvgEventFactoryTimeMillisPerEvent());
        Assert.assertEquals(0, ss.getAvgEventFactoryTimeMillisPerEvent()); // we are not
                                                                           // really
                                                                           // reading
        Assert.assertEquals(11, ss.getMaxScn());
      }
      if (si.getSourceId() == GoldenGateEventProducer.GLOBAL_SOURCE_ID)
      {
        Assert.assertEquals(6, ss.getAvgEventSerializedSize());
        Assert.assertEquals(0, ss.getNumErrors());
        Assert.assertEquals(2, ss.getNumTotalEvents());
        Assert.assertEquals(0, ss.getAvgEventFactoryTimeMillisPerEvent());
        Assert.assertEquals(0, ss.getAvgEventFactoryTimeMillisPerEvent()); // we are not
                                                                           // really
                                                                           // reading
        Assert.assertEquals(11, ss.getMaxScn());
      }
    }
    long approximateTimeSinceLastTransactionMs =
        System.currentTimeMillis() - timestamp / DbusConstants.NUM_NSECS_IN_MSEC;
    long diff =
View Full Code Here

      _eventScnChunkedQueryHints = eventScnChunkedQueryHints;
      _eventTxnChunkedQueryHints = eventTxnChunkedQueryHints;

      if(statisticsBean == null)
      {
        statisticsBean = new EventSourceStatistics(sourceName);
      }
      _statisticsBean = statisticsBean;

  }
View Full Code Here

      {
        EventSourceStatistics[] stats = new EventSourceStatistics[sourceIds.size()];
        int i=0;
        for (Integer srcId : sourceIds)
        {
          EventSourceStatistics stat = getEventSourceStat(_stats.getSourceStats(srcId));
          stats[i++] = stat;
        }
        return stats;
      }
      return null;
View Full Code Here

   
    protected EventSourceStatistics getEventSourceStat(DbusEventsTotalStats stats)
    {
      if (stats ==null ) return null;
      long numErrors = stats.getNumHeaderErrEvents() + stats.getNumPayloadErrEvents() + stats.getNumInvalidEvents();
      EventSourceStatistics eventStats = new EventSourceStatistics(_name,(int) stats.getNumDataEvents(),stats.getTimeSinceLastAccess(),
                          stats.getMaxScn(), numErrors, stats.getSizeDataEvents());
      return eventStats;
    }
View Full Code Here

TOP

Related Classes of com.linkedin.databus.monitoring.mbean.EventSourceStatistics

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.