skip accounts with malformed ids

malformed account ids or balance id
This commit is contained in:
Radu Ioan Fericean
2015-11-16 13:24:20 +02:00
parent e11479d194
commit a84449ce57

View File

@@ -121,6 +121,7 @@ func (mig MigratorRC8) migrateAccounts() error {
return err
}
newAccounts := make([]*engine.Account, len(keys))
var migratedKeys []string
// get existing accounts
for keyIndex, key := range keys {
log.Printf("Migrating account: %s...", key)
@@ -144,14 +145,18 @@ func (mig MigratorRC8) migrateAccounts() error {
// fix id
idElements := strings.Split(newAcc.Id, utils.CONCATENATED_KEY_SEP)
if len(idElements) != 3 {
return fmt.Errorf("Malformed account ID %s", oldAcc.Id)
log.Printf("Malformed account ID %s", oldAcc.Id)
continue
}
newAcc.Id = fmt.Sprintf("%s:%s", idElements[1], idElements[2])
// balances
balanceErr := false
for oldBalKey, oldBalChain := range oldAcc.BalanceMap {
keyElements := strings.Split(oldBalKey, "*")
if len(keyElements) != 3 {
return fmt.Errorf("Malformed balance key in %s: %s", oldAcc.Id, oldBalKey)
log.Printf("Malformed balance key in %s: %s", oldAcc.Id, oldBalKey)
balanceErr = true
break
}
newBalKey := "*" + keyElements[1]
newBalDirection := "*" + keyElements[2]
@@ -178,6 +183,9 @@ func (mig MigratorRC8) migrateAccounts() error {
}
}
}
if balanceErr {
continue
}
// unit counters
for _, oldUc := range oldAcc.UnitCounters {
newUc := &engine.UnitCounter{
@@ -233,6 +241,7 @@ func (mig MigratorRC8) migrateAccounts() error {
}
newAcc.InitCounters()
newAccounts[keyIndex] = newAcc
migratedKeys = append(migratedKeys, key)
}
// write data back
for _, newAcc := range newAccounts {
@@ -245,10 +254,14 @@ func (mig MigratorRC8) migrateAccounts() error {
}
}
// delete old data
log.Printf("Deleting old accounts: %s...", OLD_ACCOUNT_PREFIX+"*")
for _, key := range keys {
log.Printf("Deleting migrated accounts...")
for _, key := range migratedKeys {
_, err = mig.db.Del(key)
}
notMigrated := len(keys) - len(migratedKeys)
if notMigrated > 0 {
log.Printf("WARNING: there are %d accounts that failed migration!", notMigrated)
}
return err
}