From 472d86223e90f1e110efb60023a9192bb8f8d240 Mon Sep 17 00:00:00 2001 From: "l.albertalli" Date: Tue, 10 Feb 2015 18:17:54 -0800 Subject: [PATCH] Changed the ApplyDeltas signature --- graph/bolt/quadstore.go | 6 +++--- graph/iterator/mock_ts_test.go | 2 +- graph/leveldb/quadstore.go | 6 +++--- graph/memstore/quadstore.go | 6 +++--- graph/mongo/quadstore.go | 6 +++--- graph/quadstore.go | 2 +- graph/quadwriter.go | 4 ++++ writer/single.go | 15 ++++++++------- 8 files changed, 26 insertions(+), 21 deletions(-) diff --git a/graph/bolt/quadstore.go b/graph/bolt/quadstore.go index bd5fa9e..265f948 100644 --- a/graph/bolt/quadstore.go +++ b/graph/bolt/quadstore.go @@ -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 diff --git a/graph/iterator/mock_ts_test.go b/graph/iterator/mock_ts_test.go index 8923a69..6e2b00d 100644 --- a/graph/iterator/mock_ts_test.go +++ b/graph/iterator/mock_ts_test.go @@ -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{} } diff --git a/graph/leveldb/quadstore.go b/graph/leveldb/quadstore.go index b20f62c..0a7fe99 100644 --- a/graph/leveldb/quadstore.go +++ b/graph/leveldb/quadstore.go @@ -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 diff --git a/graph/memstore/quadstore.go b/graph/memstore/quadstore.go index 52cb298..4a62ec5 100644 --- a/graph/memstore/quadstore.go +++ b/graph/memstore/quadstore.go @@ -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: diff --git a/graph/mongo/quadstore.go b/graph/mongo/quadstore.go index cb9331a..98a5cc3 100644 --- a/graph/mongo/quadstore.go +++ b/graph/mongo/quadstore.go @@ -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 diff --git a/graph/quadstore.go b/graph/quadstore.go index 2194d25..cb7eca0 100644 --- a/graph/quadstore.go +++ b/graph/quadstore.go @@ -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 diff --git a/graph/quadwriter.go b/graph/quadwriter.go index 097b133..fdf65f3 100644 --- a/graph/quadwriter.go +++ b/graph/quadwriter.go @@ -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() diff --git a/writer/single.go b/writer/single.go index f0f7cb0..4c386b8 100644 --- a/writer/single.go +++ b/writer/single.go @@ -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 {