Important Existing Code

/vendor

The vendor folder stores all of the dependencies and libraries used by the Go program. All of the imports are not standard libraries will look for that library inside the vendor folder. You do not need to worry about code in here.

/test

The test folder contains Python code that can be used for writing and running some tests on the two phase commit participants locally. See Testing for more details.

/api

This folder contains the gRPC code that defines the Key Value store interface. It defines the service that implements Get and Put.

/pkg

This folder contains the source code for the Two Phase Commit KV Store.

/pkg/kvstore

This folder contains code that implements a file system based KV Store. It takes a path to a directory, and stores each entry as a separate file in that directory.

/pkg/journal

This folder contains code that implements a file based Journal. Each entry is stored as a separate line in the file. The journal has the following API:

NewFileJournal(path string) (Journal, error): given a path, returns a Journal based on the file at that path. If no file exists, one is created. If a file does exist, the Journal is built from the entires already in that file.

Size() int: returns the numer of entries currently in the journal

Empty(): empties the journal by truncating the underlying file and resetting the in memory linked list

Append(e Entry) error: adds an entry to the journal by writing it to the underlying file and adding it to the in memory linked list.

NewIterator() *EntryIterator: returns an iterator over the in memory linked list of entries

/pkg/rpc

This folder contains the gRPC code that defines the Two Phase Commit interface. It defines the service that implements a bi-directional stream between the Leader and the Follower along with the structure of the messages they pass. Reading the .proto file here may be useful in figuring out what the Two Phase Commit API looks like.

/pkg/tpc

This folder contains the code for the Leader and Follower state machines. It also contains code for the gRPC framework for both the leader and the follower: a gRPC server that implements both the KV and TPC gRPC interfaces along with a framework that allows the leader and follower to send and receive TPC messages.

main.go

This file contains code that parses the command line inputs, creates the appropriate 2PC participant, and starts the gRPC server.

Last updated