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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations