Skip to content

Latest commit

 

History

History
75 lines (51 loc) · 1.65 KB

File metadata and controls

75 lines (51 loc) · 1.65 KB

morty

A distributed consensus-based key-value store that replicates data across multiple nodes using a consensus algorithm, ensuring fault tolerance and consistency across the network.

Run 3 nodes (interactive)

Use three terminals and start nodes on these ports:

./morty 1 6000

./morty 2 6001

./morty 3 6002

12-factor configuration

Morty now supports environment-driven config and flag overrides.

Environment variables

  • MORTY_NODE_ID node id (for example 1)
  • MORTY_PORT node port (for example 6000)
  • MORTY_PEERS peer map, format: 1=localhost:6000,2=localhost:6001,3=localhost:6002
  • MORTY_LOG_TARGET one of stdout, stderr, file
  • MORTY_LOG_DIR log directory when MORTY_LOG_TARGET=file
  • MORTY_INTERACTIVE true|false (CLI loop on/off)

Example (service mode)

export MORTY_NODE_ID=1
export MORTY_PORT=6000
export MORTY_PEERS="1=localhost:6000,2=localhost:6001,3=localhost:6002"
export MORTY_LOG_TARGET=stdout
export MORTY_INTERACTIVE=false

./morty

Flags

./morty --node-id 1 --port 6000 --peers "1=localhost:6000,2=localhost:6001,3=localhost:6002" --log-target stdout --interactive false

HTTP KV API

All nodes expose the same API. Writes (/kv/set, /kv/delete) are proposed through Raft.

Set

curl -X POST http://localhost:6000/kv/set \
	-H "Content-Type: application/json" \
	-d '{"key":"item1","value":"tomato"}'

Get

curl "http://localhost:6001/kv/get?key=item1"

Delete

curl -X POST http://localhost:6002/kv/delete \
	-H "Content-Type: application/json" \
	-d '{"key":"item1"}'

Keys

curl "http://localhost:6000/kv/keys"