WaterbugDB

Terminal 1:

$ go build
$ ./waterbugdb --node-id node1 --raft-port 2222 --http-port 8222 --pg-port 6000

Terminal 2:

$ go build
$ ./waterbugdb --node-id node2 --raft-port 2223 --http-port 8223 --pg-port 6001

Terminal 3, tell 1 to have 2 follow it:

$ curl 'localhost:8222/join?followerAddr=localhost:2223&followerId=node2'

Terminal 3, now open psql:

$ psql -h localhost -p 6000
psql -h 127.0.0.1 -p 6000
psql (13.4, server 0.0.0)
Type "help" for help.

phil=> create table x (age int, name text);
CREATE ok
phil=> insert into x values(14, 'garry'), (20, 'ted');
could not interpret result from server: INSERT ok
INSERT ok
phil=> select name, age from x;
  name   | age 
---------+-----
 "garry" |  14
 "ted"   |  20
(2 rows)

Now exit psql and connect to the other database at port 6001. It will fail if you try to write to it but SELECTs will work:

$ psql -h 127.0.0.1 -p 6001
psql (13.4, server 0.0.0)
Type "help" for help.

phil=> select age, name from x;
 age |  name
-----+---------
  20 | "ted"
  14 | "garry"
(2 rows)

References

GitHub

View Github