heineiuo/rippledb

AssertionError [ERR_ASSERTION]: new key must bigger then last key

heineiuo opened this issue · 3 comments

There maybe something incorrect in MemTable

import path from 'path'
import LogReader from '../LogReader'
import { Options } from '../Options'
import WriteBatch from '../WriteBatch'

async function recoverLogFile(): Promise<void> {
  // Open the log file
  const logFilename = path.resolve('./000044.log')
  const options = new Options()
  const reader = new LogReader(options, logFilename)
  let lastEntry = {}
  ite1: for await (const record of reader.iterator()) {
    const batch = new WriteBatch()
    WriteBatch.setContents(batch, record.buffer)
    const sn = WriteBatch.getSequence(batch)

    for (const update of batch.iterator()) {
      const { type, key, value } = update
      console.log(sn.value, type, `${key}`, `${value}`)
      const lastSN = lastEntry[0]
      lastEntry = [sn.value, type, `${key}`, `${value}`]
      if (lastEntry[0] === lastSN) {
        break ite1
      }
    }
  }
}

and found sequence was not increased...

Bug still exist

https://github.com/heineiuo/node-level/blob/master/src/Database.ts#L600-L606

this._versionSet.lastSequence is not update util the log writer async operation. It will cause another operation read and use the old lastSequence