Skip to content

Commit

Permalink
graph update
Browse files Browse the repository at this point in the history
  • Loading branch information
ailidani authored and ailidani committed Jan 17, 2018
1 parent ba0cd3e commit a1d5066
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 27 deletions.
11 changes: 7 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
language: go
sudo: false
notifications:
email: false
go:
- 1.x
install: true
script: ./bin/build.sh
script:
- go build ./server/
- go build ./client/
- go build ./cmd/
- go build ./master/
notifications:
email: false
19 changes: 8 additions & 11 deletions checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ func (c *checker) remove(o operation) {
c.Remove(o)
}

func (c *checker) clear() {
c.Graph = lib.NewGraph()
}

// match finds the first matching write operation to the given read operation
func (c *checker) match(o operation) *operation {
for _, v := range c.Graph.BFS(o) {
Expand Down Expand Up @@ -113,6 +117,7 @@ func (c *checker) merge(read, write operation) {
}

func (c *checker) linearizable(history []operation) bool {
c.clear()
sort.Sort(byTime(history))
for i, o := range history {
select {
Expand Down Expand Up @@ -145,14 +150,6 @@ func (c *checker) linearizable(history []operation) bool {
// sort operations by invocation time
type byTime []operation

func (a byTime) Len() int {
return len(a)
}

func (a byTime) Swap(i, j int) {
a[i], a[j] = a[j], a[i]
}

func (a byTime) Less(i, j int) bool {
return a[i].start < a[j].start
}
func (a byTime) Len() int { return len(a) }
func (a byTime) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a byTime) Less(i, j int) bool { return a[i].start < a[j].start }
10 changes: 5 additions & 5 deletions epaxos/replica.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,9 @@ func (r *Replica) startPhase1(replica id, instance int, ballot int, proposals []
deps: deps,
lb: NewLeaderBookkeeping(proposals, deps),
}
r.InstanceSpace[r.ID()][instance].lb.preAcceptQuorum.ACK(r.ID())
r.InstanceSpace[r.ID()][instance].lb.prepareQuorum.ACK(r.ID())
r.InstanceSpace[r.ID()][instance].lb.acceptQuorum.ACK(r.ID())
r.InstanceSpace[r.ID()][instance].lb.preAcceptQuorum.ACK(r.Node.ID())
r.InstanceSpace[r.ID()][instance].lb.prepareQuorum.ACK(r.Node.ID())
r.InstanceSpace[r.ID()][instance].lb.acceptQuorum.ACK(r.Node.ID())

r.updateConflicts(cmds, r.ID(), instance, seq)

Expand All @@ -387,8 +387,8 @@ func (r *Replica) startPhase1(replica id, instance int, ballot int, proposals []
}

pa := &PreAccept{
LeaderId: r.ID(),
Replica: r.ID(),
LeaderId: r.Node.ID(),
Replica: r.Node.ID(),
Instance: instance,
Ballot: ballot,
Command: cmds,
Expand Down
14 changes: 7 additions & 7 deletions lib/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@ func (g *Graph) Size() int {
}

func (g *Graph) Has(v interface{}) bool {
_, exists := g.vertices[v]
return exists
return g.vertices.Has(v)
}

func (g *Graph) Add(v interface{}) {
if !g.Has(v) {
g.vertices[v] = struct{}{}
g.vertices.Add(v)
g.from[v] = NewSet()
g.to[v] = NewSet()
}
g.from[v] = NewSet()
g.to[v] = NewSet()

}

func (g *Graph) Remove(v interface{}) {
if !g.Has(v) {
return
}
delete(g.vertices, v)
g.vertices.Remove(v)

for u := range g.vertices {
g.from[u].Remove(v)
Expand Down Expand Up @@ -89,7 +89,7 @@ func (g *Graph) BFS(v interface{}) []interface{} {
vertices = append(vertices, s.Value)
queue.Remove(s)

for t := range g.from[s] {
for t := range g.from[s.Value] {
if !visited[t] {
visited[t] = true
queue.PushBack(t)
Expand Down
7 changes: 7 additions & 0 deletions lib/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "testing"

func TestGraoh(t *testing.T) {
g := NewGraph()
g.Add(1)
g.AddEdge(1, 2)
g.AddEdge(1, 3)
g.AddEdge(2, 4)
Expand All @@ -14,4 +15,10 @@ func TestGraoh(t *testing.T) {
t.Fatalf("graph BFS(1) = %v", g.BFS(1))
}
}

g.AddEdge(4, 3)
g.AddEdge(3, 2)
if !g.Cyclic() {
t.Fatal("graph cannot detect cycle")
}
}
19 changes: 19 additions & 0 deletions lib/set_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package lib

import "testing"

func TestSet(t *testing.T) {
s := NewSet()
for i := 1; i <= 10; i++ {
s.Add(i)
}

if !s.Has(5) {
t.Error("missing element")
}

s.Remove(5)
if s.Has(5) {
t.Error("cannot remove element")
}
}

0 comments on commit a1d5066

Please sign in to comment.