rosedblabs / rosedb

Lightweight, fast and reliable key/value storage engine based on Bitcask.
https://rosedblabs.github.io
Apache License 2.0
4.57k stars 633 forks source link

runtime error: slice bounds out of range [:54721] with capacity 32768 #315

Closed dustleafwjl closed 2 months ago

dustleafwjl commented 3 months ago

运行环境:

报错日志

runtime error: slice bounds out of range [:54721] with capacity 32768
D:/Go/src/runtime/panic.go:140 (0x7ff72c154cbb)
        goPanicSliceAcap: panic(boundsError{x: int64(x), signed: true, y: y, code: boundsSliceAcap})
F:/go_workspace/pkg/mod/github.com/rosedblabs/wal@v1.3.7/segment.go:414 (0x7ff72caeca64)
        (*segment).readInternal: result = append(result, bh.block[start:start+int64(length)]...)
F:/go_workspace/pkg/mod/github.com/rosedblabs/wal@v1.3.7/segment.go:365 (0x7ff72caebf85)
        (*segment).Read: value, _, err := seg.readInternal(blockNumber, chunkOffset)
F:/go_workspace/pkg/mod/github.com/rosedblabs/wal@v1.3.7/wal.go:412 (0x7ff72caf0bb9)
        (*WAL).Read: return segment.Read(pos.BlockNumber, pos.ChunkOffset)
F:/go_workspace/pkg/mod/github.com/rosedblabs/rosedb/v2@v2.3.7/batch.go:194 (0x7ff72caf5ab4)
        (*Batch).Get: chunk, err := b.db.dataFiles.Read(chunkPosition)
F:/go_workspace/pkg/mod/github.com/rosedblabs/rosedb/v2@v2.3.7/db.go:301 (0x7ff72cafb3ae)
        (*DB).Get: return batch.Get(key)
F:/go_workspace/weishi/golib/kv/rosedb/impl.go:36 (0x7ff72cb05bb9)
        (*RoseDB).GetKeyValue: kv, err := b.db.Get(key)
F:/go_workspace/weishi/xpic-agent/core/finder/finderKv.go:208 (0x7ff72d08dd95)

复现步骤

目前使用单元测试的方式还未复现,感觉像是初始化内存未完成时,批量去查询出现的问题。一段时间之后,就不会有这个问题了。我先提一个issue,过段时间在看看能不能复现。

roseduan commented 3 months ago

有几个问题:

  1. 打开 rosedb 的 Options 都是什么呢?
  2. 插入的数据大概有多少条
  3. 每条大概数据有多大(字节为单位)
dustleafwjl commented 3 months ago
  1. 参数:
    opts := rosedb.DefaultOptions
    opts.DirPath = kvdir
    opts.Sync = true
    db, err := rosedb.Open(opts)
  2. 数据多少条都会出这个问题,5w条,15w条
  3. 一条数据的大概4-8KB,key是(1024个float32),value不定(存的是文件路径)

另外还出现另外一个问题:正常使用(十分钟之后),在GetValue的时候会报错invalid crc, the data may be corrupted。看起来是CRC校验没通过。这个问题在key比较小的时候也会出现。

roseduan commented 3 months ago

已经在最新的 v2.3.8 中修复了