1bc68bb02SChiyoung Seo/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
27c0433f5SJung-Sang Ahn/*
3bc68bb02SChiyoung Seo *     Copyright 2010 Couchbase, Inc
4bc68bb02SChiyoung Seo *
5bc68bb02SChiyoung Seo *   Licensed under the Apache License, Version 2.0 (the "License");
6bc68bb02SChiyoung Seo *   you may not use this file except in compliance with the License.
7bc68bb02SChiyoung Seo *   You may obtain a copy of the License at
8bc68bb02SChiyoung Seo *
9bc68bb02SChiyoung Seo *       http://www.apache.org/licenses/LICENSE-2.0
10bc68bb02SChiyoung Seo *
11bc68bb02SChiyoung Seo *   Unless required by applicable law or agreed to in writing, software
12bc68bb02SChiyoung Seo *   distributed under the License is distributed on an "AS IS" BASIS,
13bc68bb02SChiyoung Seo *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14bc68bb02SChiyoung Seo *   See the License for the specific language governing permissions and
15bc68bb02SChiyoung Seo *   limitations under the License.
167c0433f5SJung-Sang Ahn */
177c0433f5SJung-Sang Ahn
187c0433f5SJung-Sang Ahn#ifndef _JSAHN_BTREEBLOCK_H
197c0433f5SJung-Sang Ahn#define _JSAHN_BTREEBLOCK_H
207c0433f5SJung-Sang Ahn
217c0433f5SJung-Sang Ahn#include "filemgr.h"
227c0433f5SJung-Sang Ahn#include "list.h"
23d32401daSJung-Sang Ahn#include "avltree.h"
247c0433f5SJung-Sang Ahn#include "btree.h"
25a94e4677SSundar Sridharan#include "libforestdb/fdb_errors.h"
267c0433f5SJung-Sang Ahn
27f693a021SSundar Sridharan#ifdef __cplusplus
28f693a021SSundar Sridharanextern "C" {
29f693a021SSundar Sridharan#endif
30f693a021SSundar Sridharan
3180e69aceSJung-Sang Ahnstruct btreeblk_block;
3280e69aceSJung-Sang Ahn
330ebdd56fSJung-Sang Ahnstruct btreeblk_subblocks{
340ebdd56fSJung-Sang Ahn    bid_t bid;
350ebdd56fSJung-Sang Ahn    uint32_t sb_size;
360ebdd56fSJung-Sang Ahn    uint16_t nblocks;
370ebdd56fSJung-Sang Ahn    uint8_t *bitmap;
380ebdd56fSJung-Sang Ahn};
390ebdd56fSJung-Sang Ahn
402c99bfd8SSundar Sridharanstruct dirty_snapshot_t {
412c99bfd8SSundar Sridharan    spin_t lock;
422c99bfd8SSundar Sridharan    int ref_cnt;
432c99bfd8SSundar Sridharan    struct avl_tree *snap_tree;
442c99bfd8SSundar Sridharan};
452c99bfd8SSundar Sridharan
467c0433f5SJung-Sang Ahnstruct btreeblk_handle{
472889254eSJung-Sang Ahn    uint32_t nodesize;
482889254eSJung-Sang Ahn    uint16_t nnodeperblock;
49e8dd5304SJung-Sang Ahn    uint64_t nlivenodes;
502889254eSJung-Sang Ahn    struct list alc_list;
512889254eSJung-Sang Ahn    struct list read_list;
522889254eSJung-Sang Ahn    struct filemgr *file;
5301e33605SChiyoung Seo    err_log_callback *log_callback;
54478c2f10SJung-Sang Ahn
55d32401daSJung-Sang Ahn#ifdef __BTREEBLK_READ_TREE
56d32401daSJung-Sang Ahn    struct avl_tree read_tree;
57d32401daSJung-Sang Ahn#endif
58478c2f10SJung-Sang Ahn#ifdef __BTREEBLK_BLOCKPOOL
59478c2f10SJung-Sang Ahn    struct list blockpool;
60478c2f10SJung-Sang Ahn#endif
61478c2f10SJung-Sang Ahn
62478c2f10SJung-Sang Ahn#ifdef __BTREEBLK_CACHE
63478c2f10SJung-Sang Ahn    uint16_t bin_size;
64478c2f10SJung-Sang Ahn    struct list recycle_bin;
65478c2f10SJung-Sang Ahn    struct btreeblk_block *cache[BTREEBLK_CACHE_LIMIT];
66478c2f10SJung-Sang Ahn#endif
670ebdd56fSJung-Sang Ahn
680ebdd56fSJung-Sang Ahn    uint32_t nsb;
690ebdd56fSJung-Sang Ahn    struct btreeblk_subblocks *sb;
702c99bfd8SSundar Sridharan    struct dirty_snapshot_t *dirty_snapshot;
717c0433f5SJung-Sang Ahn};
727c0433f5SJung-Sang Ahn
737c0433f5SJung-Sang Ahnstruct btree_blk_ops *btreeblk_get_ops();
745aa14abcSSundar Sridharanvoid btreeblk_init(struct btreeblk_handle *handle, struct filemgr *file,
755aa14abcSSundar Sridharan                   uint32_t nodesize);
7685762318SJung-Sang Ahnvoid btreeblk_reset_subblock_info(struct btreeblk_handle *handle);
77dd2f9e13SJung-Sang Ahnvoid btreeblk_free(struct btreeblk_handle *handle);
78d32401daSJung-Sang Ahnvoid btreeblk_discard_blocks(struct btreeblk_handle *handle);
79a94e4677SSundar Sridharanfdb_status btreeblk_end(struct btreeblk_handle *handle);
807c0433f5SJung-Sang Ahn
81bcc6f926SJung-Sang Ahnfdb_status btreeblk_create_dirty_snapshot(struct btreeblk_handle *handle);
82bcc6f926SJung-Sang Ahnvoid btreeblk_clone_dirty_snapshot(struct btreeblk_handle *dst,
83bcc6f926SJung-Sang Ahn                                   struct btreeblk_handle *src);
84bcc6f926SJung-Sang Ahnvoid btreeblk_free_dirty_snapshot(struct btreeblk_handle *handle);
85bcc6f926SJung-Sang Ahn
86f693a021SSundar Sridharan#ifdef __cplusplus
87f693a021SSundar Sridharan}
88f693a021SSundar Sridharan#endif
89f693a021SSundar Sridharan
907c0433f5SJung-Sang Ahn#endif
91