Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cs733
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Sushant Mahajan
cs733
Commits
b7cb0294
Commit
b7cb0294
authored
Feb 04, 2015
by
Harshit Pande
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of git.cse.iitb.ac.in:smahajan/cs733
parents
0f1d1b9e
cab533d6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
19 deletions
+30
-19
assignment2/replic_kvstore.go
assignment2/replic_kvstore.go
+30
-19
No files found.
assignment2/replic_kvstore.go
View file @
b7cb0294
...
@@ -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
{
I
d
uint64
i
d
uint64
D
ata
[]
byte
d
ata
[]
byte
C
ommitted
bool
c
ommitted
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
.
D
ata
return
entry
.
d
ata
}
}
func
Committed
(
entry
*
LogEntryData
)
bool
{
func
(
entry
*
LogEntryData
)
Committed
(
)
bool
{
return
entry
.
C
ommitted
return
entry
.
c
ommitted
}
}
//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
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment