From 915903c1c151df563204f76038f77df578d64cd4 Mon Sep 17 00:00:00 2001 From: Quentin Machu Date: Tue, 17 Nov 2015 19:34:06 -0500 Subject: [PATCH] database: Fix to a locking issue with PostgreSQL It appears that preparing an INSERT statement on PostgreSQL actually makes it expecting to receive INSERTs and thus, it create some kind of locks for it. If instead, you only send him DELETE statements, it will indefinitely wait for an INSERT and hung. --- Godeps/Godeps.json | 2 +- vendor/github.com/google/cayley/graph/sql/quadstore.go | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 91a9b4b4..fd766ede 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": "cfbc0b364910ab69bbced5d2f7913ee7e80a0c80" + "Rev": "2f5ce909a242795d82529658ceb586863f5dd559" }, { "ImportPath": "github.com/julienschmidt/httprouter", diff --git a/vendor/github.com/google/cayley/graph/sql/quadstore.go b/vendor/github.com/google/cayley/graph/sql/quadstore.go index d03e84ef..24ff262d 100644 --- a/vendor/github.com/google/cayley/graph/sql/quadstore.go +++ b/vendor/github.com/google/cayley/graph/sql/quadstore.go @@ -192,16 +192,10 @@ func (qs *QuadStore) runTxPostgres(tx *sql.Tx, in []graph.Delta, opts graph.Igno return qs.copyFrom(tx, in) } - insert, err := tx.Prepare(`INSERT INTO quads(subject, predicate, object, label, id, ts, subject_hash, predicate_hash, object_hash, label_hash) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)`) - defer insert.Close() - if err != nil { - glog.Errorf("Cannot prepare insert statement: %v", err) - return err - } for _, d := range in { switch d.Action { case graph.Add: - _, err := insert.Exec( + _, err := tx.Exec(`INSERT INTO quads(subject, predicate, object, label, id, ts, subject_hash, predicate_hash, object_hash, label_hash) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);`, d.Quad.Subject, d.Quad.Predicate, d.Quad.Object, @@ -214,7 +208,7 @@ func (qs *QuadStore) runTxPostgres(tx *sql.Tx, in []graph.Delta, opts graph.Igno hashOf(d.Quad.Label), ) if err != nil { - glog.Errorf("couldn't prepare INSERT statement: %v", err) + glog.Errorf("couldn't exec INSERT statement: %v", err) return err } case graph.Delete: