Skip to content

Commit

Permalink
memiavl support write old version idopodently
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Feb 27, 2025
1 parent 5eecccb commit cbb3b58
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions memiavl/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,9 +560,18 @@ func (db *DB) Commit() (int64, error) {
if err != nil {
return 0, err
}
if err := db.wal.Write(entry.index, bz); err != nil {

lastIndex, err := db.wal.LastIndex()
if err != nil {
return 0, err
}
if entry.index < lastIndex+1 {
db.logger.Error("commit old version idempotently", "expected", lastIndex+1, "actual", entry.index)

Check warning on line 569 in memiavl/db.go

View check run for this annotation

Codecov / codecov/patch

memiavl/db.go#L569

Added line #L569 was not covered by tests
} else {
if err := db.wal.Write(entry.index, bz); err != nil {
return 0, err
}

Check warning on line 573 in memiavl/db.go

View check run for this annotation

Codecov / codecov/patch

memiavl/db.go#L572-L573

Added lines #L572 - L573 were not covered by tests
}
}
}

Expand Down Expand Up @@ -591,13 +600,25 @@ func (db *DB) initAsyncCommit() {
break
}

for _, entry := range entries {
lastIndex, err := db.wal.LastIndex()
if err != nil {
walQuit <- err
return
}

Check warning on line 607 in memiavl/db.go

View check run for this annotation

Codecov / codecov/patch

memiavl/db.go#L605-L607

Added lines #L605 - L607 were not covered by tests

for i, entry := range entries {
bz, err := entry.data.Marshal()
if err != nil {
walQuit <- err
return
}
batch.Write(entry.index, bz)

if entry.index < lastIndex+uint64(i+1) {
db.logger.Error("commit old version idempotently", "expected", lastIndex+uint64(i+1), "actual", entry.index)
continue

Check warning on line 618 in memiavl/db.go

View check run for this annotation

Codecov / codecov/patch

memiavl/db.go#L617-L618

Added lines #L617 - L618 were not covered by tests
} else {
batch.Write(entry.index, bz)
}
}

if err := db.wal.WriteBatch(&batch); err != nil {
Expand Down

0 comments on commit cbb3b58

Please sign in to comment.