From 470b47f70a7d16b515866249b1177241c5e26127 Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Tue, 21 Jul 2015 12:53:55 +0200 Subject: [PATCH] Fixed endless loop in Z order range query code in SQLite3 backend. --- cmd/mtredisalize/sqlite.go | 69 +++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/cmd/mtredisalize/sqlite.go b/cmd/mtredisalize/sqlite.go index 8fd0d53..1e7ea63 100644 --- a/cmd/mtredisalize/sqlite.go +++ b/cmd/mtredisalize/sqlite.go @@ -327,49 +327,50 @@ func (ss *SqliteSession) interleavedSpatialQuery(first, second []byte, done chan zmin, zmax = order(zmin, zmax) cub := common.Cuboid{P1: c1, P2: c2} rangeStmt := ss.txStmt(ss.backend.rangeStmt) - OUTER: - for { - var ( - err error - rows *sql.Rows - ) - if rows, err = rangeStmt.Query(zmin, zmax); err != nil { - log.Printf("Error in range query: %s\n", err) + var ( + err error + rows *sql.Rows + ) + loop: + // log.Printf("query %d %d\n", zmin, zmax) + if rows, err = rangeStmt.Query(zmin, zmax); err != nil { + log.Printf("Error in range query: %s\n", err) + return + } + for rows.Next() { + var zcode int64 + var data []byte + if err = rows.Scan(&zcode, &data); err != nil { + log.Printf("Error in scanning row: %s\n", err) + rows.Close() return } - for rows.Next() { - var zcode int64 - var data []byte - if err = rows.Scan(&zcode, &data); err != nil { - log.Printf("Error in scanning row: %s\n", err) + // log.Printf("zcode: %d\n", zcode) + c := common.InterleavedToCoord(zcode) + if cub.Contains(c) { + var encodedKey []byte + if encodedKey, err = common.EncodeStringToBytes(common.CoordToPlain(c)); err != nil { + log.Printf("Key encoding failed: %s\n", err) rows.Close() return } - c := common.InterleavedToCoord(zcode) - if cub.Contains(c) { - var encodedKey []byte - if encodedKey, err = common.EncodeStringToBytes(common.CoordToPlain(c)); err != nil { - log.Printf("Key encoding failed: %s\n", err) - rows.Close() - return - } - select { - case blocks <- Block{Key: encodedKey, Data: data}: - case <-done: - rows.Close() - return - } - } else { // Left the cuboid + select { + case blocks <- Block{Key: encodedKey, Data: data}: + case <-done: rows.Close() - zmin = common.BigMin(zmin, zmax, zcode) - continue OUTER + return } + } else { // Left the cuboid + // log.Printf("Left cuboid %d\n", zcode) + rows.Close() + zmin = common.BigMin(zmin, zmax, zcode) + goto loop } - if err = rows.Err(); err != nil { - log.Printf("Error in range query: %s\n", err) - } - rows.Close() } + if err = rows.Err(); err != nil { + log.Printf("Error in range query: %s\n", err) + } + rows.Close() }() return