mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-12-24 09:10:17 +01:00
Avoid redundant decoding when sendind coordinate to change tracker or coverage index.
Don't try to store in coverage index if the key already exists. Handle more potential database errors.
This commit is contained in:
parent
fed5b32469
commit
68bb1ee320
@ -27,13 +27,7 @@ func NewChangeTracker() *ChangeTracker {
|
|||||||
return &ChangeTracker{changes: make(map[quantizedXZ]bool)}
|
return &ChangeTracker{changes: make(map[quantizedXZ]bool)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ct *ChangeTracker) BlockChanged(key []byte) {
|
func (ct *ChangeTracker) BlockChanged(coord common.Coord) {
|
||||||
var err error
|
|
||||||
var coord common.Coord
|
|
||||||
if coord, err = common.DecodeStringBytesToCoord(key); err != nil {
|
|
||||||
log.Printf("decoding key failed: %s\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ct.mutex.Lock()
|
ct.mutex.Lock()
|
||||||
ct.changes[quantizedXZ{
|
ct.changes[quantizedXZ{
|
||||||
X: coord.X / quantizationFactor,
|
X: coord.X / quantizationFactor,
|
||||||
|
@ -189,17 +189,22 @@ func (ldbs *LevelDBSession) Store(hash, key, value []byte) (exists bool, err err
|
|||||||
err = db.Put(wo, key, value)
|
err = db.Put(wo, key, value)
|
||||||
wo.Close()
|
wo.Close()
|
||||||
})
|
})
|
||||||
// This technically too early because this done in transactions
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// This technically too early because this is done in a transactions
|
||||||
// which are commited (and possible fail) later.
|
// which are commited (and possible fail) later.
|
||||||
if ldbs.backend.coverage != nil {
|
if ldbs.backend.changeTracker != nil || ldbs.backend.coverage != nil {
|
||||||
c, err := common.DecodeStringBytesToCoord(origKey)
|
c, err := common.DecodeStringBytesToCoord(origKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return exists, err
|
||||||
}
|
}
|
||||||
|
if ldbs.backend.coverage != nil && !exists {
|
||||||
ldbs.backend.coverage.Insert(c)
|
ldbs.backend.coverage.Insert(c)
|
||||||
}
|
}
|
||||||
if ldbs.backend.changeTracker != nil {
|
if ldbs.backend.changeTracker != nil {
|
||||||
ldbs.backend.changeTracker.BlockChanged(origKey)
|
ldbs.backend.changeTracker.BlockChanged(c)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -239,15 +239,21 @@ func (ss *SqliteSession) Store(hash, key, value []byte) (exists bool, err error)
|
|||||||
insertStmt := ss.txStmt(ss.backend.insertStmt)
|
insertStmt := ss.txStmt(ss.backend.insertStmt)
|
||||||
_, err = insertStmt.Exec(pos, value)
|
_, err = insertStmt.Exec(pos, value)
|
||||||
}
|
}
|
||||||
// This technically too early because this done in transactions
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// This technically too early because this is done in a transactions
|
||||||
// which are commited (and possible fail) later.
|
// which are commited (and possible fail) later.
|
||||||
if ss.backend.coverage != nil {
|
if ss.backend.changeTracker != nil || ss.backend.coverage != nil {
|
||||||
ss.backend.coverage.Insert(common.PlainToCoord(pos))
|
c := common.PlainToCoord(pos)
|
||||||
|
if ss.backend.coverage != nil && !exists {
|
||||||
|
ss.backend.coverage.Insert(c)
|
||||||
|
}
|
||||||
|
if ss.backend.changeTracker != nil {
|
||||||
|
ss.backend.changeTracker.BlockChanged(c)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ss.backend.changeTracker != nil {
|
|
||||||
ss.backend.changeTracker.BlockChanged(key)
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user