-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.h
87 lines (72 loc) · 1.5 KB
/
data.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
/*
* File: mysql.h
* Author: leo
*
* Created on 2013年5月31日, 下午11:05
*/
#ifndef DATA_H
#define DATA_H
#include<string>
#include<vector>
#include"logger.h"
#include"parse.h"
#include<mysql++/mysql++.h>
#include<semaphore.h>
#define KEYLENGTH 33
#define VALLENGTH 20000
using namespace std;
struct whereSection{
uint32_t start;
uint32_t end;
};
struct dataSet{
char key[KEYLENGTH];
char *val;
};
enum queryModeSet{
limit=0x01,
where=0x02,
};
class data {
private:
pthread_mutex_t pmt;
mysqlpp::Connection dbcon;
logger *log;
xmlParse *xp;
uint32_t batchNum;
uint32_t sleepTime;
uint32_t intervalTime;
string sql;
string keyfield;
map<string,int> keyfieldMap;
string keyPrefix;
vector<string> fieldName;
void preGrabFieldInfo();
sem_t dbsem,cachesem;
uint32_t tableMaxId;
uint32_t tableMinId;
uint32_t batchIndex;
vector<whereSection> section;
void initWhereSection();
string getWhereSection();
//cache耗时记录变量
struct timeval cacheBefore,cacheAfter;
//初始化内存块
void initMemPool();
//查询模式定义
queryModeSet queryMode;
//初始化db连接
void initDB();
public:
data();
~data();
static uint32_t counter;
void loadData();
void waitData(int sid);
void cacheDone(int sid);
int getThreadNum();
dataSet *dataset;
dataSet *begindataset;
static uint32_t loopCount;
};
#endif /* DATA_H */