18 #ifndef NdbDictionaryImpl_H
19 #define NdbDictionaryImpl_H
21 #include <ndb_types.h>
22 #include <kernel_types.h>
23 #include <NdbError.hpp>
24 #include <BaseString.hpp>
26 #include <UtilBuffer.hpp>
27 #include <SimpleProperties.hpp>
28 #include <NdbSqlUtil.hpp>
29 #include <NdbDictionary.hpp>
30 #include <Bitmask.hpp>
31 #include <AttributeList.hpp>
33 #include "DictCache.hpp"
34 #include <signaldata/DictSignal.hpp>
39 is_ndb_blob_table(
const char*
name, Uint32* ptab_id = 0, Uint32* pcol_no = 0);
43 extern int ndb_dictionary_is_mysqld;
44 #define ASSERT_NOT_MYSQLD assert(ndb_dictionary_is_mysqld == 0)
93 bool m_distributionKey;
96 Uint64 m_autoIncrementInitialValue;
113 Uint32 m_storageType;
126 bool getInterpretableType()
const ;
127 bool getCharType()
const;
128 bool getStringType()
const;
129 bool getBlobType()
const;
132 int getBlobVersion()
const;
133 void setBlobVersion(
int blobVersion);
144 static void create_pseudo_columns();
145 static void destory_pseudo_columns();
149 bool get_var_length(
const void* value, Uint32& len)
const;
163 int setFrm(
const void* data, Uint32 len);
165 Uint32 getFrmLength()
const;
169 Uint32 getFragmentDataLen()
const;
173 Uint32 getRangeListDataLen()
const;
176 Uint32* nodeIdArrayPtr,
177 Uint32 arraySize)
const;
179 const char * getMysqlName()
const;
180 int updateMysqlName();
182 bool matchDb(
const char * name,
size_t len)
const;
187 Uint32 m_primaryTableId;
196 int getDbName(
char *
buf,
size_t len)
const;
197 int getSchemaName(
char * buf,
size_t len)
const;
198 void setDbSchema(
const char * db,
const char * schema);
203 Uint32 m_columnHashMask;
212 Uint32 m_noOfAutoIncColumns;
213 void computeAggregates();
214 int buildColumnHash();
220 Uint32 m_hashpointerValue;
226 Uint32 m_default_no_part_flag;
232 bool m_force_var_part;
233 bool m_has_default_values;
237 Uint16 m_keyLenInWords;
238 Uint16 m_fragmentCount;
239 Uint8 m_single_user_mode;
241 Uint8 m_extra_row_gci_bits;
242 Uint8 m_extra_row_author_bits;
261 Uint8 m_noOfDistributionKeys;
263 Uint8 m_noOfDiskColumns;
264 Uint8 m_replicaCount;
291 Uint32
get_nodes(Uint32 partitionId,
const Uint16** nodes)
const ;
297 Uint32 m_tablespace_id;
298 Uint32 m_tablespace_version;
300 Uint32 m_hash_map_id;
301 Uint32 m_hash_map_version;
321 Uint32 m_table_version;
342 enum State { CREATED, INITIALIZED, FINISHED, ABORTED, CLOSED };
348 struct fifo_element_st {
349 fifo_element_st(
const NdbTableImpl *tab, fifo_element_st *prev)
358 fifo_element_st * previous;
359 fifo_element_st *
next;
362 fifo_element_st * m_table_queue;
363 fifo_element_st * m_table_queue_first;
364 fifo_element_st * m_table_queue_end;
382 enum State { CREATED, INITIALIZED, FINISHED, ABORTED, CLOSED };
430 ndbout_c(
"NdbEventImpl: id=%d, key=%d",
439 Uint32 m_table_version;
465 Uint32 m_extent_size;
466 Uint32 m_undo_buffer_size;
470 Uint32 m_logfile_group_id;
471 Uint32 m_logfile_group_version;
472 Uint64 m_undo_free_words;
511 Uint32 m_filegroup_id;
512 Uint32 m_filegroup_version;
592 Uint32 transId()
const {
593 return (m_state == Started) ? m_transId : 0;
595 Uint32 transKey()
const {
596 return (m_state == Started) ? m_transKey : 0;
598 Uint32 requestFlags()
const {
606 m_tx(tx), m_error(err), m_warn(warn) {
613 bool setTransporter(
class Ndb * ndb);
619 Uint32 waitsignaltype,
620 int timeout, Uint32 RETRIES,
621 const int *errcodes = 0,
int temporaryMask = 0);
630 Uint32 &change_mask);
644 int doIndexStatReq(
class Ndb& ndb,
647 int doIndexStatReq(
class Ndb& ndb,
648 Uint32 indexId, Uint32 indexVersion, Uint32 tableId,
660 int listObjects(
NdbApiSignal* signal,
bool& listTablesLongSignal);
663 bool fullyQualifiedNames);
665 bool fullyQualifiedNames);
667 NdbTableImpl * getTable(
int tableId,
bool fullyQualifiedNames);
671 Uint32 noOfSections,
bool fullyQualifiedNames);
673 int forceGCPWait(
int type);
674 int getRestartGCI(Uint32 *);
677 const Uint32 * data, Uint32 len,
678 bool fullyQualifiedNames,
679 Uint32 version= 0xFFFFFFFF);
682 const Uint32 * data, Uint32 len);
685 const Uint32 * data, Uint32 len);
688 const Uint32 * data, Uint32 len);
709 int beginSchemaTrans(
bool retry711 =
true);
710 int endSchemaTrans(Uint32
flags);
713 bool checkAllNodeVersionsMin(Uint32 minNdbVersion)
const;
715 const NdbError &getNdbError()
const;
720 Uint32 m_masterNodeId;
727 static void execSignal(
void* dictImpl,
731 static void execNodeStatus(
void* dictImpl, Uint32, Uint32);
804 struct SubStartConfData {
853 const char * tableName);
859 int updateIndexStat(Uint32 indexId, Uint32 indexVersion, Uint32 tableId);
861 int deleteIndexStat(Uint32 indexId, Uint32 indexVersion, Uint32 tableId);
865 int dropEvent(
const char * eventName,
int force);
877 bool fullyQualified);
878 int listIndexes(
List& list, Uint32 indexId);
884 const char * tableName);
888 int releaseTableGlobal(
const NdbTableImpl & impl,
int invalidate);
889 int releaseIndexGlobal(
const NdbIndexImpl & impl,
int invalidate);
891 NdbTableImpl * getTable(
const char * tableName,
void **data= 0);
897 get_local_table_info(
const BaseString& internalTableName);
899 const char * tableName);
919 {
return (m_tx.m_state == NdbDictInterface::Tx::Started); }
925 Uint32 m_local_table_data_size;
933 int initialiseColumnData(
bool isIndex,
965 static NdbDictionary::RecordType
977 Uint32& nullbit_byte_offset,
978 Uint32& nullbit_bit_in_byte);
1027 NdbColumnImpl::getInterpretableType()
const {
1034 NdbColumnImpl::getCharType()
const {
1043 NdbColumnImpl::getStringType()
const {
1054 NdbColumnImpl::getBlobType()
const {
1061 NdbColumnImpl::getBlobVersion()
const {
1062 return m_blobVersion;
1067 NdbColumnImpl::setBlobVersion(
int blobVersion) {
1068 if (blobVersion == NDB_BLOB_V1) {
1069 m_arrayType = NDB_ARRAYTYPE_FIXED;
1070 }
else if (blobVersion == NDB_BLOB_V2) {
1072 m_arrayType = NDB_ARRAYTYPE_MEDIUM_VAR;
1075 m_blobVersion = blobVersion;
1080 NdbColumnImpl::get_var_length(
const void* value, Uint32& len)
const
1082 DBUG_ENTER(
"NdbColumnImpl::get_var_length");
1083 Uint32 max_len = m_attrSize * m_arraySize;
1084 switch (m_arrayType) {
1085 case NDB_ARRAYTYPE_SHORT_VAR:
1086 len = 1 + *((Uint8*)value);
1087 DBUG_PRINT(
"info", (
"SHORT_VAR: len=%u max_len=%u", len, max_len));
1089 case NDB_ARRAYTYPE_MEDIUM_VAR:
1090 len = 2 + uint2korr((
char*)value);
1091 DBUG_PRINT(
"info", (
"MEDIUM_VAR: len=%u max_len=%u", len, max_len));
1095 DBUG_PRINT(
"info", (
"FIXED: len=%u max_len=%u", len, max_len));
1098 DBUG_RETURN(len <= max_len);
1115 NdbTableImpl::getColumn(
unsigned attrId){
1116 if(m_columns.size() > attrId){
1117 return m_columns[attrId];
1124 NdbTableImpl::getMysqlName()
const
1126 return m_mysqlName.
c_str();
1131 NdbTableImpl::matchDb(
const char *
name,
size_t len)
const
1134 len < m_internalName.
length() &&
1135 memcmp(name, m_internalName.
c_str(), len) == 0;
1140 Hash(
const char* str ){
1142 size_t len = strlen(str);
1144 h = (h << 5) + h + str[0];
1145 h = (h << 5) + h + str[1];
1146 h = (h << 5) + h + str[2];
1147 h = (h << 5) + h + str[3];
1154 h = (h << 5) + h + *str++;
1156 h = (h << 5) + h + *str++;
1158 h = (h << 5) + h + *str++;
1166 NdbTableImpl::getColumn(
const char * name){
1168 Uint32 sz = m_columns.size();
1170 const Uint32 *
hashtable = m_columnHash.getBase();
1172 if(sz > 5 &&
false){
1173 Uint32 hashValue = Hash(name) & 0xFFFE;
1174 Uint32
bucket = hashValue & m_columnHashMask;
1175 bucket = (bucket < sz ? bucket : bucket - sz);
1176 hashtable += bucket;
1177 Uint32 tmp = * hashtable;
1178 if((tmp & 1) == 1 ){
1182 hashtable += (tmp & 0xFFFE) >> 1;
1186 if(hashValue == (tmp & 0xFFFE)){
1188 if(strncmp(name, col->m_name.
c_str(), col->m_name.
length()) == 0){
1196 Uint32 dir = m_columnHash[bucket];
1197 Uint32 pos = bucket + ((dir & 0xFFFE) >> 1);
1198 Uint32 cnt = dir >> 16;
1199 ndbout_c(
"col: %s hv: %x bucket: %d dir: %x pos: %d cnt: %d tmp: %d -> 0",
1200 name, hashValue, bucket, dir, pos, cnt, tmp);
1204 for(Uint32
i = 0;
i<sz;
i++){
1206 if(col != 0 && strcmp(name, col->m_name.
c_str()) == 0)
1215 NdbTableImpl::getColumn(
unsigned attrId)
const {
1216 if(m_columns.size() > attrId){
1217 return m_columns[attrId];
1224 NdbTableImpl::getColumn(
const char * name)
const {
1225 Uint32 sz = m_columns.size();
1227 for(Uint32
i = 0;
i<sz;
i++, cols++){
1229 if(col != 0 && strcmp(name, col->m_name.
c_str()) == 0)
1271 int res= dict->getBlobTables(tab);
1273 res= dict->createDefaultNdbRecord(&tab, NULL);
1281 NdbDictionaryImpl::getTableGlobal(
const char *
table_name)
1283 if (unlikely(strchr(table_name,
'$') != 0)) {
1284 if (is_ndb_blob_table(table_name))
1293 m_error.
code = 4307;
1298 const BaseString internal_tabname(m_ndb.internalize_table_name(table_name));
1299 return fetchGlobalTableImplRef(
InitTable(internal_tabname));
1304 NdbDictionaryImpl::getTable(
const char * table_name,
void **data)
1306 DBUG_ENTER(
"NdbDictionaryImpl::getTable");
1307 DBUG_PRINT(
"enter", (
"table: %s", table_name));
1309 if (unlikely(strchr(table_name,
'$') != 0)) {
1310 Uint32 tab_id, col_no;
1311 if (is_ndb_blob_table(table_name, &tab_id, &col_no)) {
1317 const BaseString internal_tabname(m_ndb.internalize_table_name(table_name));
1319 get_local_table_info(internal_tabname);
1323 *data= info->m_local_data;
1324 DBUG_RETURN(info->m_table_impl);
1329 NdbDictionaryImpl::get_local_table_info(
const BaseString& internalTableName)
1331 DBUG_ENTER(
"NdbDictionaryImpl::get_local_table_info");
1332 DBUG_PRINT(
"enter", (
"table: %s", internalTableName.
c_str()));
1338 fetchGlobalTableImplRef(
InitTable(internalTableName));
1341 info= Ndb_local_table_info::create(tab, m_local_table_data_size);
1344 m_localHash.put(internalTableName.
c_str(), info);
1354 const char *m_index_name;
1358 const char *index_name,
1361 m_index_name(index_name),
1366 DBUG_ENTER(
"InitIndex::init");
1374 idx->m_table = &tab;
1375 if (!idx->m_externalName.
assign(m_index_name) ||
1376 !idx->m_internalName.
assign(m_name))
1381 DBUG_RETURN(dict->createDefaultNdbRecord(&tab, &m_prim));
1389 NdbDictionaryImpl::getIndexGlobal(
const char * index_name,
1392 DBUG_ENTER(
"NdbDictionaryImpl::getIndexGlobal");
1394 internal_indexname(m_ndb.internalize_index_name(&ndbtab, index_name));
1400 fetchGlobalTableImplRef(
InitIndex(internal_indexname,
1401 index_name, ndbtab));
1406 if (idx->m_table_id != (
unsigned)ndbtab.
getObjectId() ||
1409 releaseIndexGlobal(*idx, 1);
1420 old_internal_indexname(m_ndb.old_internalize_index_name(&ndbtab,
1426 fetchGlobalTableImplRef(
InitIndex(old_internal_indexname,
1427 index_name, ndbtab));
1432 if (idx->m_table_id != (
unsigned)ndbtab.
getObjectId() ||
1435 releaseIndexGlobal(*idx, 1);
1450 NdbDictionaryImpl::getIndexGlobal(
const char * indexName,
1451 const char * tableName)
1453 DBUG_ENTER(
"NdbDictionaryImpl::getIndexGlobal");
1457 DBUG_RETURN(getIndexGlobal(indexName, *t));
1461 NdbDictionaryImpl::releaseTableGlobal(
const NdbTableImpl & impl,
int invalidate)
1463 DBUG_ENTER(
"NdbDictionaryImpl::releaseTableGlobal");
1464 DBUG_PRINT(
"enter", (
"internal_name: %s", impl.m_internalName.
c_str()));
1465 m_globalHash->lock();
1466 m_globalHash->release(&impl, invalidate);
1467 m_globalHash->unlock();
1472 NdbDictionaryImpl::releaseIndexGlobal(
const NdbIndexImpl & impl,
int invalidate)
1474 DBUG_ENTER(
"NdbDictionaryImpl::releaseIndexGlobal");
1475 DBUG_PRINT(
"enter", (
"internal_name: %s", impl.m_internalName.
c_str()));
1476 m_globalHash->lock();
1477 m_globalHash->release(impl.m_table, invalidate);
1478 m_globalHash->unlock();
1484 NdbDictionaryImpl::getIndex(
const char * index_name,
1485 const char * table_name)
1487 if (table_name == 0)
1502 return getIndex(index_name, *prim);
1507 NdbDictionaryImpl::getIndex(
const char* index_name,
1512 internal_indexname(m_ndb.internalize_index_name(&prim, index_name));
1518 tab= fetchGlobalTableImplRef(
InitIndex(internal_indexname,
1524 info= Ndb_local_table_info::create(tab, 0);
1527 m_localHash.put(internal_indexname.c_str(), info);
1530 tab= info->m_table_impl;
1532 return tab->m_index;
1537 old_internal_indexname(m_ndb.old_internalize_index_name(&prim, index_name));
1539 info= m_localHash.get(old_internal_indexname.c_str());
1542 tab= fetchGlobalTableImplRef(
InitIndex(old_internal_indexname,
1548 info= Ndb_local_table_info::create(tab, 0);
1551 m_localHash.put(old_internal_indexname.c_str(), info);
1554 tab= info->m_table_impl;
1556 return tab->m_index;