forked from OpenAtomFoundation/pika
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pika_table.h
95 lines (77 loc) · 2.53 KB
/
pika_table.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright (c) 2018-present, Qihoo, Inc. All rights reserved.
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.
#ifndef PIKA_TABLE_H_
#define PIKA_TABLE_H_
#include "blackwidow/blackwidow.h"
#include "include/pika_command.h"
#include "include/pika_partition.h"
class Table : public std::enable_shared_from_this<Table>{
public:
Table(const std::string& table_name,
uint32_t partition_num,
const std::string& db_path,
const std::string& log_path);
virtual ~Table();
friend class Cmd;
friend class InfoCmd;
friend class PkClusterInfoCmd;
friend class PikaServer;
std::string GetTableName();
void BgSaveTable();
void CompactTable(const blackwidow::DataType& type);
bool FlushPartitionDB();
bool FlushPartitionSubDB(const std::string& db_name);
void SetBinlogIoError();
bool IsBinlogIoError();
uint32_t PartitionNum();
void GetAllPartitions(std::set<uint32_t>& partition_ids);
// Dynamic change partition
Status AddPartitions(const std::set<uint32_t>& partition_ids);
Status RemovePartitions(const std::set<uint32_t>& partition_ids);
// KeyScan use;
void KeyScan();
bool IsKeyScaning();
void RunKeyScan();
void StopKeyScan();
void ScanDatabase(const blackwidow::DataType& type);
KeyScanInfo GetKeyScanInfo();
Status GetPartitionsKeyScanInfo(std::map<uint32_t, KeyScanInfo>* infos);
// Compact use;
void Compact(const blackwidow::DataType& type);
void LeaveAllPartition();
std::set<uint32_t> GetPartitionIds();
std::shared_ptr<Partition> GetPartitionById(uint32_t partition_id);
std::shared_ptr<Partition> GetPartitionByKey(const std::string& key);
bool TableIsEmpty();
Status MovetoToTrash(const std::string& path);
Status Leave();
private:
std::string table_name_;
uint32_t partition_num_;
std::string db_path_;
std::string log_path_;
std::atomic<bool> binlog_io_error_;
// lock order
// partitions_rw_ > key_scan_protector_
pthread_rwlock_t partitions_rw_;
std::map<uint32_t, std::shared_ptr<Partition>> partitions_;
/*
* KeyScan use
*/
static void DoKeyScan(void *arg);
void InitKeyScan();
slash::Mutex key_scan_protector_;
KeyScanInfo key_scan_info_;
/*
* No allowed copy and copy assign
*/
Table(const Table&);
void operator=(const Table&);
};
struct BgTaskArg {
std::shared_ptr<Table> table;
std::shared_ptr<Partition> partition;
};
#endif