2007-11-29 14:18:54 +00:00
/* -*- mode: C; c-basic-offset: 4 -*- */
2007-07-13 19:37:47 +00:00
# ifndef BRT_H
# define BRT_H
2008-01-24 15:10:32 +00:00
# ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved."
2007-07-13 19:37:47 +00:00
// This must be first to make the 64-bit file mode work right in Linux
# define _FILE_OFFSET_BITS 64
# include "brttypes.h"
# include "ybt.h"
2007-09-06 20:13:56 +00:00
# include "../include/db.h"
2007-07-13 19:37:47 +00:00
# include "cachetable.h"
2007-09-28 17:11:22 +00:00
# include "log.h"
2008-01-25 15:43:37 +00:00
# include "brt-search.h"
2007-11-21 13:07:49 +00:00
2007-11-29 15:09:14 +00:00
int toku_open_brt ( const char * fname , const char * dbname , int is_create , BRT * , int nodesize , CACHETABLE , TOKUTXN , int ( * ) ( DB * , const DBT * , const DBT * ) , DB * ) ;
2007-11-14 17:58:38 +00:00
2007-11-29 14:44:03 +00:00
int toku_brt_create ( BRT * ) ;
2007-11-29 19:32:53 +00:00
int toku_brt_set_flags ( BRT , unsigned int flags ) ;
int toku_brt_get_flags ( BRT , unsigned int * flags ) ;
int toku_brt_set_nodesize ( BRT , unsigned int nodesize ) ;
int toku_brt_get_nodesize ( BRT , unsigned int * nodesize ) ;
2007-11-29 15:09:14 +00:00
int toku_brt_set_bt_compare ( BRT , int ( * bt_compare ) ( DB * , const DBT * , const DBT * ) ) ;
int toku_brt_set_dup_compare ( BRT , int ( * dup_compare ) ( DB * , const DBT * , const DBT * ) ) ;
2007-11-14 17:58:38 +00:00
int brt_set_cachetable ( BRT , CACHETABLE ) ;
2008-05-22 21:28:00 +00:00
int toku_brt_open ( BRT , const char * fname , const char * fname_in_env , const char * dbname , int is_create , int only_create , CACHETABLE ct , TOKUTXN txn , DB * db ) ;
2008-07-21 02:34:13 +00:00
2007-11-29 15:09:14 +00:00
int toku_brt_remove_subdb ( BRT brt , const char * dbname , u_int32_t flags ) ;
int toku_brt_insert ( BRT , DBT * , DBT * , TOKUTXN ) ;
int toku_brt_lookup ( BRT brt , DBT * k , DBT * v ) ;
2008-01-28 20:49:10 +00:00
int toku_brt_delete ( BRT brt , DBT * k , TOKUTXN ) ;
2008-02-25 22:46:48 +00:00
int toku_brt_delete_both ( BRT brt , DBT * k , DBT * v , TOKUTXN ) ; // Delete a pair only if both k and v are equal according to the comparison function.
2008-04-17 03:11:55 +00:00
int toku_close_brt ( BRT , TOKULOGGER ) ;
2008-07-21 02:34:13 +00:00
2013-04-16 23:57:24 -04:00
int toku_dump_brt ( FILE * , BRT brt ) ;
2007-07-13 19:37:47 +00:00
2008-07-21 02:34:13 +00:00
void brt_fsync ( BRT ) ; /* fsync, but don't clear the caches. */
2007-07-13 19:37:47 +00:00
void brt_flush ( BRT ) ; /* fsync and clear the caches. */
2008-07-21 02:34:13 +00:00
int toku_brt_get_cursor_count ( BRT brt ) ;
// get the number of cursors in the tree
// returns: the number of cursors.
// asserts: the number of cursors >= 0.
int toku_brt_flush ( BRT brt ) ;
// effect: the tree's cachefile is flushed
// returns: 0 if success
2013-04-16 23:57:27 -04:00
int toku_brt_truncate ( BRT brt ) ;
// effect: remove everything from the tree
// returns: 0 if success
2007-11-14 17:58:38 +00:00
2013-04-16 23:57:27 -04:00
// create and initialize a cache table
// cachesize is the upper limit on the size of the size of the values in the table
// pass 0 if you want the default
2007-11-29 14:44:03 +00:00
int toku_brt_create_cachetable ( CACHETABLE * t , long cachesize , LSN initial_lsn , TOKULOGGER ) ;
2007-09-21 17:55:49 +00:00
2007-11-29 14:44:03 +00:00
extern int toku_brt_debug_mode ;
2007-11-20 00:35:31 +00:00
int toku_verify_brt ( BRT brt ) ;
2007-07-13 19:37:47 +00:00
2007-11-28 19:00:21 +00:00
//int show_brt_blocknumbers(BRT);
2007-07-13 19:37:47 +00:00
typedef struct brt_cursor * BRT_CURSOR ;
2008-03-15 19:06:39 +00:00
int toku_brt_cursor ( BRT , BRT_CURSOR * , int is_temporary_cursor ) ;
2007-11-29 14:44:03 +00:00
int toku_brt_cursor_get ( BRT_CURSOR cursor , DBT * kbt , DBT * vbt , int brtc_flags , TOKUTXN ) ;
2008-07-16 22:23:29 +00:00
struct heavi_wrapper {
int ( * h ) ( const DBT * key , const DBT * value , void * extra_h ) ;
void * extra_h ;
int r_h ;
} ;
typedef struct heavi_wrapper * HEAVI_WRAPPER ;
int toku_brt_cursor_get_heavi ( BRT_CURSOR cursor , DBT * outkey , DBT * outval , TOKUTXN txn , int direction , HEAVI_WRAPPER wrapper ) ;
int toku_brt_cursor_peek_prev ( BRT_CURSOR cursor , DBT * outkey , DBT * outval ) ;
int toku_brt_cursor_peek_next ( BRT_CURSOR cursor , DBT * outkey , DBT * outval ) ;
int toku_brt_cursor_before ( BRT_CURSOR cursor , DBT * key , DBT * val , DBT * outkey , DBT * outval , TOKUTXN txn ) ;
int toku_brt_cursor_after ( BRT_CURSOR cursor , DBT * key , DBT * val , DBT * outkey , DBT * outval , TOKUTXN txn ) ;
2008-01-28 20:49:10 +00:00
int toku_brt_cursor_delete ( BRT_CURSOR cursor , int flags , TOKUTXN ) ;
2007-11-29 14:44:03 +00:00
int toku_brt_cursor_close ( BRT_CURSOR curs ) ;
2008-02-11 20:00:19 +00:00
BOOL toku_brt_cursor_uninitialized ( BRT_CURSOR c ) ;
2007-07-13 19:37:47 +00:00
2008-06-12 20:32:22 +00:00
DBT * brt_cursor_peek_prev_key ( BRT_CURSOR cursor ) ;
DBT * brt_cursor_peek_prev_val ( BRT_CURSOR cursor ) ;
DBT * brt_cursor_peek_current_key ( BRT_CURSOR cursor ) ;
DBT * brt_cursor_peek_current_val ( BRT_CURSOR cursor ) ;
2008-07-28 17:55:14 +00:00
void brt_cursor_peek_current ( BRT_CURSOR cursor , const DBT * * pkey , const DBT * * pval ) ;
2008-06-12 20:32:22 +00:00
void brt_cursor_restore_state_from_prev ( BRT_CURSOR cursor ) ;
2007-11-14 17:58:38 +00:00
typedef struct brtenv * BRTENV ;
int brtenv_checkpoint ( BRTENV env ) ;
2007-11-28 19:00:21 +00:00
extern int toku_brt_do_push_cmd ; // control whether push occurs eagerly.
2007-12-10 18:54:12 +00:00
2008-05-07 20:03:13 +00:00
int toku_brt_dbt_set ( DBT * key , DBT * key_source ) ;
2008-05-24 17:22:14 +00:00
int toku_brt_cursor_dbts_set ( BRT_CURSOR cursor ,
DBT * key , DBT * key_source , BOOL key_disposable ,
DBT * val , DBT * val_source , BOOL val_disposable ) ;
int toku_brt_cursor_dbts_set_with_dat ( BRT_CURSOR cursor , BRT pdb ,
DBT * key , DBT * key_source , BOOL key_disposable ,
DBT * val , DBT * val_source , BOOL val_disposable ,
DBT * dat , DBT * dat_source , BOOL dat_disposable ) ;
2008-01-11 14:38:49 +00:00
int toku_brt_get_fd ( BRT , int * ) ;
2008-02-25 22:46:48 +00:00
int toku_brt_height_of_root ( BRT , int * height ) ; // for an open brt, return the current height.
2008-04-02 23:40:36 +00:00
enum brt_header_flags {
TOKU_DB_DUP = 1 ,
TOKU_DB_DUPSORT = 2 ,
} ;
2008-05-13 12:14:38 +00:00
int toku_brt_keyrange ( BRT brt , DBT * key , u_int64_t * less , u_int64_t * equal , u_int64_t * greater ) ;
2013-04-16 23:57:25 -04:00
void extend_block_translation ( BLOCKNUM blocknum , struct brt_header * h ) ;
2013-04-16 23:57:30 -04:00
void toku_brt_init ( void ) ;
void toku_brt_destroy ( void ) ;
void toku_pwrite_lock_init ( void ) ;
void toku_pwrite_lock_destroy ( void ) ;
2013-04-16 23:57:30 -04:00
void maybe_preallocate_in_file ( int fd , u_int64_t size ) ;
// Effect: If file size is less than SIZE, make it bigger by either doubling it or growing by 16MB whichever is less.
2013-04-16 23:57:38 -04:00
int toku_brt_note_table_lock ( BRT brt , TOKUTXN txn ) ;
// Effect: Record the fact that the BRT has a table lock (and thus no other txn will modify it until this txn completes. As a result, we can limit the amount of information in the rollback data structure.
2007-07-13 19:37:47 +00:00
# endif