Skip to content

Commit 812e27d

Browse files
committed
updated gorp migrations
1 parent d5ce90f commit 812e27d

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

x/go/gorp/migrate.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,25 @@ type EntryCounter interface {
4646
EntriesProcessed() int
4747
}
4848

49-
const migrationProgressInterval = 10000
49+
const migrationProgressMax = 1000
50+
51+
// shouldLogProgress returns true at logarithmically spaced intervals
52+
// (1, 10, 100, 1000) then every 1000 entries after that.
53+
func shouldLogProgress(entries int) bool {
54+
if entries <= 0 {
55+
return false
56+
}
57+
if entries >= migrationProgressMax {
58+
return entries%migrationProgressMax == 0
59+
}
60+
for entries >= 10 {
61+
if entries%10 != 0 {
62+
return false
63+
}
64+
entries /= 10
65+
}
66+
return entries == 1
67+
}
5068

5169
// TransformFunc transforms an old entry of type I into a new entry of type O.
5270
type TransformFunc[I, O any] func(ctx context.Context, old I) (O, error)
@@ -105,7 +123,7 @@ func (m *typedMigration[IK, OK, I, O]) Run(
105123
}()
106124
for iter.First(); iter.Valid(); iter.Next() {
107125
m.entries++
108-
if m.entries%migrationProgressInterval == 0 {
126+
if shouldLogProgress(m.entries) {
109127
cfg.L.Debug(
110128
"migration progress",
111129
zap.String("migration", m.name),
@@ -162,7 +180,7 @@ func (m *codecTransitionMigration[K, E]) Run(
162180
}()
163181
for iter.First(); iter.Valid(); iter.Next() {
164182
m.entries++
165-
if m.entries%migrationProgressInterval == 0 {
183+
if shouldLogProgress(m.entries) {
166184
cfg.L.Debug(
167185
"migration progress",
168186
zap.String("migration", m.name),

0 commit comments

Comments
 (0)