19 #include "DbtupProxy.hpp"
22 #include <signaldata/LgmanContinueB.hpp>
24 #include <EventLogger.hpp>
34 addRecSignal(GSN_CREATE_TAB_REQ, &DbtupProxy::execCREATE_TAB_REQ);
35 addRecSignal(GSN_DROP_TAB_REQ, &DbtupProxy::execDROP_TAB_REQ);
38 addRecSignal(GSN_BUILD_INDX_IMPL_REQ, &DbtupProxy::execBUILD_INDX_IMPL_REQ);
39 addRecSignal(GSN_BUILD_INDX_IMPL_CONF, &DbtupProxy::execBUILD_INDX_IMPL_CONF);
40 addRecSignal(GSN_BUILD_INDX_IMPL_REF, &DbtupProxy::execBUILD_INDX_IMPL_REF);
43 DbtupProxy::~DbtupProxy()
48 DbtupProxy::newWorker(Uint32 instanceNo)
50 return new Dbtup(m_ctx, instanceNo);
55 DbtupProxy::callREAD_CONFIG_REQ(
Signal* signal)
58 ndbrequire(req->noOfParameters == 0);
61 m_ctx.m_config.getOwnConfigIterator();
64 ndbrequire(!ndb_mgm_get_int_parameter(p, CFG_TUP_TABLE, &c_tableRecSize));
65 c_tableRec = (Uint8*)
allocRecord(
"TableRec",
sizeof(Uint8), c_tableRecSize);
66 D(
"proxy:" << V(c_tableRecSize));
68 for (i = 0; i < c_tableRecSize; i++)
70 backREAD_CONFIG_REQ(signal);
76 DbtupProxy::callSTTOR(
Signal* signal)
78 Uint32 startPhase = signal->theData[1];
81 c_pgman = (
Pgman*)globalData.getBlock(PGMAN);
82 ndbrequire(c_pgman != 0);
91 DbtupProxy::execCREATE_TAB_REQ(
Signal* signal)
94 const Uint32 tableId = req->tableId;
95 ndbrequire(tableId < c_tableRecSize);
96 ndbrequire(c_tableRec[tableId] == 0);
97 c_tableRec[tableId] = 1;
98 D(
"proxy: created table" << V(tableId));
102 DbtupProxy::execDROP_TAB_REQ(
Signal* signal)
105 const Uint32 tableId = req->tableId;
106 ndbrequire(tableId < c_tableRecSize);
107 c_tableRec[tableId] = 0;
108 D(
"proxy: dropped table" << V(tableId));
114 DbtupProxy::execBUILD_INDX_IMPL_REQ(
Signal* signal)
117 Ss_BUILD_INDX_IMPL_REQ& ss = ssSeize<Ss_BUILD_INDX_IMPL_REQ>();
119 ndbrequire(signal->getLength() == BuildIndxImplReq::SignalLength);
124 DbtupProxy::sendBUILD_INDX_IMPL_REQ(
Signal* signal, Uint32 ssId,
127 Ss_BUILD_INDX_IMPL_REQ& ss = ssFind<Ss_BUILD_INDX_IMPL_REQ>(ssId);
131 req->senderRef = reference();
132 req->senderData = ssId;
134 signal, BuildIndxImplReq::SignalLength, JBB, handle);
138 DbtupProxy::execBUILD_INDX_IMPL_CONF(
Signal* signal)
141 Uint32 ssId = conf->senderData;
142 Ss_BUILD_INDX_IMPL_REQ& ss = ssFind<Ss_BUILD_INDX_IMPL_REQ>(ssId);
143 recvCONF(signal, ss);
147 DbtupProxy::execBUILD_INDX_IMPL_REF(
Signal* signal)
150 Uint32 ssId = ref->senderData;
151 Ss_BUILD_INDX_IMPL_REQ& ss = ssFind<Ss_BUILD_INDX_IMPL_REQ>(ssId);
152 recvREF(signal, ss, ref->errorCode);
156 DbtupProxy::sendBUILD_INDX_IMPL_CONF(
Signal* signal, Uint32 ssId)
158 Ss_BUILD_INDX_IMPL_REQ& ss = ssFind<Ss_BUILD_INDX_IMPL_REQ>(ssId);
159 BlockReference dictRef = ss.m_req.senderRef;
164 if (ss.m_error == 0) {
167 conf->senderRef = reference();
168 conf->senderData = ss.m_req.senderData;
169 sendSignal(dictRef, GSN_BUILD_INDX_IMPL_CONF,
170 signal, BuildIndxImplConf::SignalLength, JBB);
173 ref->senderRef = reference();
174 ref->senderData = ss.m_req.senderData;
175 ref->errorCode = ss.m_error;
176 sendSignal(dictRef, GSN_BUILD_INDX_IMPL_REF,
177 signal, BuildIndxImplRef::SignalLength, JBB);
180 ssRelease<Ss_BUILD_INDX_IMPL_REQ>(ssId);
187 DbtupProxy::Proxy_undo::Proxy_undo()
194 m_page_id = ~(Uint32)0;
195 m_table_id = ~(Uint32)0;
196 m_fragment_id = ~(Uint32)0;
197 m_instance_no = ~(Uint32)0;
203 DbtupProxy::disk_restart_undo(
Signal* signal, Uint64
lsn,
204 Uint32
type,
const Uint32 * ptr, Uint32 len)
206 Proxy_undo& undo = c_proxy_undo;
207 ndbrequire(!undo.m_in_use);
208 new (&undo) Proxy_undo;
209 undo.m_in_use =
true;
211 D(
"proxy: disk_restart_undo" << V(type) << hex << V(ptr) << dec << V(len) << V(lsn));
221 ndbrequire(undo.m_len <= Proxy_undo::MaxData);
222 memcpy(undo.m_data, undo.m_ptr, undo.m_len << 2);
224 switch (undo.m_type) {
225 case File_formats::Undofile::UNDO_LCP_FIRST:
226 case File_formats::Undofile::UNDO_LCP:
228 undo.m_table_id = ptr[1] >> 16;
229 undo.m_fragment_id = ptr[1] & 0xFFFF;
230 undo.m_actions |= Proxy_undo::SendToAll;
231 undo.m_actions |= Proxy_undo::SendUndoNext;
234 case File_formats::Undofile::UNDO_TUP_ALLOC:
238 undo.m_key.m_file_no = rec->m_file_no_page_idx >> 16;
239 undo.m_key.m_page_no = rec->m_page_no;
240 undo.m_key.m_page_idx = rec->m_file_no_page_idx & 0xFFFF;
241 undo.m_actions |= Proxy_undo::ReadTupPage;
242 undo.m_actions |= Proxy_undo::GetInstance;
245 case File_formats::Undofile::UNDO_TUP_UPDATE:
249 undo.m_key.m_file_no = rec->m_file_no_page_idx >> 16;
250 undo.m_key.m_page_no = rec->m_page_no;
251 undo.m_key.m_page_idx = rec->m_file_no_page_idx & 0xFFFF;
252 undo.m_actions |= Proxy_undo::ReadTupPage;
253 undo.m_actions |= Proxy_undo::GetInstance;
256 case File_formats::Undofile::UNDO_TUP_FREE:
260 undo.m_key.m_file_no = rec->m_file_no_page_idx >> 16;
261 undo.m_key.m_page_no = rec->m_page_no;
262 undo.m_key.m_page_idx = rec->m_file_no_page_idx & 0xFFFF;
263 undo.m_actions |= Proxy_undo::ReadTupPage;
264 undo.m_actions |= Proxy_undo::GetInstance;
268 case File_formats::Undofile::UNDO_TUP_CREATE:
272 Uint32 tableId = rec->m_table;
273 if (tableId < c_tableRecSize)
276 c_tableRec[tableId] = 0;
279 undo.m_actions |= Proxy_undo::SendToAll;
280 undo.m_actions |= Proxy_undo::SendUndoNext;
283 case File_formats::Undofile::UNDO_TUP_DROP:
287 Uint32 tableId = rec->m_table;
288 if (tableId < c_tableRecSize)
291 c_tableRec[tableId] = 0;
294 undo.m_actions |= Proxy_undo::SendToAll;
295 undo.m_actions |= Proxy_undo::SendUndoNext;
298 #if NOT_YET_UNDO_ALLOC_EXTENT
299 case File_formats::Undofile::UNDO_TUP_ALLOC_EXTENT:
303 #if NOT_YET_UNDO_FREE_EXTENT
304 case File_formats::Undofile::UNDO_TUP_FREE_EXTENT:
308 case File_formats::Undofile::UNDO_END:
310 undo.m_actions |= Proxy_undo::SendToAll;
318 if (undo.m_actions & Proxy_undo::ReadTupPage) {
328 req.m_page = undo.m_key;
329 req.m_callback.m_callbackData = 0;
330 req.m_callback.m_callbackFunction =
331 safe_cast(&DbtupProxy::disk_restart_undo_callback);
333 int ret = pgman.get_page(signal, req, 0);
334 ndbrequire(ret >= 0);
337 execute(signal, req.m_callback, (Uint32)ret);
342 disk_restart_undo_finish(signal);
346 DbtupProxy::disk_restart_undo_callback(
Signal* signal, Uint32, Uint32 page_id)
348 Proxy_undo& undo = c_proxy_undo;
349 undo.m_page_id = page_id;
352 m_global_page_pool.
getPtr(gptr, undo.m_page_id);
354 ndbrequire(undo.m_actions & Proxy_undo::ReadTupPage);
359 const Uint32 page_type = header.m_page_type;
361 if (page_type == 0) {
363 ndbrequire(header.m_page_lsn_hi == 0 && header.m_page_lsn_lo == 0);
364 undo.m_actions |= Proxy_undo::NoExecute;
365 undo.m_actions |= Proxy_undo::SendUndoNext;
366 D(
"proxy: callback" << V(page_type));
368 ndbrequire(page_type == File_formats::PT_Tup_fixsize_page ||
369 page_type == File_formats::PT_Tup_varsize_page);
371 Uint64 page_lsn = (Uint64(header.m_page_lsn_hi) << 32) + header.m_page_lsn_lo;
372 if (! (undo.m_lsn <= page_lsn))
375 undo.m_actions |= Proxy_undo::NoExecute;
376 undo.m_actions |= Proxy_undo::SendUndoNext;
379 undo.m_table_id = page->m_table_id;
380 undo.m_fragment_id = page->m_fragment_id;
381 D(
"proxy: callback" << V(undo.m_table_id) << V(undo.m_fragment_id));
382 const Uint32 tableId = undo.m_table_id;
383 if (tableId >= c_tableRecSize || c_tableRec[tableId] == 0) {
384 D(
"proxy: table dropped" << V(tableId));
385 undo.m_actions |= Proxy_undo::NoExecute;
386 undo.m_actions |= Proxy_undo::SendUndoNext;
391 disk_restart_undo_finish(signal);
395 DbtupProxy::disk_restart_undo_finish(
Signal* signal)
397 Proxy_undo& undo = c_proxy_undo;
399 if (undo.m_actions & Proxy_undo::SendUndoNext) {
401 signal->theData[0] = LgmanContinueB::EXECUTE_UNDO_RECORD;
402 sendSignal(LGMAN_REF, GSN_CONTINUEB, signal, 1, JBB);
405 if (undo.m_actions & Proxy_undo::NoExecute) {
410 if (undo.m_actions & Proxy_undo::GetInstance) {
412 Uint32 instanceKey = getInstanceKey(undo.m_table_id, undo.m_fragment_id);
413 Uint32 instanceNo = getInstanceFromKey(instanceKey);
414 undo.m_instance_no = instanceNo;
417 if (!(undo.m_actions & Proxy_undo::SendToAll)) {
419 ndbrequire(undo.m_instance_no != 0);
420 Uint32 i = undo.m_instance_no - 1;
421 disk_restart_undo_send(signal, i);
425 for (i = 0; i < c_workers; i++) {
426 disk_restart_undo_send(signal, i);
431 ndbrequire(undo.m_in_use);
432 undo.m_in_use =
false;
436 DbtupProxy::disk_restart_undo_send(
Signal* signal, Uint32 i)
443 Proxy_undo& undo = c_proxy_undo;
446 ptr[0].p = undo.m_data;
447 ptr[0].sz = undo.m_len;
449 signal->theData[0] = ZDISK_RESTART_UNDO;
450 signal->theData[1] = undo.m_type;
451 signal->theData[2] = undo.m_len;
452 signal->theData[3] = (Uint32)(undo.m_lsn >> 32);
453 signal->theData[4] = (Uint32)(undo.m_lsn & 0xFFFFFFFF);
454 sendSignal(workerRef(i), GSN_CONTINUEB, signal, 5, JBB, ptr, 1);
460 DbtupProxy::disk_restart_alloc_extent(Uint32 tableId, Uint32 fragId,
463 if (tableId >= c_tableRecSize || c_tableRec[tableId] == 0) {
465 D(
"proxy: table dropped" << V(tableId));
470 Uint32 instanceKey = getInstanceKey(tableId, fragId);
471 Uint32 instanceNo = getInstanceFromKey(instanceKey);
473 Uint32 i = workerIndex(instanceNo);
475 return dbtup->disk_restart_alloc_extent(tableId, fragId, key, pages);
479 DbtupProxy::disk_restart_page_bits(Uint32 tableId, Uint32 fragId,
482 ndbrequire(tableId < c_tableRecSize && c_tableRec[tableId] == 1);
485 Uint32 instanceKey = getInstanceKey(tableId, fragId);
486 Uint32 instanceNo = getInstanceFromKey(instanceKey);
488 Uint32 i = workerIndex(instanceNo);
490 dbtup->disk_restart_page_bits(tableId, fragId, key, bits);