DataReelDataReelC++ Toolkit Documentation

DataReel Replication Administrator's Guide (gxObjRepl)

This guide is for the person who runs object replication on two nodes: setting it up, watching it, taking over when the primary fails, and getting back. It covers gxObjRepl as shipped in DataReel 7.4. The class reference is gxobjrepl.htm. The tool is utils/objrepl/objrepl.cpp, and the release notes are RELEASE_NOTES_7.4.txt.

> 7.4: gxObjRepl replaces gxrepl page shipping, which 7.4 no longer has. A gxrepl binary installed > from a 7.4 beta keeps working as it is, but it is not part of 7.4. The gxrepl guide of the 7.4 betas 1 to 4 is > kept with the gxrepl source in the DataReel repository's history.

Every example uses throwaway folders under /tmp/objrepl_demo, two node names (n1 and n2) and the loopback address. Never try the commands here for the first time on production nodes: run them on a local throwaway setup first. Test status: each block marked (tested) was run as printed, in order, on a throwaway setup (section 10 says how).

1. What gxObjRepl replicates

2. Setting up a primary and a copy

2.1 Build

Build every binary from one 7.4 tree: the library, the objrepl tool and your programs. A program built from an older tree may send the old stream header, which is refused (section 6).

cmake -S datareel -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -j2
build/utils/objrepl engine        # "engine 64-bit" and exit 0 with -DDATAREEL_64BIT_DATABASE=ON; "engine 32-bit" and exit 1 by default

2.2 Certificates

utils/objrepl/objrepl_certs.sh makes a private CA and the two certificates: the copy's server certificate, and the primary's client certificate, whose CN the copy allows. It is a dry run unless you add --apply, and it never overwrites a file.

(tested)

mkdir -p /tmp/objrepl_demo
datareel/utils/objrepl/objrepl_certs.sh /tmp/objrepl_demo/certs --copy-host 127.0.0.1           # dry run
datareel/utils/objrepl/objrepl_certs.sh /tmp/objrepl_demo/certs --copy-host 127.0.0.1 --apply
ls /tmp/objrepl_demo/certs

Give each node its own certificate and key, and the CA certificate (ca.pem). Keep ca.key off the nodes. The keys are written mode 600. objrepl refuses a key that others can read, and it also checks the certificates' dates, CA and key when it starts. A Windows (Schannel) build makes those checks at the TLS handshake instead.

2.3 Configuration

Each node reads ROOT/objrepl.conf, one key value line per setting (# starts a comment). The same keys work as command line options with -- in front, and the command line wins.

keynodemeaning
name, peer-nameboththis node and the peer it expects (empty: any)
ca, cert, keyboththe CA, this node's certificate and key
copyprimarythe copy, HOST[:PORT]; port 2073 when none is given (7.4.1)
listencopy[ADDR:]PORT or ADDR (default 127.0.0.1, port 2073 since 7.4.1: replication is a gxStream object stream, and 2073 is the gxStream port registered with IANA)
allow-cncopythe CN of the primary's client certificate
linksprimaryDB:OFFSET:TARGET_DB,...: link fields (8-byte addresses) sent as ids
indexbothNAME:DB:B:OFFSET:LEN (B-tree) or NAME:DB:V:OFFSET:DIM (vector): this node's own indexes
max-lag, max-behind, min-cert-daysbothcheck thresholds: commits, seconds, certificate days (100, 60, 30)
idle-timeoutbothseconds without a frame before a connection is dropped (120)
trimprimary1: drop outbox entries the copy has (default)

(tested)

D=/tmp/objrepl_demo; C=$D/certs
mkdir -p $D/n1 $D/n2
cat > $D/n2/objrepl.conf <<EOF
name n2
peer-name n1
ca $C/ca.pem
cert $C/copy.pem
key $C/copy.key
listen 127.0.0.1:24700
allow-cn objrepl-primary
EOF
cat > $D/n1/objrepl.conf <<EOF
name n1
peer-name n2
ca $C/ca.pem
cert $C/primary.pem
key $C/primary.key
copy 127.0.0.1:24700
EOF

2.4 Start the copy, then the primary

(tested)

B=build/utils/objrepl; D=/tmp/objrepl_demo
$B copy $D/n2 > $D/n2.log 2>&1 &  echo $! > $D/n2.pid
$B primary $D/n1 --commits 200               # the demo's writer: 200 test commits, then waits for the copy
echo "exit $?"                                # 0: the copy has every commit

The copy runs until it gets TERM or INT on Linux, or Ctrl+C or Ctrl+Break on Windows. On either platform it also stops when ROOT/objrepl.stop appears. Stop it by its process id, never by a name pattern.

3. Watching it

(tested)

B=build/utils/objrepl; D=/tmp/objrepl_demo
$B status $D/n1; $B status $D/n2
$B check $D/n2; echo "exit $?"
$B digest $D/n1 > $D/n1.digest; $B digest $D/n2 > $D/n2.digest
cmp $D/n1.digest $D/n2.digest && echo "the same objects"

4. Failover and failback

Either node can be Windows or Linux. A Windows copy can take over from a Linux primary, and the Linux node then rejoins as its copy, or the other way round.

4.1 A planned switch (no commit lost)

Drain first: the primary's last run exited 0, and objrepl primary ROOT --drain sends what is left without new commits. Then stop both nodes, and switch.

(tested)

B=build/utils/objrepl; D=/tmp/objrepl_demo
kill $(cat $D/n2.pid); wait $(cat $D/n2.pid) 2>/dev/null
$B takeover $D/n2                             # n2: primary, epoch 2
$B rejoin $D/n1                               # n1: a copy again
# n1 now listens and n2 sends: swap the settings
sed -i 's/^copy .*/listen 127.0.0.1:24701/; s/primary\./copy./g' $D/n1/objrepl.conf && echo "allow-cn objrepl-primary" >> $D/n1/objrepl.conf
sed -i 's/^listen .*/copy 127.0.0.1:24701/; /^allow-cn/d; s/copy\.\(pem\|key\)/primary.\1/g' $D/n2/objrepl.conf
$B copy $D/n1 > $D/n1.log 2>&1 &  echo $! > $D/n1.pid
$B primary $D/n2 --commits 50; echo "exit $?"
$B digest $D/n1 > $D/n1.digest; $B digest $D/n2 > $D/n2.digest
cmp $D/n1.digest $D/n2.digest && echo "the same objects"
kill $(cat $D/n1.pid)

The demo swaps the certificates as well, because its copy certificate is the server certificate. With one certificate per host that can serve both roles, only copy, listen and allow-cn change.

4.2 After a crash

If the primary is gone, take over on the copy at once (objrepl takeover), and point your writers at it. When the old primary comes back, do not start it as a primary. Run objrepl rejoin on it first: the status line says how many of its commits the copy never had (dropped_at_rejoin). Then start it as a copy.

4.3 The incremental rejoin and the schema check (7.5 beta 3)

When both nodes wrote after the split, for example a standby that took over while the old primary kept writing, objrepl rejoin keeps the old primary's data and the list of objects its unacknowledged commits changed. When it connects, the new primary checks three things:

1. The histories match. Both nodes have the same digest at the seq the new primary took over at. That seq and digest are recorded in ROOT/epochs at each takeover. 2. The schemas agree. The fingerprints match: the index spec, the link map (when the copy has its own), and the schema setting, which is free text the application sets for its record layout version, such as news-v3. 3. The change set is small enough. It holds at most rejoin-max-share percent of the objects (default 50).

When all three hold, the new primary sends only the objects that either node changed since the split, each as it is now (or "absent"), followed by its digest log past the split. The rejoining node applies them, and both nodes then have the same digest. The status file of the new primary shows last_rejoin incremental and last_rejoin_objects N.

When the check fails:

mkdir NEW                                        # an empty folder, with the new schema's settings
$B copy NEW --listen PORT ... --schema news-v4   # takes a full send from the primary
$B digest NEW; $B digest PRIMARY_ROOT            # the same line
# stop the copy, then:
$B swap OLD NEW --index SPEC                     # OLD -> OLD.before-rebuild-DATE (kept), NEW -> OLD

swap refuses while either node runs, when NEW is in a full send, or when NEW's indexes fail the check. It never deletes anything.

In the running stream (not a rejoin), a schema difference is only a warning in the copy's log.

The new primary holds its lock while it sends an incremental rejoin. That is why the change set is capped: past the share, a full send, which does not hold the lock, is used instead.

5. Upgrades

6. Troubleshooting

7. Known limits

8. The journal and the lock

Each node writes through one gxdJournal (ROOT/node.jnl) in write-back mode: a commit's pages reach the files only after its batch is durable in the journal, as with write-through. This lets the journal sync run without the node's lock, so readers keep going during it. Checkpoints sync the files the same way. Begin(), Close() and a soft checkpoint wait until no commit's sync is running. Pump() gives the lock up for its network I/O. Do not copy a running node's folder: use objrepl digest to compare, and rejoin to rebuild a copy.

9. When a plain file copy is enough

You do not always need replication. A plain copy of the database folder is enough when all of these hold:

Then copy the folder with your file sync tool while the writer is stopped, and verify after with dr_digest, which prints the same digest for the same contents whatever the file's layout:

# on the primary, with the writer stopped (or between its jobs)
rsync -a --delete -n --exclude '*.jnl' /data/db/ copy-host:/data/db/   # dry run first
rsync -a --delete    --exclude '*.jnl' /data/db/ copy-host:/data/db/
# verify: the same digests on both sides
dr_digest /data/db/data.gxd --kind objects
ssh copy-host dr_digest /data/db/data.gxd --kind objects

The exclude leaves out the journal (*.jnl); leave out lock files the same way. Copy the indexes with the data or rebuild them on the copy.

On Windows, the same with robocopy, and the digests of the example program replication_copy. Your application needs its own digest, the way replication_copy.cpp makes one: the records in address order, the B-tree's keys in order, and gxVectorIndex::LogicalDigest().

(tested on Windows 11 with DataReel 7.4 beta 3)

rem with the writer stopped
robocopy C:\repl_demo\primary C:\repl_demo\copy /MIR /XF *.jnl /R:0 /L    &rem dry run first
robocopy C:\repl_demo\primary C:\repl_demo\copy /MIR /XF *.jnl /R:0
rem robocopy exit codes 0 to 7 are success, 8 and up a failure
replication_copy digest C:\repl_demo\primary > primary.digest
replication_copy digest C:\repl_demo\copy > copy.digest
fc /b primary.digest copy.digest
vix_rebuild --digest C:\repl_demo\copy\vectors.vix

robocopy cannot copy a file another program holds open, which is one more reason to stop the writer first. A copy that lost its indexes rebuilds them from its own data (replication_copy rebuild); the digests then agree again.

If the writer cannot stop, if the database changes all day, or if the copy must be seconds behind and always one whole commit, use gxObjRepl.

10. Test status of this guide

The blocks marked (tested) in sections 2 to 4 were run as printed, in order, with DataReel 7.4 beta 5 (header-fixed-width after the gxObjRepl merge) on one Linux machine: two folders under /tmp/objrepl_demo and the loopback address, with objrepl primary as the writer. The robocopy block in section 9 was run on Windows 11 with 7.4 beta 3. The cross-platform cases (Linux to Windows and back, takeover and rejoin, the 2,500-commit stress run each way, old builds refused) come from the replication tests of 11/16/2026.