comments and concretized deltas
This commit is contained in:
parent
fe0569c9d4
commit
f967b36f84
9 changed files with 31 additions and 35 deletions
|
|
@ -36,7 +36,7 @@ func (qs *store) ValueOf(s string) graph.Value {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (qs *store) ApplyDeltas([]*graph.Delta) error { return nil }
|
||||
func (qs *store) ApplyDeltas([]graph.Delta) error { return nil }
|
||||
|
||||
func (qs *store) Quad(graph.Value) quad.Quad { return quad.Quad{} }
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ type Iterator struct {
|
|||
result graph.Value
|
||||
}
|
||||
|
||||
func NewIterator(prefix string, d quad.Direction, value graph.Value, qs *TripleStore) graph.Iterator {
|
||||
func NewIterator(prefix string, d quad.Direction, value graph.Value, qs *TripleStore) *Iterator {
|
||||
vb := value.(Token)
|
||||
p := make([]byte, 0, 2+qs.hasherSize)
|
||||
p = append(p, []byte(prefix)...)
|
||||
|
|
@ -70,7 +70,6 @@ func NewIterator(prefix string, d quad.Direction, value graph.Value, qs *TripleS
|
|||
it.open = false
|
||||
it.iter.Release()
|
||||
glog.Error("Opening LevelDB iterator couldn't seek to location ", it.nextPrefix)
|
||||
return &iterator.Null{}
|
||||
}
|
||||
|
||||
return &it
|
||||
|
|
@ -108,7 +107,7 @@ func (it *Iterator) TagResults(dst map[string]graph.Value) {
|
|||
|
||||
func (it *Iterator) Clone() graph.Iterator {
|
||||
out := NewIterator(it.originalPrefix, it.dir, Token(it.checkId), it.qs)
|
||||
out.Tagger().CopyFrom(it)
|
||||
out.tags.CopyFrom(it)
|
||||
return out
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ func (qs *TripleStore) Horizon() int64 {
|
|||
return qs.horizon
|
||||
}
|
||||
|
||||
func (qa *TripleStore) createDeltaKeyFor(d *graph.Delta) []byte {
|
||||
func (qa *TripleStore) createDeltaKeyFor(d graph.Delta) []byte {
|
||||
key := make([]byte, 0, 19)
|
||||
key = append(key, 'd')
|
||||
key = append(key, []byte(fmt.Sprintf("%018x", d.ID))...)
|
||||
|
|
@ -176,7 +176,7 @@ var (
|
|||
cps = [4]quad.Direction{quad.Label, quad.Predicate, quad.Subject, quad.Object}
|
||||
)
|
||||
|
||||
func (qs *TripleStore) ApplyDeltas(deltas []*graph.Delta) error {
|
||||
func (qs *TripleStore) ApplyDeltas(deltas []graph.Delta) error {
|
||||
batch := &leveldb.Batch{}
|
||||
resizeMap := make(map[string]int64)
|
||||
size_change := int64(0)
|
||||
|
|
|
|||
|
|
@ -35,17 +35,17 @@ func NewMemstoreNodesAllIterator(ts *TripleStore) *NodesAllIterator {
|
|||
}
|
||||
|
||||
// No subiterators.
|
||||
func (nit *NodesAllIterator) SubIterators() []graph.Iterator {
|
||||
func (it *NodesAllIterator) SubIterators() []graph.Iterator {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nit *NodesAllIterator) Next() bool {
|
||||
if !nit.Int64.Next() {
|
||||
func (it *NodesAllIterator) Next() bool {
|
||||
if !it.Int64.Next() {
|
||||
return false
|
||||
}
|
||||
_, ok := nit.ts.revIdMap[nit.Int64.Result().(int64)]
|
||||
_, ok := it.ts.revIdMap[it.Int64.Result().(int64)]
|
||||
if !ok {
|
||||
return nit.Next()
|
||||
return it.Next()
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ func newTripleStore() *TripleStore {
|
|||
return &ts
|
||||
}
|
||||
|
||||
func (ts *TripleStore) ApplyDeltas(deltas []*graph.Delta) error {
|
||||
func (ts *TripleStore) ApplyDeltas(deltas []graph.Delta) error {
|
||||
for _, d := range deltas {
|
||||
var err error
|
||||
if d.Action == graph.Add {
|
||||
|
|
@ -154,13 +154,13 @@ func (ts *TripleStore) quadExists(t quad.Quad) (bool, int64) {
|
|||
return false, 0
|
||||
}
|
||||
|
||||
func (ts *TripleStore) AddDelta(d *graph.Delta) error {
|
||||
func (ts *TripleStore) AddDelta(d graph.Delta) error {
|
||||
if exists, _ := ts.quadExists(d.Quad); exists {
|
||||
return graph.ErrQuadExists
|
||||
}
|
||||
var quadID int64
|
||||
quadID = ts.quadIdCounter
|
||||
ts.log = append(ts.log, LogEntry{Delta: *d})
|
||||
ts.log = append(ts.log, LogEntry{Delta: d})
|
||||
ts.size++
|
||||
ts.quadIdCounter++
|
||||
|
||||
|
|
@ -189,7 +189,7 @@ func (ts *TripleStore) AddDelta(d *graph.Delta) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (ts *TripleStore) RemoveDelta(d *graph.Delta) error {
|
||||
func (ts *TripleStore) RemoveDelta(d graph.Delta) error {
|
||||
var prevQuadID int64
|
||||
var exists bool
|
||||
prevQuadID = 0
|
||||
|
|
@ -199,7 +199,7 @@ func (ts *TripleStore) RemoveDelta(d *graph.Delta) error {
|
|||
|
||||
var quadID int64
|
||||
quadID = ts.quadIdCounter
|
||||
ts.log = append(ts.log, LogEntry{Delta: *d})
|
||||
ts.log = append(ts.log, LogEntry{Delta: d})
|
||||
ts.log[prevQuadID].DeletedBy = quadID
|
||||
ts.size--
|
||||
ts.quadIdCounter++
|
||||
|
|
|
|||
|
|
@ -192,7 +192,7 @@ func (qs *TripleStore) checkValid(key string) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func (qs *TripleStore) updateLog(d *graph.Delta) error {
|
||||
func (qs *TripleStore) updateLog(d graph.Delta) error {
|
||||
var action string
|
||||
if d.Action == graph.Add {
|
||||
action = "Add"
|
||||
|
|
@ -212,7 +212,7 @@ func (qs *TripleStore) updateLog(d *graph.Delta) error {
|
|||
return err
|
||||
}
|
||||
|
||||
func (qs *TripleStore) ApplyDeltas(in []*graph.Delta) error {
|
||||
func (qs *TripleStore) ApplyDeltas(in []graph.Delta) error {
|
||||
qs.session.SetSafe(nil)
|
||||
ids := make(map[string]int)
|
||||
// Pre-check the existence condition.
|
||||
|
|
@ -267,17 +267,12 @@ func (qs *TripleStore) ApplyDeltas(in []*graph.Delta) error {
|
|||
}
|
||||
|
||||
func (qs *TripleStore) Quad(val graph.Value) quad.Quad {
|
||||
var bsonDoc bson.M
|
||||
err := qs.db.C("quads").FindId(val.(string)).One(&bsonDoc)
|
||||
var q quad.Quad
|
||||
err := qs.db.C("quads").FindId(val.(string)).One(&q)
|
||||
if err != nil {
|
||||
glog.Errorf("Error: Couldn't retrieve quad %s %v", val, err)
|
||||
}
|
||||
return quad.Quad{
|
||||
bsonDoc["Subject"].(string),
|
||||
bsonDoc["Predicate"].(string),
|
||||
bsonDoc["Object"].(string),
|
||||
bsonDoc["Label"].(string),
|
||||
}
|
||||
return q
|
||||
}
|
||||
|
||||
func (qs *TripleStore) TripleIterator(d quad.Direction, val graph.Value) graph.Iterator {
|
||||
|
|
|
|||
|
|
@ -53,8 +53,10 @@ func (h *Handle) Close() {
|
|||
h.QuadWriter.Close()
|
||||
}
|
||||
|
||||
var ErrQuadExists = errors.New("Quad exists")
|
||||
var ErrQuadNotExist = errors.New("Quad doesn't exist")
|
||||
var (
|
||||
ErrQuadExists = errors.New("Quad exists")
|
||||
ErrQuadNotExist = errors.New("Quad doesn't exist")
|
||||
)
|
||||
|
||||
type QuadWriter interface {
|
||||
// Add a quad to the store.
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ type Value interface{}
|
|||
type TripleStore interface {
|
||||
// The only way in is through building a transaction, which
|
||||
// is done by a replication strategy.
|
||||
ApplyDeltas([]*Delta) error
|
||||
ApplyDeltas([]Delta) error
|
||||
|
||||
// Given an opaque token, returns the triple for that token from the store.
|
||||
Quad(Value) quad.Quad
|
||||
|
|
|
|||
|
|
@ -50,8 +50,8 @@ func (s *Single) AcquireNextID() int64 {
|
|||
}
|
||||
|
||||
func (s *Single) AddQuad(q quad.Quad) error {
|
||||
deltas := make([]*graph.Delta, 1)
|
||||
deltas[0] = &graph.Delta{
|
||||
deltas := make([]graph.Delta, 1)
|
||||
deltas[0] = graph.Delta{
|
||||
ID: s.AcquireNextID(),
|
||||
Quad: q,
|
||||
Action: graph.Add,
|
||||
|
|
@ -61,9 +61,9 @@ func (s *Single) AddQuad(q quad.Quad) error {
|
|||
}
|
||||
|
||||
func (s *Single) AddQuadSet(set []quad.Quad) error {
|
||||
deltas := make([]*graph.Delta, len(set))
|
||||
deltas := make([]graph.Delta, len(set))
|
||||
for i, q := range set {
|
||||
deltas[i] = &graph.Delta{
|
||||
deltas[i] = graph.Delta{
|
||||
ID: s.AcquireNextID(),
|
||||
Quad: q,
|
||||
Action: graph.Add,
|
||||
|
|
@ -75,8 +75,8 @@ func (s *Single) AddQuadSet(set []quad.Quad) error {
|
|||
}
|
||||
|
||||
func (s *Single) RemoveQuad(q quad.Quad) error {
|
||||
deltas := make([]*graph.Delta, 1)
|
||||
deltas[0] = &graph.Delta{
|
||||
deltas := make([]graph.Delta, 1)
|
||||
deltas[0] = graph.Delta{
|
||||
ID: s.AcquireNextID(),
|
||||
Quad: q,
|
||||
Action: graph.Delete,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue