forked from joyieldInc/predixy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDC.h
72 lines (66 loc) · 1.37 KB
/
DC.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
/*
* predixy - A high performance and full features proxy for redis.
* Copyright (C) 2017 Joyield, Inc. <[email protected]>
* All rights reserved.
*/
#ifndef _PREDIXY_DC_H_
#define _PREDIXY_DC_H_
#include <vector>
#include <map>
#include "ID.h"
#include "Conf.h"
#include "String.h"
struct DCReadPolicy
{
int priority = 0;
int weight = 0;
};
class DC : public ID<DC>
{
public:
DC(const String& name, int size);
~DC();
const String& name() const
{
return mName;
}
void set(DC* oth, const ReadPolicyConf& c)
{
mReadPolicy[oth->id()].priority = c.priority;
mReadPolicy[oth->id()].weight = c.weight;
}
int getReadPriority(DC* oth) const
{
return oth ? mReadPolicy[oth->id()].priority : 1;
}
int getReadWeight(DC* oth) const
{
return oth ? mReadPolicy[oth->id()].weight : 1;
}
const DCReadPolicy& getReadPolicy(DC* oth) const
{
return mReadPolicy[oth->id()];
}
private:
String mName;
std::vector<DCReadPolicy> mReadPolicy;
};
class DataCenter
{
public:
DefException(InitFail);
public:
DataCenter();
~DataCenter();
void init(const Conf* conf);
DC* getDC(const String& addr) const;
DC* localDC() const
{
return mLocalDC;
}
private:
std::map<String, DC*> mDCs;
std::map<String, DC*> mAddrDC;
DC* mLocalDC;
};
#endif