2 * Copyright (C) 2017 Cisco Inc.
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.
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.
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/>.
17 // @author Changxue Deng <chadeng@cisco.com>
25 #include "async_writer.h"
27 #define RESOURCE_COLLECTION_TYPE_INDEX 0x01
28 #define RESOURCE_COLLECTION_TYPE_DATA 0x02
30 #define RESOURCE_COLLECTION_PHASE_REORDER 0x01
31 #define RESOURCE_COLLECTION_PHASE_COLLECT 0x02
35 // A garbage collector class
36 class ResourceCollection : public DBTraverseBase
39 ResourceCollection(const DB &db,
40 int rct = RESOURCE_COLLECTION_TYPE_INDEX |
41 RESOURCE_COLLECTION_TYPE_DATA);
42 virtual ~ResourceCollection();
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);
48 // This function should be called when writer starts up.
49 int ExceptionRecovery();
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();
57 bool MoveIndexBuffer(int phase, size_t &offset_src, int size);
58 bool MoveDataBuffer(int phase, size_t &offset_src, int size);
65 int index_reorder_status;
66 int data_reorder_status;
68 // data for print gc stats only
69 int64_t index_reorder_cnt;
70 int64_t data_reorder_cnt;
72 // Async writer pointer
73 AsyncWriter *async_writer_ptr;
75 // resource collection offsets
76 size_t rc_index_offset;
77 size_t rc_data_offset;
78 int64_t rc_loop_counter;