21 #include <ndb_global.h>
24 #include <kernel/ndb_limits.h>
27 #include "NdbQueryOperationImpl.hpp"
28 #include "ndb_cluster_connection_impl.hpp"
29 #include "NdbDictionaryImpl.hpp"
30 #include "ObjectMap.hpp"
31 #include "trp_client.hpp"
32 #include "trp_node.hpp"
33 #include "NdbWaiter.hpp"
41 int fill(
Ndb*, Uint32 cnt);
44 void release(Uint32 cnt, T* head, T* tail);
46 Uint32 get_sizeof()
const {
return sizeof(T); }
48 Uint32 m_alloc_cnt, m_free_cnt;
60 int send_event_report(
bool has_lock, Uint32 *data, Uint32 length);
63 Ndb * m_next_ndb_object, * m_prev_ndb_object;
71 Uint32 theCurrentConnectIndex;
76 Uint32 theNoOfDBnodes;
77 Uint8 theDBnodes[MAX_NDB_NODES];
80 Uint32 the_release_ind[MAX_NDB_NODES];
86 int m_optimized_node_selection;
95 if (!m_prefix.
assfmt(
"%s%c%s%c", m_dbname.
c_str(), table_name_separator,
96 m_schemaname.
c_str(), table_name_separator))
107 static inline void setNdbError(
Ndb &ndb,
int code){
108 ndb.theError.
code = code;
112 bool forceShortRequests;
114 static inline void setForceShortRequests(
Ndb* ndb,
bool val)
116 ndb->theImpl->forceShortRequests = val;
119 Uint32 get_waitfor_timeout()
const {
120 return m_ndb_cluster_connection.m_config.m_waitfor_timeout;
122 const NdbApiConfig& get_ndbapi_config_parameters()
const {
123 return m_ndb_cluster_connection.m_config;
130 Uint64 clientStats[ Ndb::NumClientStatistics ];
132 inline void incClientStat(
const Ndb::ClientStatistics stat,
const Uint64 inc) {
133 assert(stat < Ndb::NumClientStatistics);
134 if (likely(stat < Ndb::NumClientStatistics))
135 clientStats[ stat ] += inc;
138 inline void decClientStat(
const Ndb::ClientStatistics stat,
const Uint64 dec) {
139 assert(stat < Ndb::NumClientStatistics);
140 if (likely(stat < Ndb::NumClientStatistics))
141 clientStats[ stat ] -= dec;
144 inline void setClientStat(
const Ndb::ClientStatistics stat,
const Uint64 val) {
145 assert(stat < Ndb::NumClientStatistics);
146 if (likely(stat < Ndb::NumClientStatistics))
147 clientStats[ stat ] = val;
155 static bool recordGSN(Uint32 gsn)
160 case GSN_API_REGCONF:
161 case GSN_SUB_GCP_COMPLETE_REP:
162 case GSN_SUB_GCP_COMPLETE_ACK:
194 virtual void recordWaitTimeNanos(Uint64 nanos);
196 bool get_node_alive(NodeId nodeId)
const;
197 bool get_node_stopping(NodeId nodeId)
const;
198 bool getIsDbNode(NodeId nodeId)
const;
199 bool getIsNodeSendable(NodeId nodeId)
const;
200 Uint32 getNodeGrp(NodeId nodeId)
const;
201 Uint32 getNodeSequence(NodeId nodeId)
const;
202 Uint32 getNodeNdbVersion(NodeId nodeId)
const;
203 Uint32 getMinDbNodeVersion()
const;
204 bool check_send_size(Uint32 node_id, Uint32 send_size)
const {
return true;}
218 #define TRACE_DEBUG(x) ndbout << x << endl;
220 #define TRACE_DEBUG(x)
223 #define CHECK_STATUS_MACRO \
224 {if (checkInitState() == -1) { theError.code = 4100; DBUG_RETURN(-1);}}
225 #define CHECK_STATUS_MACRO_VOID \
226 {if (checkInitState() == -1) { theError.code = 4100; DBUG_VOID_RETURN;}}
227 #define CHECK_STATUS_MACRO_ZERO \
228 {if (checkInitState() == -1) { theError.code = 4100; DBUG_RETURN(0);}}
229 #define CHECK_STATUS_MACRO_NULL \
230 {if (checkInitState() == -1) { theError.code = 4100; DBUG_RETURN(NULL);}}
234 Ndb::int2void(Uint32 val){
235 return theImpl->theNdbObjectIdMap.getObject(val);
240 Ndb::void2rec(
void* val){
246 Ndb::void2con(
void* val){
252 Ndb::void2rec_op(
void* val){
258 Ndb::void2rec_iop(
void* val){
264 NdbReceiver::getTransaction()
const {
266 case NDB_UNINITIALIZED:
269 case NDB_QUERY_OPERATION:
279 Ndb::checkInitState()
283 if (theInitState != Initialised)
288 Uint32 convertEndian(Uint32
Data);
302 m_alloc_cnt= m_free_cnt= 0;
318 if (m_free_list == 0)
322 m_free_list =
new T(ndb);
323 if (m_free_list == 0)
325 NdbImpl::setNdbError(*ndb, 4000);
330 while(m_alloc_cnt < cnt)
335 NdbImpl::setNdbError(*ndb, 4000);
339 obj->next(m_free_list);
356 T* tmp = m_free_list;
359 m_free_list = (T*)tmp->next();
365 if((tmp =
new T(ndb)))
371 NdbImpl::setNdbError(*ndb, 4000);
386 obj->next(m_free_list);
400 T* obj = m_free_list;
404 obj = (T*)obj->next();
421 while (tmp != 0 && tmp != tail) tmp = (T*)tmp->next();
425 tail->next(m_free_list);
433 while (tmp != 0 && tmp != tail)
435 T * next = (T*)tmp->next();
446 NdbImpl::getIsDbNode(NodeId
n)
const {
448 getNodeInfo(n).defined &&
454 NdbImpl::getNodeGrp(NodeId
n)
const {
461 NdbImpl::get_node_alive(NodeId
n)
const {
462 return getNodeInfo(n).m_alive;
467 NdbImpl::get_node_stopping(NodeId
n)
const {
468 const trp_node & node = getNodeInfo(n);
476 NdbImpl::getIsNodeSendable(NodeId n)
const {
477 const trp_node & node = getNodeInfo(n);
478 const Uint32 startLevel = node.m_state.
startLevel;
491 NdbImpl::getNodeSequence(NodeId n)
const {
497 NdbImpl::getNodeNdbVersion(NodeId n)
const
504 NdbImpl::recordWaitTimeNanos(Uint64 nanos)
506 incClientStat( Ndb::WaitNanosCount, nanos );
511 NdbImpl::sendSignal(
NdbApiSignal * signal, Uint32 nodeId)
513 if (getIsNodeSendable(nodeId))
515 if (likely(recordGSN(signal->theVerId_signalNumber)))
517 incClientStat(Ndb::BytesSentCount, signal->getLength() << 2);
519 return raw_sendSignal(signal, nodeId);
526 NdbImpl::sendSignal(
NdbApiSignal * signal, Uint32 nodeId,
529 if (getIsNodeSendable(nodeId))
531 if (likely(recordGSN(signal->theVerId_signalNumber)))
533 incClientStat(Ndb::BytesSentCount,
534 ((signal->getLength() << 2) +
535 ((secs > 2)? ptr[2].sz << 2: 0) +
536 ((secs > 1)? ptr[1].sz << 2: 0) +
537 ((secs > 0)? ptr[0].sz << 2: 0)));
539 return raw_sendSignal(signal, nodeId, ptr, secs);
546 NdbImpl::sendSignal(
NdbApiSignal * signal, Uint32 nodeId,
549 if (getIsNodeSendable(nodeId))
551 if (likely(recordGSN(signal->theVerId_signalNumber)))
553 incClientStat(Ndb::BytesSentCount,
554 ((signal->getLength() << 2) +
555 ((secs > 2)? ptr[2].sz << 2 : 0) +
556 ((secs > 1)? ptr[1].sz << 2: 0) +
557 ((secs > 0)? ptr[0].sz << 2: 0)));
559 return raw_sendSignal(signal, nodeId, ptr, secs);
566 NdbImpl::sendFragmentedSignal(
NdbApiSignal * signal, Uint32 nodeId,
569 if (getIsNodeSendable(nodeId))
571 if (likely(recordGSN(signal->theVerId_signalNumber)))
573 incClientStat(Ndb::BytesSentCount,
574 ((signal->getLength() << 2) +
575 ((secs > 2)? ptr[2].sz << 2 : 0) +
576 ((secs > 1)? ptr[1].sz << 2: 0) +
577 ((secs > 0)? ptr[0].sz << 2: 0)));
579 return raw_sendFragmentedSignal(signal, nodeId, ptr, secs);
586 NdbImpl::sendFragmentedSignal(
NdbApiSignal * signal, Uint32 nodeId,
589 if (getIsNodeSendable(nodeId))
591 if (likely(recordGSN(signal->theVerId_signalNumber)))
593 incClientStat(Ndb::BytesSentCount,
594 ((signal->getLength() << 2) +
595 ((secs > 2)? ptr[2].sz << 2 : 0) +
596 ((secs > 1)? ptr[1].sz << 2 : 0) +
597 ((secs > 0)? ptr[0].sz << 2 : 0)));
599 return raw_sendFragmentedSignal(signal, nodeId, ptr, secs);