Commit b7cb0294 authored by Harshit Pande's avatar Harshit Pande

Merge branch 'master' of git.cse.iitb.ac.in:smahajan/cs733

parents 0f1d1b9e cab533d6
...@@ -15,20 +15,20 @@ const ( ...@@ -15,20 +15,20 @@ const (
CLIENT_PORT = 9000 CLIENT_PORT = 9000
) )
//type Lsn uint64 //Log sequence number, unique for all time. type Lsn uint64 //Log sequence number, unique for all time.
type ErrRedirect int // See Log.Append. Implements Error interface. type ErrRedirect int // See Log.Append. Implements Error interface.
type LogEntry interface { type LogEntry interface {
Lsn() uint64 Lsn() Lsn
Data() []byte Data() []byte
Committed() bool Committed() bool
} }
type LogEntryData struct { type LogEntryData struct {
Id uint64 id uint64
Data []byte data []byte
Committed bool committed bool
} }
type ServerConfig struct { type ServerConfig struct {
...@@ -43,29 +43,40 @@ type ClusterConfig struct { ...@@ -43,29 +43,40 @@ type ClusterConfig struct {
Servers []ServerConfig // All servers in this cluster Servers []ServerConfig // All servers in this cluster
} }
type ErrRedirect int type SharedLog interface {
Append(data []byte) (LogEntry, error)
}
type Raft struct {
//some good stuff needs to go here
}
var cluster_config *ClusterConfig var cluster_config *ClusterConfig
func Lsn(entry *LogEntryData) uint64 { //make LogEntryData implement the
return entry.Id func (entry *LogEntryData) Lsn() uint64 {
return entry.id
} }
func Data(entry *LogEntryData) []byte { func (entry *LogEntryData) Data() []byte {
return entry.Data return entry.data
} }
func Committed(entry *LogEntryData) bool { func (entry *LogEntryData) Committed() bool {
return entry.Committed return entry.committed
} }
//make raft implement the append function
//func (raft *Raft) Append(data []byte) (LogEntry, error) {
//}
func NewServerConfig(server_id int) (*ServerConfig, error) { func NewServerConfig(server_id int) (*ServerConfig, error) {
this_server := new(ServerConfig) server := new(ServerConfig)
this_server.Id = server_id server.Id = server_id
this_server.Hostname = "127.0.0.1" server.Hostname = "127.0.0.1"
this_server.ClientPort = CLIENT_PORT server.ClientPort = CLIENT_PORT
this_server.LogPort = CLIENT_PORT + server_id server.LogPort = CLIENT_PORT + server_id
return this_server, nil return server, nil
} }
func NewClusterConfig(num_servers int) (*ClusterConfig, error) { func NewClusterConfig(num_servers int) (*ClusterConfig, error) {
...@@ -82,7 +93,7 @@ func NewClusterConfig(num_servers int) (*ClusterConfig, error) { ...@@ -82,7 +93,7 @@ func NewClusterConfig(num_servers int) (*ClusterConfig, error) {
} }
func (e ErrRedirect) Error() string { func (e ErrRedirect) Error() string {
return "Redirect to server " + cluster_config.Servers[0].Hostname + " " + cluster_config.Servers[0].ClientPort return "Redirect to server " + strconv.Itoa(cluster_config.Servers[0].Id)
} }
func main() { func main() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment