Search in sources :

Example 11 with DbusEventKey

use of com.linkedin.databus.core.DbusEventKey in project databus by linkedin.

the class DummyRemoteExceptionHandler method createSimpleBuffer.

private DbusEventBuffer createSimpleBuffer() {
    DbusEventBuffer buf = new DbusEventBuffer(_bufCfg);
    buf.start(0);
    buf.startEvents();
    buf.appendEvent(new DbusEventKey(1), (short) 1, (short) 1, System.nanoTime(), (short) 1, new byte[16], new byte[100], false, null);
    buf.appendEvent(new DbusEventKey(2), (short) 1, (short) 1, System.nanoTime(), (short) 1, new byte[16], new byte[100], false, null);
    buf.endEvents(10);
    return buf;
}
Also used : DbusEventKey(com.linkedin.databus.core.DbusEventKey) DbusEventBuffer(com.linkedin.databus.core.DbusEventBuffer)

Example 12 with DbusEventKey

use of com.linkedin.databus.core.DbusEventKey in project databus by linkedin.

the class OpenReplicatorAvroEventFactory method createAndAppendEvent.

public int createAndAppendEvent(DbChangeEntry changeEntry, DbusEventBufferAppendable eventBuffer, boolean enableTracing, DbusEventsStatisticsCollector dbusEventsStatisticsCollector) throws EventCreationException, UnsupportedKeyException, DatabusException {
    Object keyObj = obtainKey(changeEntry);
    //Construct the Databus Event key, determine the key type and construct the key
    DbusEventKey eventKey = new DbusEventKey(keyObj);
    short lPartitionId = _partitionFunction.getPartition(eventKey);
    //Get the md5 for the schema
    SchemaId schemaId = SchemaId.createWithMd5(changeEntry.getSchema());
    byte[] payload = serializeEvent(changeEntry.getRecord());
    DbusEventInfo eventInfo = new DbusEventInfo(changeEntry.getOpCode(), changeEntry.getScn(), (short) _pSourceId, lPartitionId, changeEntry.getTimestampInNanos(), (short) _sourceId, schemaId.getByteArray(), payload, enableTracing, false);
    boolean success = eventBuffer.appendEvent(eventKey, eventInfo, dbusEventsStatisticsCollector);
    return success ? payload.length : -1;
}
Also used : DbusEventInfo(com.linkedin.databus.core.DbusEventInfo) SchemaId(com.linkedin.databus2.schemas.SchemaId) DbusEventKey(com.linkedin.databus.core.DbusEventKey)

Example 13 with DbusEventKey

use of com.linkedin.databus.core.DbusEventKey in project databus by linkedin.

the class BootstrapSeederOracleAvroGenericEventFactory method createAndAppendEvent.

/*
	 * @see com.linkedin.databus2.monitors.db.EventFactory#createEvent(long, long, java.sql.ResultSet)
	 */
@Override
public long createAndAppendEvent(long scn, long timestamp, GenericRecord record, ResultSet row, DbusEventBufferAppendable eventBuffer, boolean enableTracing, boolean isReplicated, DbusEventsStatisticsCollector dbusEventsStatisticsCollector) throws EventCreationException, UnsupportedKeyException {
    if (!(eventBuffer instanceof BootstrapEventBuffer))
        throw new RuntimeException("Expected BootstrapEventBuffer instance to be passed but received:" + eventBuffer);
    BootstrapEventBuffer bEvb = (BootstrapEventBuffer) eventBuffer;
    byte[] serializedValue = serializeEvent(record, scn, timestamp, row, eventBuffer, enableTracing, dbusEventsStatisticsCollector);
    // Append the event to the databus event buffer
    //DbusEventKey eventKey = new DbusEventKey(record.get("key"));
    DbusEventKey eventKey = new DbusEventKey(record.get(keyColumnName));
    DbusEventKey seederChunkKey = new DbusEventKey(record.get(_seederChunkKeyName));
    short lPartitionId = _partitionFunction.getPartition(eventKey);
    //short pPartitionId = PhysicalSourceConfig.DEFAULT_PHYSICAL_PARTITION.shortValue();
    bEvb.appendEvent(eventKey, seederChunkKey, _pSourceId, lPartitionId, timestamp * 1000000, _sourceId, _schemaId, serializedValue, enableTracing, isReplicated, dbusEventsStatisticsCollector);
    return serializedValue.length;
}
Also used : DbusEventKey(com.linkedin.databus.core.DbusEventKey)

Example 14 with DbusEventKey

use of com.linkedin.databus.core.DbusEventKey in project databus by linkedin.

the class DbusEventGenerator method generateEvents.

/**
   * Generate specified number of constant sized events.
   *
   * @param numEvents : Number of events desired
   * @param windowSize : Max window size (transaction size)
   * @param maxEventSize : maximum event size expected
   * @param payloadSize : payload size in bytes
   * @param useLastEventAsScn : if true, use count of last event of window as window scn; else use i/windowSize+1
   * @param eventVector : output container that is populated with the events
   * @return last window number generated
   */
public long generateEvents(int numEvents, int windowSize, int maxEventSize, int payloadSize, boolean useLastEventAsScn, Vector<DbusEvent> eventVector) {
    long lastScn = 0;
    try {
        long beginningOfTime = System.currentTimeMillis() / 1000;
        beginningOfTime *= 1000;
        short srcId = 1;
        for (int i = 0; i < numEvents; ++i) {
            if (_srcIdList != null && _srcIdList.size() > 0) {
                int srcIdIndex = RngUtils.randomPositiveInt() % _srcIdList.size();
                srcId = _srcIdList.get(srcIdIndex);
            } else {
                srcId = RngUtils.randomPositiveShort();
            }
            if (srcId == 0) {
                //0 srcId not allowed
                srcId = 1;
            }
            //assumption: serialized event fits in maxEventSize
            ByteBuffer buf = ByteBuffer.allocate(maxEventSize).order(_eventFactory.getByteOrder());
            DbusEventInfo eventInfo = new DbusEventInfo(DbusOpcode.UPSERT, // sequence number
            0L, // physical Partition
            (short) 0, RngUtils.randomPositiveShort(), (beginningOfTime - ((numEvents - i) * 1000)) * 1000 * 1000, //nanoseconds ; first event is numEvents seconds ago
            srcId, RngUtils.schemaMd5, RngUtils.randomString(payloadSize).getBytes(Charset.defaultCharset()), false, false);
            // make this explicit
            eventInfo.setEventSerializationVersion(DbusEventFactory.DBUS_EVENT_V1);
            DbusEventFactory.serializeEvent(new DbusEventKey(RngUtils.randomLong()), buf, eventInfo);
            lastScn = (useLastEventAsScn) ? _startScn + ((i / windowSize) + 1) * (long) windowSize : _startScn + (i / windowSize) + 1;
            eventVector.add((DbusEvent) DbusEventFactoryForTesting.createReadOnlyDbusEventFromBuffer(buf, 0, lastScn, DbusEventFactory.DBUS_EVENT_V1));
        }
    } catch (KeyTypeNotImplementedException e) {
    // ignore
    }
    return lastScn;
}
Also used : DbusEventInfo(com.linkedin.databus.core.DbusEventInfo) KeyTypeNotImplementedException(com.linkedin.databus.core.KeyTypeNotImplementedException) DbusEventKey(com.linkedin.databus.core.DbusEventKey) ByteBuffer(java.nio.ByteBuffer)

Example 15 with DbusEventKey

use of com.linkedin.databus.core.DbusEventKey in project databus by linkedin.

the class DbusEventAppender method addEventToBuffer.

public int addEventToBuffer(DbusEvent ev, int dataEventCount) {
    byte[] payload = new byte[((DbusEventInternalReadable) ev).payloadLength()];
    ev.value().get(payload);
    if ((_numDataEventsBeforeSkip < 0) || (dataEventCount < _numDataEventsBeforeSkip)) {
        _buffer.appendEvent(new DbusEventKey(ev.key()), ev.physicalPartitionId(), ev.logicalPartitionId(), ev.timestampInNanos(), ev.srcId(), ev.schemaId(), payload, false, _stats);
        if (!_bufferReflector.validateBuffer()) {
            throw new RuntimeException("Buffer validation 3 failed");
        }
        ++dataEventCount;
    }
    return dataEventCount;
}
Also used : DbusEventInternalReadable(com.linkedin.databus.core.DbusEventInternalReadable) DbusEventKey(com.linkedin.databus.core.DbusEventKey)

Aggregations

DbusEventKey (com.linkedin.databus.core.DbusEventKey)21 DbusEventInfo (com.linkedin.databus.core.DbusEventInfo)11 ByteBuffer (java.nio.ByteBuffer)7 Checkpoint (com.linkedin.databus.core.Checkpoint)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 DbusEventBuffer (com.linkedin.databus.core.DbusEventBuffer)4 ArrayList (java.util.ArrayList)4 Test (org.testng.annotations.Test)4 DbusEventBufferAppendable (com.linkedin.databus.core.DbusEventBufferAppendable)3 DbusEventInternalReadable (com.linkedin.databus.core.DbusEventInternalReadable)3 KeyTypeNotImplementedException (com.linkedin.databus.core.KeyTypeNotImplementedException)3 ConditionCheck (com.linkedin.databus2.test.ConditionCheck)3 Logger (org.apache.log4j.Logger)3 NettyHttpDatabusRelayConnection (com.linkedin.databus.client.netty.NettyHttpDatabusRelayConnection)2 NettyHttpDatabusRelayConnectionInspector (com.linkedin.databus.client.netty.NettyHttpDatabusRelayConnectionInspector)2 DbusEventV2Factory (com.linkedin.databus.core.DbusEventV2Factory)2 DbusEventsStatisticsCollector (com.linkedin.databus.core.monitoring.mbean.DbusEventsStatisticsCollector)2 RegisterResponseEntry (com.linkedin.databus2.core.container.request.RegisterResponseEntry)2 SchemaId (com.linkedin.databus2.schemas.SchemaId)2 SimpleObjectCaptureHandler (com.linkedin.databus2.test.container.SimpleObjectCaptureHandler)2