Database Replication Management

The database replication management module has the file name dbengrep.c. This module provides replication management features for the Bbuuzzb database server. Any mention of QNX in this document refers to the QNX 4.x OS. This API can be compiled for all stated platforms except QNX and DOS.

This module should only be linked with the Bbuuzzb database server and the functions in this module should only be called from the Bbuuzzb database server. Currently, replication is only available for the TCP IPC method. This module interfaces with the socloc API to obtain the details of other running Bbuuzzb servers.

This module manages two link lists. The first is dbengrep_servers which contains a list of currently available Bbuuzzb servers (not including the current server). The second link list is dbeng_rep which is contained within each table in use (dbeng_table). When dbengrep_init is called, the dbengep_servers link list will be loaded and each current table in use will have its replication details loaded (from the catalog) into the dbeng_rep link list. Once the replication initialization is complete, all non-system tables will have their replication details automatically loaded when the table is opened.

When a record change or delete is made, the Bbuuzzb servers listed in the replication link list will each receive the corresponding change command.

Replication details are stored in field three of the catalog. This field contains a sub-field array with each sub-field containing two sub-sub-fields Here is the layout:


      Sub-Sub-Field  Description

            1        TCP port of target Bbuuzzb server
            2        logical table name on target server

Notice that you must always supply the logical table name which means that the target table must also be cataloged and the catalog flag on all listed servers (and this one) must also be high. The replication flag of this server and every server listed in the replication details must be high also.

The replication list of each table in use is based on the list of available Bbuuzzb database servers. If a destination server listed in the catalog is not available when the source table is opened, no entry will be made in the dbeng_rep link list and the table will not be replicated. As other Bbuuzzb database servers become available or unavailable, the dbengrep_servers should be updated. Both link lists may be updated by either having the current Bbuuzzb database server call the dbengrep_init function in this module or by using the replicate.update dbm command.

You may replicate any table except system tables. You may also replicate any way you wish (server a to both server b and c or server a to server b then to server c) with the exception that you may not create a circular reference (server a to server b and back to server a). The database server will keep track of the last received replication command and will refuse to send this replication command back to the source database server.

Here is a list of functions in this module:

Module Dependencies

This module is part of the Bbuuzzb database server and must be linked with the following modules:

In the Linux and Unix platforms, this module is compiled along with the other database modules as part of the script cdbeng.

Module Header Files

This module depends on the following header files:

Module Functions

dbengrep_init

Prototype  : int dbengrep_init(void)

Returns    : dbeng code

This function initialize replication or update replication details including the dbengrep_servers and dbeng_rep link lists. Replication must be active (server replication flag) before this function is called.

dbengrep_end

Prototype  : int dbengrep_end(void)

Returns    : dbeng code

This function will de-allocate all memory used by the replication link lists. This function will not modify the server replication flag.

dbengrep_recv

Prototype  : int dbengrep_recv(char *com)
Parameters :
      Name : com
Description: received replication command

Returns    : dbeng code

This function will process a received replication command from another Bbuuzzb database server. The server replication flag of the current Bbuuzzb database server must be high in order to successfully process the received replication command.

dbengrep_send

Prototype  : int dbengrep_send(struct dbeng_table *ot,
                               int rep_code, char *irec)
Parameters :
      Name : ot
Description: dbeng_table pointer

      Name : rep_code
Description: replication code (defined in dbengrep.h)

      Name : irec
Description: record contents

Returns    : dbeng code

This function will send a replication command to every Bbuuzzb database server listed in the dbeng_rep link list. The server replication flag of the current Bbuuzzb database server and the server replication flag of every Bbuuzzb database server in the dbeng_rep link list must be high in order to successfully process the command.

dbengrep_rll_delete_all

Prototype  : int dbengrep_rll_delete_all(struct dbeng_table *ot)
Parameters :
      Name : ot
Description: dbeng_table pointer

Returns    : dbeng code

This function will delete all dbeng_rep link list nodes for a single table.

dbengrep_rll_load

Prototype  : int dbengrep_rll_load(struct dbeng_table *ot, char *tlist)
Parameters :
      Name : ot
Description: dbeng_table pointer

      Name : tlist
Description: output replication list

Returns    : dbeng code

This function will load or re-load all matching replication details from the catalog into the output replication list.

dbengrep_recv_write

Prototype  : static int dbengrep_recv_write(char *com)
Parameters :
      Name : com
Description: received replication command

Returns    : dbeng code

This private function will process a single received write record replication command.

dbengrep_recv_delete

Prototype  : static int dbengrep_recv_delete(char *com)
Parameters :
      Name : com
Description: received replication command

Returns    : dbeng code

This private function will process a single received delete record replication command.

dbengrep_recv_pack

Prototype  : static int dbengrep_recv_pack(void)

Returns    : dbeng code

This private function will process a single received pack table replication command.

dbengrep_recv_get_fpos

Prototype  : static long dbengrep_recv_get_fpos(char *com)
Parameters :
      Name : com
Description: received replication command

Returns    : file position

This private function will extract and return the specified file position from the received replication command.

dbengrep_rll_add

Prototype  : static int dbengrep_rll_add(struct dbeng_table *ot,
                                         char *tname, int port_num)
Parameters :
      Name : ot
Description: dbeng_table pointer

      Name : tname
Description: destination server logical table name

      Name : port_num
Description: destination server TCP port number

Returns    : dbeng code

This private function will add a single node to the dbeng_rep replication details link list for a single table.

dbengrep_rll_find

Prototype  : static struct dbeng_rep *dbengrep_rll_find(struct dbeng_table *ot,
                                                               int port_num)
Parameters :
      Name : ot
Description: dbeng_table pointer

      Name : port_num
Description: destination server TCP port number

Returns    : pointer to dbeng_rep node

This private function will locate a dbeng_rep node for a specific table based on the destination server TCP port number.

dbengrep_rll_delete

Prototype  : static int dbengrep_rll_delete(struct dbeng_table *ot,
                                            int port_num)
Parameters :
      Name : ot
Description: dbeng_table pointer

      Name : port_num
Description: destination server TCP port number

Returns    : dbeng code

This private function will delete a single dbeng_rep link list node for a single table by the destination server TCP port number.

dbengrep_sll_load

Prototype  : static int dbengrep_sll_load(void)

Returns    : dbeng code

This private function will load or re-load the dbengrep_servers link list (list of available Bbuuzzb database servers) from an available socloc server. Note that the current Bbuuzzb database server will be automatically excluded from the list.

dbengrep_sll_add

Prototype  : static int dbengrep_sll_add(struct dbeng_table *ot,
                                         char *hname, int port_num)
Parameters :
      Name : ot
Description: dbeng_table pointer

      Name : hname
Description: host name

      Name : port_num
Description: TCP port number

Returns    : dbeng code

This private function will add a node to the dbengrep_servers list of available Bbuuzzb database servers.

dbengrep_sll_delete

Prototype  : static int dbengrep_sll_delete(int port_num)
Parameters :
      Name : port_num
Description: TCP port number

Returns    : dbeng code

This private function will delete a dbengrep_servers node by its TCP port number.

dbengrep_sll_find

Prototype  : static struct dbengrep_servers *dbengrep_sll_find(int port_num)
Parameters :
      Name : port_num
Description: TCP port number

Returns    : pointer to dbengrep_servers node

This private function will locate a dbengrep_servers node by its TCP port number.

dbengrep_sll_delete_all

Prototype  : static void dbengrep_sll_delete_all(void)

This private function will de-allocate all memory used by the dbengrep_servers link list.

dbengrep_set_active

Prototype  : static int dbengrep_set_active(char *hname, int port_num)
Parameters :
      Name : hname
Description: host name

      Name : port_num
Description: TCP port number

Returns    : dbeng code

This private function will set the active destination Bbuuzzb database server to the host name and TCP port number.

dbengrep_send_recv

Prototype  : static int dbengrep_send_recv(char *com)
Parameters :
      Name : com
Description: replication command

Returns    : dbeng code

This private function will send a replication command to the current destination Bbuuzzb database server and receive a reply.

dbengrep_connect

Prototype  : static int dbengrep_connect(void)

Returns    : TRUE upon success, FALSE otherwise

This private function will attempt to connect to the currently defined destination Bbuuzzb database server.

Goto Top | Future Lab Home | Contact Webmaster | Feedback

Copyright © 2002-2006 Future Lab, Last Updated Jun 30, 2006