Coder Social home page Coder Social logo

KV iterator export to API about flashdb HOT 11 CLOSED

eggcar avatar eggcar commented on July 26, 2024
KV iterator export to API

from flashdb.

Comments (11)

armink avatar armink commented on July 26, 2024

是有计划公开 KV 迭代器的 API ,或者你来实现一下?完事直接 PR 上来

from flashdb.

eggcar avatar eggcar commented on July 26, 2024

好滴,我先做一版提个PR

from flashdb.

armink avatar armink commented on July 26, 2024

fixed in #12

from flashdb.

xql923 avatar xql923 commented on July 26, 2024

请检查源程序..\FlashDB-master\src\fdb_kvdb.c中第1673行:kv->addr.start == 0;
该语句是否写错了?应该为:
kv->addr.start = 0;

from flashdb.

eggcar avatar eggcar commented on July 26, 2024

请检查源程序..\FlashDB-master\src\fdb_kvdb.c中第1673行:kv->addr.start == 0;
该语句是否写错了?应该为:
kv->addr.start = 0;

已修复。晚些时候合并一个PR过来

from flashdb.

xql923 avatar xql923 commented on July 26, 2024

还有,你修改后的,能否整理出一份完整的使用例程,说明如何使用,可以吗?现在有点不太明白你的用意。

from flashdb.

eggcar avatar eggcar commented on July 26, 2024

还有,你修改后的,能否整理出一份完整的使用例程,说明如何使用,可以吗?现在有点不太明白你的用意。

要遍历kvdb,首先定义一个迭代器对象,然后调用初始化函数对迭代器对象进行初始化:

struct fdb_kv_iterator iterator;
fdb_kv_iterator_init(&iterator);

然后,用一个while循环来调用fdb_kv_iterate()函数来执行遍历:

fdb_kv_t		itr_kv;
while (fdb_kv_iterate(env_db, &iterator)) {
		itr_kv = &(iterator.curr_kv);
		data_size = (size_t)itr_kv->value_len;
		data_buf = sh_malloc(data_size);
		if (data_buf == NULL) {
			sh_printf(ofd, "Malloc failed.\r\n");
			return -ENOMEM;
		}
		fdb_blob_read(&(env_db->parent), fdb_kv_to_blob(itr_kv, fdb_blob_make(&blob, data_buf, data_size)));
		/* blahblahblah do what ever you like with blob... */
		sh_free(data_buf);
}

迭代未结束,函数返回true,while一直循环,直到遍历结束,函数返回false,退出循环

迭代器对象里有三个统计值,统计当前迭代得到有效的键值对个数、有效的value占用空间、有效的kv对象占用空间。
注意,每次遍历之前必须对迭代器对象执行初始化不要在你的应用代码里手动修改迭代器对象的内容,尤其是sector_addr成员。

from flashdb.

xql923 avatar xql923 commented on July 26, 2024

谢谢!

from flashdb.

lilealyh avatar lilealyh commented on July 26, 2024

还有,你修改后的,能否整理出一份完整的使用例程,说明如何使用,可以吗?现在有点不太明白你的用意。

要遍历kvdb,首先定义一个迭代器对象,然后调用初始化函数对迭代器对象进行初始化:

struct fdb_kv_iterator iterator;
fdb_kv_iterator_init(&iterator);

然后,用一个while循环来调用fdb_kv_iterate()函数来执行遍历:

fdb_kv_t		itr_kv;
while (fdb_kv_iterate(env_db, &iterator)) {
		itr_kv = &(iterator.curr_kv);
		data_size = (size_t)itr_kv->value_len;
		data_buf = sh_malloc(data_size);
		if (data_buf == NULL) {
			sh_printf(ofd, "Malloc failed.\r\n");
			return -ENOMEM;
		}
		fdb_blob_read(&(env_db->parent), fdb_kv_to_blob(itr_kv, fdb_blob_make(&blob, data_buf, data_size)));
		/* blahblahblah do what ever you like with blob... */
		sh_free(data_buf);
}

请问下遍历后itr_kv->name 打印一直是空的 没有什么内容是什么原因?

from flashdb.

eggcar avatar eggcar commented on July 26, 2024

@lilealyh 请问是使用的仓库最新的代码吗?itr_kv->name_len是否为0呢?
也看下iterator.iterated_cnt,这个代表当前遍历到的有效的k-v对的数量,如果一直是0,是不是kvdb本身是空的?

from flashdb.

xql923 avatar xql923 commented on July 26, 2024

from flashdb.

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.