Data Replication Techniques I – Use of Function Strings
My previous posts provided an introduction to SAP Sybase Replication Server and how it fits into heterogeneous replication systems. In this post, I would like to begin discussing specific customization and problem solving techniques that can be very useful in many data replication scenarios for both heterogeneous and non-heterogeneous systems through the internal use of SAP Sybase Replication Server function strings.
Functions strings customization allows you to change default behavior when applying commands to a replicate database, a couple of typical use cases could be:
- Example 1: Default behaviour for an insert is to perform that insert in the replicate database, but it could also be executed with other extra commands.
- Example 2: Modify deletes in a table to perform the delete in the corresponding table and also insert the deleted row in a historical table.
Customization is especially interesting in heterogeneous replication because you can use specific DBMS syntax to bulid your commands.
Function strings can be defined as templates internally used by SAP Sybase Replication Server to generate the syntax used when applying changes at each replicate database. When talking about function strings we have to define three important concepts:
- Functions: represent dataserver actions. For example:
- rs_insert in the function used when inserting rows in replicate database,
- rs_delete is used when deleteing rows, and
- rs_update when updating
- Function instance: is a combination of a Replication Server function and a row coming from the primary database log.
- Function string: is the specific language template for executing a Replication Server function.
By default, Replication Server has system functions for common dataserver actions. In case of rs_insert, rs_delete and rs_update, they are internally generated with the default behavior for each replication definition you create. For example, these are default rs_insert, rs_delete and rs_update function strings created for a table called test that has two columns (id int and c char):
insert test (id, c) values (?id!new?, ?c!new?)
update test set id=?id!new?, c=?c!new? where id=?id!old?
delete from test where id=?id!old?
How Replication Server uses functions and function strings
The following diagram shows how function and function strings internally work:
- Client inserts data in table test.
- Rep Agent forwards change to primary Replication Server in a proprietary format called LTL (Log Transfer Language).
- Primary Replication Server forwards rs_insert function instance with values from log record.
- Replicate Replication Server (the one that manages the connection to the replicate DB) retrieves function string from RSSD and uses it as template to construct the language to send to replicate database.
- Replicate Replication Server sends command to replicate database.
Replication Server includes commands to create new function string clases, create function strings, alter function strings, etc. For example, function strings can be customized to:
- Generate third-party syntax.
- Call a stored procedure instead of performing an insert.
- Discard certain primary changes, like deletes.
- Call stored procedures, extended stored procedures, or Java classes.
The following how-to-video shows how you can change default function string behavior with an interesting use case:
Note: set video resolution to HD
Knowing how function strings work in SAP Sybase Replication Server and how you can customize behavior, you can go further and think about Replication Server in terms of database event capture and change default behavior when applying changes to replicate database, or further, be able to run any specific replicate DBMS command or stored procedure.
More details in SAP Sybase documentation:
- Follow the “Database Services Content Library” to access the entire series of Database Services Blogs and join the conversation on Twitter @SAPServices
- Learn more about SAP Database Services here “http://www.sap.com/services-and-support/data-and-technology/database-services.epx“