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.
This commit is contained in:
parent
ac0e68efe7
commit
cfa960d619
2
Godeps/Godeps.json
generated
2
Godeps/Godeps.json
generated
@ -42,7 +42,7 @@
|
|||||||
{
|
{
|
||||||
"ImportPath": "github.com/google/cayley",
|
"ImportPath": "github.com/google/cayley",
|
||||||
"Comment": "v0.4.1-160-gcdf0154",
|
"Comment": "v0.4.1-160-gcdf0154",
|
||||||
"Rev": "2f5ce909a242795d82529658ceb586863f5dd559"
|
"Rev": "f143602b8ae880ec975e4c154dd010047de80c1f"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/julienschmidt/httprouter",
|
"ImportPath": "github.com/julienschmidt/httprouter",
|
||||||
|
@ -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
|
// Unlock unlocks a lock specified by its name if I own it
|
||||||
func Unlock(name, owner string) {
|
func Unlock(name, owner string) {
|
||||||
pruneLocks()
|
|
||||||
|
|
||||||
unlocked := 0
|
unlocked := 0
|
||||||
it, _ := cayley.StartPath(store, name).Has("locked", "locked").Has("locked_by", owner).Save("locked_until", "locked_until").BuildIterator().Optimize()
|
it, _ := cayley.StartPath(store, name).Has("locked", "locked").Has("locked_by", owner).Save("locked_until", "locked_until").BuildIterator().Optimize()
|
||||||
defer it.Close()
|
defer it.Close()
|
||||||
@ -133,7 +131,7 @@ func pruneLocks() {
|
|||||||
tt, _ := strconv.ParseInt(t, 10, 64)
|
tt, _ := strconv.ParseInt(t, 10, 64)
|
||||||
|
|
||||||
if now.Unix() > tt {
|
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 := cayley.NewTransaction()
|
||||||
tr.RemoveQuad(cayley.Quad(n, "locked", "locked", ""))
|
tr.RemoveQuad(cayley.Quad(n, "locked", "locked", ""))
|
||||||
@ -142,7 +140,9 @@ func pruneLocks() {
|
|||||||
err := store.ApplyTransaction(tr)
|
err := store.ApplyTransaction(tr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("failed transaction (pruneLocks): %s", err)
|
log.Errorf("failed transaction (pruneLocks): %s", err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
log.Debugf("lock %s has been successfully pruned.", n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if it.Err() != nil {
|
if it.Err() != nil {
|
||||||
|
4
vendor/github.com/google/cayley/graph/sql/quadstore.go
generated
vendored
4
vendor/github.com/google/cayley/graph/sql/quadstore.go
generated
vendored
@ -212,8 +212,8 @@ func (qs *QuadStore) runTxPostgres(tx *sql.Tx, in []graph.Delta, opts graph.Igno
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case graph.Delete:
|
case graph.Delete:
|
||||||
result, err := tx.Exec(`DELETE FROM quads WHERE subject=$1 and predicate=$2 and object=$3 and label=$4;`,
|
result, err := tx.Exec(`DELETE FROM quads WHERE subject_hash=$1 and predicate_hash=$2 and object_hash=$3 and label_hash=$4;`,
|
||||||
d.Quad.Subject, d.Quad.Predicate, d.Quad.Object, d.Quad.Label)
|
hashOf(d.Quad.Subject), hashOf(d.Quad.Predicate), hashOf(d.Quad.Object), hashOf(d.Quad.Label))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("couldn't exec DELETE statement: %v", err)
|
glog.Errorf("couldn't exec DELETE statement: %v", err)
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user