badger mremap size mismatch数据库异常

系统信息:

板子:NVIDIA Jetson Xavier NX

系统:Ubuntu 18.04.6 LTS (GNU/Linux 4.9.201-tegra aarch64)

go version go1.17.7 linux/arm64

报错信息:

while opening memtables error: while opening fid: 1 error: while updating skiplist error: mremap size mismatch: requested: 312 got: 134217728

复现(本人的代码和以下代码类似,所以直接引用,引用出处在文末贴出):

package main

import (
	"fmt"
	"github.com/dgraph-io/badger/v3"
)

func main() {
  dir := "./data/badger"
	db, err := badger.Open(badger.DefaultOptions(dir))
	if err != nil {
		fmt.Println(err)
	}

	//defer db.Close() // It's a requirement condition, not to close db
}

当成程序出现异常panic或进行kill -9 pid操作时,第二次重新启动程序出现以下错误:

while opening memtables error: while opening fid: 1 error: while updating skiplist error: mremap size mismatch: requested: 312 got: 134217728
解决:

查阅相关资料后得知,问题出现在 ristrettommap_linux.go的这行代码mmapAddr, mmapSize, errno := unix.Syscall6(unix.SYS_MREMAP,header.Data,...),在ARM64中,mmapSize是旧大小而不是不是分配的大小,这导致了if mmapSize != uintptr(size)判断时返回了一个报错*“mremap size mismatch”*信息。

而这也影响了引用了Ristretto项目的Badger数据库,而Ristretto-repo中并没有发布此问题的修复版本,只在master分支上cmomit了移除mmapSize的修复代码。

解决方案:

第一步,采用 Manish R Jainoutcaste-io/ristretto项目中发布的修复版本(Manish R Jain不再维护原repo,而是在fork中维护)

第二步,将Badgerristrettoclone到$GOPATH/src/github.com/dgraph-io/目录下,记得checkout自己想要的branch或tag

第三步,在自己项目中的go.mod中进行replace github.com/dgraph-io/badger/v3 => /yourself/gopath/src/github.com/dgraph-io/badger

第四步,在$GOPATH/src/github.com/dgraph-io/Badger的go.mod中也进行replace github.com/dgraph-io/ristretto => /yourself/gopath/src/github.com/dgraph-io/ristretto

第五步,重新编译即可解决问题

结尾:

出现问题后查阅以下相关资料:

https://discuss.dgraph.io/t/error-mremap-size-mismatch-on-arm64/15333

https://github.com/dgraph-io/ristretto/pull/281

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值