From cfa960d61903887c203af8d0a3d204a4fe0b7fb0 Mon Sep 17 00:00:00 2001 From: Quentin Machu Date: Wed, 18 Nov 2015 18:53:00 -0500 Subject: [PATCH] database: Update Cayley to fix slow deletions subject, predicate, object and labels are not indexed, thus, using a where clause on these fields for the DELETE statement does a full-table scan. Using *_hash columns instead will use the indexes. --- Godeps/Godeps.json | 2 +- database/lock.go | 6 +++--- vendor/github.com/google/cayley/graph/sql/quadstore.go | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index fd766ede..3660069a 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -42,7 +42,7 @@ { "ImportPath": "github.com/google/cayley", "Comment": "v0.4.1-160-gcdf0154", - "Rev": "2f5ce909a242795d82529658ceb586863f5dd559" + "Rev": "f143602b8ae880ec975e4c154dd010047de80c1f" }, { "ImportPath": "github.com/julienschmidt/httprouter", diff --git a/database/lock.go b/database/lock.go index 7f1121b5..49903232 100644 --- a/database/lock.go +++ b/database/lock.go @@ -66,8 +66,6 @@ func Lock(name string, duration time.Duration, owner string) (bool, time.Time) { // Unlock unlocks a lock specified by its name if I own it func Unlock(name, owner string) { - pruneLocks() - unlocked := 0 it, _ := cayley.StartPath(store, name).Has("locked", "locked").Has("locked_by", owner).Save("locked_until", "locked_until").BuildIterator().Optimize() defer it.Close() @@ -133,7 +131,7 @@ func pruneLocks() { tt, _ := strconv.ParseInt(t, 10, 64) if now.Unix() > tt { - log.Debugf("Lock %s owned by %s has expired.", n, o) + log.Debugf("lock %s owned by %s has expired.", n, o) tr := cayley.NewTransaction() tr.RemoveQuad(cayley.Quad(n, "locked", "locked", "")) @@ -142,7 +140,9 @@ func pruneLocks() { err := store.ApplyTransaction(tr) if err != nil { log.Errorf("failed transaction (pruneLocks): %s", err) + continue } + log.Debugf("lock %s has been successfully pruned.", n) } } if it.Err() != nil { diff --git a/vendor/github.com/google/cayley/graph/sql/quadstore.go b/vendor/github.com/google/cayley/graph/sql/quadstore.go index 24ff262d..09773820 100644 --- a/vendor/github.com/google/cayley/graph/sql/quadstore.go +++ b/vendor/github.com/google/cayley/graph/sql/quadstore.go @@ -212,8 +212,8 @@ func (qs *QuadStore) runTxPostgres(tx *sql.Tx, in []graph.Delta, opts graph.Igno return err } case graph.Delete: - result, err := tx.Exec(`DELETE FROM quads WHERE subject=$1 and predicate=$2 and object=$3 and label=$4;`, - d.Quad.Subject, d.Quad.Predicate, d.Quad.Object, d.Quad.Label) + result, err := tx.Exec(`DELETE FROM quads WHERE subject_hash=$1 and predicate_hash=$2 and object_hash=$3 and label_hash=$4;`, + hashOf(d.Quad.Subject), hashOf(d.Quad.Predicate), hashOf(d.Quad.Object), hashOf(d.Quad.Label)) if err != nil { glog.Errorf("couldn't exec DELETE statement: %v", err) return err