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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
/* Copyright (C) 2003 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#ifndef CHANNEL_HPP
#define CHANNEL_HPP
#include "Interval.hpp"
#include <rep/rep_version.hpp>
#include <Vector.hpp>
#include <ndb_limits.h>
#include <GrepError.hpp>
/**
* Max number of requested epochs from PS
*/
#define GREP_SYSTEM_TABLE_MAX_RANGE 20
#define MAX_NO_OF_NODE_GROUPS 32
/**
* This table struct is used in m_selectedTables
*/
struct table{
table(const char * n) {strncpy(tableName, n, MAX_TAB_NAME_SIZE);}
char tableName[MAX_TAB_NAME_SIZE];
};
/**
* @class Channel
* @brief Represents location of various epochs belonging to a subscription
*/
class Channel {
public:
enum StateSub
{
NO_SUBSCRIPTION_EXISTS,
CREATING_SUBSCRIPTION_ID,
SUBSCRIPTION_ID_CREATED,
STARTING_SUBSCRIPTION,
SUBSCRIPTION_STARTED
};
enum StateRep
{
CONSISTENT, ///< Consistent database. Grep not running.
METALOG_STARTING, ///< Starting. Starting METALOG subscription
METALOG_STARTED,
METASCAN_STARTING, ///< Starting. Starting METASCAN subscription
METASCAN_COMPLETED,
DATALOG_STARTING, ///< Starting. Starting DATALOG subscription
DATALOG_STARTED,
DATASCAN_STARTING, ///< Starting. Starting DATASCAN subscription
DATASCAN_COMPLETED,
LOG, ///< Started. Cons/Inconsistent. Grep running.
///< All scan records have been applied.
STOPPING ///< Channel is stopping
};
/**
* Storage "positions" of Epochs
*/
enum Position {
PS = 0, ///< Stored on Primary System REP
SSReq = 1, ///< Requested for transfer to Standby System
SS = 2, ///< Stored on Standby System REP
AppReq = 3, ///< Requested to be applied to Standby System
App = 4, ///< Has been applied to Standby System
DelReq = 5, ///< Has been requested to be deleted on PS REP & SS REP
NO_OF_POSITIONS = 6
}; //DONT FORGET TO ADD STUFF in position2Name if u add somehting here,
/***************************************************************************
* CONSTRUCTOR / DESTRUCTOR
***************************************************************************/
Channel();
~Channel();
/**
* Get and set no of nodegroups that actually exists on PS
*/
void setNoOfNodeGroups(Uint32 n) { m_noOfNodeGroups = n; };
Uint32 getNoOfNodeGroups() { return m_noOfNodeGroups; };
void getEpochState(Position p,
Uint32 nodeGrp,
Uint32 * first,
Uint32 * last);
Uint32 getEpochState(Position p, Uint32 nodegroup);
bool m_requestorEnabled;
bool m_transferEnabled;
bool m_applyEnabled;
bool m_deleteEnabled;
bool m_autoStartEnabled;
/***************************************************************************
* GETTERS and SETTERS
***************************************************************************/
bool requestTransfer(Uint32 nodeGrp, Interval * i);
bool requestApply(Uint32 nodeGrp, Uint32 * epoch);
bool requestDelete(Uint32 nodeGrp, Interval * i);
void add(Position pos, Uint32 nodeGrp, const Interval i);
void clear(Position pos, Uint32 nodeGrp, const Interval i);
void setSubId(Uint32 subId) { m_subId=subId; };
Uint32 getSubId() { return m_subId; };
Uint32 getSubKey() { return m_subKey; };
void setSubKey(Uint32 subKey) { m_subKey=subKey; };
bool isSynchable(Uint32 nodeGrp);
GrepError::Code addTable(const char * tableName);
GrepError::Code removeTable(const char * tableName);
void printTables();
bool isSelective() {return m_selectedTables.size()>0;};
Vector<struct table *> * getSelectedTables();
void reset();
StateRep getState() { return m_stateRep; }
void setState(StateRep sr) { m_stateRep = sr; }
StateSub getStateSub() { return m_stateSub; }
void setStateSub(StateSub ss) { m_stateSub = ss; }
Interval getMetaScanEpochs() { return m_metaScanEpochs; }
void setMetaScanEpochs(Interval i) { m_metaScanEpochs = i; }
Interval getDataScanEpochs() { return m_dataScanEpochs; }
void setDataScanEpochs(Interval i) { m_dataScanEpochs = i; }
GrepError::Code setStopEpochId(Uint32 n);
Uint32 getStopEpochId() { return m_stopEpochId; };
bool isStoppable();
bool shouldStop();
bool subscriptionExists() { return (m_subId != 0 && m_subKey != 0); }
/***************************************************************************
* GETTERS
***************************************************************************/
Uint32 getFirst(Position pos, Uint32 nodeGrp) {
return state[nodeGrp][pos].first();
}
Uint32 getLast(Position pos, Uint32 nodeGrp) {
return state[nodeGrp][pos].last();
}
void getFullyAppliedEpochs(Interval * i);
/***************************************************************************
* PRINT METHODS
***************************************************************************/
void print();
void print(Position pos);
void print(Position pos, Uint32 nodeGrp);
void print(Uint32 nodeGrp);
/***************************************************************************
* PUBLIC ATTRIBUTES
***************************************************************************/
private:
/***************************************************************************
* PRIVATE ATTRIBUTES
***************************************************************************/
StateRep m_stateRep; // Replication state
StateSub m_stateSub; // Subscription state
Uint32 m_subId;
Uint32 m_subKey;
Uint32 m_noOfNodeGroups; // Number of node grps in this channel
Uint32 m_stopEpochId; // Epoch id to stop subscription
Interval state[MAX_NO_OF_NODE_GROUPS][NO_OF_POSITIONS];
Interval m_metaScanEpochs;
Interval m_dataScanEpochs;
Vector<struct table *> m_selectedTables;
void invariant(); // Abort if channel metadata is inconsistent
char * position2Name(Position p);
public:
bool copy(Position from, Position to, Uint32 range,
Uint32 * f, Uint32 * l, Uint32 nodeGrp);
};
#endif
|