This commit is contained in:
Barak Michener 2014-07-24 17:59:39 -04:00
parent 929b4f539b
commit 9793096b9a
2 changed files with 19 additions and 18 deletions

View file

@ -27,13 +27,14 @@ import (
type Procedure byte type Procedure byte
// The different types of actions a transaction can do.
const ( const (
Add Procedure = iota Add Procedure = iota
Delete Delete
) )
type Transaction struct { type Transaction struct {
Id int64 ID int64
Triple *Triple Triple *Triple
Action Procedure Action Procedure
} }
@ -44,7 +45,7 @@ type Replication interface {
AcquireNextIds(size int64) (start int64, end int64) AcquireNextIds(size int64) (start int64, end int64)
// Returns the highest current ID. // Returns the highest current ID.
GetLastId() int64 GetLastID() int64
// Sends the transactions to the replicas. // Sends the transactions to the replicas.
Replicate([]*Transaction) Replicate([]*Transaction)

View file

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package local package replication
import ( import (
"sync" "sync"
@ -20,38 +20,38 @@ import (
"github.com/google/cayley/graph" "github.com/google/cayley/graph"
) )
type LocalReplication struct { type Single struct {
lastId int64 lastID int64
ts graph.TripleStore ts graph.TripleStore
mut sync.Mutex mut sync.Mutex
} }
func NewLocalReplication(ts graph.TripleStore, opts graph.Options) (graph.Replication, error) { func NewSingleReplication(ts graph.TripleStore, opts graph.Options) (graph.Replication, error) {
rep := &LocalReplication{lastId: ts.Horizon(), ts: ts} rep := &Single{lastID: ts.Horizon(), ts: ts}
ts.SetReplication(rep) ts.SetReplication(rep)
return rep, nil return rep, nil
} }
func (l *LocalReplication) AcquireNextIds(size int64) (start int64, end int64) { func (s *Single) AcquireNextIds(size int64) (start int64, end int64) {
l.mut.Lock() s.mut.Lock()
defer l.mut.Unlock() defer s.mut.Unlock()
start = l.lastId + 1 start = s.lastID + 1
end = l.lastId + size end = s.lastID + size
l.lastId += size s.lastID += size
return return
} }
func (l *LocalReplication) GetLastId() int64 { func (s *Single) GetLastID() int64 {
return l.lastId return s.lastID
} }
func (l *LocalReplication) Replicate([]*graph.Transaction) { func (s *Single) Replicate([]*graph.Transaction) {
// Noop, single-machines don't replicate out anywhere. // Noop, single-machines don't replicate out anywhere.
} }
func (l *LocalReplication) RequestTransactionRange(int64, int64) { func (s *Single) RequestTransactionRange(int64, int64) {
// Single machines also can't catch up. // Single machines also can't catch up.
} }
func init() { func init() {
graph.RegisterReplication("local", NewLocalReplication) graph.RegisterReplication("local", NewSingleReplication)
} }