forestdb.lib: Add byseq mapper and unit test some deletion.

db4
Doug Coleman 2014-11-10 16:56:41 -08:00
parent 89c33e9e30
commit 089b6e2570
2 changed files with 58 additions and 2 deletions

View File

@ -27,6 +27,9 @@ IN: forestdb.lib
: set-kv-n ( n -- )
make-kv-n [ fdb-set-kv ] assoc-each ;
: del-kv-n ( n -- )
make-kv-n keys [ fdb-del-kv ] each ;
: set-kv-nth ( n -- )
make-kv-nth fdb-set-kv ;
@ -363,7 +366,38 @@ IN: forestdb.lib
0 10 [
[ seqnum>> ]
[ [ key>> ] [ keylen>> ] bi alien/length>string ] bi 2array ,
] with-fdb-byseq-iterator
] with-fdb-byseq-each
] { } make
] with-forestdb-path
] unit-test
! Test byseq mapping
{
V{ 1 2 3 4 5 }
} [
delete-test-db-1
test-db-1 [
5 set-kv-n
fdb-commit-normal
0 10 [
fdb_doc>doc
] with-fdb-byseq-map
[ seqnum>> ] map
] with-forestdb-path
] unit-test
! Deleting 5 keys gives you 5 new seqnums that are those docs, but deleted
{
V{ { 6 t } { 7 t } { 8 t } { 9 t } { 10 t } }
} [
delete-test-db-1
test-db-1 [
5 set-kv-n
5 del-kv-n
fdb-commit-normal
0 10 [
fdb_doc>doc
] with-fdb-byseq-map
[ [ seqnum>> ] [ deleted?>> ] bi 2array ] map
] with-forestdb-path
] unit-test

View File

@ -333,6 +333,24 @@ T{ doc
] curry loop
] with-destructors ; inline
<PRIVATE
: collector-for-when ( quot exemplar -- quot' vec )
[ length ] keep new-resizable [ [ over [ push ] [ 2drop ] if ] curry compose ] keep ; inline
: collector-when ( quot -- quot' vec )
V{ } collector-for-when ; inline
PRIVATE>
: with-fdb-map ( start-key end-key fdb_iterator_opt_t iterator-init iterator-next quot: ( obj -- ) -- )
[ execute ] 2dip
'[
_ &dispose handle>> [
_ execute [ _ with-doc t ] [ f f ] if* swap
] curry collector-when [ loop ] dip
] with-destructors ; inline
: with-fdb-normal-iterator ( start-key end-key quot -- )
[ FDB_ITR_NONE \ fdb-iterator-init \ fdb-iterator-next ] dip
with-fdb-iterator ; inline
@ -341,10 +359,14 @@ T{ doc
[ FDB_ITR_NONE \ fdb-iterator-init \ fdb-iterator-next-meta-only ] dip
with-fdb-iterator ; inline
: with-fdb-byseq-iterator ( start-seq end-seq quot -- )
: with-fdb-byseq-each ( start-seq end-seq quot -- )
[ FDB_ITR_NONE \ fdb-iterator-byseq-init \ fdb-iterator-next-meta-only ] dip
with-fdb-iterator ; inline
: with-fdb-byseq-map ( start-seq end-seq quot -- )
[ FDB_ITR_NONE \ fdb-iterator-byseq-init \ fdb-iterator-next-meta-only ] dip
with-fdb-map ; inline
! Do not try to commit here, as it will fail with FDB_RESULT_RONLY_VIOLATION
! fdb-current is weird, it gets replaced if you call fdb-rollback
! Therefore, only clean up fdb-current once, and clean it up at the end