From f6bf779cd6a8eda505c8392cbbba9d9d0fc4c96e Mon Sep 17 00:00:00 2001 From: mpl Date: Thu, 12 Mar 2015 16:15:56 +0100 Subject: [PATCH] sorted/kvtest: close iterator ASAP to make sqlite happy Change-Id: I7dcca4447bea262fedc6a5fbe572034bfd8cc61d --- pkg/sorted/kvtest/kvtest.go | 4 +++- pkg/sorted/sqlkv/sqlkv.go | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/sorted/kvtest/kvtest.go b/pkg/sorted/kvtest/kvtest.go index 344930fc7..0d4dd1014 100644 --- a/pkg/sorted/kvtest/kvtest.go +++ b/pkg/sorted/kvtest/kvtest.go @@ -96,12 +96,14 @@ func testInsertLarge(t *testing.T, kv sorted.KeyValue) { if err := kv.Set(string(largeKey), "whatever"); err != nil { t.Fatalf("Insertion of large key failed: %v", err) } + // and verify we can get it back, i.e. that the key hasn't been truncated. it := kv.Find(string(largeKey), "") - defer it.Close() if !it.Next() || it.Key() != string(largeKey) || it.Value() != "whatever" { + it.Close() t.Fatalf("Find(largeKey) = %q, %q; want %q, %q", it.Key(), it.Value(), largeKey, "whatever") } + it.Close() // insert with large value if err := kv.Set("whatever", string(largeValue)); err != nil { diff --git a/pkg/sorted/sqlkv/sqlkv.go b/pkg/sorted/sqlkv/sqlkv.go index 0e571e037..54b585a45 100644 --- a/pkg/sorted/sqlkv/sqlkv.go +++ b/pkg/sorted/sqlkv/sqlkv.go @@ -177,6 +177,9 @@ func (kv *KeyValue) Close() error { return kv.DB.Close() } func (kv *KeyValue) Find(start, end string) sorted.Iterator { if kv.Serial { kv.mu.Lock() + // TODO(mpl): looks like sqlite considers the db locked until we've closed + // the iterator, so we can't do anything else until then. We should probably + // move that Unlock to the closing of the iterator. Investigating. defer kv.mu.Unlock() } var rows *sql.Rows