summaryrefslogtreecommitdiff
path: root/ndb/src/old_files/rep/state/RepStateEvent.cpp
blob: 9be304c8bfa42882ee58dcfe5e2f67ed0fe58027 (plain)
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
/* 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 */

#include "RepState.hpp"

/****************************************************************************
 * Public Event Handlers : CREATE SUBSCRIPTION ID
 ****************************************************************************/

void 
RepState::eventSubscriptionIdCreated(Uint32 subId, Uint32 subKey)
{
  if (m_channel.getStateSub() == Channel::CREATING_SUBSCRIPTION_ID)
  {
    m_channel.setSubId(subId);
    m_channel.setSubKey(subKey);
    m_channel.setStateSub(Channel::SUBSCRIPTION_ID_CREATED);
  }
  else 
  {
    REPABORT("Illegal state for create subscription id conf");
  }
}

void 
RepState::eventSubscriptionIdCreateFailed(Uint32 subId, Uint32 subKey, 
					  GrepError::Code error)
{
  ndbout_c("\nSubscription id creation failed");
  ndbout_c("Error %d: %s", error, GrepError::getErrorDesc(error));
  ndbout_c("Subscription Id: %d, Key: %d", subId, subKey);
}

/****************************************************************************
 * Public Event Handlers : CREATE SUBSCRIPTION
 ****************************************************************************/

void
RepState::eventSubscriptionCreated(Uint32 subId, Uint32 subKey)
{
  if (m_channel.getStateSub() == Channel::STARTING_SUBSCRIPTION)
  {
    m_channel.setStateSub(Channel::SUBSCRIPTION_STARTED);
  }
  else 
  {
    REPABORT("Illegal state for create subscription conf");
  }
}

void
RepState::eventSubscriptionCreateFailed(Uint32 subId, Uint32 subKey,
					GrepError::Code error)
{
  ndbout_c("\nSubscription creation failed");
  ndbout_c("Error %d: %s", error, GrepError::getErrorDesc(error));
  ndbout_c("Subscription Id: %d, Key: %d", subId, subKey);
}


/****************************************************************************
 * Public Event Handlers : META LOG
 ****************************************************************************/

void 
RepState::eventMetaLogStarted(NdbApiSignal* signal, 
			      Uint32 subId, Uint32 subKey)
{
  if (m_channel.getState() != Channel::METALOG_STARTING) 
  {
    RLOG(("WARNING! Metalog started in state %d, should be %d",
	  m_channel.getState(), Channel::METALOG_STARTING));
  }
  
  if (!isAutoStartEnabled())
  {
    m_channel.setState(Channel::METALOG_STARTED);
  }
  else 
  {
    m_channel.setState(Channel::METALOG_STARTED);
    m_channel.setState(Channel::METASCAN_STARTING);
    m_funcRequestStartMetaScan(m_extSender, signal, subId, subKey);
  }
}

void 
RepState::eventMetaLogStartFailed(Uint32 subId, Uint32 subKey, 
				  GrepError::Code error)
{
  ndbout_c("\nMetalog start failed");
  ndbout_c("Error %d: %s", error, GrepError::getErrorDesc(error));
  ndbout_c("Subscription Id: %d, Key: %d", subId, subKey);
}

/****************************************************************************
 * Public Event Handlers : META SCAN
 ****************************************************************************/

void 
RepState::eventMetaScanCompleted(NdbApiSignal* signal, 
				 Uint32 subId, Uint32 subKey, Interval epochs) 
{
  if (m_channel.getState() != Channel::METASCAN_STARTING) 
  {
    RLOG(("WARNING! Metascan completed in state %d, should be %d",
	  m_channel.getState(), Channel::METASCAN_STARTING));
  }
  RLOG(("Metascan completed. Subscription %d-%d, Epochs [%d-%d]",
	subId, subKey, epochs.first(), epochs.last()));

  m_channel.setState(Channel::METASCAN_COMPLETED);
  
  if (isAutoStartEnabled())
  {
    m_channel.setState(Channel::DATALOG_STARTING);
    m_funcRequestStartDataLog(m_extSender, signal, subId, subKey);
  }
  m_channel.setMetaScanEpochs(epochs);
}

/****************************************************************************
 * Public Event Handlers : DATA LOG
 ****************************************************************************/

void 
RepState::eventDataLogStarted(NdbApiSignal* signal,
			      Uint32 subId, Uint32 subKey)
{
  if (m_channel.getState() != Channel::DATALOG_STARTING) 
  {
    RLOG(("WARNING! Datalog started in state %d, should be %d",
	  m_channel.getState(), Channel::DATALOG_STARTING));
  }

  m_channel.setState(Channel::DATALOG_STARTED);

  if (isAutoStartEnabled())
  {
    m_channel.setState(Channel::DATASCAN_STARTING);
    m_funcRequestStartDataScan(m_extSender, signal, subId, subKey);
  }
}

void 
RepState::eventDataLogStartFailed(Uint32 subId, Uint32 subKey, 
				  GrepError::Code error)
{
  ndbout_c("\nDatalog start failed");
  ndbout_c("Error %d: %s", error, GrepError::getErrorDesc(error));
  ndbout_c("Subscription Id: %d, Key: %d", subId, subKey);
}

/****************************************************************************
 * Public Event Handlers : DATA SCAN
 ****************************************************************************/

void 
RepState::eventDataScanCompleted(NdbApiSignal* signal, 
				 Uint32 subId, Uint32 subKey,
				 Interval epochs) 
{
  if (m_channel.getState() != Channel::DATASCAN_STARTING) 
  {
    RLOG(("WARNING! Datascan completed in state %d, should be %d",
	  m_channel.getState(), Channel::DATASCAN_STARTING));
  }
  RLOG(("Datascan completed. Subscription %d-%d, Epochs [%d-%d]",
	subId, subKey, epochs.first(), epochs.last()));
  
  m_channel.setState(Channel::DATASCAN_COMPLETED);
  m_channel.setDataScanEpochs(epochs);
}

/****************************************************************************
 * Public Event Handlers : FAILURES
 ****************************************************************************/

void
RepState::eventMetaScanFailed(Uint32 subId, Uint32 subKey,
			     GrepError::Code error)
{
  ndbout_c("\nMetascan failed");
  ndbout_c("Error %d: %s", error, GrepError::getErrorDesc(error));
  ndbout_c("Subscription Id: %d, Key: %d", subId, subKey);
}

void 
RepState::eventDataScanFailed(Uint32 subId, Uint32 subKey, 
			     GrepError::Code error)
{
  ndbout_c("\nDatascan failed");
  ndbout_c("Error %d: %s", error, GrepError::getErrorDesc(error));
  ndbout_c("Subscription Id: %d, Key: %d", subId, subKey);
}

/****************************************************************************
 * Public Event Handlers : APPLY
 ****************************************************************************/

void
RepState::eventInsertConf(Uint32 gci, Uint32 nodeGrp) 
{
  Interval app(gci, gci);
  add(Channel::App, nodeGrp, app);
  clear(Channel::AppReq, nodeGrp, app);

#ifdef DEBUG_GREP
  ndbout_c("RepState: GCI Buffer %d:[%d] applied", nodeGrp, gci);
#endif
}

void
RepState::eventInsertRef(Uint32 gci, Uint32 nodeGrp, Uint32 tableId, 
			 GrepError::Code err) 
{
  ndbout_c("\nTable %d, used in replication, did not exist");
  RLOG(("ERROR %d:%s. Apply failed (%d[%d] in table %d)", 
	err, GrepError::getErrorDesc(err), nodeGrp, gci, tableId));
}


void
RepState::eventCreateTableRef(Uint32 gci,			  
			      Uint32 tableId, 
			      const char * tableName,
			      GrepError::Code err) 
{
  ndbout_c("\nFailed to create table %s with source site table id %d",
	   tableName,
	   tableId);

  RLOG(("ERROR %d:%s. Failed to create table %s with source site table id %d!",
	err, GrepError::getErrorDesc(err), tableName, tableId));
}

/****************************************************************************
 * Public Event Handlers : Connected/Disconnected
 ****************************************************************************/

void 
RepState::eventNodeConnected(Uint32 nodeId)
{
  m_repConnected = CONNECTED;
}
 
void 
RepState::eventNodeDisconnected(Uint32 nodeId)
{
  m_repConnected = DISCONNECTED;
}

void 
RepState::eventNodeConnectable(Uint32 nodeId)
{
  m_repConnected = CONNECTABLE;
}

/****************************************************************************
 * Public Event Handlers : Connected/Disconnected
 ****************************************************************************/

void 
RepState::eventSubscriptionDeleted(Uint32 subId, Uint32 subKey) 
{
  m_gciContainer->reset();
  m_channel.setState(Channel::CONSISTENT);
  m_channel.reset();
  m_subIdToRemove = 0;
  m_subKeyToRemove = 0;
}