1 /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3  *     Copyright 2010 Couchbase, Inc
4  *
5  *   Licensed under the Apache License, Version 2.0 (the "License");
6  *   you may not use this file except in compliance with the License.
7  *   You may obtain a copy of the License at
8  *
9  *       http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *   Unless required by applicable law or agreed to in writing, software
12  *   distributed under the License is distributed on an "AS IS" BASIS,
13  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *   See the License for the specific language governing permissions and
15  *   limitations under the License.
16  */
17 
18 #ifndef _JSAHN_BTREEBLOCK_H
19 #define _JSAHN_BTREEBLOCK_H
20 
21 #include "filemgr.h"
22 #include "list.h"
23 #include "avltree.h"
24 #include "btree.h"
25 #include "libforestdb/fdb_errors.h"
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 struct btreeblk_block;
32 
33 struct btreeblk_subblocks{
34     bid_t bid;
35     uint32_t sb_size;
36     uint16_t nblocks;
37     uint8_t *bitmap;
38 };
39 
40 struct dirty_snapshot_t {
41     spin_t lock;
42     int ref_cnt;
43     struct avl_tree *snap_tree;
44 };
45 
46 struct btreeblk_handle{
47     uint32_t nodesize;
48     uint16_t nnodeperblock;
49     uint64_t nlivenodes;
50     struct list alc_list;
51     struct list read_list;
52     struct filemgr *file;
53     err_log_callback *log_callback;
54 
55 #ifdef __BTREEBLK_READ_TREE
56     struct avl_tree read_tree;
57 #endif
58 #ifdef __BTREEBLK_BLOCKPOOL
59     struct list blockpool;
60 #endif
61 
62 #ifdef __BTREEBLK_CACHE
63     uint16_t bin_size;
64     struct list recycle_bin;
65     struct btreeblk_block *cache[BTREEBLK_CACHE_LIMIT];
66 #endif
67 
68     uint32_t nsb;
69     struct btreeblk_subblocks *sb;
70     struct dirty_snapshot_t *dirty_snapshot;
71 };
72 
73 struct btree_blk_ops *btreeblk_get_ops();
74 void btreeblk_init(struct btreeblk_handle *handle, struct filemgr *file,
75                    uint32_t nodesize);
76 void btreeblk_reset_subblock_info(struct btreeblk_handle *handle);
77 void btreeblk_free(struct btreeblk_handle *handle);
78 void btreeblk_discard_blocks(struct btreeblk_handle *handle);
79 fdb_status btreeblk_end(struct btreeblk_handle *handle);
80 
81 fdb_status btreeblk_create_dirty_snapshot(struct btreeblk_handle *handle);
82 void btreeblk_clone_dirty_snapshot(struct btreeblk_handle *dst,
83                                    struct btreeblk_handle *src);
84 void btreeblk_free_dirty_snapshot(struct btreeblk_handle *handle);
85 
86 #ifdef __cplusplus
87 }
88 #endif
89 
90 #endif
91