Giter Club home page Giter Club logo

Comments (7)

xujiajun avatar xujiajun commented on June 3, 2024

@ranzhendong hi,你能把你写的代码发出来看下吗?什么版本的NutsDB也说下

from nutsdb.

ranzhendong avatar ranzhendong commented on June 3, 2024

版本
nutsdb v0.5.0

场景
通过gorountine做周期性key插入动作。

func connect() (db *nutsdb.DB) {
	var (
		err error
		c   datastruck.Config
	)

	if err = c.Config(); err != nil {
		log.Println(MyERR.ErrorLog(12012), fmt.Sprintf("%v", err))
		return nil,err
	}
	opt := nutsdb.DefaultOptions
	opt.Dir = c.NutsDB.Path

	if db, err = nutsdb.Open(opt); err != nil {
		log.Println(err)
		return nil,err
	}
	return db,nil
}

func Put(bct string, key, val interface{}) error {
	var (
		keyByte, valByte []byte
		err              error
		db               *nutsdb.DB
	)

	if db, err = connect(); err != nil {
		return err
	}

	defer func() {
		_ = db.Close()
	}()

	err = db.Update(
		func(tx *nutsdb.Tx) error {
			//judge key type
			switch key.(type) {
			case string:
				keyByte = []byte(key.(string))
			case int:
				keyByte, _ = IntToBytes(val.(int), 3)
			case []uint8:
				keyByte = key.([]byte)
			}

			switch val.(type) {
			case string:
				valByte = []byte(val.(string))
			case int:
				valByte, _ = IntToBytes(val.(int), 3)
			case []uint8:
				valByte = val.([]byte)
			}
			if err = tx.Put(bct, keyByte, valByte, 0); err != nil {
				return err
			}
			return nil
		})
	if err != nil {
		log.Println("NutsDB PUT ERR",err)
		return err
	}
	return nil
}

其他库去调用PUT函数去插入的值的时候,在频率比较高的时候就会出错,大概8-10/s次的写入速率。

现象

db.buildIndexes error: when build activeDataIndex readAt err: crc error

from nutsdb.

xujiajun avatar xujiajun commented on June 3, 2024

@ranzhendong , hi ,你写的代码有问题,db连一次就好了,不用每次put的时候连一次。

from nutsdb.

ranzhendong avatar ranzhendong commented on June 3, 2024

@ranzhendong , hi ,你写的代码有问题,db连一次就好了,不用每次put的时候连一次。

我在每次put之后,将获取的连接对象关闭了,这样的写法是有问题的吧?

	defer func() {
		_ = db.Close()
	}()

徐老师,你的意思是刚开始创建连接,获取连接对象,来进行反复读写操作。而不是每一次读写操作就执行一次完整的创建连接关闭连接过程是吧?

from nutsdb.

xujiajun avatar xujiajun commented on June 3, 2024

@ranzhendong

from nutsdb.

staugur avatar staugur commented on June 3, 2024

您好,同发现此问题( nutsdb v0.5.0,go1.16),出现这个错误后,本地数据貌似就不能用了,读写都提示 db.buildIndexes error,如何修复呢?

from nutsdb.

xujiajun avatar xujiajun commented on June 3, 2024

您好,同发现此问题( nutsdb v0.5.0,go1.16),出现这个错误后,本地数据貌似就不能用了,读写都提示 db.buildIndexes error,如何修复呢?

你好,这个issue 已经关闭,有问题你重新提issue,因为关闭的,一般close的issue,我不会再看了。

from nutsdb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.