NdbImpl.hpp 4.07 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/* 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 NDB_IMPL_HPP
#define NDB_IMPL_HPP

20
#include <ndb_global.h>
21
#include <Ndb.hpp>
22
#include <NdbOut.hpp>
23 24 25 26 27 28 29 30
#include <NdbError.hpp>
#include <NdbCondition.h>
#include <NdbReceiver.hpp>
#include <NdbOperation.hpp>
#include <kernel/ndb_limits.h>

#include <NdbTick.h>

31 32
#include "ndb_cluster_connection_impl.hpp"
#include "NdbDictionaryImpl.hpp"
33 34 35 36 37 38 39
#include "ObjectMap.hpp"

/**
 * Private parts of the Ndb object (corresponding to Ndb.hpp in public API)
 */
class NdbImpl {
public:
40
  NdbImpl(Ndb_cluster_connection *, Ndb&);
41
  ~NdbImpl();
42

43 44 45 46
  Ndb_cluster_connection_impl &m_ndb_cluster_connection;

  NdbDictionaryImpl m_dictionary;

47 48
  // Ensure good distribution of connects
  Uint32 theCurrentConnectIndex;
49
  Ndb_cluster_connection_node_iter m_node_iter;
50

51
  NdbObjectIdMap theNdbObjectIdMap;
52

53 54 55 56 57
  Uint32 theNoOfDBnodes; // The number of DB nodes  
  Uint8 theDBnodes[MAX_NDB_NODES]; // The node number of the DB nodes

 // 1 indicates to release all connections to node 
  Uint32 the_release_ind[MAX_NDB_NODES];
58 59 60 61

  NdbWaiter             theWaiter;

  int m_optimized_node_selection;
unknown's avatar
unknown committed
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


  BaseString m_dbname; // Database name
  BaseString m_schemaname; // Schema name

  BaseString m_prefix; // Buffer for preformatted internal name <db>/<schema>/
  BaseString m_internalname;

  void update_prefix()
  {
    m_prefix.assfmt("%s%c%s%c", m_dbname.c_str(), table_name_separator,
                    m_schemaname.c_str(), table_name_separator);
  }

  const char* internalize_table_name(const char* ext_name)
  {
    // Internal table name format <db>/<schema>/<table>
    return m_internalname.assign(m_prefix).append(ext_name).c_str();
  }

  const char* internalize_index_name(const NdbTableImpl *table,
                                     const char* ext_name)
  {
    // Internal index name format <db>/<schema>/<tabid>/<table>
    return m_internalname.assign(m_prefix).appfmt("%d%c%s",
                                                  table->m_tableId,
                                                  table_name_separator,
                                                  ext_name).c_str();
  }


93
};
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112

#ifdef VM_TRACE
#define TRACE_DEBUG(x) ndbout << x << endl;
#else
#define TRACE_DEBUG(x)
#endif

#define CHECK_STATUS_MACRO \
   {if (checkInitState() == -1) { theError.code = 4100; return -1;}}
#define CHECK_STATUS_MACRO_VOID \
   {if (checkInitState() == -1) { theError.code = 4100; return;}}
#define CHECK_STATUS_MACRO_ZERO \
   {if (checkInitState() == -1) { theError.code = 4100; return 0;}}
#define CHECK_STATUS_MACRO_NULL \
   {if (checkInitState() == -1) { theError.code = 4100; return NULL;}}

inline
void *
Ndb::int2void(Uint32 val){
113
  return theImpl->theNdbObjectIdMap.getObject(val);
114 115 116 117 118 119 120 121 122
}

inline
NdbReceiver *
Ndb::void2rec(void* val){
  return (NdbReceiver*)val;
}

inline
unknown's avatar
merge  
unknown committed
123
NdbTransaction *
124
Ndb::void2con(void* val){
unknown's avatar
merge  
unknown committed
125
  return (NdbTransaction*)val;
126 127 128 129 130 131 132 133 134 135 136 137 138 139
}

inline
NdbOperation*
Ndb::void2rec_op(void* val){
  return (NdbOperation*)(void2rec(val)->getOwner());
}

inline
NdbIndexOperation*
Ndb::void2rec_iop(void* val){
  return (NdbIndexOperation*)(void2rec(val)->getOwner());
}

unknown's avatar
unknown committed
140
inline 
unknown's avatar
merge  
unknown committed
141
NdbTransaction * 
unknown's avatar
unknown committed
142 143
NdbReceiver::getTransaction(){ 
  return ((NdbOperation*)m_owner)->theNdbCon;
144 145
}

unknown's avatar
unknown committed
146

147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
inline
int
Ndb::checkInitState()
{
  theError.code = 0;

  if (theInitState != Initialised)
    return -1;
  return 0;
}

Uint32 convertEndian(Uint32 Data);

enum LockMode { 
  Read, 
  Update,
  Insert,
  Delete 
};

#endif