From bc12a60a4907d7de5cfe9988a648a58dc68683c8 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 21 Nov 2014 23:58:26 -0800 Subject: [PATCH] forestdb: fdb-handle -> fdb-kvs-handle. etc. --- extra/forestdb/ffi/ffi.factor | 42 ++++++++++----------- extra/forestdb/lib/lib.factor | 70 +++++++++++++++++------------------ 2 files changed, 56 insertions(+), 56 deletions(-) diff --git a/extra/forestdb/ffi/ffi.factor b/extra/forestdb/ffi/ffi.factor index 83af1c645d..d42a07f246 100644 --- a/extra/forestdb/ffi/ffi.factor +++ b/extra/forestdb/ffi/ffi.factor @@ -22,7 +22,7 @@ TYPEDEF: void* fdb_custom_cmp_fixed TYPEDEF: void* fdb_custom_cmp_variable TYPEDEF: void* fdb_log_callback TYPEDEF: void* fdb_file_handle -TYPEDEF: void* fdb_handle +TYPEDEF: void* fdb_kvs_handle TYPEDEF: void* fdb_iterator ENUM: fdb_commit_opt_t @@ -161,33 +161,33 @@ FUNCTION: fdb_kvs_config fdb_get_default_kvs_config ( ) ; FUNCTION: fdb_status fdb_open ( fdb_file_handle** ptr_fhandle, c-string filename, fdb_config* fconfig ) ; FUNCTION: fdb_status fdb_open_custom_cmp ( fdb_file_handle** ptr_fhandle, c-string filename, fdb_config* fconfig, size_t num_functions, char** kvs_names, fdb_custom_cmp_variable* functions ) ; -FUNCTION: fdb_status fdb_set_log_callback ( fdb_handle* handle, fdb_log_callback log_callback, void* ctx_data ) ; +FUNCTION: fdb_status fdb_set_log_callback ( fdb_kvs_handle* handle, fdb_log_callback log_callback, void* ctx_data ) ; ! doc is calloc'd FUNCTION: fdb_status fdb_doc_create ( fdb_doc** doc, c-string key, size_t keylen, c-string meta, size_t metalen, c-string body, size_t bodylen ) ; FUNCTION: fdb_status fdb_doc_update ( fdb_doc** doc, c-string meta, size_t metalen, c-string body, size_t bodylen ) ; FUNCTION: fdb_status fdb_doc_free ( fdb_doc* doc ) ; -FUNCTION: fdb_status fdb_get ( fdb_handle* handle, fdb_doc* doc ) ; -FUNCTION: fdb_status fdb_get_metaonly ( fdb_handle* handle, fdb_doc* doc ) ; -FUNCTION: fdb_status fdb_get_byseq ( fdb_handle* handle, fdb_doc* doc ) ; -FUNCTION: fdb_status fdb_get_metaonly_byseq ( fdb_handle* handle, fdb_doc* doc ) ; -FUNCTION: fdb_status fdb_get_byoffset ( fdb_handle* handle, fdb_doc* doc ) ; +FUNCTION: fdb_status fdb_get ( fdb_kvs_handle* handle, fdb_doc* doc ) ; +FUNCTION: fdb_status fdb_get_metaonly ( fdb_kvs_handle* handle, fdb_doc* doc ) ; +FUNCTION: fdb_status fdb_get_byseq ( fdb_kvs_handle* handle, fdb_doc* doc ) ; +FUNCTION: fdb_status fdb_get_metaonly_byseq ( fdb_kvs_handle* handle, fdb_doc* doc ) ; +FUNCTION: fdb_status fdb_get_byoffset ( fdb_kvs_handle* handle, fdb_doc* doc ) ; -FUNCTION: fdb_status fdb_set ( fdb_handle* handle, fdb_doc* doc ) ; -FUNCTION: fdb_status fdb_del ( fdb_handle* handle, fdb_doc* doc ) ; +FUNCTION: fdb_status fdb_set ( fdb_kvs_handle* handle, fdb_doc* doc ) ; +FUNCTION: fdb_status fdb_del ( fdb_kvs_handle* handle, fdb_doc* doc ) ; -FUNCTION: fdb_status fdb_get_kv ( fdb_handle* handle, c-string key, size_t keylen, void** value_out, size_t* valuelen_out ) ; -FUNCTION: fdb_status fdb_set_kv ( fdb_handle* handle, c-string key, size_t keylen, c-string value, size_t valuelen ) ; -FUNCTION: fdb_status fdb_del_kv ( fdb_handle* handle, c-string key, size_t keylen ) ; +FUNCTION: fdb_status fdb_get_kv ( fdb_kvs_handle* handle, c-string key, size_t keylen, void** value_out, size_t* valuelen_out ) ; +FUNCTION: fdb_status fdb_set_kv ( fdb_kvs_handle* handle, c-string key, size_t keylen, c-string value, size_t valuelen ) ; +FUNCTION: fdb_status fdb_del_kv ( fdb_kvs_handle* handle, c-string key, size_t keylen ) ; FUNCTION: fdb_status fdb_commit ( fdb_file_handle* fhandle, fdb_commit_opt_t opt ) ; -FUNCTION: fdb_status fdb_snapshot_open ( fdb_handle* handle_in, fdb_handle** handle_out, fdb_seqnum_t snapshot_seqnum ) ; +FUNCTION: fdb_status fdb_snapshot_open ( fdb_kvs_handle* handle_in, fdb_kvs_handle** handle_out, fdb_seqnum_t snapshot_seqnum ) ; ! Swaps out the handle for a new one -FUNCTION: fdb_status fdb_rollback ( fdb_handle** handle_ptr, fdb_seqnum_t rollback_seqnum ) ; +FUNCTION: fdb_status fdb_rollback ( fdb_kvs_handle** handle_ptr, fdb_seqnum_t rollback_seqnum ) ; -FUNCTION: fdb_status fdb_iterator_init ( fdb_handle* handle, fdb_iterator** iterator, c-string start_key, size_t start_keylen, c-string end_key, size_t end_keylen, fdb_iterator_opt_t opt ) ; -FUNCTION: fdb_status fdb_iterator_sequence_init ( fdb_handle* handle, fdb_iterator** iterator, fdb_seqnum_t start_seq, fdb_seqnum_t end_seq, fdb_iterator_opt_t opt ) ; +FUNCTION: fdb_status fdb_iterator_init ( fdb_kvs_handle* handle, fdb_iterator** iterator, c-string start_key, size_t start_keylen, c-string end_key, size_t end_keylen, fdb_iterator_opt_t opt ) ; +FUNCTION: fdb_status fdb_iterator_sequence_init ( fdb_kvs_handle* handle, fdb_iterator** iterator, fdb_seqnum_t start_seq, fdb_seqnum_t end_seq, fdb_iterator_opt_t opt ) ; FUNCTION: fdb_status fdb_iterator_prev ( fdb_iterator* iterator, fdb_doc** doc ) ; FUNCTION: fdb_status fdb_iterator_next ( fdb_iterator* iterator, fdb_doc** doc ) ; FUNCTION: fdb_status fdb_iterator_next_metaonly ( fdb_iterator* iterator, fdb_doc** doc ) ; @@ -197,8 +197,8 @@ FUNCTION: fdb_status fdb_iterator_close ( fdb_iterator* iterator ) ; FUNCTION: fdb_status fdb_compact ( fdb_file_handle* handle, c-string new_filename ) ; FUNCTION: size_t fdb_estimate_space_used ( fdb_file_handle* fhandle ) ; FUNCTION: fdb_status fdb_get_file_info ( fdb_file_handle* handle, fdb_file_info* info ) ; -FUNCTION: fdb_status fdb_get_kvs_info ( fdb_handle* handle, fdb_kvs_info* info ) ; -FUNCTION: fdb_status fdb_get_kvs_seqnum ( fdb_handle* handle, fdb_seqnum_t* seqnum ) ; +FUNCTION: fdb_status fdb_get_kvs_info ( fdb_kvs_handle* handle, fdb_kvs_info* info ) ; +FUNCTION: fdb_status fdb_get_kvs_seqnum ( fdb_kvs_handle* handle, fdb_seqnum_t* seqnum ) ; FUNCTION: fdb_status fdb_switch_compaction_mode ( fdb_file_handle* fhandle, fdb_compaction_mode_t mode, size_t new_threshold ) ; FUNCTION: fdb_status fdb_get_kvs_name_list ( fdb_file_handle *fhandle, fdb_kvs_name_list *kvs_name_list ) ; @@ -212,16 +212,16 @@ FUNCTION: fdb_status fdb_begin_transaction ( fdb_file_handle* fhandle, fdb_isola FUNCTION: fdb_status fdb_end_transaction ( fdb_file_handle* fhandle, fdb_commit_opt_t opt ) ; FUNCTION: fdb_status fdb_abort_transaction ( fdb_file_handle* fhandle ) ; FUNCTION: fdb_status fdb_kvs_open ( fdb_file_handle* fhandle, - fdb_handle** ptr_handle, + fdb_kvs_handle** ptr_handle, char* kvs_name, fdb_kvs_config* config ) ; FUNCTION: fdb_status fdb_kvs_open_default ( fdb_file_handle* fhandle, - fdb_handle** ptr_handle, + fdb_kvs_handle** ptr_handle, fdb_kvs_config* config ) ; -FUNCTION: fdb_status fdb_kvs_close ( fdb_handle* handle ) ; +FUNCTION: fdb_status fdb_kvs_close ( fdb_kvs_handle* handle ) ; FUNCTION: fdb_status fdb_kvs_remove ( fdb_file_handle* fhandle, char* kvs_name ) ; FUNCTION: char* fdb_error_msg ( fdb_status err_code ) ; diff --git a/extra/forestdb/lib/lib.factor b/extra/forestdb/lib/lib.factor index d3705b4bd8..6e65b05c3d 100644 --- a/extra/forestdb/lib/lib.factor +++ b/extra/forestdb/lib/lib.factor @@ -22,12 +22,12 @@ ERROR: fdb-error error ; : fdb-check-error ( ret -- ) dup FDB_RESULT_SUCCESS = [ drop ] [ fdb-error ] if ; -TUPLE: fdb-handle < disposable handle ; -: ( handle -- obj ) - fdb-handle new-disposable +TUPLE: fdb-kvs-handle < disposable handle ; +: ( handle -- obj ) + fdb-kvs-handle new-disposable swap >>handle ; inline -M: fdb-handle dispose* +M: fdb-kvs-handle dispose* handle>> fdb_kvs_close fdb-check-error ; @@ -40,7 +40,7 @@ M: fdb-file-handle dispose* handle>> fdb_close fdb-check-error ; SYMBOL: current-fdb-file-handle -SYMBOL: current-fdb-handle +SYMBOL: current-fdb-kvs-handle : get-kvs-default-config ( -- kvs-config ) S{ fdb_kvs_config @@ -48,14 +48,14 @@ SYMBOL: current-fdb-handle { custom_cmp f } } clone ; -: fdb-open-kvs' ( file-handle fdb-handle kvs-config -- file-handle handle ) +: fdb-open-kvs' ( file-handle fdb-kvs-handle kvs-config -- file-handle handle ) [ dup handle>> ] 2dip [ handle>> ] dip [ fdb_kvs_open_default fdb-check-error ] 2keep drop - void* deref ; + void* deref ; : fdb-open-kvs ( fdb-file-handle kvs-config -- file-handle handle ) - [ f void* ] dip fdb-open-kvs' ; + [ f void* ] dip fdb-open-kvs' ; : fdb-open ( path config kvs-config -- file-handle handle ) [ @@ -75,11 +75,11 @@ SYMBOL: current-fdb-handle : get-file-handle ( -- handle ) current-fdb-file-handle get handle>> ; -: get-handle ( -- handle ) - current-fdb-handle get handle>> ; +: get-kvs-handle ( -- handle ) + current-fdb-kvs-handle get handle>> ; : fdb-set-kv ( key value -- ) - [ get-handle ] 2dip + [ get-kvs-handle ] 2dip [ dup length ] bi@ fdb_set_kv fdb-check-error ; : ( key -- doc ) @@ -92,30 +92,30 @@ SYMBOL: current-fdb-handle ! Fill in document by exemplar : fdb-get ( doc -- doc ) - [ get-handle ] dip [ fdb_get fdb-check-error ] keep ; + [ get-kvs-handle ] dip [ fdb_get fdb-check-error ] keep ; : fdb-get-metaonly ( doc -- doc ) - [ get-handle ] dip [ fdb_get_metaonly fdb-check-error ] keep ; + [ get-kvs-handle ] dip [ fdb_get_metaonly fdb-check-error ] keep ; : fdb-get-byseq ( doc -- doc ) - [ get-handle ] dip [ fdb_get_byseq fdb-check-error ] keep ; + [ get-kvs-handle ] dip [ fdb_get_byseq fdb-check-error ] keep ; : fdb-get-metaonly-byseq ( doc -- doc ) - [ get-handle ] dip [ fdb_get_metaonly_byseq fdb-check-error ] keep ; + [ get-kvs-handle ] dip [ fdb_get_metaonly_byseq fdb-check-error ] keep ; : fdb-get-byoffset ( doc -- doc ) - [ get-handle ] dip [ fdb_get_byoffset fdb-check-error ] keep ; + [ get-kvs-handle ] dip [ fdb_get_byoffset fdb-check-error ] keep ; ! Set/delete documents : fdb-set ( doc -- ) - [ get-handle ] dip fdb_set fdb-check-error ; + [ get-kvs-handle ] dip fdb_set fdb-check-error ; : fdb-del ( doc -- ) - [ get-handle ] dip fdb_del fdb-check-error ; + [ get-kvs-handle ] dip fdb_del fdb-check-error ; : fdb-get-kv ( key -- value/f ) - [ get-handle ] dip + [ get-kvs-handle ] dip dup length f void* 0 size_t [ fdb_get_kv ] 2keep rot { @@ -125,7 +125,7 @@ SYMBOL: current-fdb-handle } case ; : fdb-del-kv ( key -- ) - [ get-handle ] dip dup length fdb_del_kv fdb-check-error ; + [ get-kvs-handle ] dip dup length fdb_del_kv fdb-check-error ; : fdb-doc-create ( key meta body -- doc ) [ f void* ] 3dip @@ -156,7 +156,7 @@ SYMBOL: current-fdb-handle fdb_file_info [ fdb_get_file_info fdb-check-error ] keep ; : fdb-get-kvs-info ( -- fdb_kvs_info ) - get-handle + get-kvs-handle fdb_kvs_info [ fdb_get_kvs_info fdb-check-error ] keep ; : fdb-commit ( fdb_commit_opt_t -- ) @@ -177,10 +177,10 @@ SYMBOL: current-fdb-handle fdb-compact fdb-commit-wal-flush ; : fdb-swap-current-db ( new-path -- ) - current-fdb-handle [ dispose f ] change + current-fdb-kvs-handle [ dispose f ] change fdb-open-default-config [ current-fdb-file-handle set ] - [ current-fdb-handle set ] bi* ; + [ current-fdb-kvs-handle set ] bi* ; : fdb-compact-and-swap-db ( path -- ) next-vnode-version-name @@ -190,19 +190,19 @@ SYMBOL: current-fdb-handle ! Call from within with-foresdb : fdb-open-snapshot ( seqnum -- handle ) [ - get-handle + get-kvs-handle f void* ] dip [ fdb_snapshot_open fdb-check-error - ] 2keep drop void* deref ; + ] 2keep drop void* deref ; ! fdb_rollback returns a new handle, so we ! have to replace our current handle with that one ! XXX: can't call dispose on old handle, library handles that : fdb-rollback ( seqnum -- ) - [ get-handle void* ] dip + [ get-kvs-handle void* ] dip [ fdb_rollback fdb-check-error ] 2keep drop - void* deref current-fdb-handle set ; + void* deref current-fdb-kvs-handle set ; TUPLE: fdb-iterator < disposable handle ; @@ -215,13 +215,13 @@ M: fdb-iterator dispose* handle>> fdb_iterator_close fdb-check-error ; : fdb-iterator-init ( start-key end-key fdb_iterator_opt_t -- iterator ) - [ get-handle f void* ] 3dip + [ get-kvs-handle f void* ] 3dip [ [ dup length ] bi@ ] dip [ fdb_iterator_init fdb-check-error ] 7 nkeep 5 ndrop nip void* deref ; : fdb-iterator-byseq-init ( start-seq end-seq fdb_iterator_opt_t -- iterator ) - [ get-handle f void* ] 3dip + [ get-kvs-handle f void* ] 3dip [ fdb_iterator_sequence_init fdb-check-error ] 5 nkeep 3 ndrop nip void* deref ; @@ -359,16 +359,16 @@ PRIVATE> : with-forestdb-handles ( file-handle handle quot fdb_commit_opt_t/f -- ) '[ _ current-fdb-file-handle [ - _ current-fdb-handle [ + _ current-fdb-kvs-handle [ [ @ _ fdb-maybe-commit current-fdb-file-handle get &dispose drop - current-fdb-handle get &dispose drop + current-fdb-kvs-handle get &dispose drop ] [ [ current-fdb-file-handle get &dispose drop - current-fdb-handle get &dispose drop + current-fdb-kvs-handle get &dispose drop ] with-destructors rethrow ] recover @@ -386,12 +386,12 @@ PRIVATE> : with-forestdb-snapshot ( n quot -- ) [ fdb-open-snapshot ] dip '[ - _ current-fdb-handle [ + _ current-fdb-kvs-handle [ [ @ - current-fdb-handle get &dispose drop + current-fdb-kvs-handle get &dispose drop ] [ - current-fdb-handle get [ &dispose drop ] when* + current-fdb-kvs-handle get [ &dispose drop ] when* rethrow ] recover ] with-variable