Commit b96c4289 authored by unknown's avatar unknown

removing the usage if the ndb local dict cache to adress the 241 errors we get now and then

parent a8138ec7
...@@ -62,4 +62,6 @@ t4 ...@@ -62,4 +62,6 @@ t4
drop table t1, t2, t3, t4; drop table t1, t2, t3, t4;
drop table if exists t1, t3, t4; drop table if exists t1, t3, t4;
Warnings: Warnings:
Error 155 Table 'test.t1' doesn't exist
Error 155 Table 'test.t3' doesn't exist Error 155 Table 'test.t3' doesn't exist
Error 155 Table 'test.t4' doesn't exist
This diff is collapsed.
...@@ -70,8 +70,8 @@ typedef enum ndb_index_status { ...@@ -70,8 +70,8 @@ typedef enum ndb_index_status {
typedef struct ndb_index_data { typedef struct ndb_index_data {
NDB_INDEX_TYPE type; NDB_INDEX_TYPE type;
NDB_INDEX_STATUS status; NDB_INDEX_STATUS status;
void *index; const NdbDictionary::Index *index;
void *unique_index; const NdbDictionary::Index *unique_index;
unsigned char *unique_index_attrid_map; unsigned char *unique_index_attrid_map;
// In this version stats are not shared between threads // In this version stats are not shared between threads
NdbIndexStat* index_stat; NdbIndexStat* index_stat;
...@@ -560,6 +560,7 @@ class ha_ndbcluster: public handler ...@@ -560,6 +560,7 @@ class ha_ndbcluster: public handler
ha_ndbcluster(TABLE_SHARE *table); ha_ndbcluster(TABLE_SHARE *table);
~ha_ndbcluster(); ~ha_ndbcluster();
int ha_initialise();
int open(const char *name, int mode, uint test_if_locked); int open(const char *name, int mode, uint test_if_locked);
int close(void); int close(void);
...@@ -708,19 +709,15 @@ static void set_tabname(const char *pathname, char *tabname); ...@@ -708,19 +709,15 @@ static void set_tabname(const char *pathname, char *tabname);
Ndb *ndb, NdbEventOperation *pOp, Ndb *ndb, NdbEventOperation *pOp,
NDB_SHARE *share); NDB_SHARE *share);
int alter_table_name(const char *to);
static int delete_table(ha_ndbcluster *h, Ndb *ndb, static int delete_table(ha_ndbcluster *h, Ndb *ndb,
const char *path, const char *path,
const char *db, const char *db,
const char *table_name); const char *table_name);
int drop_ndb_table();
int create_ndb_index(const char *name, KEY *key_info, bool unique); int create_ndb_index(const char *name, KEY *key_info, bool unique);
int create_ordered_index(const char *name, KEY *key_info); int create_ordered_index(const char *name, KEY *key_info);
int create_unique_index(const char *name, KEY *key_info); int create_unique_index(const char *name, KEY *key_info);
int create_index(const char *name, KEY *key_info, int create_index(const char *name, KEY *key_info,
NDB_INDEX_TYPE idx_type, uint idx_no); NDB_INDEX_TYPE idx_type, uint idx_no);
int drop_ndb_index(const char *name);
int table_changed(const void *pack_frm_data, uint pack_frm_len);
// Index list management // Index list management
int create_indexes(Ndb *ndb, TABLE *tab); int create_indexes(Ndb *ndb, TABLE *tab);
void clear_index(int i); void clear_index(int i);
...@@ -732,7 +729,7 @@ static void set_tabname(const char *pathname, char *tabname); ...@@ -732,7 +729,7 @@ static void set_tabname(const char *pathname, char *tabname);
KEY *key_info, const char *index_name, uint index_no); KEY *key_info, const char *index_name, uint index_no);
int initialize_autoincrement(const void *table); int initialize_autoincrement(const void *table);
int get_metadata(const char* path); int get_metadata(const char* path);
void release_metadata(); void release_metadata(THD *thd, Ndb *ndb);
NDB_INDEX_TYPE get_index_type(uint idx_no) const; NDB_INDEX_TYPE get_index_type(uint idx_no) const;
NDB_INDEX_TYPE get_index_type_from_table(uint index_no) const; NDB_INDEX_TYPE get_index_type_from_table(uint index_no) const;
NDB_INDEX_TYPE get_index_type_from_key(uint index_no, KEY *key_info, NDB_INDEX_TYPE get_index_type_from_key(uint index_no, KEY *key_info,
...@@ -795,8 +792,6 @@ static void set_tabname(const char *pathname, char *tabname); ...@@ -795,8 +792,6 @@ static void set_tabname(const char *pathname, char *tabname);
void print_results(); void print_results();
ulonglong get_auto_increment(); ulonglong get_auto_increment();
int invalidate_dictionary_cache(bool global,
const NdbDictionary::Table *ndbtab);
int ndb_err(NdbTransaction*); int ndb_err(NdbTransaction*);
bool uses_blob_value(); bool uses_blob_value();
...@@ -834,7 +829,6 @@ static void set_tabname(const char *pathname, char *tabname); ...@@ -834,7 +829,6 @@ static void set_tabname(const char *pathname, char *tabname);
NdbTransaction *m_active_trans; NdbTransaction *m_active_trans;
NdbScanOperation *m_active_cursor; NdbScanOperation *m_active_cursor;
const NdbDictionary::Table *m_table; const NdbDictionary::Table *m_table;
int m_table_version;
struct Ndb_local_table_statistics *m_table_info; struct Ndb_local_table_statistics *m_table_info;
char m_dbname[FN_HEADLEN]; char m_dbname[FN_HEADLEN];
//char m_schemaname[FN_HEADLEN]; //char m_schemaname[FN_HEADLEN];
......
This diff is collapsed.
...@@ -41,14 +41,15 @@ enum SCHEMA_OP_TYPE ...@@ -41,14 +41,15 @@ enum SCHEMA_OP_TYPE
{ {
SOT_DROP_TABLE= 0, SOT_DROP_TABLE= 0,
SOT_CREATE_TABLE= 1, SOT_CREATE_TABLE= 1,
SOT_RENAME_TABLE= 2, SOT_RENAME_TABLE_NEW= 2,
SOT_ALTER_TABLE= 3, SOT_ALTER_TABLE= 3,
SOT_DROP_DB= 4, SOT_DROP_DB= 4,
SOT_CREATE_DB= 5, SOT_CREATE_DB= 5,
SOT_ALTER_DB= 6, SOT_ALTER_DB= 6,
SOT_CLEAR_SLOCK= 7, SOT_CLEAR_SLOCK= 7,
SOT_TABLESPACE= 8, SOT_TABLESPACE= 8,
SOT_LOGFILE_GROUP= 9 SOT_LOGFILE_GROUP= 9,
SOT_RENAME_TABLE= 10
}; };
const uint max_ndb_nodes= 64; /* multiple of 32 */ const uint max_ndb_nodes= 64; /* multiple of 32 */
...@@ -56,6 +57,45 @@ const uint max_ndb_nodes= 64; /* multiple of 32 */ ...@@ -56,6 +57,45 @@ const uint max_ndb_nodes= 64; /* multiple of 32 */
static const char *ha_ndb_ext=".ndb"; static const char *ha_ndb_ext=".ndb";
static const char share_prefix[]= "./"; static const char share_prefix[]= "./";
class Ndb_table_guard
{
public:
Ndb_table_guard(NDBDICT *dict, const char *tabname)
: m_dict(dict)
{
DBUG_ENTER("Ndb_table_guard");
m_ndbtab= m_dict->getTableGlobal(tabname);
m_invalidate= 0;
DBUG_PRINT("info", ("m_ndbtab: %p", m_ndbtab));
DBUG_VOID_RETURN;
}
~Ndb_table_guard()
{
DBUG_ENTER("~Ndb_table_guard");
if (m_ndbtab)
{
DBUG_PRINT("info", ("m_ndbtab: %p m_invalidate: %d",
m_ndbtab, m_invalidate));
m_dict->removeTableGlobal(*m_ndbtab, m_invalidate);
}
DBUG_VOID_RETURN;
}
const NDBTAB *get_table() { return m_ndbtab; }
void invalidate() { m_invalidate= 1; }
const NDBTAB *release()
{
DBUG_ENTER("Ndb_table_guard::release");
const NDBTAB *tmp= m_ndbtab;
DBUG_PRINT("info", ("m_ndbtab: %p", m_ndbtab));
m_ndbtab = 0;
DBUG_RETURN(tmp);
}
private:
const NDBTAB *m_ndbtab;
NDBDICT *m_dict;
int m_invalidate;
};
#ifdef HAVE_NDB_BINLOG #ifdef HAVE_NDB_BINLOG
extern pthread_t ndb_binlog_thread; extern pthread_t ndb_binlog_thread;
extern pthread_mutex_t injector_mutex; extern pthread_mutex_t injector_mutex;
...@@ -98,8 +138,8 @@ int ndbcluster_log_schema_op(THD *thd, NDB_SHARE *share, ...@@ -98,8 +138,8 @@ int ndbcluster_log_schema_op(THD *thd, NDB_SHARE *share,
uint32 ndb_table_id, uint32 ndb_table_id,
uint32 ndb_table_version, uint32 ndb_table_version,
enum SCHEMA_OP_TYPE type, enum SCHEMA_OP_TYPE type,
const char *old_db= 0, const char *new_db= 0,
const char *old_table_name= 0); const char *new_table_name= 0);
int ndbcluster_handle_drop_table(Ndb *ndb, const char *event_name, int ndbcluster_handle_drop_table(Ndb *ndb, const char *event_name,
NDB_SHARE *share, NDB_SHARE *share,
const char *type_str); const char *type_str);
......
...@@ -1470,6 +1470,8 @@ public: ...@@ -1470,6 +1470,8 @@ public:
* *
* @return tuple id or 0 on error * @return tuple id or 0 on error
*/ */
int initAutoIncrement();
Uint64 getAutoIncrementValue(const char* aTableName, Uint64 getAutoIncrementValue(const char* aTableName,
Uint32 cacheSize = 1); Uint32 cacheSize = 1);
Uint64 getAutoIncrementValue(const NdbDictionary::Table * aTable, Uint64 getAutoIncrementValue(const NdbDictionary::Table * aTable,
...@@ -1694,6 +1696,7 @@ private: ...@@ -1694,6 +1696,7 @@ private:
// The tupleId is retreived from DB the // The tupleId is retreived from DB the
// tupleId is unique for each tableid. // tupleId is unique for each tableid.
const NdbDictionary::Table *m_sys_tab_0;
Uint64 theFirstTupleId[2048]; Uint64 theFirstTupleId[2048];
Uint64 theLastTupleId[2048]; Uint64 theLastTupleId[2048];
......
...@@ -798,6 +798,7 @@ public: ...@@ -798,6 +798,7 @@ public:
* Get object status * Get object status
*/ */
virtual Object::Status getObjectStatus() const; virtual Object::Status getObjectStatus() const;
void setStatusInvalid() const;
/** /**
* Get object version * Get object version
...@@ -1734,6 +1735,7 @@ public: ...@@ -1734,6 +1735,7 @@ public:
* @return 0 if successful otherwise -1. * @return 0 if successful otherwise -1.
*/ */
int createIndex(const Index &index); int createIndex(const Index &index);
int createIndex(const Index &index, const Table &table);
/** /**
* Drop index with given name * Drop index with given name
...@@ -1805,6 +1807,15 @@ public: ...@@ -1805,6 +1807,15 @@ public:
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
const Table * getTable(const char * name, void **data) const; const Table * getTable(const char * name, void **data) const;
void set_local_table_data_size(unsigned sz); void set_local_table_data_size(unsigned sz);
const Index * getIndexGlobal(const char * indexName,
const Table &ndbtab) const;
const Table * getTableGlobal(const char * tableName) const;
int alterTableGlobal(const Table &f, const Table &t);
int dropTableGlobal(const Table &ndbtab);
int dropIndexGlobal(const Index &index);
int removeIndexGlobal(const Index &ndbidx, int invalidate) const;
int removeTableGlobal(const Table &ndbtab, int invalidate) const;
#endif #endif
}; };
}; };
......
...@@ -56,7 +56,7 @@ public: ...@@ -56,7 +56,7 @@ public:
* multiplied by a percentage obtained from the cache (result zero is * multiplied by a percentage obtained from the cache (result zero is
* returned as 1). * returned as 1).
*/ */
int records_in_range(NdbDictionary::Index* index, int records_in_range(const NdbDictionary::Index* index,
NdbIndexScanOperation* op, NdbIndexScanOperation* op,
Uint64 table_rows, Uint64 table_rows,
Uint64* count, Uint64* count,
......
...@@ -63,6 +63,7 @@ LocalDictCache::~LocalDictCache(){ ...@@ -63,6 +63,7 @@ LocalDictCache::~LocalDictCache(){
Ndb_local_table_info * Ndb_local_table_info *
LocalDictCache::get(const char * name){ LocalDictCache::get(const char * name){
ASSERT_NOT_MYSQLD;
assert(! is_ndb_blob_table(name)); assert(! is_ndb_blob_table(name));
const Uint32 len = strlen(name); const Uint32 len = strlen(name);
return m_tableHash.getData(name, len); return m_tableHash.getData(name, len);
...@@ -70,6 +71,7 @@ LocalDictCache::get(const char * name){ ...@@ -70,6 +71,7 @@ LocalDictCache::get(const char * name){
void void
LocalDictCache::put(const char * name, Ndb_local_table_info * tab_info){ LocalDictCache::put(const char * name, Ndb_local_table_info * tab_info){
ASSERT_NOT_MYSQLD;
assert(! is_ndb_blob_table(name)); assert(! is_ndb_blob_table(name));
const Uint32 id = tab_info->m_table_impl->m_id; const Uint32 id = tab_info->m_table_impl->m_id;
m_tableHash.insertKey(name, strlen(name), id, tab_info); m_tableHash.insertKey(name, strlen(name), id, tab_info);
...@@ -77,6 +79,7 @@ LocalDictCache::put(const char * name, Ndb_local_table_info * tab_info){ ...@@ -77,6 +79,7 @@ LocalDictCache::put(const char * name, Ndb_local_table_info * tab_info){
void void
LocalDictCache::drop(const char * name){ LocalDictCache::drop(const char * name){
ASSERT_NOT_MYSQLD;
assert(! is_ndb_blob_table(name)); assert(! is_ndb_blob_table(name));
Ndb_local_table_info *info= m_tableHash.deleteKey(name, strlen(name)); Ndb_local_table_info *info= m_tableHash.deleteKey(name, strlen(name));
DBUG_ASSERT(info != 0); DBUG_ASSERT(info != 0);
...@@ -100,8 +103,15 @@ GlobalDictCache::~GlobalDictCache(){ ...@@ -100,8 +103,15 @@ GlobalDictCache::~GlobalDictCache(){
Vector<TableVersion> * vers = curr->theData; Vector<TableVersion> * vers = curr->theData;
const unsigned sz = vers->size(); const unsigned sz = vers->size();
for(unsigned i = 0; i<sz ; i++){ for(unsigned i = 0; i<sz ; i++){
if((* vers)[i].m_impl != 0) TableVersion tv= (*vers)[i];
DBUG_PRINT(" ", ("vers[%d]: ver: %d, refCount: %d, status: %d",
i, tv.m_version, tv.m_refCount, tv.m_status));
if(tv.m_impl != 0)
{
DBUG_PRINT(" ", ("m_impl: internalname: %s",
tv.m_impl->m_internalName.c_str()));
delete (* vers)[i].m_impl; delete (* vers)[i].m_impl;
}
} }
delete curr->theData; delete curr->theData;
curr->theData= NULL; curr->theData= NULL;
...@@ -164,11 +174,18 @@ GlobalDictCache::get(const char * name) ...@@ -164,11 +174,18 @@ GlobalDictCache::get(const char * name)
TableVersion * ver = & versions->back(); TableVersion * ver = & versions->back();
switch(ver->m_status){ switch(ver->m_status){
case OK: case OK:
if (ver->m_impl->m_status == NdbDictionary::Object::Invalid)
{
ver->m_status = DROPPED;
retreive = true; // Break loop
break;
}
ver->m_refCount++; ver->m_refCount++;
DBUG_PRINT("info", ("Table OK version=%x.%x refCount=%u", DBUG_PRINT("info", ("Table OK tab: %p version=%x.%x refCount=%u",
ver->m_impl->m_version & 0xFFFFFF, ver->m_impl,
ver->m_impl->m_version >> 24, ver->m_impl->m_version & 0xFFFFFF,
ver->m_refCount)); ver->m_impl->m_version >> 24,
ver->m_refCount));
DBUG_RETURN(ver->m_impl); DBUG_RETURN(ver->m_impl);
case DROPPED: case DROPPED:
retreive = true; // Break loop retreive = true; // Break loop
...@@ -197,8 +214,8 @@ NdbTableImpl * ...@@ -197,8 +214,8 @@ NdbTableImpl *
GlobalDictCache::put(const char * name, NdbTableImpl * tab) GlobalDictCache::put(const char * name, NdbTableImpl * tab)
{ {
DBUG_ENTER("GlobalDictCache::put"); DBUG_ENTER("GlobalDictCache::put");
DBUG_PRINT("enter", ("name: %s, internal_name: %s version: %x.%x", DBUG_PRINT("enter", ("tab: %p name: %s, internal_name: %s version: %x.%x",
name, tab, name,
tab ? tab->m_internalName.c_str() : "tab NULL", tab ? tab->m_internalName.c_str() : "tab NULL",
tab ? tab->m_version & 0xFFFFFF : 0, tab ? tab->m_version & 0xFFFFFF : 0,
tab ? tab->m_version >> 24 : 0)); tab ? tab->m_version >> 24 : 0));
...@@ -264,66 +281,11 @@ GlobalDictCache::put(const char * name, NdbTableImpl * tab) ...@@ -264,66 +281,11 @@ GlobalDictCache::put(const char * name, NdbTableImpl * tab)
} }
void void
GlobalDictCache::drop(NdbTableImpl * tab) GlobalDictCache::release(NdbTableImpl * tab, int invalidate)
{
DBUG_ENTER("GlobalDictCache::drop");
DBUG_PRINT("enter", ("internal_name: %s", tab->m_internalName.c_str()));
assert(! is_ndb_blob_table(tab));
unsigned i;
const Uint32 len = strlen(tab->m_internalName.c_str());
Vector<TableVersion> * vers =
m_tableHash.getData(tab->m_internalName.c_str(), len);
if(vers == 0){
// Should always tried to retreive it first
// and thus there should be a record
abort();
}
const Uint32 sz = vers->size();
if(sz == 0){
// Should always tried to retreive it first
// and thus there should be a record
abort();
}
for(i = 0; i < sz; i++){
TableVersion & ver = (* vers)[i];
if(ver.m_impl == tab){
if(ver.m_refCount == 0 || ver.m_status == RETREIVING ||
ver.m_version != tab->m_version){
DBUG_PRINT("info", ("Dropping with refCount=%d status=%d impl=%p",
ver.m_refCount, ver.m_status, ver.m_impl));
break;
}
DBUG_PRINT("info", ("Found table to drop, i: %d, name: %s",
i, ver.m_impl->m_internalName.c_str()));
ver.m_refCount--;
ver.m_status = DROPPED;
if(ver.m_refCount == 0){
DBUG_PRINT("info", ("refCount is zero, deleting m_impl"));
delete ver.m_impl;
vers->erase(i);
}
DBUG_VOID_RETURN;
}
}
for(i = 0; i<sz; i++){
TableVersion & ver = (* vers)[i];
ndbout_c("%d: version: %d refCount: %d status: %d impl: %p",
i, ver.m_version, ver.m_refCount,
ver.m_status, ver.m_impl);
}
abort();
}
void
GlobalDictCache::release(NdbTableImpl * tab)
{ {
DBUG_ENTER("GlobalDictCache::release"); DBUG_ENTER("GlobalDictCache::release");
DBUG_PRINT("enter", ("internal_name: %s", tab->m_internalName.c_str())); DBUG_PRINT("enter", ("tab: %p internal_name: %s",
tab, tab->m_internalName.c_str()));
assert(! is_ndb_blob_table(tab)); assert(! is_ndb_blob_table(tab));
unsigned i; unsigned i;
...@@ -354,6 +316,17 @@ GlobalDictCache::release(NdbTableImpl * tab) ...@@ -354,6 +316,17 @@ GlobalDictCache::release(NdbTableImpl * tab)
} }
ver.m_refCount--; ver.m_refCount--;
if (ver.m_impl->m_status == NdbDictionary::Object::Invalid || invalidate)
{
ver.m_impl->m_status = NdbDictionary::Object::Invalid;
ver.m_status = DROPPED;
}
if (ver.m_refCount == 0 && ver.m_status == DROPPED)
{
DBUG_PRINT("info", ("refCount is zero, deleting m_impl"));
delete ver.m_impl;
vers->erase(i);
}
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
} }
...@@ -374,6 +347,7 @@ GlobalDictCache::alter_table_rep(const char * name, ...@@ -374,6 +347,7 @@ GlobalDictCache::alter_table_rep(const char * name,
Uint32 tableVersion, Uint32 tableVersion,
bool altered) bool altered)
{ {
DBUG_ENTER("GlobalDictCache::alter_table_rep");
assert(! is_ndb_blob_table(name)); assert(! is_ndb_blob_table(name));
const Uint32 len = strlen(name); const Uint32 len = strlen(name);
Vector<TableVersion> * vers = Vector<TableVersion> * vers =
...@@ -381,13 +355,13 @@ GlobalDictCache::alter_table_rep(const char * name, ...@@ -381,13 +355,13 @@ GlobalDictCache::alter_table_rep(const char * name,
if(vers == 0) if(vers == 0)
{ {
return; DBUG_VOID_RETURN;
} }
const Uint32 sz = vers->size(); const Uint32 sz = vers->size();
if(sz == 0) if(sz == 0)
{ {
return; DBUG_VOID_RETURN;
} }
for(Uint32 i = 0; i < sz; i++) for(Uint32 i = 0; i < sz; i++)
...@@ -399,15 +373,16 @@ GlobalDictCache::alter_table_rep(const char * name, ...@@ -399,15 +373,16 @@ GlobalDictCache::alter_table_rep(const char * name,
ver.m_status = DROPPED; ver.m_status = DROPPED;
ver.m_impl->m_status = altered ? ver.m_impl->m_status = altered ?
NdbDictionary::Object::Altered : NdbDictionary::Object::Invalid; NdbDictionary::Object::Altered : NdbDictionary::Object::Invalid;
return; DBUG_VOID_RETURN;
} }
if(i == sz - 1 && ver.m_status == RETREIVING) if(i == sz - 1 && ver.m_status == RETREIVING)
{ {
ver.m_impl = altered ? &f_altered_table : &f_invalid_table; ver.m_impl = altered ? &f_altered_table : &f_invalid_table;
return; DBUG_VOID_RETURN;
} }
} }
DBUG_VOID_RETURN;
} }
template class Vector<GlobalDictCache::TableVersion>; template class Vector<GlobalDictCache::TableVersion>;
...@@ -63,11 +63,11 @@ public: ...@@ -63,11 +63,11 @@ public:
GlobalDictCache(); GlobalDictCache();
~GlobalDictCache(); ~GlobalDictCache();
NdbTableImpl * get(NdbTableImpl *tab);
NdbTableImpl * get(const char * name); NdbTableImpl * get(const char * name);
NdbTableImpl* put(const char * name, NdbTableImpl *); NdbTableImpl* put(const char * name, NdbTableImpl *);
void drop(NdbTableImpl *); void release(NdbTableImpl *, int invalidate = 0);
void release(NdbTableImpl *);
void alter_table_rep(const char * name, void alter_table_rep(const char * name,
Uint32 tableId, Uint32 tableVersion, bool altered); Uint32 tableId, Uint32 tableVersion, bool altered);
......
...@@ -901,6 +901,27 @@ Ndb::setTupleIdInNdb(Uint32 aTableId, Uint64 val, bool increase ) ...@@ -901,6 +901,27 @@ Ndb::setTupleIdInNdb(Uint32 aTableId, Uint64 val, bool increase )
DBUG_RETURN((opTupleIdOnNdb(aTableId, val, 1) == val)); DBUG_RETURN((opTupleIdOnNdb(aTableId, val, 1) == val));
} }
int Ndb::initAutoIncrement()
{
if (m_sys_tab_0)
return 0;
BaseString currentDb(getDatabaseName());
BaseString currentSchema(getDatabaseSchemaName());
setDatabaseName("sys");
setDatabaseSchemaName("def");
m_sys_tab_0 = getDictionary()->getTableGlobal("SYSTAB_0");
// Restore current name space
setDatabaseName(currentDb.c_str());
setDatabaseSchemaName(currentSchema.c_str());
return (m_sys_tab_0 == NULL);
}
Uint64 Uint64
Ndb::opTupleIdOnNdb(Uint32 aTableId, Uint64 opValue, Uint32 op) Ndb::opTupleIdOnNdb(Uint32 aTableId, Uint64 opValue, Uint32 op)
{ {
...@@ -916,19 +937,14 @@ Ndb::opTupleIdOnNdb(Uint32 aTableId, Uint64 opValue, Uint32 op) ...@@ -916,19 +937,14 @@ Ndb::opTupleIdOnNdb(Uint32 aTableId, Uint64 opValue, Uint32 op)
CHECK_STATUS_MACRO_ZERO; CHECK_STATUS_MACRO_ZERO;
BaseString currentDb(getDatabaseName()); if (initAutoIncrement())
BaseString currentSchema(getDatabaseSchemaName()); goto error_return;
setDatabaseName("sys");
setDatabaseSchemaName("def");
tConnection = this->startTransaction(); tConnection = this->startTransaction();
if (tConnection == NULL) if (tConnection == NULL)
goto error_return; goto error_return;
if (usingFullyQualifiedNames()) tOperation = tConnection->getNdbOperation(m_sys_tab_0);
tOperation = tConnection->getNdbOperation("SYSTAB_0");
else
tOperation = tConnection->getNdbOperation("sys/def/SYSTAB_0");
if (tOperation == NULL) if (tOperation == NULL)
goto error_handler; goto error_handler;
...@@ -997,20 +1013,12 @@ Ndb::opTupleIdOnNdb(Uint32 aTableId, Uint64 opValue, Uint32 op) ...@@ -997,20 +1013,12 @@ Ndb::opTupleIdOnNdb(Uint32 aTableId, Uint64 opValue, Uint32 op)
this->closeTransaction(tConnection); this->closeTransaction(tConnection);
// Restore current name space
setDatabaseName(currentDb.c_str());
setDatabaseSchemaName(currentSchema.c_str());
DBUG_RETURN(ret); DBUG_RETURN(ret);
error_handler: error_handler:
theError.code = tConnection->theError.code; theError.code = tConnection->theError.code;
this->closeTransaction(tConnection); this->closeTransaction(tConnection);
error_return: error_return:
// Restore current name space
setDatabaseName(currentDb.c_str());
setDatabaseSchemaName(currentSchema.c_str());
DBUG_PRINT("error", ("ndb=%d con=%d op=%d", DBUG_PRINT("error", ("ndb=%d con=%d op=%d",
theError.code, theError.code,
tConnection ? tConnection->theError.code : -1, tConnection ? tConnection->theError.code : -1,
......
...@@ -559,6 +559,11 @@ NdbDictionary::Table::getObjectStatus() const { ...@@ -559,6 +559,11 @@ NdbDictionary::Table::getObjectStatus() const {
return m_impl.m_status; return m_impl.m_status;
} }
void
NdbDictionary::Table::setStatusInvalid() const {
m_impl.m_status = NdbDictionary::Object::Invalid;
}
int int
NdbDictionary::Table::getObjectVersion() const { NdbDictionary::Table::getObjectVersion() const {
return m_impl.m_version; return m_impl.m_version;
...@@ -1330,6 +1335,11 @@ NdbDictionary::Dictionary::dropTable(Table & t){ ...@@ -1330,6 +1335,11 @@ NdbDictionary::Dictionary::dropTable(Table & t){
return m_impl.dropTable(NdbTableImpl::getImpl(t)); return m_impl.dropTable(NdbTableImpl::getImpl(t));
} }
int
NdbDictionary::Dictionary::dropTableGlobal(const Table & t){
return m_impl.dropTableGlobal(NdbTableImpl::getImpl(t));
}
int int
NdbDictionary::Dictionary::dropTable(const char * name){ NdbDictionary::Dictionary::dropTable(const char * name){
return m_impl.dropTable(name); return m_impl.dropTable(name);
...@@ -1340,6 +1350,14 @@ NdbDictionary::Dictionary::alterTable(const Table & t){ ...@@ -1340,6 +1350,14 @@ NdbDictionary::Dictionary::alterTable(const Table & t){
return m_impl.alterTable(NdbTableImpl::getImpl(t)); return m_impl.alterTable(NdbTableImpl::getImpl(t));
} }
int
NdbDictionary::Dictionary::alterTableGlobal(const Table & f,
const Table & t)
{
return m_impl.alterTableGlobal(NdbTableImpl::getImpl(f),
NdbTableImpl::getImpl(t));
}
const NdbDictionary::Table * const NdbDictionary::Table *
NdbDictionary::Dictionary::getTable(const char * name, void **data) const NdbDictionary::Dictionary::getTable(const char * name, void **data) const
{ {
...@@ -1349,6 +1367,40 @@ NdbDictionary::Dictionary::getTable(const char * name, void **data) const ...@@ -1349,6 +1367,40 @@ NdbDictionary::Dictionary::getTable(const char * name, void **data) const
return 0; return 0;
} }
const NdbDictionary::Index *
NdbDictionary::Dictionary::getIndexGlobal(const char * indexName,
const Table &ndbtab) const
{
NdbIndexImpl * i = m_impl.getIndexGlobal(indexName,
NdbTableImpl::getImpl(ndbtab));
if(i)
return i->m_facade;
return 0;
}
const NdbDictionary::Table *
NdbDictionary::Dictionary::getTableGlobal(const char * name) const
{
NdbTableImpl * t = m_impl.getTableGlobal(name);
if(t)
return t->m_facade;
return 0;
}
int
NdbDictionary::Dictionary::removeIndexGlobal(const Index &ndbidx,
int invalidate) const
{
return m_impl.releaseIndexGlobal(NdbIndexImpl::getImpl(ndbidx), invalidate);
}
int
NdbDictionary::Dictionary::removeTableGlobal(const Table &ndbtab,
int invalidate) const
{
return m_impl.releaseTableGlobal(NdbTableImpl::getImpl(ndbtab), invalidate);
}
void NdbDictionary::Dictionary::putTable(const NdbDictionary::Table * table) void NdbDictionary::Dictionary::putTable(const NdbDictionary::Table * table)
{ {
NdbDictionary::Table *copy_table = new NdbDictionary::Table; NdbDictionary::Table *copy_table = new NdbDictionary::Table;
...@@ -1420,6 +1472,13 @@ NdbDictionary::Dictionary::createIndex(const Index & ind) ...@@ -1420,6 +1472,13 @@ NdbDictionary::Dictionary::createIndex(const Index & ind)
return m_impl.createIndex(NdbIndexImpl::getImpl(ind)); return m_impl.createIndex(NdbIndexImpl::getImpl(ind));
} }
int
NdbDictionary::Dictionary::createIndex(const Index & ind, const Table & tab)
{
return m_impl.createIndex(NdbIndexImpl::getImpl(ind),
NdbTableImpl::getImpl(tab));
}
int int
NdbDictionary::Dictionary::dropIndex(const char * indexName, NdbDictionary::Dictionary::dropIndex(const char * indexName,
const char * tableName) const char * tableName)
...@@ -1427,6 +1486,12 @@ NdbDictionary::Dictionary::dropIndex(const char * indexName, ...@@ -1427,6 +1486,12 @@ NdbDictionary::Dictionary::dropIndex(const char * indexName,
return m_impl.dropIndex(indexName, tableName); return m_impl.dropIndex(indexName, tableName);
} }
int
NdbDictionary::Dictionary::dropIndexGlobal(const Index &ind)
{
return m_impl.dropIndexGlobal(NdbIndexImpl::getImpl(ind));
}
const NdbDictionary::Index * const NdbDictionary::Index *
NdbDictionary::Dictionary::getIndex(const char * indexName, NdbDictionary::Dictionary::getIndex(const char * indexName,
const char * tableName) const const char * tableName) const
......
...@@ -35,6 +35,9 @@ is_ndb_blob_table(const char* name, Uint32* ptab_id = 0, Uint32* pcol_no = 0); ...@@ -35,6 +35,9 @@ is_ndb_blob_table(const char* name, Uint32* ptab_id = 0, Uint32* pcol_no = 0);
bool bool
is_ndb_blob_table(const class NdbTableImpl* t); is_ndb_blob_table(const class NdbTableImpl* t);
extern int ndb_dictionary_is_mysqld;
#define ASSERT_NOT_MYSQLD assert(ndb_dictionary_is_mysqld == 0)
class NdbDictObjectImpl { class NdbDictObjectImpl {
public: public:
int m_id; int m_id;
...@@ -253,6 +256,8 @@ public: ...@@ -253,6 +256,8 @@ public:
BaseString m_internalName; BaseString m_internalName;
BaseString m_externalName; BaseString m_externalName;
BaseString m_tableName; BaseString m_tableName;
Uint32 m_table_id;
Uint32 m_table_version;
Vector<NdbColumnImpl *> m_columns; Vector<NdbColumnImpl *> m_columns;
Vector<int> m_key_ids; Vector<int> m_key_ids;
...@@ -539,6 +544,21 @@ private: ...@@ -539,6 +544,21 @@ private:
UtilBuffer m_buffer; UtilBuffer m_buffer;
}; };
class NdbDictionaryImpl;
class GlobalCacheInitObject
{
public:
NdbDictionaryImpl *m_dict;
const BaseString &m_name;
GlobalCacheInitObject(NdbDictionaryImpl *dict,
const BaseString &name) :
m_dict(dict),
m_name(name)
{}
virtual ~GlobalCacheInitObject() {}
virtual int init(NdbTableImpl &tab) const = 0;
};
class NdbDictionaryImpl : public NdbDictionary::Dictionary { class NdbDictionaryImpl : public NdbDictionary::Dictionary {
public: public:
NdbDictionaryImpl(Ndb &ndb); NdbDictionaryImpl(Ndb &ndb);
...@@ -558,6 +578,7 @@ public: ...@@ -558,6 +578,7 @@ public:
int removeCachedObject(NdbTableImpl &); int removeCachedObject(NdbTableImpl &);
int createIndex(NdbIndexImpl &ix); int createIndex(NdbIndexImpl &ix);
int createIndex(NdbIndexImpl &ix, NdbTableImpl & tab);
int dropIndex(const char * indexName, int dropIndex(const char * indexName,
const char * tableName); const char * tableName);
int dropIndex(NdbIndexImpl &, const char * tableName); int dropIndex(NdbIndexImpl &, const char * tableName);
...@@ -578,6 +599,15 @@ public: ...@@ -578,6 +599,15 @@ public:
int listObjects(List& list, NdbDictionary::Object::Type type); int listObjects(List& list, NdbDictionary::Object::Type type);
int listIndexes(List& list, Uint32 indexId); int listIndexes(List& list, Uint32 indexId);
NdbTableImpl * getTableGlobal(const char * tableName);
NdbIndexImpl * getIndexGlobal(const char * indexName,
NdbTableImpl &ndbtab);
int alterTableGlobal(NdbTableImpl &orig_impl, NdbTableImpl &impl);
int dropTableGlobal(NdbTableImpl &);
int dropIndexGlobal(NdbIndexImpl & impl);
int releaseTableGlobal(NdbTableImpl & impl, int invalidate);
int releaseIndexGlobal(NdbIndexImpl & impl, int invalidate);
NdbTableImpl * getTable(const char * tableName, void **data= 0); NdbTableImpl * getTable(const char * tableName, void **data= 0);
NdbTableImpl * getBlobTable(const NdbTableImpl&, uint col_no); NdbTableImpl * getBlobTable(const NdbTableImpl&, uint col_no);
NdbTableImpl * getBlobTable(uint tab_id, uint col_no); NdbTableImpl * getBlobTable(uint tab_id, uint col_no);
...@@ -616,10 +646,14 @@ public: ...@@ -616,10 +646,14 @@ public:
NdbDictInterface m_receiver; NdbDictInterface m_receiver;
Ndb & m_ndb; Ndb & m_ndb;
private: NdbIndexImpl* getIndexImpl(const char * externalName,
const BaseString& internalName,
NdbTableImpl &tab,
NdbTableImpl &prim);
NdbIndexImpl * getIndexImpl(const char * name, NdbIndexImpl * getIndexImpl(const char * name,
const BaseString& internalName); const BaseString& internalName);
Ndb_local_table_info * fetchGlobalTableImpl(const BaseString& internalName); private:
NdbTableImpl * fetchGlobalTableImplRef(const GlobalCacheInitObject &obj);
}; };
inline inline
...@@ -852,6 +886,27 @@ NdbDictionaryImpl::getImpl(const NdbDictionary::Dictionary & t){ ...@@ -852,6 +886,27 @@ NdbDictionaryImpl::getImpl(const NdbDictionary::Dictionary & t){
* Inline:d getters * Inline:d getters
*/ */
class InitTable : public GlobalCacheInitObject
{
public:
InitTable(NdbDictionaryImpl *dict,
const BaseString &name) :
GlobalCacheInitObject(dict, name)
{}
int init(NdbTableImpl &tab) const
{
return m_dict->getBlobTables(tab);
}
};
inline
NdbTableImpl *
NdbDictionaryImpl::getTableGlobal(const char * table_name)
{
const BaseString internal_tabname(m_ndb.internalize_table_name(table_name));
return fetchGlobalTableImplRef(InitTable(this, internal_tabname));
}
inline inline
NdbTableImpl * NdbTableImpl *
NdbDictionaryImpl::getTable(const char * table_name, void **data) NdbDictionaryImpl::getTable(const char * table_name, void **data)
...@@ -885,21 +940,134 @@ NdbDictionaryImpl::get_local_table_info(const BaseString& internalTableName) ...@@ -885,21 +940,134 @@ NdbDictionaryImpl::get_local_table_info(const BaseString& internalTableName)
DBUG_PRINT("enter", ("table: %s", internalTableName.c_str())); DBUG_PRINT("enter", ("table: %s", internalTableName.c_str()));
Ndb_local_table_info *info= m_localHash.get(internalTableName.c_str()); Ndb_local_table_info *info= m_localHash.get(internalTableName.c_str());
if (info == 0) { if (info == 0)
info= fetchGlobalTableImpl(internalTableName); {
if (info == 0) { NdbTableImpl *tab=
DBUG_RETURN(0); fetchGlobalTableImplRef(InitTable(this, internalTableName));
if (tab)
{
info= Ndb_local_table_info::create(tab, m_local_table_data_size);
if (info)
{
m_localHash.put(internalTableName.c_str(), info);
m_ndb.theFirstTupleId[tab->getTableId()] = ~0;
m_ndb.theLastTupleId[tab->getTableId()] = ~0;
}
} }
} }
DBUG_RETURN(info); // autoincrement already initialized DBUG_RETURN(info); // autoincrement already initialized
} }
class InitIndexGlobal : public GlobalCacheInitObject
{
public:
const char *m_index_name;
NdbTableImpl &m_prim;
InitIndexGlobal(NdbDictionaryImpl *dict,
const BaseString &internal_indexname,
const char *index_name,
NdbTableImpl &prim) :
GlobalCacheInitObject(dict, internal_indexname),
m_index_name(index_name),
m_prim(prim)
{}
int init(NdbTableImpl &tab) const
{
tab.m_index= m_dict->getIndexImpl(m_index_name, m_name, tab, m_prim);
if (tab.m_index == 0)
return 1;
tab.m_index->m_table= &tab;
return 0;
}
};
class InitIndex : public GlobalCacheInitObject
{
public:
const char *m_index_name;
InitIndex(NdbDictionaryImpl *dict,
const BaseString &internal_indexname,
const char *index_name) :
GlobalCacheInitObject(dict, internal_indexname),
m_index_name(index_name)
{}
int init(NdbTableImpl &tab) const
{
DBUG_ASSERT(tab.m_index == 0);
tab.m_index= m_dict->getIndexImpl(m_index_name, m_name);
if (tab.m_index)
{
tab.m_index->m_table= &tab;
return 0;
}
return 1;
}
};
inline
NdbIndexImpl *
NdbDictionaryImpl::getIndexGlobal(const char * index_name,
NdbTableImpl &ndbtab)
{
DBUG_ENTER("NdbDictionaryImpl::getIndexGlobal");
const BaseString
internal_indexname(m_ndb.internalize_index_name(&ndbtab, index_name));
int retry= 2;
while (retry)
{
NdbTableImpl *tab=
fetchGlobalTableImplRef(InitIndexGlobal(this, internal_indexname,
index_name, ndbtab));
if (tab)
{
// tab->m_index sould be set. otherwise tab == 0
NdbIndexImpl *idx= tab->m_index;
if (idx->m_table_id != ndbtab.getObjectId() ||
idx->m_table_version != ndbtab.getObjectVersion())
{
releaseIndexGlobal(*idx, 1);
retry--;
continue;
}
DBUG_RETURN(idx);
}
break;
}
m_error.code= 4243;
DBUG_RETURN(0);
}
inline int
NdbDictionaryImpl::releaseTableGlobal(NdbTableImpl & impl, int invalidate)
{
DBUG_ENTER("NdbDictionaryImpl::releaseTableGlobal");
DBUG_PRINT("enter", ("internal_name: %s", impl.m_internalName.c_str()));
m_globalHash->lock();
m_globalHash->release(&impl, invalidate);
m_globalHash->unlock();
DBUG_RETURN(0);
}
inline int
NdbDictionaryImpl::releaseIndexGlobal(NdbIndexImpl & impl, int invalidate)
{
DBUG_ENTER("NdbDictionaryImpl::releaseIndexGlobal");
DBUG_PRINT("enter", ("internal_name: %s", impl.m_internalName.c_str()));
m_globalHash->lock();
m_globalHash->release(impl.m_table, invalidate);
m_globalHash->unlock();
DBUG_RETURN(0);
}
inline inline
NdbIndexImpl * NdbIndexImpl *
NdbDictionaryImpl::getIndex(const char * index_name, NdbDictionaryImpl::getIndex(const char * index_name,
const char * table_name) const char * table_name)
{ {
if (table_name || m_ndb.usingFullyQualifiedNames()) while (table_name || m_ndb.usingFullyQualifiedNames())
{ {
const BaseString internal_indexname( const BaseString internal_indexname(
(table_name) (table_name)
...@@ -910,18 +1078,28 @@ NdbDictionaryImpl::getIndex(const char * index_name, ...@@ -910,18 +1078,28 @@ NdbDictionaryImpl::getIndex(const char * index_name,
if (internal_indexname.length()) if (internal_indexname.length())
{ {
Ndb_local_table_info * info= Ndb_local_table_info *info= m_localHash.get(internal_indexname.c_str());
get_local_table_info(internal_indexname); NdbTableImpl *tab;
if (info) if (info == 0)
{ {
NdbTableImpl * tab= info->m_table_impl; tab= fetchGlobalTableImplRef(InitIndex(this, internal_indexname,
if (tab->m_index == 0) index_name));
tab->m_index= getIndexImpl(index_name, internal_indexname); if (tab)
if (tab->m_index != 0) {
tab->m_index->m_table= tab; info= Ndb_local_table_info::create(tab, 0);
return tab->m_index; if (info)
m_localHash.put(internal_indexname.c_str(), info);
else
break;
}
else
break;
} }
else
tab= info->m_table_impl;
return tab->m_index;
} }
break;
} }
m_error.code= 4243; m_error.code= 4243;
......
...@@ -377,7 +377,7 @@ NdbIndexStat::stat_select(const Uint32* key1, Uint32 keylen1, const Uint32* key2 ...@@ -377,7 +377,7 @@ NdbIndexStat::stat_select(const Uint32* key1, Uint32 keylen1, const Uint32* key2
} }
int int
NdbIndexStat::records_in_range(NdbDictionary::Index* index, NdbIndexScanOperation* op, Uint64 table_rows, Uint64* count, int flags) NdbIndexStat::records_in_range(const NdbDictionary::Index* index, NdbIndexScanOperation* op, Uint64 table_rows, Uint64* count, int flags)
{ {
DBUG_ENTER("NdbIndexStat::records_in_range"); DBUG_ENTER("NdbIndexStat::records_in_range");
Uint64 rows; Uint64 rows;
......
...@@ -99,6 +99,7 @@ void Ndb::setup(Ndb_cluster_connection *ndb_cluster_connection, ...@@ -99,6 +99,7 @@ void Ndb::setup(Ndb_cluster_connection *ndb_cluster_connection,
for (i = 0; i < MAX_NDB_NODES ; i++) { for (i = 0; i < MAX_NDB_NODES ; i++) {
theConnectionArray[i] = NULL; theConnectionArray[i] = NULL;
}//forg }//forg
m_sys_tab_0 = NULL;
for (i = 0; i < 2048 ; i++) { for (i = 0; i < 2048 ; i++) {
theFirstTupleId[i] = 0; theFirstTupleId[i] = 0;
theLastTupleId[i] = 0; theLastTupleId[i] = 0;
...@@ -137,6 +138,9 @@ Ndb::~Ndb() ...@@ -137,6 +138,9 @@ Ndb::~Ndb()
DBUG_ENTER("Ndb::~Ndb()"); DBUG_ENTER("Ndb::~Ndb()");
DBUG_PRINT("enter",("this=0x%x",this)); DBUG_PRINT("enter",("this=0x%x",this));
if (m_sys_tab_0)
getDictionary()->removeTableGlobal(*m_sys_tab_0, 0);
assert(theImpl->m_ev_op == 0); // user should return NdbEventOperation's assert(theImpl->m_ev_op == 0); // user should return NdbEventOperation's
for (NdbEventOperationImpl *op= theImpl->m_ev_op; op; op=op->m_next) for (NdbEventOperationImpl *op= theImpl->m_ev_op; op; op=op->m_next)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment