[#135] frostfsid: Make migration idempotent
Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
This commit is contained in:
parent
762d7f9f9f
commit
c102a44c56
1 changed files with 19 additions and 10 deletions
|
@ -114,22 +114,31 @@ func _deploy(data any, isUpdate bool) {
|
|||
}
|
||||
|
||||
if isUpdate {
|
||||
it := storage.Find(ctx, subjectKeysPrefix, storage.ValuesOnly)
|
||||
it := storage.Find(ctx, addressPrefix, storage.KeysOnly)
|
||||
migrationCompleted := false
|
||||
for iterator.Next(it) {
|
||||
subjectRaw := iterator.Value(it)
|
||||
subject := std.Deserialize(subjectRaw.([]byte)).(Subject)
|
||||
address := addressKey(contract.CreateStandardAccount(subject.PrimaryKey))
|
||||
if storage.Get(ctx, address) != nil {
|
||||
panic("frostfsid contract contains duplicate keys")
|
||||
}
|
||||
storage.Put(ctx, address, true)
|
||||
migrationCompleted = true
|
||||
break
|
||||
}
|
||||
|
||||
for i := 0; i < len(subject.AdditionalKeys); i++ {
|
||||
address = addressKey(contract.CreateStandardAccount(subject.AdditionalKeys[i]))
|
||||
if !migrationCompleted {
|
||||
it = storage.Find(ctx, subjectKeysPrefix, storage.ValuesOnly)
|
||||
for iterator.Next(it) {
|
||||
subjectRaw := iterator.Value(it)
|
||||
subject := std.Deserialize(subjectRaw.([]byte)).(Subject)
|
||||
address := addressKey(contract.CreateStandardAccount(subject.PrimaryKey))
|
||||
if storage.Get(ctx, address) != nil {
|
||||
panic("frostfsid contract contains duplicate keys")
|
||||
}
|
||||
storage.Put(ctx, address, true)
|
||||
|
||||
for i := 0; i < len(subject.AdditionalKeys); i++ {
|
||||
address = addressKey(contract.CreateStandardAccount(subject.AdditionalKeys[i]))
|
||||
if storage.Get(ctx, address) != nil {
|
||||
panic("frostfsid contract contains duplicate keys")
|
||||
}
|
||||
storage.Put(ctx, address, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue