diff options
author | Ferenc Szabo <frncmx@gmail.com> | 2018-11-13 22:22:53 +0800 |
---|---|---|
committer | Anton Evangelatov <anton.evangelatov@gmail.com> | 2018-11-13 22:22:53 +0800 |
commit | c41e1bd1ebf8a625dd22a07c31bcd6837705e0d7 (patch) | |
tree | 8f9414a1f46a9ab95f0544b4d9aa0efce05725bf /swarm/storage/localstore.go | |
parent | 4fecc7a3b1b9c51efad47ea128abcb7259158487 (diff) | |
download | dexon-c41e1bd1ebf8a625dd22a07c31bcd6837705e0d7.tar dexon-c41e1bd1ebf8a625dd22a07c31bcd6837705e0d7.tar.gz dexon-c41e1bd1ebf8a625dd22a07c31bcd6837705e0d7.tar.bz2 dexon-c41e1bd1ebf8a625dd22a07c31bcd6837705e0d7.tar.lz dexon-c41e1bd1ebf8a625dd22a07c31bcd6837705e0d7.tar.xz dexon-c41e1bd1ebf8a625dd22a07c31bcd6837705e0d7.tar.zst dexon-c41e1bd1ebf8a625dd22a07c31bcd6837705e0d7.zip |
swarm/storage: fix garbage collector index skew (#18080)
On file access LDBStore's tryAccessIdx() function created a faulty
GC Index Data entry, because not indexing the ikey correctly.
That caused the chunk addresses/hashes to start with '00' and the last
two digits were dropped. => Incorrect chunk address.
Besides the fix, the commit also contains a schema change which will
run the CleanGCIndex() function to clean the GC index from erroneous
entries.
Note: CleanGCIndex() rebuilds the index from scratch which can take
a really-really long time with a huge DB (possibly an hour).
Diffstat (limited to 'swarm/storage/localstore.go')
-rw-r--r-- | swarm/storage/localstore.go | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/swarm/storage/localstore.go b/swarm/storage/localstore.go index 6971d759e..fa98848dd 100644 --- a/swarm/storage/localstore.go +++ b/swarm/storage/localstore.go @@ -196,31 +196,48 @@ func (ls *LocalStore) Close() { // Migrate checks the datastore schema vs the runtime schema, and runs migrations if they don't match func (ls *LocalStore) Migrate() error { - schema, err := ls.DbStore.GetSchema() + actualDbSchema, err := ls.DbStore.GetSchema() if err != nil { log.Error(err.Error()) return err } - log.Debug("found schema", "schema", schema, "runtime-schema", CurrentDbSchema) - if schema != CurrentDbSchema { - // run migrations + log.Debug("running migrations for", "schema", actualDbSchema, "runtime-schema", CurrentDbSchema) - if schema == "" { - log.Debug("running migrations for", "schema", schema, "runtime-schema", CurrentDbSchema) + if actualDbSchema == CurrentDbSchema { + return nil + } + + if actualDbSchema == DbSchemaNone { + ls.migrateFromNoneToPurity() + actualDbSchema = DbSchemaPurity + } - // delete chunks that are not valid, i.e. chunks that do not pass any of the ls.Validators - ls.DbStore.Cleanup(func(c *chunk) bool { - return !ls.isValid(c) - }) + if err := ls.DbStore.PutSchema(actualDbSchema); err != nil { + return err + } - err := ls.DbStore.PutSchema(DbSchemaPurity) - if err != nil { - log.Error(err.Error()) - return err - } + if actualDbSchema == DbSchemaPurity { + if err := ls.migrateFromPurityToHalloween(); err != nil { + return err } + actualDbSchema = DbSchemaHalloween } + if err := ls.DbStore.PutSchema(actualDbSchema); err != nil { + return err + } return nil } + +func (ls *LocalStore) migrateFromNoneToPurity() { + // delete chunks that are not valid, i.e. chunks that do not pass + // any of the ls.Validators + ls.DbStore.Cleanup(func(c *chunk) bool { + return !ls.isValid(c) + }) +} + +func (ls *LocalStore) migrateFromPurityToHalloween() error { + return ls.DbStore.CleanGCIndex() +} |