Changed the ApplyDeltas signature

This commit is contained in:
l.albertalli 2015-02-10 18:17:54 -08:00
parent 50c3e5f93c
commit 472d86223e
8 changed files with 26 additions and 21 deletions

View file

@ -185,7 +185,7 @@ var (
metaBucket = []byte("meta")
)
func (qs *QuadStore) ApplyDeltas(deltas []graph.Delta, ignoreDup, ignoreMiss bool) error {
func (qs *QuadStore) ApplyDeltas(deltas []graph.Delta, ignoreOpts graph.IgnoreOpts) error {
oldSize := qs.size
oldHorizon := qs.horizon
err := qs.db.Update(func(tx *bolt.Tx) error {
@ -209,10 +209,10 @@ func (qs *QuadStore) ApplyDeltas(deltas []graph.Delta, ignoreDup, ignoreMiss boo
for _, d := range deltas {
err := qs.buildQuadWrite(tx, d.Quad, d.ID.Int(), d.Action == graph.Add)
if err != nil {
if err == graph.ErrQuadExists && ignoreDup{
if err == graph.ErrQuadExists && ignoreOpts.IgnoreDup{
continue
}
if err == graph.ErrQuadNotExist && ignoreMiss{
if err == graph.ErrQuadNotExist && ignoreOpts.IgnoreMissing{
continue
}
return err

View file

@ -35,7 +35,7 @@ func (qs *store) ValueOf(s string) graph.Value {
return nil
}
func (qs *store) ApplyDeltas([]graph.Delta, bool, bool) error { return nil }
func (qs *store) ApplyDeltas([]graph.Delta, graph.IgnoreOpts) error { return nil }
func (qs *store) Quad(graph.Value) quad.Quad { return quad.Quad{} }

View file

@ -181,7 +181,7 @@ var (
cps = [4]quad.Direction{quad.Label, quad.Predicate, quad.Subject, quad.Object}
)
func (qs *QuadStore) ApplyDeltas(deltas []graph.Delta, ignoreDup, ignoreMiss bool) error {
func (qs *QuadStore) ApplyDeltas(deltas []graph.Delta, ignoreOpts graph.IgnoreOpts) error {
batch := &leveldb.Batch{}
resizeMap := make(map[string]int64)
sizeChange := int64(0)
@ -196,10 +196,10 @@ func (qs *QuadStore) ApplyDeltas(deltas []graph.Delta, ignoreDup, ignoreMiss boo
batch.Put(keyFor(d), bytes)
err = qs.buildQuadWrite(batch, d.Quad, d.ID.Int(), d.Action == graph.Add)
if err != nil {
if err == graph.ErrQuadExists && ignoreDup{
if err == graph.ErrQuadExists && ignoreOpts.IgnoreDup {
continue
}
if err == graph.ErrQuadNotExist && ignoreMiss{
if err == graph.ErrQuadNotExist && ignoreOpts.IgnoreMissing {
continue
}
return err

View file

@ -100,18 +100,18 @@ func newQuadStore() *QuadStore {
}
}
func (qs *QuadStore) ApplyDeltas(deltas []graph.Delta, ignoreDupl, ignoreMiss bool) error {
func (qs *QuadStore) ApplyDeltas(deltas []graph.Delta, ignoreOpts graph.IgnoreOpts) error {
for _, d := range deltas {
var err error
switch d.Action {
case graph.Add:
err = qs.AddDelta(d)
if err != nil && ignoreDupl{
if err != nil && ignoreOpts.IgnoreDup{
err = nil
}
case graph.Delete:
err = qs.RemoveDelta(d)
if err != nil && ignoreMiss{
if err != nil && ignoreOpts.IgnoreMissing{
err = nil
}
default:

View file

@ -214,7 +214,7 @@ func (qs *QuadStore) updateLog(d graph.Delta) error {
return err
}
func (qs *QuadStore) ApplyDeltas(in []graph.Delta, ignoreDup, ignoreMiss bool) error {
func (qs *QuadStore) ApplyDeltas(in []graph.Delta, ignoreOpts graph.IgnoreOpts) error {
qs.session.SetSafe(nil)
ids := make(map[string]int)
// Pre-check the existence condition.
@ -226,7 +226,7 @@ func (qs *QuadStore) ApplyDeltas(in []graph.Delta, ignoreDup, ignoreMiss bool) e
switch d.Action {
case graph.Add:
if qs.checkValid(key) {
if ignoreDup {
if ignoreOpts.IgnoreDup {
continue
}else{
return graph.ErrQuadExists
@ -234,7 +234,7 @@ func (qs *QuadStore) ApplyDeltas(in []graph.Delta, ignoreDup, ignoreMiss bool) e
}
case graph.Delete:
if !qs.checkValid(key) {
if ignoreMiss {
if ignoreOpts.IgnoreMissing {
continue
}else{
return graph.ErrQuadNotExist

View file

@ -44,7 +44,7 @@ type Value interface{}
type QuadStore interface {
// The only way in is through building a transaction, which
// is done by a replication strategy.
ApplyDeltas([]Delta, bool, bool) error
ApplyDeltas([]Delta, IgnoreOpts) error
// Given an opaque token, returns the quad for that token from the store.
Quad(Value) quad.Quad

View file

@ -49,6 +49,10 @@ type Handle struct {
QuadWriter QuadWriter
}
type IgnoreOpts struct {
IgnoreDup, IgnoreMissing bool
}
func (h *Handle) Close() {
h.QuadStore.Close()
h.QuadWriter.Close()

View file

@ -28,8 +28,7 @@ func init() {
type Single struct {
currentID graph.PrimaryKey
qs graph.QuadStore
ignoreMissing bool
ignoreDuplicate bool
ignoreOpts graph.IgnoreOpts
}
func NewSingleReplication(qs graph.QuadStore, opts graph.Options) (graph.QuadWriter, error) {
@ -50,8 +49,10 @@ func NewSingleReplication(qs graph.QuadStore, opts graph.Options) (graph.QuadWri
return &Single{
currentID: qs.Horizon(),
qs: qs,
ignoreMissing: ignoreMissing,
ignoreDuplicate: ignoreDuplicate,
ignoreOpts: graph.IgnoreOpts{
IgnoreDup: ignoreDuplicate,
IgnoreMissing:ignoreMissing,
},
}, nil
}
@ -63,7 +64,7 @@ func (s *Single) AddQuad(q quad.Quad) error {
Action: graph.Add,
Timestamp: time.Now(),
}
return s.qs.ApplyDeltas(deltas, s.ignoreDuplicate, s.ignoreMissing)
return s.qs.ApplyDeltas(deltas, s.ignoreOpts)
}
func (s *Single) AddQuadSet(set []quad.Quad) error {
@ -77,7 +78,7 @@ func (s *Single) AddQuadSet(set []quad.Quad) error {
}
}
return s.qs.ApplyDeltas(deltas, s.ignoreDuplicate, s.ignoreMissing)
return s.qs.ApplyDeltas(deltas, s.ignoreOpts)
}
func (s *Single) RemoveQuad(q quad.Quad) error {
@ -88,7 +89,7 @@ func (s *Single) RemoveQuad(q quad.Quad) error {
Action: graph.Delete,
Timestamp: time.Now(),
}
return s.qs.ApplyDeltas(deltas, s.ignoreDuplicate, s.ignoreMissing)
return s.qs.ApplyDeltas(deltas, s.ignoreOpts)
}
func (s *Single) Close() error {