remove conflict
[c11concurrency-benchmarks.git] / mabain / src / mb_rc.h
1 /**
2  * Copyright (C) 2017 Cisco Inc.
3  *
4  * This program is free software: you can redistribute it and/or  modify
5  * it under the terms of the GNU General Public License, version 2,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15  */
16
17 // @author Changxue Deng <chadeng@cisco.com>
18
19 #ifndef __MB_RC_H__
20 #define __MB_RC_H__
21
22 #include "db.h"
23 #include "dict.h"
24 #include "mbt_base.h"
25 #include "async_writer.h"
26
27 #define RESOURCE_COLLECTION_TYPE_INDEX            0x01
28 #define RESOURCE_COLLECTION_TYPE_DATA             0x02
29
30 #define RESOURCE_COLLECTION_PHASE_REORDER         0x01
31 #define RESOURCE_COLLECTION_PHASE_COLLECT         0x02
32
33 namespace mabain {
34
35 // A garbage collector class
36 class ResourceCollection : public DBTraverseBase
37 {
38 public:
39     ResourceCollection(const DB &db,
40         int rct = RESOURCE_COLLECTION_TYPE_INDEX |
41                   RESOURCE_COLLECTION_TYPE_DATA);
42     virtual ~ResourceCollection();
43
44     void ReclaimResource(int64_t min_index_size, int64_t min_data_size,
45                          int64_t max_dbsz, int64_t max_dbcnt,
46                          AsyncWriter *awr = NULL);
47
48     // This function should be called when writer starts up.
49     int  ExceptionRecovery();
50
51 private:
52     void DoTask(int phase, DBTraverseNode &dbt_node);
53     void Prepare(int64_t min_index_size, int64_t min_data_size);
54     void CollectBuffers();
55     void ReorderBuffers();
56     void Finish();
57     bool MoveIndexBuffer(int phase, size_t &offset_src, int size);
58     bool MoveDataBuffer(int phase, size_t &offset_src, int size);
59     int  LRUEviction();
60     void ProcessRCTree();
61
62     int     rc_type;
63     int     index_rc_status;
64     int     data_rc_status;
65     int     index_reorder_status;
66     int     data_reorder_status;
67
68     // data for print gc stats only
69     int64_t index_reorder_cnt;
70     int64_t data_reorder_cnt;
71
72     // Async writer pointer
73     AsyncWriter *async_writer_ptr;
74
75     // resource collection offsets
76     size_t  rc_index_offset;
77     size_t  rc_data_offset;
78     int64_t rc_loop_counter;
79
80     int64_t db_cnt;
81     size_t  edge_str_size;
82     int64_t node_cnt;
83 };
84
85 }
86
87 #endif