single writer
This commit is contained in:
parent
7a8d4194bd
commit
e13e65d09b
3 changed files with 36 additions and 3 deletions
|
|
@ -38,7 +38,7 @@ type Transaction struct {
|
||||||
ID int64
|
ID int64
|
||||||
Triple *Triple
|
Triple *Triple
|
||||||
Action Procedure
|
Action Procedure
|
||||||
Timestamp *time.Time
|
Timestamp time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
type TripleWriter interface {
|
type TripleWriter interface {
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ type Value interface{}
|
||||||
type TripleStore interface {
|
type TripleStore interface {
|
||||||
// The only way in is through building a transaction, which
|
// The only way in is through building a transaction, which
|
||||||
// is done by a replication strategy.
|
// is done by a replication strategy.
|
||||||
ApplyTransactions([]*Transaction)
|
ApplyTransactions([]*Transaction) error
|
||||||
|
|
||||||
// Given an opaque token, returns the triple for that token from the store.
|
// Given an opaque token, returns the triple for that token from the store.
|
||||||
Triple(Value) *Triple
|
Triple(Value) *Triple
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ package replication
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/google/cayley/graph"
|
"github.com/google/cayley/graph"
|
||||||
)
|
)
|
||||||
|
|
@ -42,10 +43,42 @@ func (s *Single) AcquireNextId() int64 {
|
||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddTriple(*graph.Triple) error {
|
func (s *Single) AddTriple(t *graph.Triple) error {
|
||||||
|
trans := make([]*graph.Transaction, 1)
|
||||||
|
trans[0] = &graph.Transaction{
|
||||||
|
ID: s.AcquireNextId(),
|
||||||
|
Triple: t,
|
||||||
|
Action: graph.Add,
|
||||||
|
Timestamp: time.Now(),
|
||||||
|
}
|
||||||
|
return s.ts.ApplyTransactions(trans)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Single) AddTripleSet(set []*graph.Triple) error {
|
||||||
|
trans := make([]*graph.Transaction, len(set))
|
||||||
|
for i, t := range set {
|
||||||
|
trans[i] = &graph.Transaction{
|
||||||
|
ID: s.AcquireNextId(),
|
||||||
|
Triple: t,
|
||||||
|
Action: graph.Add,
|
||||||
|
Timestamp: time.Now(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s.ts.ApplyTransactions(trans)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Single) RemoveTriple(t *graph.Triple) error {
|
||||||
|
trans := make([]*graph.Transaction, 1)
|
||||||
|
trans[0] = &graph.Transaction{
|
||||||
|
ID: s.AcquireNextId(),
|
||||||
|
Triple: t,
|
||||||
|
Action: graph.Delete,
|
||||||
|
Timestamp: time.Now(),
|
||||||
|
}
|
||||||
|
return s.ts.ApplyTransactions(trans)
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
graph.RegisterWriter("single", NewSingleReplication)
|
graph.RegisterWriter("single", NewSingleReplication)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue