mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-12-24 17:20:18 +01:00
Started coverage index support for non-interleaved LevelDb backends.
This commit is contained in:
parent
3fc89ad0f5
commit
d53cea250c
@ -17,8 +17,10 @@ type LevelDBBackend struct {
|
|||||||
cache *leveldb.Cache
|
cache *leveldb.Cache
|
||||||
db *leveldb.DB
|
db *leveldb.DB
|
||||||
interleaved bool
|
interleaved bool
|
||||||
|
coverage *common.Coverage3D
|
||||||
encoder common.KeyTranscoder
|
encoder common.KeyTranscoder
|
||||||
decoder common.KeyTranscoder
|
decoder common.KeyTranscoder
|
||||||
|
|
||||||
changeTracker *ChangeTracker
|
changeTracker *ChangeTracker
|
||||||
mutex sync.RWMutex
|
mutex sync.RWMutex
|
||||||
}
|
}
|
||||||
@ -71,8 +73,41 @@ func NewLeveDBBackend(
|
|||||||
encoder: encoder,
|
encoder: encoder,
|
||||||
decoder: decoder,
|
decoder: decoder,
|
||||||
changeTracker: changeTracker}
|
changeTracker: changeTracker}
|
||||||
|
|
||||||
|
if !interleaved {
|
||||||
|
if err = ldb.buildCoverage(); err != nil {
|
||||||
|
ldb.Shutdown()
|
||||||
|
ldb = nil
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ldb *LevelDBBackend) buildCoverage() error {
|
||||||
|
log.Println("INFO: Start building coverage index (this may take some time)...")
|
||||||
|
|
||||||
|
coverage := common.NewCoverage3D()
|
||||||
|
|
||||||
|
ro := leveldb.NewReadOptions()
|
||||||
|
defer ro.Close()
|
||||||
|
ro.SetFillCache(false)
|
||||||
|
it := ldb.db.NewIterator(ro)
|
||||||
|
it.SeekToFirst()
|
||||||
|
for ; it.Valid(); it.Next() {
|
||||||
|
c, err := common.DecodeStringBytesToCoord(it.Key())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
coverage.Insert(c)
|
||||||
|
}
|
||||||
|
if err := it.GetError(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
ldb.coverage = coverage
|
||||||
|
log.Println("INFO: Finished building coverage index.")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (ldb *LevelDBBackend) doRead(f func(db *leveldb.DB)) {
|
func (ldb *LevelDBBackend) doRead(f func(db *leveldb.DB)) {
|
||||||
ldb.mutex.RLock()
|
ldb.mutex.RLock()
|
||||||
@ -156,6 +191,13 @@ func (ldbs *LevelDBSession) Store(hash, key, value []byte) (exists bool, err err
|
|||||||
})
|
})
|
||||||
// This technically too early because this done in transactions
|
// This technically too early because this done in transactions
|
||||||
// which are commited (and possible fail) later.
|
// which are commited (and possible fail) later.
|
||||||
|
if ldbs.backend.coverage != nil {
|
||||||
|
c, err := common.DecodeStringBytesToCoord(origKey)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
ldbs.backend.coverage.Insert(c)
|
||||||
|
}
|
||||||
if ldbs.backend.changeTracker != nil {
|
if ldbs.backend.changeTracker != nil {
|
||||||
ldbs.backend.changeTracker.BlockChanged(origKey)
|
ldbs.backend.changeTracker.BlockChanged(origKey)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user