From 29eeb5e3016e12da5bd3867e6ba582503f74404e Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Fri, 24 Jul 2015 08:30:52 +0200 Subject: [PATCH] Implemented usage of coverage index in non-interleaved LevelDB backend. Untested, yet! --- cmd/mtredisalize/leveldb.go | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/cmd/mtredisalize/leveldb.go b/cmd/mtredisalize/leveldb.go index f8ede70..b1307ca 100644 --- a/cmd/mtredisalize/leveldb.go +++ b/cmd/mtredisalize/leveldb.go @@ -274,14 +274,19 @@ func (ldbs *LevelDBSession) AllKeys(hash []byte, done chan struct{}) (keys chan return } -func (ldbs *LevelDBSession) SpatialQuery(hash, first, second []byte, done chan struct{}) (chan Block, error) { +func (ldbs *LevelDBSession) SpatialQuery( + hash, first, second []byte, + done chan struct{}) (chan Block, error) { + if ldbs.backend.interleaved { return ldbs.interleavedSpatialQuery(first, second, done) } return ldbs.plainSpatialQuery(first, second, done) } -func (ldbs *LevelDBSession) plainSpatialQuery(first, second []byte, done chan struct{}) (blocks chan Block, err error) { +func (ldbs *LevelDBSession) plainSpatialQuery( + first, second []byte, + done chan struct{}) (blocks chan Block, err error) { var ( firstKey int64 @@ -311,21 +316,20 @@ func (ldbs *LevelDBSession) plainSpatialQuery(first, second []byte, done chan st it := ldbs.backend.db.NewIterator(ro) defer it.Close() - a, b := common.Coord{X: c1.X}, common.Coord{X: c2.X} - + var a, b common.Coord var err error - for a.Z = c1.Z; a.Z <= c2.Z; a.Z++ { - b.Z = a.Z - for a.Y = c1.Y; a.Y <= c2.Y; a.Y++ { + for _, r := range ldbs.backend.coverage.Query(c1, c2) { + a.Z, b.Z = int16(r.Z), int16(r.Z) + a.X, b.X = int16(r.X1), int16(r.X2) + // log.Printf("y1 y2 x1 x2 z: %d %d, %d %d, %d\n", r.Y1, r.Y2, r.X1, r.X2, r.Z) + for a.Y = r.Y2; a.Y >= r.Y1; a.Y-- { b.Y = a.Y - from, to := order(common.CoordToPlain(a), common.CoordToPlain(b)) + from, to := common.CoordToPlain(a), common.CoordToPlain(b) it.Seek(common.StringToBytes(from)) for ; it.Valid(); it.Next() { - var ( - key = it.Key() - pos int64 - ) + key := it.Key() + var pos int64 if pos, err = common.DecodeStringFromBytes(key); err != nil { log.Printf("decoding key failed: %s\n", err) return @@ -349,7 +353,10 @@ func (ldbs *LevelDBSession) plainSpatialQuery(first, second []byte, done chan st return } -func (ldbs *LevelDBSession) interleavedSpatialQuery(first, second []byte, done chan struct{}) (blocks chan Block, err error) { +func (ldbs *LevelDBSession) interleavedSpatialQuery( + first, second []byte, + done chan struct{}) (blocks chan Block, err error) { + var ( firstKey int64 secondKey int64