Chapter 5. Configuring for Write Forwarding

Table of Contents

Application with Write Forwarding Overview
Program Listing
Class: RepWrforConfig
Class: RepQuoteWrforExampleGSG
Method: RepQuoteWrforExampleGSG.main()
Method: RepQuoteWrforExampleGSG.init()
Method: RepQuoteWrforExampleGSG.doloop()
Method: RepQuoteWrforExampleGSG.printStocks()

By default, write operations cannot be performed on a replication client site. Replication Manager provides automatic write forwarding as a configurable option for applications with simple data and transaction models. (See the Configuring for Write Forwarding section in the Berkeley DB Programmer's Reference Guide for more information.)

In this chapter, we configure write forwarding for the simple transaction-protected DB application that you created in the Transactional Application chapter.

Application with Write Forwarding Overview

Write forwarding simplifies adding replication to the stock market quotes database application. Once write forwarding is configured, this application allows any site to accept stock quote updates. There is no need to confine write operations to the master or even to know which site is the master.

The application operates by presenting you with a command line prompt. You then enter the stock symbol and its value, separated by a space. The application takes this information and writes it to the database.

To see the contents of the database, simply press return at the command prompt.

To quit the application, type 'quit' or 'exit' at the command prompt.

For example, the following illustrates the application's usage. In it, we use entirely fictitious stock market symbols and price values.

node01> java db.repquote_gsg.RepQuoteWrforExampleGSG -h env_home_dir -L \ 
node01:5000
QUOTESERVER> stock1 88
QUOTESERVER> stock2 .08
QUOTESERVER> 
        Symbol  Price
        ======  =====
        stock1  88
        stock2 .08 

where L is used to identify the local site as group creator, which creates the database and starts this site as master.

With write forwarding, we can add a new stock value in the client site. In the client site (node02), specify the new local client site and the existing remote site in the replication group.

node02> java db.repquote_gsg.RepQuoteWrforExampleGSG -l \
node02:5001 -r node01:5000
QUOTESERVER> stock3 99
QUOTESERVER> 
        Symbol  Price
        ======  =====
        stock1  88
        stock2  .08
        stock3  99

QUOTESERVER> quit 

Finally, verify that the stock3 value replicated to the master:

QUOTESERVER> 
        Symbol  Price
        ======  =====
        stock1  88
        stock2  .08
        stock3  99

QUOTESERVER> quit