Commit 90913a03 authored by unknown's avatar unknown

ndb - bug#20053

  make sure we can only drop files from correct file group


mysql-test/r/ndb_dd_ddl.result:
  add testcase
mysql-test/t/ndb_dd_ddl.test:
  add testcase
sql/ha_ndbcluster.cc:
  Make sure correct tablespace for dropping datafile
storage/ndb/include/ndbapi/NdbDictionary.hpp:
  Cleanup {data/undo}file get{tablespace/logfilegroup}
storage/ndb/src/ndbapi/NdbDictionary.cpp:
  Cleanup {data/undo}file get{tablespace/logfilegroup}
storage/ndb/src/ndbapi/NdbDictionaryImpl.hpp:
  Cleanup {data/undo}file get{tablespace/logfilegroup}
storage/ndb/tools/restore/consumer_restore.cpp:
  Cleanup {data/undo}file get{tablespace/logfilegroup}
parent 9aa82e53
...@@ -188,6 +188,19 @@ ENGINE NDB; ...@@ -188,6 +188,19 @@ ENGINE NDB;
CREATE INDEX b_i on t1(b); CREATE INDEX b_i on t1(b);
CREATE INDEX bc_i on t1(b, c); CREATE INDEX bc_i on t1(b, c);
DROP TABLE t1; DROP TABLE t1;
CREATE TABLESPACE ts2
ADD DATAFILE 'datafile3.dat'
USE LOGFILE GROUP lg1
INITIAL_SIZE 1M
ENGINE NDB;
ALTER TABLESPACE ts1
DROP DATAFILE 'datafile3.dat'
ENGINE NDB;
ERROR HY000: Failed to alter: NO SUCH FILE
ALTER TABLESPACE ts2
DROP DATAFILE 'datafile2.dat'
ENGINE NDB;
ERROR HY000: Failed to alter: NO SUCH FILE
ALTER TABLESPACE ts1 ALTER TABLESPACE ts1
DROP DATAFILE 'datafile2.dat' DROP DATAFILE 'datafile2.dat'
ENGINE NDB; ENGINE NDB;
...@@ -196,6 +209,11 @@ DROP DATAFILE 'datafile.dat' ...@@ -196,6 +209,11 @@ DROP DATAFILE 'datafile.dat'
ENGINE NDB; ENGINE NDB;
DROP TABLESPACE ts1 DROP TABLESPACE ts1
ENGINE NDB; ENGINE NDB;
ALTER TABLESPACE ts2
DROP DATAFILE 'datafile3.dat'
ENGINE NDB;
DROP TABLESPACE ts2
ENGINE NDB;
DROP LOGFILE GROUP lg1 DROP LOGFILE GROUP lg1
ENGINE NDB; ENGINE NDB;
**** End = And No = **** **** End = And No = ****
......
...@@ -280,6 +280,25 @@ CREATE INDEX bc_i on t1(b, c); ...@@ -280,6 +280,25 @@ CREATE INDEX bc_i on t1(b, c);
DROP TABLE t1; DROP TABLE t1;
# bug#20053
CREATE TABLESPACE ts2
ADD DATAFILE 'datafile3.dat'
USE LOGFILE GROUP lg1
INITIAL_SIZE 1M
ENGINE NDB;
--error ER_ALTER_FILEGROUP_FAILED
ALTER TABLESPACE ts1
DROP DATAFILE 'datafile3.dat'
ENGINE NDB;
--error ER_ALTER_FILEGROUP_FAILED
ALTER TABLESPACE ts2
DROP DATAFILE 'datafile2.dat'
ENGINE NDB;
# bug#20053
ALTER TABLESPACE ts1 ALTER TABLESPACE ts1
DROP DATAFILE 'datafile2.dat' DROP DATAFILE 'datafile2.dat'
ENGINE NDB; ENGINE NDB;
...@@ -291,6 +310,13 @@ ENGINE NDB; ...@@ -291,6 +310,13 @@ ENGINE NDB;
DROP TABLESPACE ts1 DROP TABLESPACE ts1
ENGINE NDB; ENGINE NDB;
ALTER TABLESPACE ts2
DROP DATAFILE 'datafile3.dat'
ENGINE NDB;
DROP TABLESPACE ts2
ENGINE NDB;
DROP LOGFILE GROUP lg1 DROP LOGFILE GROUP lg1
ENGINE NDB; ENGINE NDB;
......
...@@ -9949,7 +9949,7 @@ int ndbcluster_alter_tablespace(THD* thd, st_alter_tablespace *info) ...@@ -9949,7 +9949,7 @@ int ndbcluster_alter_tablespace(THD* thd, st_alter_tablespace *info)
} }
NdbError err; NdbError err;
NDBDICT *dict = ndb->getDictionary(); NDBDICT *dict= ndb->getDictionary();
int error; int error;
const char * errmsg; const char * errmsg;
LINT_INIT(errmsg); LINT_INIT(errmsg);
...@@ -10013,9 +10013,12 @@ int ndbcluster_alter_tablespace(THD* thd, st_alter_tablespace *info) ...@@ -10013,9 +10013,12 @@ int ndbcluster_alter_tablespace(THD* thd, st_alter_tablespace *info)
} }
else if(info->ts_alter_tablespace_type == ALTER_TABLESPACE_DROP_FILE) else if(info->ts_alter_tablespace_type == ALTER_TABLESPACE_DROP_FILE)
{ {
NdbDictionary::Datafile df = dict->getDatafile(0, NdbDictionary::Tablespace ts= dict->getTablespace(info->tablespace_name);
info->data_file_name); NdbDictionary::Datafile df= dict->getDatafile(0, info->data_file_name);
if (strcmp(df.getPath(), info->data_file_name) == 0) NdbDictionary::ObjectId objid;
df.getTablespaceId(&objid);
if (ts.getObjectId() == objid.getObjectId() &&
strcmp(df.getPath(), info->data_file_name) == 0)
{ {
errmsg= " DROP DATAFILE"; errmsg= " DROP DATAFILE";
if (dict->dropDatafile(df)) if (dict->dropDatafile(df))
...@@ -10344,10 +10347,12 @@ static int ndbcluster_fill_files_table(THD *thd, TABLE_LIST *tables, ...@@ -10344,10 +10347,12 @@ static int ndbcluster_fill_files_table(THD *thd, TABLE_LIST *tables,
table->field[c++]->set_null(); // TABLE_NAME table->field[c++]->set_null(); // TABLE_NAME
// LOGFILE_GROUP_NAME // LOGFILE_GROUP_NAME
NdbDictionary::ObjectId objid;
uf.getLogfileGroupId(&objid);
table->field[c++]->store(uf.getLogfileGroup(), table->field[c++]->store(uf.getLogfileGroup(),
strlen(uf.getLogfileGroup()), strlen(uf.getLogfileGroup()),
system_charset_info); system_charset_info);
table->field[c++]->store(uf.getLogfileGroupId()); // LOGFILE_GROUP_NUMBER table->field[c++]->store(objid.getObjectId()); // LOGFILE_GROUP_NUMBER
table->field[c++]->store(ndbcluster_hton_name, table->field[c++]->store(ndbcluster_hton_name,
ndbcluster_hton_name_length, ndbcluster_hton_name_length,
system_charset_info); // ENGINE system_charset_info); // ENGINE
......
...@@ -184,7 +184,7 @@ public: ...@@ -184,7 +184,7 @@ public:
virtual int getObjectId() const; virtual int getObjectId() const;
private: private:
friend class Dictionary; friend class NdbDictObjectImpl;
class NdbDictObjectImpl & m_impl; class NdbDictObjectImpl & m_impl;
}; };
...@@ -1462,11 +1462,11 @@ public: ...@@ -1462,11 +1462,11 @@ public:
void setSize(Uint64); void setSize(Uint64);
Uint64 getSize() const; Uint64 getSize() const;
Uint64 getFree() const; Uint64 getFree() const;
void setTablespace(const char * name); void setTablespace(const char * name);
void setTablespace(const class Tablespace &); void setTablespace(const class Tablespace &);
const char * getTablespace() const; const char * getTablespace() const;
Uint32 getTablespaceId() const; void getTablespaceId(ObjectId * dst) const;
void setNode(Uint32 nodeId); void setNode(Uint32 nodeId);
Uint32 getNode() const; Uint32 getNode() const;
...@@ -1509,7 +1509,7 @@ public: ...@@ -1509,7 +1509,7 @@ public:
void setLogfileGroup(const char * name); void setLogfileGroup(const char * name);
void setLogfileGroup(const class LogfileGroup &); void setLogfileGroup(const class LogfileGroup &);
const char * getLogfileGroup() const; const char * getLogfileGroup() const;
Uint32 getLogfileGroupId() const; void getLogfileGroupId(ObjectId * dst) const;
void setNode(Uint32 nodeId); void setNode(Uint32 nodeId);
Uint32 getNode() const; Uint32 getNode() const;
......
...@@ -1224,9 +1224,14 @@ NdbDictionary::Datafile::getTablespace() const { ...@@ -1224,9 +1224,14 @@ NdbDictionary::Datafile::getTablespace() const {
return m_impl.m_filegroup_name.c_str(); return m_impl.m_filegroup_name.c_str();
} }
Uint32 void
NdbDictionary::Datafile::getTablespaceId() const { NdbDictionary::Datafile::getTablespaceId(NdbDictionary::ObjectId* dst) const
return m_impl.m_filegroup_id; {
if (dst)
{
NdbDictObjectImpl::getImpl(* dst).m_id = m_impl.m_filegroup_id;
NdbDictObjectImpl::getImpl(* dst).m_version = m_impl.m_filegroup_version;
}
} }
NdbDictionary::Object::Status NdbDictionary::Object::Status
...@@ -1310,9 +1315,14 @@ NdbDictionary::Undofile::getLogfileGroup() const { ...@@ -1310,9 +1315,14 @@ NdbDictionary::Undofile::getLogfileGroup() const {
return m_impl.m_filegroup_name.c_str(); return m_impl.m_filegroup_name.c_str();
} }
Uint32 void
NdbDictionary::Undofile::getLogfileGroupId() const { NdbDictionary::Undofile::getLogfileGroupId(NdbDictionary::ObjectId * dst)const
return m_impl.m_filegroup_id; {
if (dst)
{
NdbDictObjectImpl::getImpl(* dst).m_id = m_impl.m_filegroup_id;
NdbDictObjectImpl::getImpl(* dst).m_version = m_impl.m_filegroup_version;
}
} }
NdbDictionary::Object::Status NdbDictionary::Object::Status
...@@ -1829,7 +1839,8 @@ NdbDictionary::Dictionary::createLogfileGroup(const LogfileGroup & lg, ...@@ -1829,7 +1839,8 @@ NdbDictionary::Dictionary::createLogfileGroup(const LogfileGroup & lg,
ObjectId * obj) ObjectId * obj)
{ {
return m_impl.createLogfileGroup(NdbLogfileGroupImpl::getImpl(lg), return m_impl.createLogfileGroup(NdbLogfileGroupImpl::getImpl(lg),
obj ? &obj->m_impl : 0); obj ?
& NdbDictObjectImpl::getImpl(* obj) : 0);
} }
int int
...@@ -1852,7 +1863,8 @@ NdbDictionary::Dictionary::createTablespace(const Tablespace & lg, ...@@ -1852,7 +1863,8 @@ NdbDictionary::Dictionary::createTablespace(const Tablespace & lg,
ObjectId * obj) ObjectId * obj)
{ {
return m_impl.createTablespace(NdbTablespaceImpl::getImpl(lg), return m_impl.createTablespace(NdbTablespaceImpl::getImpl(lg),
obj ? &obj->m_impl : 0); obj ?
& NdbDictObjectImpl::getImpl(* obj) : 0);
} }
int int
...@@ -1887,7 +1899,7 @@ NdbDictionary::Dictionary::createDatafile(const Datafile & df, ...@@ -1887,7 +1899,7 @@ NdbDictionary::Dictionary::createDatafile(const Datafile & df,
{ {
return m_impl.createDatafile(NdbDatafileImpl::getImpl(df), return m_impl.createDatafile(NdbDatafileImpl::getImpl(df),
force, force,
obj ? &obj->m_impl : 0); obj ? & NdbDictObjectImpl::getImpl(* obj) : 0);
} }
int int
...@@ -1913,7 +1925,7 @@ NdbDictionary::Dictionary::createUndofile(const Undofile & df, ...@@ -1913,7 +1925,7 @@ NdbDictionary::Dictionary::createUndofile(const Undofile & df,
{ {
return m_impl.createUndofile(NdbUndofileImpl::getImpl(df), return m_impl.createUndofile(NdbUndofileImpl::getImpl(df),
force, force,
obj ? &obj->m_impl : 0); obj ? & NdbDictObjectImpl::getImpl(* obj) : 0);
} }
int int
......
...@@ -46,14 +46,22 @@ public: ...@@ -46,14 +46,22 @@ public:
NdbDictionary::Object::Status m_status; NdbDictionary::Object::Status m_status;
bool change(); bool change();
static NdbDictObjectImpl & getImpl(NdbDictionary::ObjectId & t) {
return t.m_impl;
}
static const NdbDictObjectImpl & getImpl(const NdbDictionary::ObjectId & t){
return t.m_impl;
}
protected: protected:
friend class NdbDictionary::ObjectId;
NdbDictObjectImpl(NdbDictionary::Object::Type type) : NdbDictObjectImpl(NdbDictionary::Object::Type type) :
m_type(type), m_type(type),
m_status(NdbDictionary::Object::New) { m_status(NdbDictionary::Object::New) {
m_id = -1; m_id = -1;
} }
friend class NdbDictionary::ObjectId;
}; };
/** /**
......
...@@ -533,9 +533,11 @@ BackupRestore::object(Uint32 type, const void * ptr) ...@@ -533,9 +533,11 @@ BackupRestore::object(Uint32 type, const void * ptr)
if (!m_no_restore_disk) if (!m_no_restore_disk)
{ {
NdbDictionary::Datafile old(*(NdbDictionary::Datafile*)ptr); NdbDictionary::Datafile old(*(NdbDictionary::Datafile*)ptr);
NdbDictionary::Tablespace * ts = m_tablespaces[old.getTablespaceId()]; NdbDictionary::ObjectId objid;
old.getTablespaceId(&objid);
NdbDictionary::Tablespace * ts = m_tablespaces[objid.getObjectId()];
debug << "Connecting datafile " << old.getPath() debug << "Connecting datafile " << old.getPath()
<< " to tablespace: oldid: " << old.getTablespaceId() << " to tablespace: oldid: " << objid.getObjectId()
<< " newid: " << ts->getObjectId() << endl; << " newid: " << ts->getObjectId() << endl;
old.setTablespace(* ts); old.setTablespace(* ts);
info << "Creating datafile \"" << old.getPath() << "\"..." << flush; info << "Creating datafile \"" << old.getPath() << "\"..." << flush;
...@@ -554,10 +556,11 @@ BackupRestore::object(Uint32 type, const void * ptr) ...@@ -554,10 +556,11 @@ BackupRestore::object(Uint32 type, const void * ptr)
if (!m_no_restore_disk) if (!m_no_restore_disk)
{ {
NdbDictionary::Undofile old(*(NdbDictionary::Undofile*)ptr); NdbDictionary::Undofile old(*(NdbDictionary::Undofile*)ptr);
NdbDictionary::LogfileGroup * lg = NdbDictionary::ObjectId objid;
m_logfilegroups[old.getLogfileGroupId()]; old.getLogfileGroupId(&objid);
NdbDictionary::LogfileGroup * lg = m_logfilegroups[objid.getObjectId()];
debug << "Connecting undofile " << old.getPath() debug << "Connecting undofile " << old.getPath()
<< " to logfile group: oldid: " << old.getLogfileGroupId() << " to logfile group: oldid: " << objid.getObjectId()
<< " newid: " << lg->getObjectId() << " newid: " << lg->getObjectId()
<< " " << (void*)lg << endl; << " " << (void*)lg << endl;
old.setLogfileGroup(* lg); old.setLogfileGroup(* lg);
......
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