ReplDBMSEvent
Objects
The base object from which all of the data about replication can be
obtained is the ReplDBMSEvent
class. The class
contains all of the information about each event, including the global
transaction ID and statement or row data.
The interface to the underlying information is through a series of methods that provide the embedded information or data structures, described in the table below.
Method | Description |
---|---|
getAppliedLatency()
|
Returns the latency of the embedded event. See
Section E.2.8, “Terminology: Fields appliedLatency ”
|
getData()
|
Returns an array of the DBMSData
objects within the event
|
getDBMSEvent()
|
Returns the original DBMSEvent object
|
getEpochNumber()
| Get the Epoch number of the stored event. See THL EPOCH# |
getEventId()
| Returns the native event ID. See THL EVENTID |
getExtractedTstamp()
| Returns the timestamp of the event. |
getFragno()
| Returns the fragment ID. See THL SEQNO |
getLastFrag()
| Returns true if the fragment is the last fragment in the event. |
getSeqno()
| Returns the native sequence number. See THL SEQNO |
getShardId()
| Returns the shard ID for the event. |
getSourceId()
| Returns the source ID of the event. See THL SOURCEID |
setShardId()
| Sets the shard ID for the event, which can be used by the filter to set the shard. |
The primary method used is getData()
, which
returns an array of the individual DBMSData
objects contain in the event:
function filter(event) { data = event.getData(); if(data != null) { for (i = 0; i < data.size(); i++) { change = data.get(i); ...
Access to the underlying array structure uses the
get()
method to request individual objects
from the array. The size()
method returns the
length of the array.
Removing or Adding Data Changes
Individual DBMSData
objects can be removed from
the replication stream by using the remove()
method, supplying the index of the object to remove:
data.remove(1);
The add()
method can be used to add new data
changes into the stream. For example, data can be duplicated across
tables by creating and adding a new version of the event, for example:
if(d.getDefaultSchema() != null && d.getDefaultSchema().compareTo(sourceName)==0) { newStatement = new com.continuent.tungsten.replicator.dbms.StatementData(d.getQuery(), null, targetName); data.add(data.size(),newStatement); }
The above code looks for statements within the
sourceName
schema and creates a
copy of each statement into the
targetName
schema.
The first argument to add()
is the index
position to add the statement. Zero (0) indicates before any existing
changes, while using size()
on the array
effectively adds the new statement change at the end of the array.
Updating the Shard ID
The setShardId()
method can also be used to
set the shard ID within an event. This can be used in filters where
the shard ID is updated by examining the schema or table being updated
within the embedded SQL or row data. An example of this is provided in
Section 10.4.43, “shardbytable.js
Filter”.