├── m4 ├── .gitignore └── ax_check_compile_flag.m4 ├── daemon ├── dummy.cc ├── slot_type.cc ├── rsm.h ├── deferred_msg.h ├── settings.h ├── slot_type.h ├── settings.cc ├── controller.h ├── failure_tracker.h ├── commander.h ├── unordered_command.cc ├── ballot.h ├── pvalue.h ├── condition.h ├── controller.cc ├── commander.cc ├── snapshot.h └── unordered_command.h ├── doc ├── replicant.xtx ├── .gitignore ├── Makefile └── replicant.tex ├── AUTHORS ├── .tarballignore ├── README ├── test ├── example-echo.gremlin ├── example-log.gremlin ├── example-nop.gremlin ├── example-tick.gremlin ├── example-counter.gremlin ├── example-condition.gremlin ├── env.sh ├── chaos.valgrind.gremlin ├── lock-break.valgrind.gremlin ├── example-echo.valgrind.gremlin ├── example-log.valgrind.gremlin ├── example-nop.valgrind.gremlin ├── example-tick.valgrind.gremlin ├── lock-normal.valgrind.gremlin ├── 5-node-cluster.valgrind.gremlin ├── example-counter.valgrind.gremlin ├── leader-rotate.valgrind.gremlin ├── example-condition.valgrind.gremlin ├── restart-diff-address.valgrind.gremlin ├── lock-break.gremlin ├── lock-normal.gremlin ├── 5-node-cluster.gremlin ├── chaos.gremlin ├── leader-rotate.gremlin └── restart-diff-address.gremlin ├── replicant.pc.in ├── .gitignore ├── maint └── valgrind-gremlins ├── LICENSE ├── visibility.h ├── replicant.supp ├── namespace.h ├── common ├── generate_token.h ├── macros.h ├── quorum_calc.h ├── constants.h ├── packing.cc ├── packing.h ├── generate_token.cc ├── atomic_io.h ├── ids.cc ├── server.h ├── server.cc ├── atomic_io.cc ├── network_msgtype.h ├── ids.h └── network_msgtype.cc ├── client ├── server_status.h ├── controller.cc ├── server_selector.h ├── pending_robust.cc ├── pending.cc ├── controller.h ├── server_selector.cc ├── pending_poke.h ├── pending_poke.cc ├── pending_robust.h ├── pending_generate_unique_number.h ├── pending_cond_wait.h ├── pending_call.h ├── pending_call_robust.h ├── server_status.cc ├── pending_defended_call.h ├── pending_generate_unique_number.cc └── pending_cond_follow.h ├── examples ├── nop.c ├── echo.c ├── tick.c ├── condition.c └── log.c ├── replicant-debug.cc ├── benchmarks └── replicant-call │ └── main.go ├── tools ├── new-object.cc ├── poke.cc ├── del-object.cc ├── kill-object.cc ├── conn-str.cc ├── generate-unique-number.cc ├── list-objects.cc ├── availability-check.cc └── kill-server.cc └── include └── rsm.h /m4/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /daemon/dummy.cc: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /doc/replicant.xtx: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Robert Escriva 2 | Sean Ogden 3 | -------------------------------------------------------------------------------- /.tarballignore: -------------------------------------------------------------------------------- 1 | .gitignore 2 | m4/.gitignore 3 | .tarballignore 4 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Replicant is a tool for creating replicated state machines 2 | -------------------------------------------------------------------------------- /test/example-echo.gremlin: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env gremlin 2 | 3 | include 5-node-cluster.gremlin 4 | run replicant new-object --host 127.0.0.1 --port 1982 echo ${REPLICANT_BUILDDIR}/.libs/libreplicant-example-echo.so 5 | -------------------------------------------------------------------------------- /test/example-log.gremlin: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env gremlin 2 | 3 | include 5-node-cluster.gremlin 4 | run replicant new-object --host 127.0.0.1 --port 1982 log ${REPLICANT_BUILDDIR}/.libs/libreplicant-example-log.so 5 | -------------------------------------------------------------------------------- /test/example-nop.gremlin: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env gremlin 2 | 3 | include 5-node-cluster.gremlin 4 | run replicant new-object --host 127.0.0.1 --port 1982 nop ${REPLICANT_BUILDDIR}/.libs/libreplicant-example-nop.so 5 | -------------------------------------------------------------------------------- /test/example-tick.gremlin: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env gremlin 2 | 3 | include 5-node-cluster.gremlin 4 | run replicant new-object --host 127.0.0.1 --port 1982 tick ${REPLICANT_BUILDDIR}/.libs/libreplicant-example-tick.so 5 | -------------------------------------------------------------------------------- /test/example-counter.gremlin: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env gremlin 2 | 3 | include 5-node-cluster.gremlin 4 | run replicant new-object --host 127.0.0.1 --port 1982 counter ${REPLICANT_BUILDDIR}/.libs/libreplicant-example-counter.so 5 | -------------------------------------------------------------------------------- /test/example-condition.gremlin: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env gremlin 2 | 3 | include 5-node-cluster.gremlin 4 | run replicant new-object --host 127.0.0.1 --port 1982 condition ${REPLICANT_BUILDDIR}/.libs/libreplicant-example-condition.so 5 | -------------------------------------------------------------------------------- /test/env.sh: -------------------------------------------------------------------------------- 1 | export REPLICANT_SRCDIR="$1" 2 | export REPLICANT_BUILDDIR="$2" 3 | export REPLICANT_VERSION="$3" 4 | 5 | export REPLICANT_EXEC_PATH="${REPLICANT_BUILDDIR}" 6 | 7 | export PATH=${REPLICANT_BUILDDIR}:${REPLICANT_BUILDDIR}/examples/lock:${REPLICANT_SRCDIR}:${PATH} 8 | -------------------------------------------------------------------------------- /test/chaos.valgrind.gremlin: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env gremlin 2 | env GREMLIN_PREFIX 'libtool --mode=execute valgrind --tool=memcheck --trace-children=yes --error-exitcode=127 --vgdb=no --leak-check=full --gen-suppressions=all --suppressions="${REPLICANT_SRCDIR}/replicant.supp"' 3 | include chaos.gremlin 4 | -------------------------------------------------------------------------------- /test/lock-break.valgrind.gremlin: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env gremlin 2 | env GREMLIN_PREFIX 'libtool --mode=execute valgrind --tool=memcheck --trace-children=yes --error-exitcode=127 --vgdb=no --leak-check=full --gen-suppressions=all --suppressions="${REPLICANT_SRCDIR}/replicant.supp"' 3 | include lock-break.gremlin 4 | -------------------------------------------------------------------------------- /test/example-echo.valgrind.gremlin: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env gremlin 2 | env GREMLIN_PREFIX 'libtool --mode=execute valgrind --tool=memcheck --trace-children=yes --error-exitcode=127 --vgdb=no --leak-check=full --gen-suppressions=all --suppressions="${REPLICANT_SRCDIR}/replicant.supp"' 3 | include example-echo.gremlin 4 | -------------------------------------------------------------------------------- /test/example-log.valgrind.gremlin: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env gremlin 2 | env GREMLIN_PREFIX 'libtool --mode=execute valgrind --tool=memcheck --trace-children=yes --error-exitcode=127 --vgdb=no --leak-check=full --gen-suppressions=all --suppressions="${REPLICANT_SRCDIR}/replicant.supp"' 3 | include example-log.gremlin 4 | -------------------------------------------------------------------------------- /test/example-nop.valgrind.gremlin: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env gremlin 2 | env GREMLIN_PREFIX 'libtool --mode=execute valgrind --tool=memcheck --trace-children=yes --error-exitcode=127 --vgdb=no --leak-check=full --gen-suppressions=all --suppressions="${REPLICANT_SRCDIR}/replicant.supp"' 3 | include example-nop.gremlin 4 | -------------------------------------------------------------------------------- /test/example-tick.valgrind.gremlin: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env gremlin 2 | env GREMLIN_PREFIX 'libtool --mode=execute valgrind --tool=memcheck --trace-children=yes --error-exitcode=127 --vgdb=no --leak-check=full --gen-suppressions=all --suppressions="${REPLICANT_SRCDIR}/replicant.supp"' 3 | include example-tick.gremlin 4 | -------------------------------------------------------------------------------- /test/lock-normal.valgrind.gremlin: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env gremlin 2 | env GREMLIN_PREFIX 'libtool --mode=execute valgrind --tool=memcheck --trace-children=yes --error-exitcode=127 --vgdb=no --leak-check=full --gen-suppressions=all --suppressions="${REPLICANT_SRCDIR}/replicant.supp"' 3 | include lock-normal.gremlin 4 | -------------------------------------------------------------------------------- /test/5-node-cluster.valgrind.gremlin: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env gremlin 2 | env GREMLIN_PREFIX 'libtool --mode=execute valgrind --tool=memcheck --trace-children=yes --error-exitcode=127 --vgdb=no --leak-check=full --gen-suppressions=all --suppressions="${REPLICANT_SRCDIR}/replicant.supp"' 3 | include 5-node-cluster.gremlin 4 | -------------------------------------------------------------------------------- /test/example-counter.valgrind.gremlin: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env gremlin 2 | env GREMLIN_PREFIX 'libtool --mode=execute valgrind --tool=memcheck --trace-children=yes --error-exitcode=127 --vgdb=no --leak-check=full --gen-suppressions=all --suppressions="${REPLICANT_SRCDIR}/replicant.supp"' 3 | include example-counter.gremlin 4 | -------------------------------------------------------------------------------- /test/leader-rotate.valgrind.gremlin: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env gremlin 2 | env GREMLIN_PREFIX 'libtool --mode=execute valgrind --tool=memcheck --trace-children=yes --error-exitcode=127 --vgdb=no --leak-check=full --gen-suppressions=all --suppressions="${REPLICANT_SRCDIR}/replicant.supp"' 3 | include leader-rotate.gremlin 4 | -------------------------------------------------------------------------------- /test/example-condition.valgrind.gremlin: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env gremlin 2 | env GREMLIN_PREFIX 'libtool --mode=execute valgrind --tool=memcheck --trace-children=yes --error-exitcode=127 --vgdb=no --leak-check=full --gen-suppressions=all --suppressions="${REPLICANT_SRCDIR}/replicant.supp"' 3 | include example-condition.gremlin 4 | -------------------------------------------------------------------------------- /test/restart-diff-address.valgrind.gremlin: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env gremlin 2 | env GREMLIN_PREFIX 'libtool --mode=execute valgrind --tool=memcheck --trace-children=yes --error-exitcode=127 --vgdb=no --leak-check=full --gen-suppressions=all --suppressions="${REPLICANT_SRCDIR}/replicant.supp"' 3 | include restart-diff-address.gremlin 4 | -------------------------------------------------------------------------------- /doc/.gitignore: -------------------------------------------------------------------------------- 1 | /replicant.aux 2 | /replicant.bbl 3 | /replicant.dvi 4 | /replicant.idx 5 | /replicant.ilg 6 | /replicant.ind 7 | /replicant.log 8 | /replicant.out 9 | /replicant.P 10 | /replicant.pdf 11 | /replicant.ps 12 | /replicant.stdout.log 13 | /replicant.toc 14 | /.replicant.xtx.cache 15 | /_minted-replicant/ 16 | -------------------------------------------------------------------------------- /replicant.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: replicant 7 | Description: Replicated State Machine Library 8 | Version: @VERSION@ 9 | 10 | Requires: libpo6 >= 0.3.1 libe >= 0.3.2 busybee >= 0.3.0 11 | Libs: -L${libdir} -lreplicant 12 | Cflags: -I${includedir} 13 | -------------------------------------------------------------------------------- /test/lock-break.gremlin: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env gremlin 2 | include 5-node-cluster.gremlin 3 | 4 | run replicant new-object --host 127.0.0.1 --port 1982 lock ${REPLICANT_BUILDDIR}/.libs/libreplicant-example-lock.so 5 | 6 | run with-lock "going to fail" false 7 | daemon with-lock "sleeper" sleep 10 8 | run sleep 5 9 | run break-lock 0 "going to fail" 10 | -------------------------------------------------------------------------------- /test/lock-normal.gremlin: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env gremlin 2 | include 5-node-cluster.gremlin 3 | 4 | run replicant new-object --host 127.0.0.1 --port 1982 lock ${REPLICANT_BUILDDIR}/.libs/libreplicant-example-lock.so 5 | 6 | daemon with-lock "sleeper A" sleep 10 7 | daemon with-lock "sleeper B" sleep 10 8 | run sleep 1 9 | run with-lock "sleeper C" sleep 10 10 | -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all clean clobber data 2 | 3 | # Configuration variables 4 | 5 | TARGET = replicant 6 | 7 | export CROSSTEX_FLAGS:= --add-in --add-proceedings --titlecase=title 8 | 9 | # Rules that derive from configuration variables 10 | 11 | all: $(TARGET).pdf $(TARGET).ps 12 | @echo "SUCCESS: dvi, ps, pdf all up-to-date" 13 | 14 | $(TARGET).dvi: $(TARGET).tex $(TARGET).xtx latex.py Makefile 15 | python2 latex.py $(TARGET) 16 | 17 | $(TARGET).ps: $(TARGET).dvi 18 | dvips $(TARGET).dvi 19 | 20 | $(TARGET).pdf: $(TARGET).ps 21 | ps2pdf -dPDFSETTINGS=/prepress -dEmbedAllFonts=true $(TARGET).ps $(TARGET).pdf 22 | 23 | -include $(TARGET).P 24 | 25 | clean: 26 | rm -f $(TARGET).aux $(TARGET).bbl $(TARGET).log $(TARGET).stdout.log $(TARGET).pgf .$(TARGET).xtx.cache $(TARGET).P 27 | 28 | clobber: clean 29 | rm -f $(TARGET).dvi $(TARGET).pdf $(TARGET).ps 30 | -------------------------------------------------------------------------------- /test/5-node-cluster.gremlin: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env gremlin 2 | 3 | timeout 60 4 | 5 | env GLOG_logtostderr 6 | env GLOG_minloglevel 0 7 | env GLOG_logbufsecs 0 8 | 9 | tcp-port 1982 1983 1984 1985 1986 10 | 11 | run mkdir replica0 replica1 replica2 replica3 replica4 12 | 13 | daemon replicant daemon --debug --foreground --data=replica0 --listen 127.0.0.1 --listen-port 1982 14 | run replicant server-status --host 127.0.0.1 --port 1982 15 | daemon replicant daemon --debug --foreground --data=replica1 --listen 127.0.0.1 --listen-port 1983 --connect-port 1982 16 | run replicant server-status --host 127.0.0.1 --port 1983 17 | daemon replicant daemon --debug --foreground --data=replica2 --listen 127.0.0.1 --listen-port 1984 --connect-port 1983 18 | run replicant server-status --host 127.0.0.1 --port 1984 19 | daemon replicant daemon --debug --foreground --data=replica3 --listen 127.0.0.1 --listen-port 1985 --connect-port 1984 20 | run replicant server-status --host 127.0.0.1 --port 1985 21 | daemon replicant daemon --debug --foreground --data=replica4 --listen 127.0.0.1 --listen-port 1986 --connect-port 1985 22 | run replicant server-status --host 127.0.0.1 --port 1986 23 | run replicant availability-check --servers 5 --timeout 10 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # wildcards 2 | .deps 3 | .dirstamp 4 | .libs 5 | *.la 6 | *.lo 7 | *.o 8 | # specific files 9 | /aclocal.m4 10 | /autom4te.cache 11 | /config.guess 12 | /compile 13 | /config.h 14 | /config.h.in 15 | /config.h.in~ 16 | /config.log 17 | /config.status 18 | /config.sub 19 | /configure 20 | /depcomp 21 | /examples/lock/break-lock 22 | /examples/lock/with-lock 23 | /install-sh 24 | /libtool 25 | /ltmain.sh 26 | /m4 27 | /Makefile 28 | /Makefile.in 29 | /missing 30 | /replicant 31 | /replicant-availability-check 32 | /replicant-backup-object 33 | /replicant-benchmark 34 | /replicant-block 35 | /replicant-cli 36 | /replicant-conn-str 37 | /replicant-daemon 38 | /replicant-debug 39 | /replicant-debug-call 40 | /replicant-debug-condition 41 | /replicant-debug-defended-call 42 | /replicant-debug-dump 43 | /replicant-del-object 44 | /replicant-generate-unique-number 45 | /replicant-integrity-check 46 | /replicant-kill-object 47 | /replicant-kill-server 48 | /replicant-list-objects 49 | /replicant-list-servers 50 | /replicant-new_object 51 | /replicant-new-object 52 | /replicant.pc 53 | /replicant-poke 54 | /replicant-restore-object 55 | /replicant-rsm-dlopen 56 | /replicant-server-status 57 | /replicant.upack 58 | /stamp-h1 59 | /test-driver 60 | -------------------------------------------------------------------------------- /test/chaos.gremlin: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env gremlin 2 | 3 | env GLOG_logtostderr 4 | env GLOG_minloglevel 0 5 | env GLOG_logbufsecs 0 6 | 7 | tcp-port 1982 1983 1984 1985 1986 8 | 9 | run mkdir replica0 replica1 replica2 replica3 replica4 10 | 11 | daemon replicant daemon --debug --foreground --data=replica0 --listen 127.0.0.1 --listen-port 1982 12 | daemon replicant daemon --debug --foreground --data=replica1 --listen 127.0.0.1 --listen-port 1983 --connect-port 1982 13 | daemon replicant daemon --debug --foreground --data=replica2 --listen 127.0.0.1 --listen-port 1984 --connect-port 1983 14 | daemon replicant daemon --debug --foreground --data=replica3 --listen 127.0.0.1 --listen-port 1985 --connect-port 1984 15 | daemon replicant daemon --debug --foreground --data=replica4 --listen 127.0.0.1 --listen-port 1986 --connect-port 1985 16 | run replicant server-status --host 127.0.0.1 --port 1982 17 | run replicant server-status --host 127.0.0.1 --port 1983 18 | run replicant server-status --host 127.0.0.1 --port 1984 19 | run replicant server-status --host 127.0.0.1 --port 1985 20 | run replicant server-status --host 127.0.0.1 --port 1986 21 | run replicant new-object --host 127.0.0.1 --port 1982 nop ${REPLICANT_BUILDDIR}/.libs/libreplicant-example-nop.so 22 | -------------------------------------------------------------------------------- /maint/valgrind-gremlins: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import os 4 | import os.path 5 | import stat 6 | 7 | def lines(): 8 | for line in open('Makefile.am'): 9 | yield 'file', line 10 | x = line.split('+=') 11 | if len(x) != 2: continue 12 | g = x[1].strip() 13 | if not g.endswith('.gremlin'): continue 14 | if g.endswith('.valgrind.gremlin'): continue 15 | if not os.path.exists(g): continue 16 | v = g[:-len('.gremlin')] + '.valgrind.gremlin' 17 | f = open(v, 'w') 18 | f.write('#!/usr/bin/env gremlin\n') 19 | f.write("env GREMLIN_PREFIX 'libtool --mode=execute valgrind --tool=memcheck --trace-children=yes --error-exitcode=127 --vgdb=no --leak-check=full --gen-suppressions=all --suppressions=\"${REPLICANT_SRCDIR}/replicant.supp\"'\n") 20 | f.write('include ' + os.path.basename(g) + '\n') 21 | f.flush() 22 | f.close() 23 | os.chmod(v, stat.S_IRWXU) 24 | yield 'auto', (x[0] + '+= ' + v + '\n') 25 | 26 | prev = None 27 | fout = open('Makefile.am.tmp', 'w') 28 | for line in lines(): 29 | if prev is None or prev[0] != 'auto' or prev[1] != line[1]: 30 | fout.write(line[1]) 31 | prev = line 32 | fout.flush() 33 | fout.close 34 | os.rename('Makefile.am.tmp', 'Makefile.am') 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012, Robert Escriva 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Replicant nor the names of its contributors may be 13 | used to endorse or promote products derived from this software without 14 | specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /visibility.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2015, Robert Escriva 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Replicant nor the names of its contributors may be 13 | * used to endorse or promote products derived from this software without 14 | * specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef replicant_visibility_h_ 30 | #define replicant_visibility_h_ 31 | 32 | #define REPLICANT_API __attribute__ ((visibility ("default"))) 33 | 34 | #endif /* replicant_visibility_h_ */ 35 | -------------------------------------------------------------------------------- /replicant.supp: -------------------------------------------------------------------------------- 1 | { 2 | 3 | Memcheck:Leak 4 | ... 5 | obj:*/bash 6 | ... 7 | } 8 | { 9 | 10 | Memcheck:Leak 11 | ... 12 | obj:*/sed 13 | ... 14 | } 15 | { 16 | 17 | Memcheck:Leak 18 | ... 19 | obj:*/g++-4.8 20 | ... 21 | } 22 | { 23 | 24 | Memcheck:Leak 25 | ... 26 | obj:/usr/lib/librt*.so 27 | fun:aio_fsync 28 | ... 29 | } 30 | { 31 | 32 | Memcheck:Leak 33 | ... 34 | fun:poptGetNextOpt 35 | ... 36 | } 37 | { 38 | 39 | Memcheck:Leak 40 | fun:calloc 41 | fun:allocate_dtv 42 | fun:_dl_allocate_tls 43 | fun:pthread_create@@* 44 | ... 45 | } 46 | { 47 | 48 | Memcheck:Leak 49 | fun:calloc 50 | fun:allocate_dtv 51 | fun:_dl_allocate_tls 52 | fun:allocate_stack 53 | fun:pthread_create@@GLIBC_2.2.5 54 | ... 55 | } 56 | { 57 | 58 | Memcheck:Addr1 59 | ... 60 | fun:_ZN6google24glog_internal_namespace_26InitGoogleLoggingUtilitiesEPKc 61 | ... 62 | } 63 | { 64 | 65 | Memcheck:Addr1 66 | ... 67 | fun:_ZN6google11LogToStderrEv 68 | ... 69 | } 70 | { 71 | 72 | Memcheck:Addr2 73 | ... 74 | fun:_ZN6google11LogToStderrEv 75 | ... 76 | } 77 | { 78 | 79 | Memcheck:Addr4 80 | ... 81 | fun:_ZN6google11LogToStderrEv 82 | ... 83 | } 84 | { 85 | 86 | Memcheck:Addr8 87 | ... 88 | fun:_ZN6google11LogToStderrEv 89 | ... 90 | } 91 | { 92 | 93 | Memcheck:Leak 94 | ... 95 | fun:_ZN6google11LogToStderrEv 96 | ... 97 | } 98 | { 99 | 100 | Memcheck:Leak 101 | ... 102 | fun:_ZN3fLS25dont_pass0toDEFINE_stringEPcPKc 103 | ... 104 | } 105 | -------------------------------------------------------------------------------- /namespace.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Cornell University 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #ifndef replicant_namespace_h_ 29 | #define replicant_namespace_h_ 30 | 31 | #define BEGIN_REPLICANT_NAMESPACE \ 32 | namespace replicant __attribute__ ((visibility ("hidden"))) { 33 | 34 | #define END_REPLICANT_NAMESPACE } 35 | 36 | #endif // replicant_namespace_h_ 37 | -------------------------------------------------------------------------------- /common/generate_token.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #ifndef replicant_client_generate_token_h_ 29 | #define replicant_client_generate_token_h_ 30 | 31 | // C 32 | #include 33 | 34 | // Replicant 35 | #include "namespace.h" 36 | 37 | BEGIN_REPLICANT_NAMESPACE 38 | 39 | bool 40 | generate_token(uint64_t* token); 41 | 42 | END_REPLICANT_NAMESPACE 43 | 44 | #endif // replicant_client_generate_token_h_ 45 | -------------------------------------------------------------------------------- /common/macros.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #ifndef replicant_common_macros_h_ 29 | #define replicant_common_macros_h_ 30 | 31 | #define _XSTR(x) #x 32 | #define XSTR(x) _XSTR(x) 33 | #define STRINGIFY(x) case (x): lhs << XSTR(x); break 34 | #define CSTRINGIFY(x) case (x): return XSTR(x); 35 | 36 | #define _CONCAT(x, y) x ## y 37 | #define CONCAT(x, y) _CONCAT(x, y) 38 | 39 | #endif // replicant_common_macros_h_ 40 | -------------------------------------------------------------------------------- /common/quorum_calc.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #ifndef replicant_daemon_quorum_calc_h_ 29 | #define replicant_daemon_quorum_calc_h_ 30 | 31 | // C 32 | #include 33 | 34 | // Replicant 35 | #include "namespace.h" 36 | 37 | BEGIN_REPLICANT_NAMESPACE 38 | 39 | inline unsigned 40 | quorum_calc(unsigned size) 41 | { 42 | return size / 2 + 1; 43 | } 44 | 45 | END_REPLICANT_NAMESPACE 46 | 47 | #endif // replicant_daemon_quorum_calc_h_ 48 | -------------------------------------------------------------------------------- /doc/replicant.tex: -------------------------------------------------------------------------------- 1 | \documentclass[10pt,oneside]{book} 2 | 3 | \ifx \HCode\Undef 4 | \newcommand*{\topdir}{.}% 5 | \else 6 | \def\pgfsysdriver{pgfsys-tex4ht.def} 7 | \newcommand*{\topdir}{..}% 8 | \fi 9 | 10 | \usepackage{hyperref} 11 | \usepackage{nameref} 12 | \usepackage{minted} 13 | \usepackage{graphicx} 14 | \usepackage{enumitem} 15 | \usepackage{calc} 16 | \usepackage{ulem} 17 | \usepackage{tikz} 18 | \usepackage{comment} 19 | \usepackage[margin=1in]{geometry} 20 | \usepackage[small,compact]{titlesec} 21 | \usepackage[binary,squaren]{SIunits} 22 | \usetikzlibrary{arrows} 23 | \usetikzlibrary{decorations.markings} 24 | \usepackage{makeidx} 25 | 26 | \makeindex 27 | \AtBeginDocument{\renewcommand{\bibname}{References}} 28 | 29 | \newcommand{\ReplicantVersion}{0.1.dev} 30 | \newcommand{\code}[1]{\texttt{#1}} 31 | 32 | % http://texblog.org/2012/03/21/cross-referencing-list-items/ 33 | \makeatletter 34 | \def\namedlabel#1#2{\begingroup 35 | #2% 36 | \def\@currentlabel{#2}% 37 | \phantomsection\label{#1}\endgroup 38 | } 39 | \makeatother 40 | 41 | \setcounter{secnumdepth}{3} 42 | \setcounter{tocdepth}{2} 43 | 44 | \title{Replicant Reference Manual v\ReplicantVersion} 45 | \author{Replicant Team} 46 | 47 | \newminted{c}{samepage} 48 | \newminted{console}{samepage} 49 | \newminted{go}{samepage} 50 | \newminted{java}{samepage} 51 | \newminted{javascript}{samepage} 52 | \newminted{json}{samepage} 53 | \newminted{pycon}{samepage} 54 | \newminted{python}{samepage} 55 | \newminted{ruby}{samepage} 56 | 57 | \begin{document} 58 | 59 | \frontmatter 60 | \maketitle 61 | \tableofcontents 62 | 63 | \mainmatter 64 | 65 | \part{For Developers} 66 | \label{part:for-developers} 67 | 68 | \part{For Administrators} 69 | \label{part:for-admins} 70 | 71 | \part{API Reference} 72 | \label{part:api-ref} 73 | 74 | \ifx \HCode\Undef % >>>>>>>>>>>>>>>>>>> 75 | \backmatter 76 | 77 | % Index 78 | \clearpage 79 | \addcontentsline{toc}{chapter}{Index} 80 | \printindex 81 | 82 | % References 83 | \clearpage 84 | \addcontentsline{toc}{chapter}{References} 85 | \bibliographystyle{plain} 86 | \bibliography{replicant} 87 | \fi % <<<<<<<<<<<<<<<<<<< 88 | 89 | \end{document} 90 | -------------------------------------------------------------------------------- /client/server_status.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #ifndef replicant_client_server_status_h_ 29 | #define replicant_client_server_status_h_ 30 | 31 | // C 32 | #include 33 | 34 | // Replicant 35 | #include 36 | #include "namespace.h" 37 | 38 | BEGIN_REPLICANT_NAMESPACE 39 | 40 | int 41 | server_status(const char* host, uint16_t port, int timeout, 42 | replicant_returncode* status, 43 | char** human_readable); 44 | 45 | END_REPLICANT_NAMESPACE 46 | 47 | #endif // replicant_client_server_status_h_ 48 | -------------------------------------------------------------------------------- /common/constants.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #ifndef replicant_common_constants_h_ 29 | #define replicant_common_constants_h_ 30 | 31 | #define REPLICANT_MAX_REPLICAS 9 32 | 33 | #define REPLICANT_SLOTS_WINDOW 256 34 | 35 | #define REPLICANT_COMMANDS_TO_LEADER (4 * REPLICANT_SLOTS_WINDOW) 36 | 37 | #define REPLICANT_NONCE_INCREMENT 65536 38 | #define REPLICANT_NONCE_GENERATE_WHEN_FEWER_THAN 256 39 | 40 | #define REPLICANT_SERVER_DRIVEN_NONCE_HISTORY 65536 41 | 42 | #define REPLICANT_MINIMUM_RETRANSMISSION (PO6_SECONDS) 43 | 44 | #endif // replicant_common_constants_h_ 45 | -------------------------------------------------------------------------------- /daemon/slot_type.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | // Replicant 29 | #include "daemon/slot_type.h" 30 | 31 | e::packer 32 | replicant :: operator << (e::packer lhs, const slot_type& rhs) 33 | { 34 | uint8_t mt = static_cast(rhs); 35 | return lhs << mt; 36 | } 37 | 38 | e::unpacker 39 | replicant :: operator >> (e::unpacker lhs, slot_type& rhs) 40 | { 41 | uint8_t mt; 42 | lhs = lhs >> mt; 43 | rhs = static_cast(mt); 44 | return lhs; 45 | } 46 | 47 | size_t 48 | replicant :: pack_size(const slot_type&) 49 | { 50 | return sizeof(uint8_t); 51 | } 52 | -------------------------------------------------------------------------------- /common/packing.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | // Replicant 29 | #include "common/packing.h" 30 | 31 | size_t 32 | replicant ::pack_size(const replicant_returncode&) 33 | { 34 | return e::pack_size(uint16_t()); 35 | } 36 | 37 | e::packer 38 | replicant ::operator << (e::packer lhs, const replicant_returncode& rhs) 39 | { 40 | return lhs << static_cast(rhs); 41 | } 42 | 43 | e::unpacker 44 | replicant ::operator >> (e::unpacker lhs, replicant_returncode& rhs) 45 | { 46 | uint16_t x; 47 | lhs = lhs >> x; 48 | rhs = static_cast(x); 49 | return lhs; 50 | } 51 | -------------------------------------------------------------------------------- /client/controller.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | // Replicant 29 | #include "client/controller.h" 30 | 31 | using replicant::controller; 32 | 33 | controller :: controller(configuration* c) 34 | : m_c(c) 35 | { 36 | } 37 | 38 | controller :: ~controller() throw () 39 | { 40 | } 41 | 42 | po6::net::location 43 | controller :: lookup(uint64_t si) 44 | { 45 | for (size_t i = 0; i < m_c->servers().size(); ++i) 46 | { 47 | if (m_c->servers()[i].id.get() == si) 48 | { 49 | return m_c->servers()[i].bind_to; 50 | } 51 | } 52 | 53 | return po6::net::location(); 54 | } 55 | -------------------------------------------------------------------------------- /test/leader-rotate.gremlin: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env gremlin 2 | 3 | env GLOG_logtostderr 4 | env GLOG_minloglevel 0 5 | env GLOG_logbufsecs 0 6 | 7 | tcp-port 1982 1983 1984 1985 1986 8 | 9 | run mkdir replica0 replica1 replica2 replica3 replica4 10 | 11 | daemon replicant daemon --debug --foreground --data=replica0 --listen 127.0.0.1 --listen-port 1982 12 | daemon replicant daemon --debug --foreground --data=replica1 --listen 127.0.0.1 --listen-port 1983 --connect-port 1982 13 | daemon replicant daemon --debug --foreground --data=replica2 --listen 127.0.0.1 --listen-port 1984 --connect-port 1983 14 | daemon replicant daemon --debug --foreground --data=replica3 --listen 127.0.0.1 --listen-port 1985 --connect-port 1984 15 | daemon replicant daemon --debug --foreground --data=replica4 --listen 127.0.0.1 --listen-port 1986 --connect-port 1985 16 | run replicant server-status --host 127.0.0.1 --port 1982 17 | run replicant server-status --host 127.0.0.1 --port 1983 18 | run replicant server-status --host 127.0.0.1 --port 1984 19 | run replicant server-status --host 127.0.0.1 --port 1985 20 | run replicant server-status --host 127.0.0.1 --port 1986 21 | 22 | kill STOP 0 23 | run sleep 10 24 | kill STOP 1 25 | run sleep 10 26 | kill STOP 2 27 | run sleep 10 28 | kill STOP 3 29 | run sleep 10 30 | kill STOP 4 31 | run sleep 10 32 | 33 | kill CONT 0 34 | run sleep 10 35 | kill CONT 1 36 | run sleep 10 37 | kill CONT 2 38 | run sleep 10 39 | kill CONT 3 40 | run sleep 10 41 | kill CONT 4 42 | run sleep 10 43 | 44 | run replicant server-status --host 127.0.0.1 --port 1982 45 | run replicant server-status --host 127.0.0.1 --port 1983 46 | run replicant server-status --host 127.0.0.1 --port 1984 47 | run replicant server-status --host 127.0.0.1 --port 1985 48 | run replicant server-status --host 127.0.0.1 --port 1986 49 | 50 | kill STOP 0 51 | run sleep 10 52 | kill STOP 1 53 | run sleep 10 54 | kill CONT 0 55 | run sleep 10 56 | kill STOP 2 57 | run sleep 10 58 | kill CONT 1 59 | run sleep 10 60 | kill STOP 3 61 | run sleep 10 62 | kill CONT 2 63 | run sleep 10 64 | kill STOP 4 65 | run sleep 10 66 | kill CONT 3 67 | run sleep 10 68 | kill CONT 4 69 | run sleep 10 70 | 71 | run replicant new-object --host 127.0.0.1 --port 1982 nop ${REPLICANT_BUILDDIR}/.libs/libreplicant-example-nop.so 72 | -------------------------------------------------------------------------------- /common/packing.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #ifndef replicant_common_packing_h_ 29 | #define replicant_common_packing_h_ 30 | 31 | // e 32 | #include 33 | 34 | // Replicant 35 | #include 36 | #include "namespace.h" 37 | 38 | BEGIN_REPLICANT_NAMESPACE 39 | using ::pack_size; 40 | using e::pack_size; 41 | 42 | size_t 43 | pack_size(const replicant_returncode& rhs); 44 | e::packer 45 | operator << (e::packer lhs, const replicant_returncode& rhs); 46 | e::unpacker 47 | operator >> (e::unpacker lhs, replicant_returncode& rhs); 48 | 49 | END_REPLICANT_NAMESPACE 50 | 51 | #endif // replicant_common_packing_h_ 52 | -------------------------------------------------------------------------------- /daemon/rsm.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2015, Robert Escriva 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Replicant nor the names of its contributors may be 13 | * used to endorse or promote products derived from this software without 14 | * specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef replicant_daemon_rsm_h_ 29 | #define replicant_daemon_rsm_h_ 30 | 31 | #ifdef __cplusplus 32 | extern "C" 33 | { 34 | #endif /* __cplusplus */ 35 | 36 | struct object_interface; 37 | 38 | struct rsm_context 39 | { 40 | struct object_interface* obj_int; 41 | int status; 42 | char* output; 43 | size_t output_sz; 44 | }; 45 | 46 | void rsm_context_init(struct rsm_context* ctx, struct object_interface* obj_int); 47 | void rsm_context_finish(struct rsm_context* ctx); 48 | 49 | #ifdef __cplusplus 50 | } /* extern "C" */ 51 | #endif /* __cplusplus */ 52 | #endif /* replicant_daemon_rsm_h_ */ 53 | -------------------------------------------------------------------------------- /common/generate_token.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | // po6 29 | #include 30 | 31 | // BusyBee 32 | #include 33 | 34 | // Replicant 35 | #include "common/generate_token.h" 36 | 37 | bool 38 | replicant :: generate_token(uint64_t* token) 39 | { 40 | po6::io::fd sysrand(open("/dev/urandom", O_RDONLY)); 41 | 42 | if (sysrand.get() < 0) 43 | { 44 | return false; 45 | } 46 | 47 | *token = 0; 48 | 49 | while (*token == 0 || BUSYBEE_IS_ANONYMOUS(*token)) 50 | { 51 | if (sysrand.read(token, sizeof(*token)) != sizeof(*token)) 52 | { 53 | return false; 54 | } 55 | } 56 | 57 | return true; 58 | } 59 | -------------------------------------------------------------------------------- /client/server_selector.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #ifndef replicant_client_server_selector_h_ 29 | #define replicant_client_server_selector_h_ 30 | 31 | // STL 32 | #include 33 | 34 | // Replicant 35 | #include "namespace.h" 36 | #include "common/ids.h" 37 | 38 | BEGIN_REPLICANT_NAMESPACE 39 | 40 | class server_selector 41 | { 42 | public: 43 | server_selector(const std::vector& servers, uint64_t rand); 44 | ~server_selector() throw (); 45 | 46 | public: 47 | server_id next(); 48 | 49 | private: 50 | std::vector m_servers; 51 | size_t m_consumed_idx; 52 | }; 53 | 54 | END_REPLICANT_NAMESPACE 55 | 56 | #endif // replicant_client_server_selector_h_ 57 | -------------------------------------------------------------------------------- /client/pending_robust.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | // Replicant 29 | #include "client/pending_robust.h" 30 | 31 | using replicant::pending_robust; 32 | 33 | pending_robust :: pending_robust(int64_t id, replicant_returncode* st) 34 | : pending(id, st) 35 | , m_command_nonce(0) 36 | , m_min_slot(0) 37 | { 38 | } 39 | 40 | pending_robust :: ~pending_robust() throw () 41 | { 42 | } 43 | 44 | void 45 | pending_robust :: set_params(uint64_t cn, uint64_t ms) 46 | { 47 | m_command_nonce = cn; 48 | m_min_slot = ms; 49 | } 50 | 51 | uint64_t 52 | pending_robust :: command_nonce() const 53 | { 54 | return m_command_nonce; 55 | } 56 | 57 | uint64_t 58 | pending_robust :: min_slot() const 59 | { 60 | return m_min_slot; 61 | } 62 | -------------------------------------------------------------------------------- /common/atomic_io.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #ifndef replicant_common_atomic_io_h_ 29 | #define replicant_common_atomic_io_h_ 30 | 31 | // STL 32 | #include 33 | 34 | // Replicant 35 | #include "namespace.h" 36 | 37 | BEGIN_REPLICANT_NAMESPACE 38 | 39 | // This is called "atomic_read" because it's the read equivalent to 40 | // atomic_write, but it's only atomic wrt calls to atomic_write. 41 | bool 42 | atomic_read(int dir, const char* path, std::string* contents); 43 | 44 | bool 45 | atomic_write(int dir, const char* path, mode_t mode, const std::string& contents); 46 | bool 47 | atomic_write(int dir, const char* path, const std::string& contents); 48 | 49 | END_REPLICANT_NAMESPACE 50 | 51 | #endif // replicant_common_atomic_io_h_ 52 | -------------------------------------------------------------------------------- /daemon/deferred_msg.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #ifndef replicant_deferred_msg_h_ 29 | #define replicant_deferred_msg_h_ 30 | 31 | // Replicant 32 | #include "namespace.h" 33 | #include "common/constants.h" 34 | #include "common/ids.h" 35 | 36 | BEGIN_REPLICANT_NAMESPACE 37 | 38 | struct deferred_msg 39 | { 40 | deferred_msg(uint64_t w, server_id t, e::buffer* m) : when(w), si(t), msg(m) {} 41 | deferred_msg(const deferred_msg& other) : when(other.when), si(other.si), msg(other.msg) {} 42 | ~deferred_msg() throw () {} 43 | 44 | deferred_msg& operator = (const deferred_msg&); 45 | 46 | uint64_t when; 47 | server_id si; 48 | e::buffer* msg; 49 | }; 50 | 51 | END_REPLICANT_NAMESPACE 52 | 53 | #endif // replicant_deferred_msg_h_ 54 | -------------------------------------------------------------------------------- /client/pending.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | // Replicant 29 | #include "client/pending.h" 30 | 31 | using replicant::pending; 32 | 33 | pending :: pending(int64_t id, 34 | replicant_returncode* st) 35 | : m_ref(0) 36 | , m_client_visible_id(id) 37 | , m_status(st) 38 | , m_error() 39 | { 40 | } 41 | 42 | pending :: ~pending() throw () 43 | { 44 | } 45 | 46 | std::ostream& 47 | pending :: error(const char* file, size_t line) 48 | { 49 | m_error.set_loc(file, line); 50 | return m_error.set_msg(); 51 | } 52 | 53 | void 54 | pending :: set_error(const e::error& err) 55 | { 56 | m_error = err; 57 | } 58 | 59 | void 60 | pending :: success() 61 | { 62 | set_status(REPLICANT_SUCCESS); 63 | m_error = e::error(); 64 | } 65 | -------------------------------------------------------------------------------- /daemon/settings.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #ifndef replicant_daemon_settings_h_ 29 | #define replicant_daemon_settings_h_ 30 | 31 | // C 32 | #include 33 | 34 | // e 35 | #include 36 | 37 | // Replicant 38 | #include "namespace.h" 39 | 40 | BEGIN_REPLICANT_NAMESPACE 41 | 42 | class settings 43 | { 44 | public: 45 | settings(); 46 | 47 | public: 48 | uint64_t SUSPECT_TIMEOUT; 49 | uint64_t SUSPECT_STRIKES; 50 | uint64_t DEFEND_TIMEOUT; 51 | }; 52 | 53 | e::packer 54 | operator << (e::packer lhs, const settings& rhs); 55 | e::unpacker 56 | operator >> (e::unpacker lhs, settings& rhs); 57 | size_t 58 | pack_size(const settings& rhs); 59 | 60 | END_REPLICANT_NAMESPACE 61 | 62 | #endif // replicant_daemon_settings_h_ 63 | -------------------------------------------------------------------------------- /common/ids.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2015, Cornell University 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | // Replicant 29 | #include "common/ids.h" 30 | 31 | #define CREATE_ID(TYPE) \ 32 | std::ostream& \ 33 | operator << (std::ostream& lhs, const TYPE ## _id& rhs) \ 34 | { \ 35 | return lhs << #TYPE "(" << rhs.get() << ")"; \ 36 | } \ 37 | e::packer \ 38 | operator << (e::packer pa, const TYPE ## _id& rhs) \ 39 | { \ 40 | return pa << rhs.get(); \ 41 | } \ 42 | e::unpacker \ 43 | operator >> (e::unpacker up, TYPE ## _id& rhs) \ 44 | { \ 45 | uint64_t id; \ 46 | up = up >> id; \ 47 | rhs = TYPE ## _id(id); \ 48 | return up; \ 49 | } 50 | 51 | BEGIN_REPLICANT_NAMESPACE 52 | 53 | CREATE_ID(cluster) 54 | CREATE_ID(version) 55 | CREATE_ID(server) 56 | 57 | END_REPLICANT_NAMESPACE 58 | 59 | #undef CREATE_ID 60 | -------------------------------------------------------------------------------- /examples/nop.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012, Robert Escriva 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Replicant nor the names of its contributors may be 13 | * used to endorse or promote products derived from this software without 14 | * specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* Replicant */ 30 | #include 31 | 32 | void* 33 | nop_create(struct rsm_context* ctx) 34 | { 35 | return (void*) -1; 36 | } 37 | 38 | void* 39 | nop_recreate(struct rsm_context* ctx, 40 | const char* data, size_t data_sz) 41 | { 42 | return (void*) -1; 43 | } 44 | 45 | int 46 | nop_snapshot(struct rsm_context* ctx, 47 | void* obj, 48 | char** data, size_t* data_sz) 49 | { 50 | *data = NULL; 51 | *data_sz = 0; 52 | return 0; 53 | } 54 | 55 | void 56 | nop_nop(struct rsm_context* ctx, 57 | void* obj, 58 | const char* data, size_t data_sz) 59 | { 60 | } 61 | 62 | struct state_machine rsm = { 63 | nop_create, 64 | nop_recreate, 65 | nop_snapshot, 66 | {{"nop", nop_nop}, 67 | {NULL, NULL}} 68 | }; 69 | -------------------------------------------------------------------------------- /client/controller.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012, Robert Escriva 2 | // Copyright (c) 2017, Robert Escriva, Cornell University 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, 9 | // this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above copyright 11 | // notice, this list of conditions and the following disclaimer in the 12 | // documentation and/or other materials provided with the distribution. 13 | // * Neither the name of Replicant nor the names of its contributors may be 14 | // used to endorse or promote products derived from this software without 15 | // specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | // POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #ifndef replicant_client_controller_h_ 30 | #define replicant_client_controller_h_ 31 | 32 | // BusyBee 33 | #include 34 | 35 | // Replicant 36 | #include "namespace.h" 37 | #include "common/configuration.h" 38 | 39 | BEGIN_REPLICANT_NAMESPACE 40 | 41 | class controller : public busybee_controller 42 | { 43 | public: 44 | controller(configuration* c); 45 | ~controller() throw (); 46 | 47 | public: 48 | virtual po6::net::location lookup(uint64_t server_id); 49 | 50 | private: 51 | configuration* m_c; 52 | 53 | private: 54 | controller(const controller&); 55 | controller& operator = (const controller&); 56 | }; 57 | 58 | END_REPLICANT_NAMESPACE 59 | 60 | #endif // replicant_client_controller_h_ 61 | -------------------------------------------------------------------------------- /examples/echo.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012, Robert Escriva 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Replicant nor the names of its contributors may be 13 | * used to endorse or promote products derived from this software without 14 | * specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* Replicant */ 30 | #include 31 | 32 | void* 33 | echo_create(struct rsm_context* ctx) 34 | { 35 | return (void*) -1; 36 | } 37 | 38 | void* 39 | echo_recreate(struct rsm_context* ctx, 40 | const char* data, size_t data_sz) 41 | { 42 | return (void*) -1; 43 | } 44 | 45 | int 46 | echo_snapshot(struct rsm_context* ctx, 47 | void* obj, 48 | char** data, size_t* data_sz) 49 | { 50 | *data = NULL; 51 | *data_sz = 0; 52 | return 0; 53 | } 54 | 55 | void 56 | echo_echo(struct rsm_context* ctx, 57 | void* obj, 58 | const char* data, size_t data_sz) 59 | { 60 | rsm_set_output(ctx, data, data_sz); 61 | } 62 | 63 | struct state_machine rsm = { 64 | echo_create, 65 | echo_recreate, 66 | echo_snapshot, 67 | {{"echo", echo_echo}, 68 | {NULL, NULL}} 69 | }; 70 | -------------------------------------------------------------------------------- /replicant-debug.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012-2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #ifdef HAVE_CONFIG_H 29 | #include "config.h" 30 | #endif 31 | 32 | // STL 33 | #include 34 | 35 | // e 36 | #include 37 | 38 | int 39 | main(int argc, const char* argv[]) 40 | { 41 | std::vector cmds; 42 | cmds.push_back(e::subcommand("call", "Call a particular function on a replicated object")); 43 | cmds.push_back(e::subcommand("condition", "Track the state of a particular condition variable")); 44 | return dispatch_to_subcommands(argc, argv, 45 | "replicant debug", "Replicant", 46 | PACKAGE_VERSION, 47 | "replicant-debug-", 48 | "REPLICANT_EXEC_PATH", REPLICANT_EXEC_DIR, 49 | &cmds.front(), cmds.size()); 50 | } 51 | -------------------------------------------------------------------------------- /client/server_selector.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | // STL 29 | #include 30 | 31 | // Replicant 32 | #include "client/server_selector.h" 33 | 34 | using replicant::server_id; 35 | using replicant::server_selector; 36 | 37 | server_selector :: server_selector(const std::vector& servers, uint64_t rand) 38 | : m_servers(servers) 39 | , m_consumed_idx(0) 40 | { 41 | std::sort(m_servers.begin(), m_servers.end()); 42 | std::vector::iterator it; 43 | it = std::lower_bound(m_servers.begin(), m_servers.end(), server_id(rand)); 44 | std::rotate(m_servers.begin(), it, m_servers.end()); 45 | } 46 | 47 | server_selector :: ~server_selector() throw () 48 | { 49 | } 50 | 51 | server_id 52 | server_selector :: next() 53 | { 54 | if (m_consumed_idx >= m_servers.size()) 55 | { 56 | return server_id(); 57 | } 58 | else 59 | { 60 | return m_servers[m_consumed_idx++]; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /examples/tick.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2013, Robert Escriva 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Replicant nor the names of its contributors may be 13 | * used to endorse or promote products derived from this software without 14 | * specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* Replicant */ 30 | #include 31 | 32 | void* 33 | tick_create(struct rsm_context* ctx) 34 | { 35 | rsm_tick_interval(ctx, "callback", 5); 36 | return (void*) -1; 37 | } 38 | 39 | void* 40 | tick_recreate(struct rsm_context* ctx, 41 | const char* data, size_t data_sz) 42 | { 43 | return (void*) -1; 44 | } 45 | 46 | int 47 | tick_snapshot(struct rsm_context* ctx, 48 | void* obj, 49 | char** data, size_t* data_sz) 50 | { 51 | *data = NULL; 52 | *data_sz = 0; 53 | return 0; 54 | } 55 | 56 | void 57 | tick_callback(struct rsm_context* ctx, 58 | void* obj, 59 | const char* data, size_t data_sz) 60 | { 61 | rsm_log(ctx, "from within the tick callback\n"); 62 | } 63 | 64 | struct state_machine rsm = { 65 | tick_create, 66 | tick_recreate, 67 | tick_snapshot, 68 | {{"callback", tick_callback}, 69 | {NULL, NULL}} 70 | }; 71 | -------------------------------------------------------------------------------- /client/pending_poke.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #ifndef replicant_client_pending_poke_h_ 29 | #define replicant_client_pending_poke_h_ 30 | 31 | // Replicant 32 | #include "client/pending.h" 33 | 34 | BEGIN_REPLICANT_NAMESPACE 35 | 36 | class pending_poke : public pending 37 | { 38 | public: 39 | pending_poke(int64_t client_visible_id, 40 | replicant_returncode* status); 41 | virtual ~pending_poke() throw (); 42 | 43 | public: 44 | virtual std::auto_ptr request(uint64_t nonce); 45 | virtual bool resend_on_failure(); 46 | virtual void handle_response(client* cl, 47 | std::auto_ptr msg, 48 | e::unpacker up); 49 | 50 | private: 51 | pending_poke(const pending_poke&); 52 | pending_poke& operator = (const pending_poke&); 53 | }; 54 | 55 | END_REPLICANT_NAMESPACE 56 | 57 | #endif // replicant_client_pending_poke_h_ 58 | -------------------------------------------------------------------------------- /daemon/slot_type.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #ifndef replicant_daemon_slot_type_h_ 29 | #define replicant_daemon_slot_type_h_ 30 | 31 | // e 32 | #include 33 | 34 | // Replicant 35 | #include "namespace.h" 36 | 37 | BEGIN_REPLICANT_NAMESPACE 38 | 39 | enum slot_type 40 | { 41 | SLOT_SERVER_BECOME_MEMBER = 1, 42 | SLOT_SERVER_SET_GC_THRESH = 2, 43 | SLOT_SERVER_CHANGE_ADDRESS = 10, 44 | SLOT_SERVER_RECORD_STRIKE = 11, 45 | SLOT_INCREMENT_COUNTER = 3, 46 | SLOT_OBJECT_FAILED = 9, 47 | SLOT_OBJECT_REPAIR = 8, 48 | SLOT_TICK = 7, 49 | SLOT_POKE = 4, 50 | SLOT_CALL = 5, 51 | SLOT_NOP = 0 52 | }; 53 | 54 | std::ostream& 55 | operator << (std::ostream& lhs, slot_type rhs); 56 | 57 | e::packer 58 | operator << (e::packer lhs, const slot_type& rhs); 59 | e::unpacker 60 | operator >> (e::unpacker lhs, slot_type& rhs); 61 | size_t 62 | pack_size(const slot_type& rhs); 63 | 64 | END_REPLICANT_NAMESPACE 65 | 66 | #endif // replicant_daemon_slot_type_h_ 67 | -------------------------------------------------------------------------------- /common/server.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2015, Cornell University 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #ifndef replicant_common_server_h_ 29 | #define replicant_common_server_h_ 30 | 31 | // po6 32 | #include 33 | 34 | // Replicant 35 | #include "namespace.h" 36 | #include "common/ids.h" 37 | 38 | BEGIN_REPLICANT_NAMESPACE 39 | 40 | class server 41 | { 42 | public: 43 | server(); 44 | explicit server(server_id id, const po6::net::location& bind_to); 45 | 46 | public: 47 | server_id id; 48 | po6::net::location bind_to; 49 | }; 50 | 51 | bool 52 | operator < (const server& lhs, const server& rhs); 53 | bool 54 | operator == (const server& lhs, const server& rhs); 55 | 56 | std::ostream& 57 | operator << (std::ostream& lhs, const server& rhs); 58 | 59 | e::packer 60 | operator << (e::packer lhs, const server& rhs); 61 | e::unpacker 62 | operator >> (e::unpacker lhs, server& rhs); 63 | size_t 64 | pack_size(const server& rhs); 65 | 66 | END_REPLICANT_NAMESPACE 67 | 68 | #endif // replicant_common_server_h_ 69 | -------------------------------------------------------------------------------- /daemon/settings.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | // Replicant 29 | #include "common/packing.h" 30 | #include "daemon/settings.h" 31 | 32 | #define NANOS 1ULL 33 | #define MICROS (1000ULL * NANOS) 34 | #define MILLIS (1000ULL * MICROS) 35 | #define SECONDS (1000ULL * MILLIS) 36 | 37 | using replicant::settings; 38 | 39 | settings :: settings() 40 | : SUSPECT_TIMEOUT(5 * SECONDS) 41 | , SUSPECT_STRIKES(5) 42 | , DEFEND_TIMEOUT(10) 43 | { 44 | } 45 | 46 | e::packer 47 | replicant :: operator << (e::packer lhs, const settings& rhs) 48 | { 49 | return lhs << rhs.SUSPECT_TIMEOUT 50 | << rhs.SUSPECT_STRIKES 51 | << rhs.DEFEND_TIMEOUT; 52 | } 53 | 54 | e::unpacker 55 | replicant :: operator >> (e::unpacker lhs, settings& rhs) 56 | { 57 | return lhs >> rhs.SUSPECT_TIMEOUT 58 | >> rhs.SUSPECT_STRIKES 59 | >> rhs.DEFEND_TIMEOUT; 60 | } 61 | 62 | size_t 63 | replicant :: pack_size(const settings&) 64 | { 65 | return 3 * pack_size(uint64_t()); 66 | } 67 | -------------------------------------------------------------------------------- /client/pending_poke.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | // BusyBee 29 | #include 30 | 31 | // Replicant 32 | #include "common/network_msgtype.h" 33 | #include "client/pending_poke.h" 34 | 35 | using replicant::pending_poke; 36 | 37 | pending_poke :: pending_poke(int64_t id, replicant_returncode* st) 38 | : pending(id, st) 39 | { 40 | } 41 | 42 | pending_poke :: ~pending_poke() throw () 43 | { 44 | } 45 | 46 | std::auto_ptr 47 | pending_poke :: request(uint64_t nonce) 48 | { 49 | const size_t sz = BUSYBEE_HEADER_SIZE 50 | + pack_size(REPLNET_POKE) 51 | + sizeof(uint64_t); 52 | std::auto_ptr msg(e::buffer::create(sz)); 53 | msg->pack_at(BUSYBEE_HEADER_SIZE) << REPLNET_POKE << nonce; 54 | return msg; 55 | } 56 | 57 | bool 58 | pending_poke :: resend_on_failure() 59 | { 60 | return true; 61 | } 62 | 63 | void 64 | pending_poke :: handle_response(client*, std::auto_ptr, e::unpacker) 65 | { 66 | this->success(); 67 | } 68 | -------------------------------------------------------------------------------- /client/pending_robust.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #ifndef replicant_client_pending_robust_h_ 29 | #define replicant_client_pending_robust_h_ 30 | 31 | // Replicant 32 | #include "client/pending.h" 33 | 34 | BEGIN_REPLICANT_NAMESPACE 35 | 36 | class pending_robust : public pending 37 | { 38 | public: 39 | pending_robust(int64_t client_visible_id, 40 | replicant_returncode* status); 41 | virtual ~pending_robust() throw (); 42 | 43 | public: 44 | void set_params(uint64_t command_nonce, uint64_t min_slot); 45 | uint64_t command_nonce() const; 46 | uint64_t min_slot() const; 47 | 48 | private: 49 | friend class e::intrusive_ptr; 50 | uint64_t m_command_nonce; 51 | uint64_t m_min_slot; 52 | 53 | private: 54 | pending_robust(const pending_robust&); 55 | pending_robust& operator = (const pending_robust&); 56 | }; 57 | 58 | END_REPLICANT_NAMESPACE 59 | 60 | #endif // replicant_client_pending_robust_h_ 61 | -------------------------------------------------------------------------------- /benchmarks/replicant-call/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "os" 7 | "time" 8 | "git.rescrv.net/replicant/bindings/go" 9 | "git.rescrv.net/ygor/bindings/go" 10 | ) 11 | 12 | func consume(errChan chan replicant.Error) { 13 | for e := range errChan { 14 | fmt.Printf("error: %s\n", e) 15 | os.Exit(1) 16 | } 17 | } 18 | 19 | func work(c *replicant.Client, C <-chan time.Time, stop chan bool, done chan bool, dl *ygor.DataLogger) { 20 | defer func() { 21 | done<-true 22 | }() 23 | for { 24 | select { 25 | case <- C: 26 | break 27 | case <- stop: 28 | return 29 | } 30 | start := time.Now() 31 | _, err := c.Call("echo", "echo", []byte("hello world"), 0) 32 | end := time.Now() 33 | if err.Status == replicant.SUCCESS { 34 | when := uint64(end.UnixNano()) 35 | data := uint64(end.Sub(start).Nanoseconds()) 36 | er := dl.Record(1, when, data) 37 | if er != nil { 38 | fmt.Printf("error: %s\n", er) 39 | os.Exit(1) 40 | } 41 | } else { 42 | fmt.Printf("error: %s\n", err) 43 | os.Exit(1) 44 | } 45 | } 46 | } 47 | 48 | func main() { 49 | connStr := flag.String("connect", "127.0.0.1:1982", "cluster connection string") 50 | targetTput := flag.Float64("target", 1000, "target throughput") 51 | maxConcurrent := flag.Int("max-concurrent", 1000, "maximum concurrent operations") 52 | output := flag.String("output", "benchmark.dat.bz2", "benchmark output") 53 | flag.Parse() 54 | ticker := time.NewTicker(time.Second / time.Duration(*targetTput * 1.01)) 55 | stopper := make(chan bool, 1) 56 | done := make(chan bool, *maxConcurrent) 57 | c, er, errChan := replicant.NewClient(*connStr) 58 | if er != nil { 59 | fmt.Printf("error: %s\n", er) 60 | os.Exit(1) 61 | } 62 | dl, err := ygor.NewDataLogger(*output, uint64(time.Millisecond), uint64(time.Microsecond * 100)) 63 | if err != nil { 64 | fmt.Printf("error: %s\n", err) 65 | os.Exit(1) 66 | } 67 | go consume(errChan) 68 | for i := 0; i < *maxConcurrent; i++ { 69 | go work(c, ticker.C, stopper, done, dl) 70 | } 71 | time.Sleep(time.Duration(60) * time.Second) 72 | ticker.Stop() 73 | for i := 0; i < *maxConcurrent; i++ { 74 | stopper<-true 75 | <-done 76 | } 77 | err = dl.FlushAndDestroy() 78 | if err != nil { 79 | fmt.Printf("error: %s\n", err) 80 | os.Exit(1) 81 | } 82 | os.Exit(0) 83 | } 84 | -------------------------------------------------------------------------------- /daemon/controller.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #ifndef replicant_daemon_controller_h_ 29 | #define replicant_daemon_controller_h_ 30 | 31 | // po6 32 | #include 33 | 34 | // BusyBee 35 | #include 36 | 37 | // Replicant 38 | #include "namespace.h" 39 | #include "common/configuration.h" 40 | 41 | BEGIN_REPLICANT_NAMESPACE 42 | 43 | class controller : public busybee_controller 44 | { 45 | public: 46 | controller(po6::threads::mutex* mtx, configuration* c); 47 | ~controller() throw (); 48 | 49 | public: 50 | virtual po6::net::location lookup(uint64_t si); 51 | void add_aux(const server& s); 52 | void clear_aux(); 53 | 54 | private: 55 | po6::threads::mutex* m_mtx; 56 | configuration* m_c; 57 | std::vector m_aux; 58 | 59 | private: 60 | controller(const controller&); 61 | controller& operator = (const controller&); 62 | }; 63 | 64 | END_REPLICANT_NAMESPACE 65 | 66 | #endif // replicant_daemon_controller_h_ 67 | -------------------------------------------------------------------------------- /daemon/failure_tracker.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #ifndef replicant_failure_tracker_h_ 29 | #define replicant_failure_tracker_h_ 30 | 31 | // Replicant 32 | #include "namespace.h" 33 | #include "common/configuration.h" 34 | #include "common/constants.h" 35 | #include "common/ids.h" 36 | 37 | BEGIN_REPLICANT_NAMESPACE 38 | 39 | class failure_tracker 40 | { 41 | public: 42 | failure_tracker(configuration* config); 43 | ~failure_tracker() throw (); 44 | 45 | public: 46 | void set_server_id(server_id us); 47 | void assume_all_alive(); 48 | void proof_of_life(server_id si); 49 | bool suspect_failed(server_id si, uint64_t timeout); 50 | 51 | private: 52 | failure_tracker(const failure_tracker&); 53 | failure_tracker& operator = (const failure_tracker&); 54 | 55 | private: 56 | configuration* m_config; 57 | server_id m_us; 58 | uint64_t m_last_seen[REPLICANT_MAX_REPLICAS]; 59 | }; 60 | 61 | END_REPLICANT_NAMESPACE 62 | 63 | #endif // replicant_failure_tracker_h_ 64 | -------------------------------------------------------------------------------- /test/restart-diff-address.gremlin: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env gremlin 2 | 3 | env GLOG_logtostderr 4 | env GLOG_minloglevel 0 5 | env GLOG_logbufsecs 0 6 | 7 | tcp-port 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 8 | 9 | run mkdir replica0 replica1 replica2 replica3 replica4 10 | 11 | daemon replicant daemon --foreground --data=replica0 --listen 127.0.0.1 --listen-port 1982 12 | daemon replicant daemon --foreground --data=replica1 --listen 127.0.0.1 --listen-port 1983 --connect-port 1982 13 | daemon replicant daemon --foreground --data=replica2 --listen 127.0.0.1 --listen-port 1984 --connect-port 1983 14 | daemon replicant daemon --foreground --data=replica3 --listen 127.0.0.1 --listen-port 1985 --connect-port 1984 15 | daemon replicant daemon --foreground --data=replica4 --listen 127.0.0.1 --listen-port 1986 --connect-port 1985 16 | run replicant server-status --host 127.0.0.1 --port 1982 17 | run replicant server-status --host 127.0.0.1 --port 1983 18 | run replicant server-status --host 127.0.0.1 --port 1984 19 | run replicant server-status --host 127.0.0.1 --port 1985 20 | run replicant server-status --host 127.0.0.1 --port 1986 21 | 22 | run replicant new-object --host 127.0.0.1 --port 1982 nop1 ${REPLICANT_BUILDDIR}/.libs/libreplicant-example-nop.so 23 | 24 | kill TERM 0 25 | kill TERM 1 26 | kill TERM 2 27 | kill TERM 3 28 | kill TERM 4 29 | 30 | run sleep 10 31 | 32 | daemon replicant daemon --foreground --data=replica0 --listen 127.0.0.1 --listen-port 1987 --connect-string 127.0.0.1:1987,127.0.0.1:1988,127.0.0.1:1989,127.0.0.1:1990,127.0.0.1:1991 33 | daemon replicant daemon --foreground --data=replica1 --listen 127.0.0.1 --listen-port 1988 --connect-string 127.0.0.1:1987,127.0.0.1:1988,127.0.0.1:1989,127.0.0.1:1990,127.0.0.1:1991 34 | daemon replicant daemon --foreground --data=replica2 --listen 127.0.0.1 --listen-port 1989 --connect-string 127.0.0.1:1987,127.0.0.1:1988,127.0.0.1:1989,127.0.0.1:1990,127.0.0.1:1991 35 | daemon replicant daemon --foreground --data=replica3 --listen 127.0.0.1 --listen-port 1990 --connect-string 127.0.0.1:1987,127.0.0.1:1988,127.0.0.1:1989,127.0.0.1:1990,127.0.0.1:1991 36 | daemon replicant daemon --foreground --data=replica4 --listen 127.0.0.1 --listen-port 1991 --connect-string 127.0.0.1:1987,127.0.0.1:1988,127.0.0.1:1989,127.0.0.1:1990,127.0.0.1:1991 37 | 38 | run sleep 10 39 | 40 | run replicant new-object --host 127.0.0.1 --port 1987 nop2 ${REPLICANT_BUILDDIR}/.libs/libreplicant-example-nop.so 41 | 42 | run replicant server-status --host 127.0.0.1 --port 1987 43 | run replicant server-status --host 127.0.0.1 --port 1988 44 | run replicant server-status --host 127.0.0.1 --port 1989 45 | run replicant server-status --host 127.0.0.1 --port 1990 46 | run replicant server-status --host 127.0.0.1 --port 1991 47 | -------------------------------------------------------------------------------- /examples/condition.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012, Robert Escriva 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Replicant nor the names of its contributors may be 13 | * used to endorse or promote products derived from this software without 14 | * specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* C */ 30 | #include 31 | #include 32 | 33 | /* Replicant */ 34 | #include 35 | 36 | void* 37 | condition_create(struct rsm_context* ctx) 38 | { 39 | rsm_cond_create(ctx, "cond"); 40 | return (void*) -1; 41 | } 42 | 43 | void* 44 | condition_recreate(struct rsm_context* ctx, 45 | const char* data, size_t data_sz) 46 | { 47 | return (void*) -1; 48 | } 49 | 50 | int 51 | condition_snapshot(struct rsm_context* ctx, 52 | void* obj, 53 | char** data, size_t* data_sz) 54 | { 55 | *data = NULL; 56 | *data_sz = 0; 57 | return 0; 58 | } 59 | 60 | void 61 | condition_broadcast(struct rsm_context* ctx, 62 | void* obj, 63 | const char* data, size_t data_sz) 64 | { 65 | rsm_cond_broadcast_data(ctx, "cond", data, data_sz); 66 | } 67 | 68 | struct state_machine rsm = { 69 | condition_create, 70 | condition_recreate, 71 | condition_snapshot, 72 | {{"broadcast", condition_broadcast}, 73 | {NULL, NULL}} 74 | }; 75 | -------------------------------------------------------------------------------- /daemon/commander.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #ifndef replicant_daemon_commander_h_ 29 | #define replicant_daemon_commander_h_ 30 | 31 | // Replicant 32 | #include "namespace.h" 33 | #include "common/constants.h" 34 | #include "daemon/pvalue.h" 35 | 36 | BEGIN_REPLICANT_NAMESPACE 37 | 38 | class commander 39 | { 40 | public: 41 | commander(const pvalue& pval); 42 | commander(const commander&); 43 | ~commander() throw (); 44 | 45 | public: 46 | const pvalue& pval() const { return m_pval; } 47 | void set_ballot(const ballot& b) { m_pval.b = b; } 48 | bool accepted_by(server_id si); 49 | void accept(server_id si); 50 | size_t accepted(); 51 | uint64_t timestamp(unsigned idx); 52 | void timestamp(unsigned idx, uint64_t ts); 53 | 54 | public: 55 | commander& operator = (const commander&); 56 | 57 | private: 58 | pvalue m_pval; 59 | std::vector m_accepted_by; 60 | uint64_t m_timestamps[REPLICANT_MAX_REPLICAS]; 61 | }; 62 | 63 | END_REPLICANT_NAMESPACE 64 | 65 | #endif // replicant_daemon_commander_h_ 66 | -------------------------------------------------------------------------------- /daemon/unordered_command.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | // Replicant 29 | #include "daemon/unordered_command.h" 30 | 31 | using replicant::unordered_command; 32 | 33 | unordered_command :: unordered_command(server_id obo, 34 | uint64_t rn, 35 | slot_type t, 36 | const std::string& c) 37 | : m_on_behalf_of(obo) 38 | , m_request_nonce(rn) 39 | , m_type(t) 40 | , m_command(c) 41 | , m_command_nonce(0) 42 | , m_last_used_ballot() 43 | , m_lowest_possible_slot(0) 44 | , m_robust(false) 45 | { 46 | } 47 | 48 | unordered_command :: ~unordered_command() throw () 49 | { 50 | } 51 | 52 | void 53 | unordered_command :: set_command_nonce(uint64_t cn) 54 | { 55 | assert(m_command_nonce == 0); 56 | m_command_nonce = cn; 57 | } 58 | 59 | void 60 | unordered_command :: set_last_used_ballot(const ballot& b) 61 | { 62 | m_last_used_ballot = b; 63 | } 64 | 65 | void 66 | unordered_command :: set_lowest_possible_slot(uint64_t slot) 67 | { 68 | assert(!m_robust); 69 | assert(m_lowest_possible_slot <= slot); 70 | m_lowest_possible_slot = slot; 71 | } 72 | -------------------------------------------------------------------------------- /tools/new-object.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #define __STDC_LIMIT_MACROS 29 | 30 | // Replicant 31 | #include 32 | #include "tools/common.h" 33 | 34 | int 35 | main(int argc, const char* argv[]) 36 | { 37 | connect_opts conn; 38 | e::argparser ap; 39 | ap.autohelp(); 40 | ap.option_string("[OPTIONS] "); 41 | ap.add("Connect to a cluster:", conn.parser()); 42 | 43 | if (!ap.parse(argc, argv)) 44 | { 45 | return EXIT_FAILURE; 46 | } 47 | 48 | if (ap.args_sz() != 2) 49 | { 50 | std::cerr << "command requires the object name and library path\n" << std::endl; 51 | ap.usage(); 52 | return EXIT_FAILURE; 53 | } 54 | 55 | if (!conn.validate()) 56 | { 57 | std::cerr << "invalid host:port specification\n" << std::endl; 58 | ap.usage(); 59 | return EXIT_FAILURE; 60 | } 61 | 62 | replicant_client* r = replicant_client_create(conn.host(), conn.port()); 63 | replicant_returncode re = REPLICANT_GARBAGE; 64 | int64_t rid = replicant_client_new_object(r, ap.args()[0], ap.args()[1], &re); 65 | int ret = cli_finish(r, rid, &re) ? EXIT_SUCCESS : EXIT_FAILURE; 66 | replicant_client_destroy(r); 67 | return ret; 68 | } 69 | -------------------------------------------------------------------------------- /common/server.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2015, Cornell University 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | // e 29 | #include 30 | 31 | // Replicant 32 | #include "common/packing.h" 33 | #include "common/server.h" 34 | 35 | using replicant::server; 36 | 37 | server :: server() 38 | : id() 39 | , bind_to() 40 | { 41 | } 42 | 43 | server :: server(server_id sid, const po6::net::location& bt) 44 | : id(sid) 45 | , bind_to(bt) 46 | { 47 | } 48 | 49 | bool 50 | replicant :: operator < (const server& lhs, const server& rhs) 51 | { 52 | return lhs.id < rhs.id; 53 | } 54 | 55 | bool 56 | replicant :: operator == (const server& lhs, const server& rhs) 57 | { 58 | return lhs.id == rhs.id; 59 | } 60 | 61 | std::ostream& 62 | replicant :: operator << (std::ostream& lhs, const server& rhs) 63 | { 64 | return lhs << "server(id=" << rhs.id.get() << ", bind_to=" << rhs.bind_to << ")"; 65 | } 66 | 67 | e::packer 68 | replicant :: operator << (e::packer lhs, const server& rhs) 69 | { 70 | return lhs << rhs.id << rhs.bind_to; 71 | } 72 | 73 | e::unpacker 74 | replicant :: operator >> (e::unpacker lhs, server& rhs) 75 | { 76 | return lhs >> rhs.id >> rhs.bind_to; 77 | } 78 | 79 | size_t 80 | replicant :: pack_size(const server& rhs) 81 | { 82 | return pack_size(rhs.id) + pack_size(rhs.bind_to); 83 | } 84 | -------------------------------------------------------------------------------- /client/pending_generate_unique_number.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #ifndef replicant_client_pending_generate_unique_number_h_ 29 | #define replicant_client_pending_generate_unique_number_h_ 30 | 31 | // Replicant 32 | #include "client/pending.h" 33 | 34 | BEGIN_REPLICANT_NAMESPACE 35 | 36 | class pending_generate_unique_number : public pending 37 | { 38 | public: 39 | pending_generate_unique_number(int64_t client_visible_id, 40 | replicant_returncode* status, 41 | uint64_t* number); 42 | virtual ~pending_generate_unique_number() throw (); 43 | 44 | public: 45 | virtual std::auto_ptr request(uint64_t nonce); 46 | virtual bool resend_on_failure(); 47 | virtual void handle_response(client* cl, 48 | std::auto_ptr msg, 49 | e::unpacker up); 50 | 51 | private: 52 | uint64_t* m_number; 53 | 54 | private: 55 | pending_generate_unique_number(const pending_generate_unique_number&); 56 | pending_generate_unique_number& operator = (const pending_generate_unique_number&); 57 | }; 58 | 59 | END_REPLICANT_NAMESPACE 60 | 61 | #endif // replicant_client_pending_generate_unique_number_h_ 62 | -------------------------------------------------------------------------------- /daemon/ballot.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #ifndef replicant_daemon_ballot_h_ 29 | #define replicant_daemon_ballot_h_ 30 | 31 | // Replicant 32 | #include "namespace.h" 33 | #include "common/ids.h" 34 | 35 | BEGIN_REPLICANT_NAMESPACE 36 | 37 | class ballot 38 | { 39 | public: 40 | ballot(); 41 | ballot(uint64_t number, server_id leader); 42 | ballot(const ballot& other); 43 | ~ballot() throw (); 44 | 45 | public: 46 | ballot& operator = (const ballot& rhs); 47 | 48 | public: 49 | uint64_t number; 50 | server_id leader; 51 | }; 52 | 53 | int 54 | compare(const ballot& lhs, const ballot& rhs); 55 | 56 | bool operator < (const ballot& lhs, const ballot& rhs); 57 | bool operator <= (const ballot& lhs, const ballot& rhs); 58 | bool operator == (const ballot& lhs, const ballot& rhs); 59 | bool operator != (const ballot& lhs, const ballot& rhs); 60 | bool operator >= (const ballot& lhs, const ballot& rhs); 61 | bool operator > (const ballot& lhs, const ballot& rhs); 62 | 63 | std::ostream& 64 | operator << (std::ostream& lhs, const ballot& rhs); 65 | 66 | e::packer 67 | operator << (e::packer lhs, const ballot& rhs); 68 | e::unpacker 69 | operator >> (e::unpacker lhs, ballot& rhs); 70 | size_t 71 | pack_size(const ballot& p); 72 | 73 | END_REPLICANT_NAMESPACE 74 | 75 | #endif // replicant_daemon_ballot_h_ 76 | -------------------------------------------------------------------------------- /tools/poke.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #define __STDC_LIMIT_MACROS 29 | 30 | // Replicant 31 | #include 32 | #include "tools/common.h" 33 | 34 | int 35 | main(int argc, const char* argv[]) 36 | { 37 | connect_opts conn; 38 | e::argparser ap; 39 | ap.autohelp(); 40 | ap.option_string("[OPTIONS]"); 41 | ap.add("Connect to a cluster:", conn.parser()); 42 | 43 | if (!ap.parse(argc, argv)) 44 | { 45 | return EXIT_FAILURE; 46 | } 47 | 48 | if (ap.args_sz() != 0) 49 | { 50 | std::cerr << "command takes no positional arguments\n" << std::endl; 51 | ap.usage(); 52 | return EXIT_FAILURE; 53 | } 54 | 55 | if (!conn.validate()) 56 | { 57 | std::cerr << "invalid host:port specification\n" << std::endl; 58 | ap.usage(); 59 | return EXIT_FAILURE; 60 | } 61 | 62 | try 63 | { 64 | replicant_client* r = replicant_client_create(conn.host(), conn.port()); 65 | replicant_returncode re = REPLICANT_GARBAGE; 66 | int64_t rid = replicant_client_poke(r, &re); 67 | 68 | if (!cli_finish(r, rid, &re)) 69 | { 70 | return EXIT_FAILURE; 71 | } 72 | 73 | return EXIT_SUCCESS; 74 | } 75 | catch (std::exception& e) 76 | { 77 | std::cerr << "error: " << e.what() << std::endl; 78 | return EXIT_FAILURE; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /client/pending_cond_wait.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #ifndef replicant_client_pending_cond_wait_h_ 29 | #define replicant_client_pending_cond_wait_h_ 30 | 31 | // Replicant 32 | #include "client/pending.h" 33 | 34 | BEGIN_REPLICANT_NAMESPACE 35 | 36 | class pending_cond_wait : public pending 37 | { 38 | public: 39 | pending_cond_wait(int64_t client_visible_id, 40 | const char* object, const char* cond, 41 | uint64_t state, 42 | replicant_returncode* status, 43 | char** data, size_t* data_sz); 44 | virtual ~pending_cond_wait() throw (); 45 | 46 | public: 47 | virtual std::auto_ptr request(uint64_t nonce); 48 | virtual bool resend_on_failure(); 49 | virtual void handle_response(client* cl, 50 | std::auto_ptr msg, 51 | e::unpacker up); 52 | 53 | private: 54 | const std::string m_object; 55 | const std::string m_cond; 56 | const uint64_t m_state; 57 | char** const m_data; 58 | size_t* const m_data_sz; 59 | 60 | private: 61 | pending_cond_wait(const pending_cond_wait&); 62 | pending_cond_wait& operator = (const pending_cond_wait&); 63 | }; 64 | 65 | END_REPLICANT_NAMESPACE 66 | 67 | #endif // replicant_client_pending_cond_wait_h_ 68 | -------------------------------------------------------------------------------- /daemon/pvalue.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #ifndef replicant_daemon_pvalue_h_ 29 | #define replicant_daemon_pvalue_h_ 30 | 31 | // Replicant 32 | #include "namespace.h" 33 | #include "common/ids.h" 34 | #include "daemon/ballot.h" 35 | 36 | BEGIN_REPLICANT_NAMESPACE 37 | 38 | class pvalue 39 | { 40 | public: 41 | pvalue(); 42 | pvalue(const ballot& b, uint64_t s, const std::string& c); 43 | pvalue(const pvalue& other); 44 | ~pvalue() throw (); 45 | 46 | public: 47 | pvalue& operator = (const pvalue& rhs); 48 | 49 | public: 50 | ballot b; 51 | uint64_t s; 52 | std::string c; 53 | }; 54 | 55 | int 56 | compare(const pvalue& lhs, const pvalue& rhs); 57 | 58 | bool operator < (const pvalue& lhs, const pvalue& rhs); 59 | bool operator <= (const pvalue& lhs, const pvalue& rhs); 60 | bool operator == (const pvalue& lhs, const pvalue& rhs); 61 | bool operator != (const pvalue& lhs, const pvalue& rhs); 62 | bool operator >= (const pvalue& lhs, const pvalue& rhs); 63 | bool operator > (const pvalue& lhs, const pvalue& rhs); 64 | 65 | std::ostream& 66 | operator << (std::ostream& lhs, const pvalue& rhs); 67 | 68 | size_t 69 | pack_size(const pvalue& p); 70 | e::packer 71 | operator << (e::packer lhs, const pvalue& rhs); 72 | e::unpacker 73 | operator >> (e::unpacker lhs, pvalue& rhs); 74 | 75 | END_REPLICANT_NAMESPACE 76 | 77 | #endif // replicant_daemon_pvalue_h_ 78 | -------------------------------------------------------------------------------- /tools/del-object.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #define __STDC_LIMIT_MACROS 29 | 30 | // Replicant 31 | #include 32 | #include "tools/common.h" 33 | 34 | int 35 | main(int argc, const char* argv[]) 36 | { 37 | connect_opts conn; 38 | e::argparser ap; 39 | ap.autohelp(); 40 | ap.option_string("[OPTIONS] "); 41 | ap.add("Connect to a cluster:", conn.parser()); 42 | 43 | if (!ap.parse(argc, argv)) 44 | { 45 | return EXIT_FAILURE; 46 | } 47 | 48 | if (ap.args_sz() != 1) 49 | { 50 | std::cerr << "command requires the object name\n" << std::endl; 51 | ap.usage(); 52 | return EXIT_FAILURE; 53 | } 54 | 55 | if (!conn.validate()) 56 | { 57 | std::cerr << "invalid host:port specification\n" << std::endl; 58 | ap.usage(); 59 | return EXIT_FAILURE; 60 | } 61 | 62 | try 63 | { 64 | replicant_client* r = replicant_client_create(conn.host(), conn.port()); 65 | replicant_returncode re = REPLICANT_GARBAGE; 66 | int64_t rid = replicant_client_del_object(r, ap.args()[0], &re); 67 | 68 | if (!cli_finish(r, rid, &re)) 69 | { 70 | return EXIT_FAILURE; 71 | } 72 | 73 | return EXIT_SUCCESS; 74 | } 75 | catch (std::exception& e) 76 | { 77 | std::cerr << "error: " << e.what() << std::endl; 78 | return EXIT_FAILURE; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /tools/kill-object.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #define __STDC_LIMIT_MACROS 29 | 30 | // Replicant 31 | #include 32 | #include "tools/common.h" 33 | 34 | int 35 | main(int argc, const char* argv[]) 36 | { 37 | connect_opts conn; 38 | e::argparser ap; 39 | ap.autohelp(); 40 | ap.option_string("[OPTIONS] "); 41 | ap.add("Connect to a cluster:", conn.parser()); 42 | 43 | if (!ap.parse(argc, argv)) 44 | { 45 | return EXIT_FAILURE; 46 | } 47 | 48 | if (ap.args_sz() != 1) 49 | { 50 | std::cerr << "command takes the object's name as an argument\n" << std::endl; 51 | ap.usage(); 52 | return EXIT_FAILURE; 53 | } 54 | 55 | if (!conn.validate()) 56 | { 57 | std::cerr << "invalid host:port specification\n" << std::endl; 58 | ap.usage(); 59 | return EXIT_FAILURE; 60 | } 61 | 62 | try 63 | { 64 | replicant_client* r = replicant_client_create(conn.host(), conn.port()); 65 | replicant_returncode re = REPLICANT_GARBAGE; 66 | int64_t rid = replicant_client_kill_object(r, ap.args()[0], &re); 67 | 68 | if (!cli_finish(r, rid, &re)) 69 | { 70 | return EXIT_FAILURE; 71 | } 72 | 73 | return EXIT_SUCCESS; 74 | } 75 | catch (std::exception& e) 76 | { 77 | std::cerr << "error: " << e.what() << std::endl; 78 | return EXIT_FAILURE; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /client/pending_call.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #ifndef replicant_client_pending_call_h_ 29 | #define replicant_client_pending_call_h_ 30 | 31 | // Replicant 32 | #include "client/pending.h" 33 | 34 | BEGIN_REPLICANT_NAMESPACE 35 | 36 | class pending_call : public pending 37 | { 38 | public: 39 | pending_call(int64_t id, 40 | const char* object, 41 | const char* func, 42 | const char* input, size_t input_sz, 43 | bool idempotent, 44 | replicant_returncode* status, 45 | char** output, size_t* output_sz); 46 | virtual ~pending_call() throw (); 47 | 48 | public: 49 | virtual std::auto_ptr request(uint64_t nonce); 50 | virtual bool resend_on_failure(); 51 | virtual void handle_response(client* cl, 52 | std::auto_ptr msg, 53 | e::unpacker up); 54 | 55 | private: 56 | const std::string m_object; 57 | const std::string m_func; 58 | const std::string m_input; 59 | const bool m_idempotent; 60 | char** m_output; 61 | size_t* m_output_sz; 62 | 63 | private: 64 | pending_call(const pending_call&); 65 | pending_call& operator = (const pending_call&); 66 | }; 67 | 68 | END_REPLICANT_NAMESPACE 69 | 70 | #endif // replicant_client_pending_call_h_ 71 | -------------------------------------------------------------------------------- /common/atomic_io.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | // POSIX 29 | #include 30 | #include 31 | #include 32 | 33 | // po6 34 | #include 35 | 36 | // Replicant 37 | #include "common/atomic_io.h" 38 | 39 | bool 40 | replicant :: atomic_read(int dir, const char* path, std::string* contents) 41 | { 42 | contents->clear(); 43 | po6::io::fd fd(openat(dir, path, O_RDONLY)); 44 | 45 | if (fd.get() < 0) 46 | { 47 | return false; 48 | } 49 | 50 | char buf[512]; 51 | ssize_t amt; 52 | 53 | while ((amt = fd.xread(buf, 512)) > 0) 54 | { 55 | contents->append(buf, amt); 56 | } 57 | 58 | if (amt < 0) 59 | { 60 | return false; 61 | } 62 | 63 | return true; 64 | } 65 | 66 | bool 67 | replicant :: atomic_write(int dir, const char* path, mode_t mode, const std::string& contents) 68 | { 69 | po6::io::fd fd(openat(dir, ".atomic.tmp", O_WRONLY|O_CREAT|O_TRUNC, mode)); 70 | return fd.get() >= 0 && 71 | fd.xwrite(contents.data(), contents.size()) == ssize_t(contents.size()) && 72 | fsync(fd.get()) >= 0 && 73 | (dir == AT_FDCWD || fsync(dir) >= 0) && 74 | renameat(dir, ".atomic.tmp", dir, path) >= 0 && 75 | (dir == AT_FDCWD || fsync(dir) >= 0); 76 | } 77 | 78 | bool 79 | replicant :: atomic_write(int dir, const char* path, const std::string& contents) 80 | { 81 | return atomic_write(dir, path, S_IRUSR|S_IWUSR, contents); 82 | } 83 | -------------------------------------------------------------------------------- /client/pending_call_robust.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #ifndef replicant_client_pending_call_robust_h_ 29 | #define replicant_client_pending_call_robust_h_ 30 | 31 | // Replicant 32 | #include "client/pending_robust.h" 33 | 34 | BEGIN_REPLICANT_NAMESPACE 35 | 36 | class pending_call_robust : public pending_robust 37 | { 38 | public: 39 | pending_call_robust(int64_t id, 40 | const char* object, 41 | const char* func, 42 | const char* input, size_t input_sz, 43 | replicant_returncode* status, 44 | char** output, size_t* output_sz); 45 | virtual ~pending_call_robust() throw (); 46 | 47 | public: 48 | virtual std::auto_ptr request(uint64_t nonce); 49 | virtual bool resend_on_failure(); 50 | virtual void handle_response(client* cl, 51 | std::auto_ptr msg, 52 | e::unpacker up); 53 | 54 | private: 55 | const std::string m_object; 56 | const std::string m_func; 57 | const std::string m_input; 58 | char** m_output; 59 | size_t* m_output_sz; 60 | 61 | private: 62 | pending_call_robust(const pending_call_robust&); 63 | pending_call_robust& operator = (const pending_call_robust&); 64 | }; 65 | 66 | END_REPLICANT_NAMESPACE 67 | 68 | #endif // replicant_client_pending_call_robust_h_ 69 | -------------------------------------------------------------------------------- /tools/conn-str.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #define __STDC_LIMIT_MACROS 29 | 30 | // Replicant 31 | #include 32 | #include "tools/common.h" 33 | 34 | int 35 | main(int argc, const char* argv[]) 36 | { 37 | connect_opts conn; 38 | e::argparser ap; 39 | ap.autohelp(); 40 | ap.option_string("[OPTIONS]"); 41 | ap.add("Connect to a cluster:", conn.parser()); 42 | 43 | if (!ap.parse(argc, argv)) 44 | { 45 | return EXIT_FAILURE; 46 | } 47 | 48 | if (ap.args_sz() != 0) 49 | { 50 | std::cerr << "command takes no positional arguments\n" << std::endl; 51 | ap.usage(); 52 | return EXIT_FAILURE; 53 | } 54 | 55 | if (!conn.validate()) 56 | { 57 | std::cerr << "invalid host:port specification\n" << std::endl; 58 | ap.usage(); 59 | return EXIT_FAILURE; 60 | } 61 | 62 | try 63 | { 64 | replicant_client* r = replicant_client_create(conn.host(), conn.port()); 65 | replicant_returncode re = REPLICANT_GARBAGE; 66 | char* str = NULL; 67 | 68 | if (replicant_client_conn_str(r, &re, &str) < 0) 69 | { 70 | cli_log_error(r, re); 71 | return EXIT_FAILURE; 72 | } 73 | 74 | std::cout << str << std::endl; 75 | free(str); 76 | return EXIT_SUCCESS; 77 | } 78 | catch (std::exception& e) 79 | { 80 | std::cerr << "error: " << e.what() << std::endl; 81 | return EXIT_FAILURE; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /tools/generate-unique-number.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #define __STDC_LIMIT_MACROS 29 | 30 | // Replicant 31 | #include 32 | #include "tools/common.h" 33 | 34 | int 35 | main(int argc, const char* argv[]) 36 | { 37 | connect_opts conn; 38 | e::argparser ap; 39 | ap.autohelp(); 40 | ap.option_string("[OPTIONS]"); 41 | ap.add("Connect to a cluster:", conn.parser()); 42 | 43 | if (!ap.parse(argc, argv)) 44 | { 45 | return EXIT_FAILURE; 46 | } 47 | 48 | if (ap.args_sz() != 0) 49 | { 50 | std::cerr << "command takes no positional arguments\n" << std::endl; 51 | ap.usage(); 52 | return EXIT_FAILURE; 53 | } 54 | 55 | if (!conn.validate()) 56 | { 57 | std::cerr << "invalid host:port specification\n" << std::endl; 58 | ap.usage(); 59 | return EXIT_FAILURE; 60 | } 61 | 62 | try 63 | { 64 | uint64_t number = 0; 65 | replicant_client* r = replicant_client_create(conn.host(), conn.port()); 66 | replicant_returncode re = REPLICANT_GARBAGE; 67 | int64_t rid = replicant_client_generate_unique_number(r, &re, &number); 68 | 69 | if (!cli_finish(r, rid, &re)) 70 | { 71 | return EXIT_FAILURE; 72 | } 73 | 74 | std::cout << number << std::endl; 75 | return EXIT_SUCCESS; 76 | } 77 | catch (std::exception& e) 78 | { 79 | std::cerr << "error: " << e.what() << std::endl; 80 | return EXIT_FAILURE; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /tools/list-objects.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #define __STDC_LIMIT_MACROS 29 | 30 | // Replicant 31 | #include 32 | #include "tools/common.h" 33 | 34 | int 35 | main(int argc, const char* argv[]) 36 | { 37 | connect_opts conn; 38 | e::argparser ap; 39 | ap.autohelp(); 40 | ap.option_string("[OPTIONS]"); 41 | ap.add("Connect to a cluster:", conn.parser()); 42 | 43 | if (!ap.parse(argc, argv)) 44 | { 45 | return EXIT_FAILURE; 46 | } 47 | 48 | if (ap.args_sz() != 0) 49 | { 50 | std::cerr << "command takes no positional arguments\n" << std::endl; 51 | ap.usage(); 52 | return EXIT_FAILURE; 53 | } 54 | 55 | if (!conn.validate()) 56 | { 57 | std::cerr << "invalid host:port specification\n" << std::endl; 58 | ap.usage(); 59 | return EXIT_FAILURE; 60 | } 61 | 62 | try 63 | { 64 | replicant_client* r = replicant_client_create(conn.host(), conn.port()); 65 | replicant_returncode re = REPLICANT_GARBAGE; 66 | char* objects = NULL; 67 | int64_t rid = replicant_client_list_objects(r, &re, &objects); 68 | 69 | if (!cli_finish(r, rid, &re)) 70 | { 71 | return EXIT_FAILURE; 72 | } 73 | 74 | std::cout << objects; 75 | free(objects); 76 | return EXIT_SUCCESS; 77 | } 78 | catch (std::exception& e) 79 | { 80 | std::cerr << "error: " << e.what() << std::endl; 81 | return EXIT_FAILURE; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /client/server_status.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | // Replicant 28 | #include "common/bootstrap.h" 29 | #include "common/configuration.h" 30 | #include "client/server_status.h" 31 | 32 | int 33 | replicant :: server_status(const char* host, uint16_t port, int timeout, 34 | replicant_returncode* status, 35 | char** human_readable) 36 | { 37 | *status = REPLICANT_INTERNAL; 38 | *human_readable = NULL; 39 | bootstrap bs(host, port); 40 | 41 | if (!bs.valid()) 42 | { 43 | *status = REPLICANT_COMM_FAILED; 44 | *human_readable = strdup("invalid host/port combination"); 45 | 46 | if (!*human_readable) 47 | { 48 | *status = REPLICANT_SEE_ERRNO; 49 | } 50 | 51 | return -1; 52 | } 53 | 54 | configuration c; 55 | e::error e; 56 | *status = bs.do_it(timeout, &c, &e); 57 | 58 | if (*status != REPLICANT_SUCCESS) 59 | { 60 | *human_readable = strdup(e.msg()); 61 | 62 | if (!*human_readable) 63 | { 64 | *status = REPLICANT_SEE_ERRNO; 65 | } 66 | 67 | return -1; 68 | } 69 | 70 | std::ostringstream ostr; 71 | ostr << "cluster: " << c.cluster().get() << " version " << c.version().get() << "\n" 72 | << "bootstrap: " << c.current_bootstrap().conn_str() << "\n"; 73 | 74 | *human_readable = strdup(ostr.str().c_str()); 75 | 76 | if (!*human_readable) 77 | { 78 | *status = REPLICANT_SEE_ERRNO; 79 | } 80 | 81 | return 0; 82 | } 83 | -------------------------------------------------------------------------------- /daemon/condition.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #ifndef replicant_daemon_condition_h_ 29 | #define replicant_daemon_condition_h_ 30 | 31 | // C 32 | #include 33 | 34 | // STL 35 | #include 36 | 37 | // Replicant 38 | #include "namespace.h" 39 | 40 | BEGIN_REPLICANT_NAMESPACE 41 | class daemon; 42 | 43 | class condition 44 | { 45 | public: 46 | condition(); 47 | condition(uint64_t initial); 48 | ~condition() throw (); 49 | 50 | public: 51 | void wait(daemon* d, server_id si, uint64_t nonce, uint64_t state); 52 | void broadcast(daemon* d); 53 | void broadcast(daemon* d, const char* data, size_t data_sz); 54 | uint64_t peek_state() const; 55 | void peek_state(uint64_t* state, const char** data, size_t* data_sz) const; 56 | 57 | private: 58 | struct waiter; 59 | uint64_t m_state; 60 | std::string m_data; 61 | std::vector m_waiters; 62 | 63 | private: 64 | friend e::packer operator << (e::packer lhs, const condition& rhs); 65 | friend e::unpacker operator >> (e::unpacker lhs, condition& rhs); 66 | friend size_t pack_size(const condition& rhs); 67 | 68 | private: 69 | condition(const condition&); 70 | condition& operator = (const condition&); 71 | }; 72 | 73 | e::packer 74 | operator << (e::packer lhs, const condition& rhs); 75 | e::unpacker 76 | operator >> (e::unpacker lhs, condition& rhs); 77 | size_t 78 | pack_size(const condition& rhs); 79 | 80 | END_REPLICANT_NAMESPACE 81 | 82 | #endif // replicant_daemon_condition_h_ 83 | -------------------------------------------------------------------------------- /client/pending_defended_call.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #ifndef replicant_client_pending_defended_call_h_ 29 | #define replicant_client_pending_defended_call_h_ 30 | 31 | // Replicant 32 | #include "client/pending_call_robust.h" 33 | 34 | BEGIN_REPLICANT_NAMESPACE 35 | 36 | class pending_defended_call : public pending_robust 37 | { 38 | public: 39 | pending_defended_call(int64_t id, 40 | const char* object, 41 | const char* enter_func, 42 | const char* enter_input, size_t enter_input_sz, 43 | const char* exit_func, 44 | const char* exit_input, size_t exit_input_sz, 45 | replicant_returncode* status); 46 | virtual ~pending_defended_call() throw (); 47 | 48 | public: 49 | virtual std::auto_ptr request(uint64_t nonce); 50 | virtual bool resend_on_failure(); 51 | virtual void handle_response(client* cl, 52 | std::auto_ptr msg, 53 | e::unpacker up); 54 | 55 | private: 56 | const std::string m_object; 57 | const std::string m_enter_func; 58 | const std::string m_enter_input; 59 | const std::string m_exit_func; 60 | const std::string m_exit_input; 61 | 62 | private: 63 | pending_defended_call(const pending_defended_call&); 64 | pending_defended_call& operator = (const pending_defended_call&); 65 | }; 66 | 67 | END_REPLICANT_NAMESPACE 68 | 69 | #endif // replicant_client_pending_defended_call_h_ 70 | -------------------------------------------------------------------------------- /client/pending_generate_unique_number.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | // BusyBee 29 | #include 30 | 31 | // Replicant 32 | #include "common/network_msgtype.h" 33 | #include "client/pending_generate_unique_number.h" 34 | 35 | using replicant::pending_generate_unique_number; 36 | 37 | pending_generate_unique_number :: pending_generate_unique_number(int64_t id, 38 | replicant_returncode* st, 39 | uint64_t* number) 40 | : pending(id, st) 41 | , m_number(number) 42 | { 43 | } 44 | 45 | pending_generate_unique_number :: ~pending_generate_unique_number() throw () 46 | { 47 | } 48 | 49 | std::auto_ptr 50 | pending_generate_unique_number :: request(uint64_t nonce) 51 | { 52 | const size_t sz = BUSYBEE_HEADER_SIZE 53 | + pack_size(REPLNET_UNIQUE_NUMBER) 54 | + sizeof(uint64_t); 55 | std::auto_ptr msg(e::buffer::create(sz)); 56 | msg->pack_at(BUSYBEE_HEADER_SIZE) << REPLNET_UNIQUE_NUMBER << nonce; 57 | return msg; 58 | } 59 | 60 | bool 61 | pending_generate_unique_number :: resend_on_failure() 62 | { 63 | return true; 64 | } 65 | 66 | void 67 | pending_generate_unique_number :: handle_response(client*, 68 | std::auto_ptr, 69 | e::unpacker up) 70 | { 71 | up = up >> *m_number; 72 | 73 | if (up.error() || up.remain()) 74 | { 75 | PENDING_ERROR(SERVER_ERROR) << "received bad unique number response"; 76 | } 77 | else 78 | { 79 | this->success(); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /daemon/controller.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | // Replicant 29 | #include "daemon/controller.h" 30 | 31 | using replicant::controller; 32 | 33 | controller :: controller(po6::threads::mutex* mtx, configuration* c) 34 | : m_mtx(mtx) 35 | , m_c(c) 36 | , m_aux() 37 | { 38 | } 39 | 40 | controller :: ~controller() throw () 41 | { 42 | } 43 | 44 | po6::net::location 45 | controller :: lookup(uint64_t si) 46 | { 47 | po6::threads::mutex::hold hold(m_mtx); 48 | 49 | for (size_t i = 0; i < m_aux.size(); ++i) 50 | { 51 | if (m_aux[i].id.get() == si) 52 | { 53 | return m_aux[i].bind_to; 54 | } 55 | } 56 | 57 | for (size_t i = 0; i < m_c->servers().size(); ++i) 58 | { 59 | if (m_c->servers()[i].id.get() == si) 60 | { 61 | return m_c->servers()[i].bind_to; 62 | } 63 | } 64 | 65 | return po6::net::location(); 66 | } 67 | 68 | void 69 | controller :: add_aux(const server& s) 70 | { 71 | po6::threads::mutex::hold hold(m_mtx); 72 | const std::vector& servers(m_c->servers()); 73 | 74 | for (size_t i = 0; i < servers.size(); ++i) 75 | { 76 | if (servers[i].id == s.id && servers[i].bind_to == s.bind_to) 77 | { 78 | return; 79 | } 80 | } 81 | 82 | for (size_t i = 0; i < m_aux.size(); ++i) 83 | { 84 | if (m_aux[i].id == s.id) 85 | { 86 | m_aux[i] = s; 87 | return; 88 | } 89 | } 90 | 91 | m_aux.push_back(s); 92 | } 93 | 94 | void 95 | controller :: clear_aux() 96 | { 97 | po6::threads::mutex::hold hold(m_mtx); 98 | m_aux.clear(); 99 | } 100 | -------------------------------------------------------------------------------- /common/network_msgtype.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012-2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #ifndef replicant_common_network_msgtype_h_ 29 | #define replicant_common_network_msgtype_h_ 30 | 31 | // e 32 | #include 33 | 34 | // Replicant 35 | #include "namespace.h" 36 | 37 | BEGIN_REPLICANT_NAMESPACE 38 | 39 | enum network_msgtype 40 | { 41 | REPLNET_NOP = 0, 42 | 43 | REPLNET_BOOTSTRAP = 28, 44 | REPLNET_PING = 29, 45 | REPLNET_PONG = 30, 46 | REPLNET_STATE_TRANSFER = 31, 47 | // 26 is dead 48 | REPLNET_WHO_ARE_YOU = 25, 49 | REPLNET_IDENTITY = 24, 50 | 51 | REPLNET_PAXOS_PHASE1A = 32, 52 | REPLNET_PAXOS_PHASE1B = 33, 53 | REPLNET_PAXOS_PHASE2A = 34, 54 | REPLNET_PAXOS_PHASE2B = 35, 55 | REPLNET_PAXOS_LEARN = 36, 56 | REPLNET_PAXOS_SUBMIT = 37, 57 | 58 | REPLNET_SERVER_BECOME_MEMBER = 48, 59 | REPLNET_UNIQUE_NUMBER = 63, 60 | REPLNET_OBJECT_FAILED = 62, 61 | REPLNET_POKE = 64, 62 | REPLNET_COND_WAIT = 69, 63 | REPLNET_CALL = 70, 64 | REPLNET_GET_ROBUST_PARAMS = 72, 65 | REPLNET_CALL_ROBUST = 73, 66 | 67 | REPLNET_CLIENT_RESPONSE = 224, 68 | 69 | REPLNET_GARBAGE = 255 70 | }; 71 | 72 | std::ostream& 73 | operator << (std::ostream& lhs, network_msgtype rhs); 74 | 75 | e::packer 76 | operator << (e::packer lhs, const network_msgtype& rhs); 77 | e::unpacker 78 | operator >> (e::unpacker lhs, network_msgtype& rhs); 79 | size_t 80 | pack_size(const network_msgtype& rhs); 81 | 82 | END_REPLICANT_NAMESPACE 83 | 84 | #endif // replicant_common_network_msgtype_h_ 85 | -------------------------------------------------------------------------------- /tools/availability-check.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | // e 29 | #include 30 | 31 | // Replicant 32 | #include 33 | #include "tools/common.h" 34 | 35 | int 36 | main(int argc, const char* argv[]) 37 | { 38 | long servers = 5; 39 | long timeout = 10; 40 | connect_opts conn; 41 | e::argparser ap; 42 | ap.autohelp(); 43 | ap.option_string("[OPTIONS]"); 44 | ap.arg().name('s', "servers") 45 | .description("wait for N servers to join the cluster (default: 5)") 46 | .metavar("N").as_long(&servers); 47 | ap.arg().name('t', "timeout") 48 | .description("wait at most S seconds (default: 10)") 49 | .metavar("S").as_long(&timeout); 50 | ap.add("Connect to a cluster:", conn.parser()); 51 | 52 | if (!ap.parse(argc, argv)) 53 | { 54 | return EXIT_FAILURE; 55 | } 56 | 57 | if (ap.args_sz() != 0) 58 | { 59 | std::cerr << "command takes no positional arguments\n" << std::endl; 60 | ap.usage(); 61 | return EXIT_FAILURE; 62 | } 63 | 64 | if (!conn.validate()) 65 | { 66 | std::cerr << "invalid host:port specification\n" << std::endl; 67 | ap.usage(); 68 | return EXIT_FAILURE; 69 | } 70 | 71 | replicant_client* r = replicant_client_create(conn.host(), conn.port()); 72 | 73 | if (!r) 74 | { 75 | std::cerr << "could not create replicant client" << std::endl; 76 | return EXIT_FAILURE; 77 | } 78 | 79 | e::guard g_r = e::makeguard(replicant_client_destroy, r); 80 | replicant_returncode re = REPLICANT_GARBAGE; 81 | int ret = replicant_client_availability_check(r, servers, timeout, &re); 82 | 83 | if (ret < 0) 84 | { 85 | return EXIT_FAILURE; 86 | } 87 | 88 | return EXIT_SUCCESS; 89 | } 90 | -------------------------------------------------------------------------------- /include/rsm.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2015, Robert Escriva 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Replicant nor the names of its contributors may be 13 | * used to endorse or promote products derived from this software without 14 | * specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef replicant_rsm_h_ 29 | #define replicant_rsm_h_ 30 | 31 | /* C */ 32 | #include 33 | #include 34 | 35 | #ifdef __cplusplus 36 | extern "C" 37 | { 38 | #endif /* __cplusplus */ 39 | 40 | struct rsm_context; 41 | 42 | #pragma GCC diagnostic push 43 | #pragma GCC diagnostic ignored "-pedantic" 44 | 45 | struct state_machine_transition 46 | { 47 | const char* name; 48 | void (*func)(struct rsm_context* ctx, void* obj, const char* data, size_t data_sz); 49 | }; 50 | 51 | struct state_machine 52 | { 53 | void* (*ctor)(struct rsm_context* ctx); 54 | void* (*rtor)(struct rsm_context* ctx, const char* data, size_t data_sz); 55 | int (*snap)(struct rsm_context* ctx, void* obj, char** data, size_t* data_sz); 56 | struct state_machine_transition transitions[]; 57 | }; 58 | 59 | #pragma GCC diagnostic pop 60 | 61 | void rsm_log(struct rsm_context* ctx, const char* format, ...); 62 | void rsm_set_output(struct rsm_context* ctx, const char* output, size_t output_sz); 63 | 64 | void rsm_cond_create(struct rsm_context* ctx, const char* cond); 65 | void rsm_cond_destroy(struct rsm_context* ctx, const char* cond); 66 | int rsm_cond_broadcast(struct rsm_context* ctx, const char* cond); 67 | int rsm_cond_broadcast_data(struct rsm_context* ctx, 68 | const char* cond, 69 | const char* data, size_t data_sz); 70 | int rsm_cond_current_value(struct rsm_context* ctx, 71 | const char* cond, uint64_t* state, 72 | const char** data, size_t* data_sz); 73 | 74 | void rsm_tick_interval(struct rsm_context* ctx, const char* func, uint64_t seconds); 75 | 76 | #ifdef __cplusplus 77 | } /* extern "C" */ 78 | #endif /* __cplusplus */ 79 | #endif /* replicant_rsm_h_ */ 80 | -------------------------------------------------------------------------------- /tools/kill-server.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #define __STDC_LIMIT_MACROS 29 | 30 | // POSIX 31 | #include 32 | 33 | // Replicant 34 | #include 35 | #include "tools/common.h" 36 | 37 | int 38 | main(int argc, const char* argv[]) 39 | { 40 | connect_opts conn; 41 | e::argparser ap; 42 | ap.autohelp(); 43 | ap.option_string("[OPTIONS] "); 44 | ap.add("Connect to a cluster:", conn.parser()); 45 | 46 | if (!ap.parse(argc, argv)) 47 | { 48 | return EXIT_FAILURE; 49 | } 50 | 51 | if (ap.args_sz() != 1) 52 | { 53 | std::cerr << "command takes one server's token as an argument\n" << std::endl; 54 | ap.usage(); 55 | return EXIT_FAILURE; 56 | } 57 | 58 | if (!conn.validate()) 59 | { 60 | std::cerr << "invalid host:port specification\n" << std::endl; 61 | ap.usage(); 62 | return EXIT_FAILURE; 63 | } 64 | 65 | char* end = NULL; 66 | errno = 0; 67 | uint64_t token = strtoull(ap.args()[0], &end, 10); 68 | 69 | if (token == 0 || errno != 0 || *end != '\0') 70 | { 71 | std::cerr << token << std::endl; 72 | std::cerr << "invalid token\n" << std::endl; 73 | ap.usage(); 74 | return EXIT_FAILURE; 75 | } 76 | 77 | try 78 | { 79 | replicant_client* r = replicant_client_create(conn.host(), conn.port()); 80 | replicant_returncode re = REPLICANT_GARBAGE; 81 | int64_t rid = replicant_client_kill_server(r, token, &re); 82 | 83 | if (!cli_finish(r, rid, &re)) 84 | { 85 | return EXIT_FAILURE; 86 | } 87 | 88 | return EXIT_SUCCESS; 89 | } 90 | catch (std::exception& e) 91 | { 92 | std::cerr << "error: " << e.what() << std::endl; 93 | return EXIT_FAILURE; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /common/ids.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012-2015, Cornell University 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #ifndef replicant_common_ids_h_ 29 | #define replicant_common_ids_h_ 30 | 31 | // C 32 | #include 33 | 34 | // C++ 35 | #include 36 | 37 | // e 38 | #include 39 | 40 | // Replicant 41 | #include "namespace.h" 42 | 43 | // An ID is a simple wrapper around uint64_t in order to prevent devs from 44 | // accidently using one type of ID as another. 45 | 46 | #define OPERATOR(TYPE, OP) \ 47 | inline bool \ 48 | operator OP (const TYPE ## _id& lhs, const TYPE ## _id& rhs) \ 49 | { \ 50 | return lhs.get() OP rhs.get(); \ 51 | } 52 | #define CREATE_ID(TYPE) \ 53 | class TYPE ## _id \ 54 | { \ 55 | public: \ 56 | static uint64_t hash(const TYPE ## _id& x) { return x.get(); } \ 57 | TYPE ## _id() : m_id(0) {} \ 58 | explicit TYPE ## _id(uint64_t id) : m_id(id) {} \ 59 | public: \ 60 | uint64_t get() const { return m_id; } \ 61 | private: \ 62 | uint64_t m_id; \ 63 | }; \ 64 | std::ostream& \ 65 | operator << (std::ostream& lhs, const TYPE ## _id& rhs); \ 66 | inline size_t \ 67 | pack_size(const TYPE ## _id&) \ 68 | { \ 69 | return sizeof(uint64_t); \ 70 | } \ 71 | e::packer \ 72 | operator << (e::packer pa, const TYPE ## _id& rhs); \ 73 | e::unpacker \ 74 | operator >> (e::unpacker up, TYPE ## _id& rhs); \ 75 | OPERATOR(TYPE, <) \ 76 | OPERATOR(TYPE, <=) \ 77 | OPERATOR(TYPE, ==) \ 78 | OPERATOR(TYPE, !=) \ 79 | OPERATOR(TYPE, >=) \ 80 | OPERATOR(TYPE, >) 81 | 82 | BEGIN_REPLICANT_NAMESPACE 83 | 84 | CREATE_ID(cluster) 85 | CREATE_ID(version) 86 | CREATE_ID(server) 87 | 88 | END_REPLICANT_NAMESPACE 89 | 90 | #undef OPERATOR 91 | #undef CREATE_ID 92 | #endif // replicant_common_ids_h_ 93 | -------------------------------------------------------------------------------- /examples/log.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012, Robert Escriva 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Replicant nor the names of its contributors may be 13 | * used to endorse or promote products derived from this software without 14 | * specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* C */ 30 | #include 31 | 32 | /* Replicant */ 33 | #include 34 | 35 | void* 36 | log_create(struct rsm_context* ctx) 37 | { 38 | return (void*) -1; 39 | } 40 | 41 | void* 42 | log_recreate(struct rsm_context* ctx, 43 | const char* data, size_t data_sz) 44 | { 45 | return (void*) -1; 46 | } 47 | 48 | int 49 | log_snapshot(struct rsm_context* ctx, 50 | void* obj, 51 | char** data, size_t* data_sz) 52 | { 53 | *data = NULL; 54 | *data_sz = 0; 55 | return 0; 56 | } 57 | 58 | void 59 | log_log(struct rsm_context* ctx, 60 | void* obj, 61 | const char* data, size_t data_sz) 62 | { 63 | rsm_log(ctx, "begin logging of function"); 64 | int is_print = 1; 65 | int saw_null = 0; 66 | size_t i = 0; 67 | 68 | for (i = 0; i < data_sz; ++i) 69 | { 70 | if (data[i] == '\0') 71 | { 72 | saw_null = 1; 73 | break; 74 | } 75 | else if (!isprint(data[i])) 76 | { 77 | is_print = 0; 78 | } 79 | } 80 | 81 | if (is_print && !saw_null) 82 | { 83 | rsm_log(ctx, "log was asked to log \"%.*s\" and it is %lld bytes long", data_sz, data, i); 84 | } 85 | else if (is_print && saw_null) 86 | { 87 | rsm_log(ctx, "log was asked to log \"%s\" and it is %lld bytes long", data, i); 88 | } 89 | else 90 | { 91 | rsm_log(ctx, "will not log unprintable characters"); 92 | } 93 | 94 | rsm_log(ctx, "end logging of function"); 95 | } 96 | 97 | struct state_machine rsm = { 98 | log_create, 99 | log_recreate, 100 | log_snapshot, 101 | {{"log", log_log}, 102 | {NULL, NULL}} 103 | }; 104 | -------------------------------------------------------------------------------- /m4/ax_check_compile_flag.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # http://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS]) 8 | # 9 | # DESCRIPTION 10 | # 11 | # Check whether the given FLAG works with the current language's compiler 12 | # or gives an error. (Warnings, however, are ignored) 13 | # 14 | # ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on 15 | # success/failure. 16 | # 17 | # If EXTRA-FLAGS is defined, it is added to the current language's default 18 | # flags (e.g. CFLAGS) when the check is done. The check is thus made with 19 | # the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to 20 | # force the compiler to issue an error when a bad flag is given. 21 | # 22 | # NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this 23 | # macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG. 24 | # 25 | # LICENSE 26 | # 27 | # Copyright (c) 2008 Guido U. Draheim 28 | # Copyright (c) 2011 Maarten Bosmans 29 | # 30 | # This program is free software: you can redistribute it and/or modify it 31 | # under the terms of the GNU General Public License as published by the 32 | # Free Software Foundation, either version 3 of the License, or (at your 33 | # option) any later version. 34 | # 35 | # This program is distributed in the hope that it will be useful, but 36 | # WITHOUT ANY WARRANTY; without even the implied warranty of 37 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 38 | # Public License for more details. 39 | # 40 | # You should have received a copy of the GNU General Public License along 41 | # with this program. If not, see . 42 | # 43 | # As a special exception, the respective Autoconf Macro's copyright owner 44 | # gives unlimited permission to copy, distribute and modify the configure 45 | # scripts that are the output of Autoconf when processing the Macro. You 46 | # need not follow the terms of the GNU General Public License when using 47 | # or distributing such scripts, even though portions of the text of the 48 | # Macro appear in them. The GNU General Public License (GPL) does govern 49 | # all other use of the material that constitutes the Autoconf Macro. 50 | # 51 | # This special exception to the GPL applies to versions of the Autoconf 52 | # Macro released by the Autoconf Archive. When you make and distribute a 53 | # modified version of the Autoconf Macro, you may extend this special 54 | # exception to the GPL to apply to your modified version as well. 55 | 56 | #serial 2 57 | 58 | AC_DEFUN([AX_CHECK_COMPILE_FLAG], 59 | [AC_PREREQ(2.59)dnl for _AC_LANG_PREFIX 60 | AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl 61 | AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [ 62 | ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS 63 | _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1" 64 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], 65 | [AS_VAR_SET(CACHEVAR,[yes])], 66 | [AS_VAR_SET(CACHEVAR,[no])]) 67 | _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags]) 68 | AS_IF([test x"AS_VAR_GET(CACHEVAR)" = xyes], 69 | [m4_default([$2], :)], 70 | [m4_default([$3], :)]) 71 | AS_VAR_POPDEF([CACHEVAR])dnl 72 | ])dnl AX_CHECK_COMPILE_FLAGS 73 | -------------------------------------------------------------------------------- /client/pending_cond_follow.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #ifndef replicant_client_pending_cond_follow_h_ 29 | #define replicant_client_pending_cond_follow_h_ 30 | 31 | // Replicant 32 | #include "client/pending.h" 33 | 34 | BEGIN_REPLICANT_NAMESPACE 35 | 36 | class pending_cond_follow : public pending 37 | { 38 | public: 39 | pending_cond_follow(int64_t client_visible_id, 40 | const char* object, const char* cond, 41 | replicant_returncode* status, 42 | uint64_t* state, 43 | char** data, size_t* data_sz); 44 | pending_cond_follow(int64_t client_visible_id, 45 | const char* object, const char* cond, 46 | replicant_returncode* status, 47 | uint64_t* state, 48 | char** data, size_t* data_sz, 49 | void (client::*callback)()); 50 | virtual ~pending_cond_follow() throw (); 51 | 52 | public: 53 | virtual std::auto_ptr request(uint64_t nonce); 54 | virtual bool resend_on_failure(); 55 | virtual void handle_response(client* cl, 56 | std::auto_ptr msg, 57 | e::unpacker up); 58 | 59 | private: 60 | const std::string m_object; 61 | const std::string m_cond; 62 | uint64_t* const m_state; 63 | char** const m_data; 64 | size_t* const m_data_sz; 65 | bool m_has_callback; 66 | void (client::*m_callback)(); 67 | 68 | private: 69 | pending_cond_follow(const pending_cond_follow&); 70 | pending_cond_follow& operator = (const pending_cond_follow&); 71 | }; 72 | 73 | END_REPLICANT_NAMESPACE 74 | 75 | #endif // replicant_client_pending_cond_follow_h_ 76 | -------------------------------------------------------------------------------- /daemon/commander.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | // STL 29 | #include 30 | 31 | // Replicant 32 | #include "daemon/commander.h" 33 | 34 | using replicant::commander; 35 | 36 | commander :: commander(const pvalue& p) 37 | : m_pval(p) 38 | , m_accepted_by() 39 | { 40 | for (size_t i = 0; i < REPLICANT_MAX_REPLICAS; ++i) 41 | { 42 | m_timestamps[i] = 0; 43 | } 44 | } 45 | 46 | commander :: commander(const commander& other) 47 | : m_pval(other.m_pval) 48 | , m_accepted_by(other.m_accepted_by) 49 | { 50 | for (size_t i = 0; i < REPLICANT_MAX_REPLICAS; ++i) 51 | { 52 | m_timestamps[i] = other.m_timestamps[i]; 53 | } 54 | } 55 | 56 | commander :: ~commander() throw () 57 | { 58 | } 59 | 60 | bool 61 | commander :: accepted_by(server_id si) 62 | { 63 | return std::find(m_accepted_by.begin(), m_accepted_by.end(), si) != m_accepted_by.end(); 64 | } 65 | 66 | void 67 | commander :: accept(server_id si) 68 | { 69 | if (!accepted_by(si)) 70 | { 71 | m_accepted_by.push_back(si); 72 | } 73 | } 74 | 75 | size_t 76 | commander :: accepted() 77 | { 78 | return m_accepted_by.size(); 79 | } 80 | 81 | uint64_t 82 | commander :: timestamp(unsigned idx) 83 | { 84 | assert(idx < REPLICANT_MAX_REPLICAS); 85 | return m_timestamps[idx]; 86 | } 87 | 88 | void 89 | commander :: timestamp(unsigned idx, uint64_t ts) 90 | { 91 | assert(idx < REPLICANT_MAX_REPLICAS); 92 | m_timestamps[idx] = ts; 93 | } 94 | 95 | commander& 96 | commander :: operator = (const commander& rhs) 97 | { 98 | m_pval = rhs.m_pval; 99 | m_accepted_by = rhs.m_accepted_by; 100 | 101 | for (size_t i = 0; i < REPLICANT_MAX_REPLICAS; ++i) 102 | { 103 | m_timestamps[i] = rhs.m_timestamps[i]; 104 | } 105 | 106 | return *this; 107 | } 108 | -------------------------------------------------------------------------------- /common/network_msgtype.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | // C++ 29 | #include 30 | 31 | // Replicant 32 | #include "common/macros.h" 33 | #include "common/network_msgtype.h" 34 | 35 | std::ostream& 36 | replicant :: operator << (std::ostream& lhs, network_msgtype rhs) 37 | { 38 | switch (rhs) 39 | { 40 | STRINGIFY(REPLNET_NOP); 41 | STRINGIFY(REPLNET_BOOTSTRAP); 42 | STRINGIFY(REPLNET_PING); 43 | STRINGIFY(REPLNET_PONG); 44 | STRINGIFY(REPLNET_STATE_TRANSFER); 45 | STRINGIFY(REPLNET_WHO_ARE_YOU); 46 | STRINGIFY(REPLNET_IDENTITY); 47 | STRINGIFY(REPLNET_PAXOS_PHASE1A); 48 | STRINGIFY(REPLNET_PAXOS_PHASE1B); 49 | STRINGIFY(REPLNET_PAXOS_PHASE2A); 50 | STRINGIFY(REPLNET_PAXOS_PHASE2B); 51 | STRINGIFY(REPLNET_PAXOS_LEARN); 52 | STRINGIFY(REPLNET_PAXOS_SUBMIT); 53 | STRINGIFY(REPLNET_SERVER_BECOME_MEMBER); 54 | STRINGIFY(REPLNET_UNIQUE_NUMBER); 55 | STRINGIFY(REPLNET_OBJECT_FAILED); 56 | STRINGIFY(REPLNET_POKE); 57 | STRINGIFY(REPLNET_COND_WAIT); 58 | STRINGIFY(REPLNET_CALL); 59 | STRINGIFY(REPLNET_GET_ROBUST_PARAMS); 60 | STRINGIFY(REPLNET_CALL_ROBUST); 61 | STRINGIFY(REPLNET_CLIENT_RESPONSE); 62 | STRINGIFY(REPLNET_GARBAGE); 63 | default: 64 | lhs << "unknown msgtype"; 65 | } 66 | 67 | return lhs; 68 | } 69 | 70 | e::packer 71 | replicant :: operator << (e::packer lhs, const network_msgtype& rhs) 72 | { 73 | uint8_t mt = static_cast(rhs); 74 | return lhs << mt; 75 | } 76 | 77 | e::unpacker 78 | replicant :: operator >> (e::unpacker lhs, network_msgtype& rhs) 79 | { 80 | uint8_t mt; 81 | lhs = lhs >> mt; 82 | rhs = static_cast(mt); 83 | return lhs; 84 | } 85 | 86 | size_t 87 | replicant :: pack_size(const network_msgtype&) 88 | { 89 | return sizeof(uint8_t); 90 | } 91 | -------------------------------------------------------------------------------- /daemon/snapshot.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #ifndef replicant_daemon_snapshot_h_ 29 | #define replicant_daemon_snapshot_h_ 30 | 31 | // C 32 | #include 33 | 34 | // STL 35 | #include 36 | 37 | // po6 38 | #include 39 | #include 40 | 41 | // e 42 | #include 43 | #include 44 | 45 | // Replicant 46 | #include "namespace.h" 47 | #include "common/packing.h" 48 | #include "daemon/robust_history.h" 49 | 50 | BEGIN_REPLICANT_NAMESPACE 51 | 52 | class snapshot 53 | { 54 | public: 55 | snapshot(uint64_t up_to, robust_history* rh); 56 | ~snapshot() throw (); 57 | 58 | public: 59 | uint64_t slot() const { return m_up_to; } 60 | void wait(); 61 | void replica_internals(const e::slice& replica); 62 | void start_object(const std::string& name); 63 | void finish_object(const std::string& name, const std::string& snap); 64 | void abort_snapshot(); 65 | bool done(); 66 | const std::string& contents(); 67 | 68 | private: 69 | bool done_condition(); 70 | 71 | // refcount 72 | private: 73 | friend class e::intrusive_ptr; 74 | void inc() { __sync_add_and_fetch(&m_ref, 1); } 75 | void dec() { if (__sync_sub_and_fetch(&m_ref, 1) == 0) delete this; } 76 | size_t m_ref; 77 | 78 | private: 79 | const uint64_t m_up_to; 80 | po6::threads::mutex m_mtx; 81 | po6::threads::cond m_cond; 82 | bool m_failed; 83 | robust_history* m_history; 84 | std::set m_objects; 85 | std::string m_serialized_prefix; 86 | std::string m_serialized_objects; 87 | e::packer m_obj_packer; 88 | std::string m_serialized_altogether; 89 | 90 | private: 91 | snapshot(const snapshot&); 92 | snapshot& operator = (const snapshot&); 93 | }; 94 | 95 | END_REPLICANT_NAMESPACE 96 | 97 | #endif // replicant_daemon_snapshot_h_ 98 | -------------------------------------------------------------------------------- /daemon/unordered_command.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Robert Escriva 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // * Neither the name of Replicant nor the names of its contributors may be 13 | // used to endorse or promote products derived from this software without 14 | // specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #ifndef replicant_daemon_unordered_command_h_ 29 | #define replicant_daemon_unordered_command_h_ 30 | 31 | // Replicant 32 | #include "namespace.h" 33 | #include "common/ids.h" 34 | #include "daemon/ballot.h" 35 | #include "daemon/slot_type.h" 36 | 37 | BEGIN_REPLICANT_NAMESPACE 38 | 39 | class unordered_command 40 | { 41 | public: 42 | unordered_command(server_id on_behalf_of, 43 | uint64_t request_nonce, 44 | slot_type t, 45 | const std::string& command); 46 | virtual ~unordered_command() throw (); 47 | 48 | public: 49 | server_id on_behalf_of() const { return m_on_behalf_of; } 50 | uint64_t request_nonce() const { return m_request_nonce; } 51 | slot_type type() const { return m_type; } 52 | const std::string& command() const { return m_command; } 53 | uint64_t command_nonce() const { return m_command_nonce; } 54 | void set_command_nonce(uint64_t command_nonce); 55 | 56 | const ballot& last_used_ballot() const { return m_last_used_ballot; } 57 | void set_last_used_ballot(const ballot& b); 58 | 59 | uint64_t lowest_possible_slot() const { return m_lowest_possible_slot; } 60 | void set_lowest_possible_slot(uint64_t slot); 61 | 62 | bool robust() const { return m_robust; } 63 | void set_robust() { m_robust = true; } 64 | 65 | private: 66 | const server_id m_on_behalf_of; 67 | const uint64_t m_request_nonce; 68 | const slot_type m_type; 69 | const std::string m_command; 70 | uint64_t m_command_nonce; 71 | ballot m_last_used_ballot; 72 | uint64_t m_lowest_possible_slot; 73 | bool m_robust; 74 | 75 | // noncopyable 76 | private: 77 | unordered_command(const unordered_command&); 78 | unordered_command& operator = (const unordered_command&); 79 | }; 80 | 81 | END_REPLICANT_NAMESPACE 82 | 83 | #endif // replicant_daemon_unordered_command_h_ 84 | --------------------------------------------------------------------------------