Skip to content

Commit a5960aa

Browse files
committed
Bug#31180526 CHANGING TABLESPACE BY INPLACE ALTER CORRUPTION
Changing the tablespace of a table using an inplace alter table fails to update NDB dictionary with the new tablespace name and tablespace id. Even if an attempt to update the NDB dictionary was made, it would not properly move over data to the new tablespace. Fix by not allowing TABLESPACE to be changed by inplace alter table until NDB supports changing tablespace online. Restrict both cases: 1) Assigning a table (which does not already has one) to a tablespace 2) Changing the tablespace of a table Add printout of tablespace id and name to make them visible in for example ndb_desc. Change-Id: I78c81cb4b5fc460d1f75560c053c3d21a5a2fbc9
1 parent a6b9533 commit a5960aa

File tree

8 files changed

+134
-29
lines changed

8 files changed

+134
-29
lines changed

mysql-test/suite/ndb/include/ndb_desc_print.inc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ replace_regex /Version: [0-9]*/Version: Any/
1818
/Length of frm data: [0-9]*/Length of frm data: XXX/
1919
/IndexTable [0-9]*/IndexTable XX/
2020
/^([0-9][0-9]*) [0-9 ]*/\1 .../
21-
/Table id: [0-9]*/Table id: XXX/;
21+
/Table id: [0-9]*/Table id: XXX/
22+
/Tablespace id: [0-9]*/Tablespace id: XX/;
2223
--exec $ndb_desc_cmd
2324

2425
# Reset argument variable in order to detect missing assignment

mysql-test/suite/ndb/r/ndb_add_partition.result

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ ExtraRowAuthorBits: 0
198198
TableStatus: Retrieved
199199
Table options: readbackup
200200
HashMap: DEFAULT-HASHMAP-3840-2
201+
Tablespace id: XX
202+
Tablespace: ts1
201203
-- Attributes --
202204
a Unsigned PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
203205
b Unsigned PRIMARY KEY AT=FIXED ST=MEMORY
@@ -916,6 +918,8 @@ ExtraRowAuthorBits: 0
916918
TableStatus: Retrieved
917919
Table options: readbackup
918920
HashMap: DEFAULT-HASHMAP-3840-2
921+
Tablespace id: XX
922+
Tablespace: ts1
919923
-- Attributes --
920924
a Unsigned PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
921925
b Unsigned PRIMARY KEY AT=FIXED ST=MEMORY
@@ -1388,6 +1392,8 @@ ExtraRowAuthorBits: 0
13881392
TableStatus: Retrieved
13891393
Table options: readbackup
13901394
HashMap: DEFAULT-HASHMAP-3840-6
1395+
Tablespace id: XX
1396+
Tablespace: ts1
13911397
-- Attributes --
13921398
a Unsigned PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
13931399
b Unsigned PRIMARY KEY AT=FIXED ST=MEMORY
@@ -2052,6 +2058,8 @@ ExtraRowAuthorBits: 0
20522058
TableStatus: Retrieved
20532059
Table options: readbackup
20542060
HashMap: HASHMAP-3840-6-7
2061+
Tablespace id: XX
2062+
Tablespace: ts1
20552063
-- Attributes --
20562064
a Unsigned PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
20572065
b Unsigned PRIMARY KEY AT=FIXED ST=MEMORY

mysql-test/suite/ndb/r/ndb_storage.result

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ ADD DATAFILE 'ts1_datafile.dat'
99
INITIAL_SIZE 10M
1010
ENGINE ndb;
1111
CREATE TABLE t5 (a int PRIMARY KEY, t5b int, t5c int)
12-
ENGINE ndb;
12+
ENGINE ndb TABLESPACE ts1;
1313
INSERT INTO t5 VALUES (1, 1, 1);
14-
ALTER TABLE t5 ALGORITHM=inplace, STORAGE disk TABLESPACE ts1;
14+
ALTER TABLE t5 ALGORITHM=inplace, STORAGE disk;
1515
ERROR 0A000: ALGORITHM=INPLACE is not supported. Reason: Column storage media is changed due to change in table storage media. Try ALGORITHM=COPY.
16-
ALTER TABLE t5 STORAGE DISK TABLESPACE ts1;
16+
ALTER TABLE t5 STORAGE DISK;
1717
ALTER TABLESPACE ts1
1818
DROP DATAFILE 'ts1_datafile.dat';
1919
ERROR HY000: Failed to alter: DROP DATAFILE FAILED

mysql-test/suite/ndb/t/ndb_storage.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ CREATE TABLESPACE ts1
3131
## verify whether the copy algorithm is used.
3232

3333
CREATE TABLE t5 (a int PRIMARY KEY, t5b int, t5c int)
34-
ENGINE ndb;
34+
ENGINE ndb TABLESPACE ts1;
3535
INSERT INTO t5 VALUES (1, 1, 1);
3636

3737
# Moving implicit memory columns to disk will be
3838
# an automatic copy alter (no need to specify alg=copy)
3939
--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
40-
ALTER TABLE t5 ALGORITHM=inplace, STORAGE disk TABLESPACE ts1;
41-
ALTER TABLE t5 STORAGE DISK TABLESPACE ts1;
40+
ALTER TABLE t5 ALGORITHM=inplace, STORAGE disk;
41+
ALTER TABLE t5 STORAGE DISK;
4242

4343
#Check if the disk data is on disk
4444
--error ER_ALTER_FILEGROUP_FAILED
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
CREATE LOGFILE GROUP lg1
2+
ADD UNDOFILE 'lg1_undofile.dat'
3+
INITIAL_SIZE 1M
4+
UNDO_BUFFER_SIZE = 1M
5+
ENGINE NDB;
6+
CREATE TABLESPACE ts1
7+
ADD DATAFILE 'ts1_datafile.dat'
8+
USE LOGFILE GROUP lg1
9+
INITIAL_SIZE 16M
10+
ENGINE NDB;
11+
CREATE TABLESPACE ts2
12+
ADD DATAFILE 'ts2_datafile.dat'
13+
USE LOGFILE GROUP lg1
14+
INITIAL_SIZE 16M
15+
ENGINE NDB;
16+
CREATE TABLE t1 (
17+
a int PRIMARY KEY,
18+
b int
19+
) ENGINE = NDB;
20+
ALTER TABLE t1 ALGORITHM=inplace, TABLESPACE ts1;
21+
ERROR 0A000: ALGORITHM=INPLACE is not supported. Reason: Adding or changing TABLESPACE. Try ALGORITHM=COPY.
22+
ALTER TABLE t1 TABLESPACE ts1;
23+
ALTER TABLE t1 ALGORITHM=inplace, TABLESPACE=ts2;
24+
ERROR 0A000: ALGORITHM=INPLACE is not supported. Reason: Adding or changing TABLESPACE. Try ALGORITHM=COPY.
25+
ALTER TABLE t1 ALGORITHM=inplace, TABLESPACE=ts1;
26+
ERROR 0A000: ALGORITHM=INPLACE is not supported. Reason: Adding or changing TABLESPACE. Try ALGORITHM=COPY.
27+
ALTER TABLE t1 TABLESPACE ts2;
28+
DROP TABLE t1;
29+
ALTER TABLESPACE ts1
30+
DROP DATAFILE 'ts1_datafile.dat';
31+
DROP TABLESPACE ts1;
32+
ALTER TABLESPACE ts2
33+
DROP DATAFILE 'ts2_datafile.dat';
34+
DROP TABLESPACE ts2;
35+
DROP LOGFILE GROUP lg1
36+
ENGINE NDB;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
--source include/have_ndb.inc
2+
3+
# Test that inplace alter table does not support adding or changing tablespace
4+
# for a table
5+
#
6+
7+
CREATE LOGFILE GROUP lg1
8+
ADD UNDOFILE 'lg1_undofile.dat'
9+
INITIAL_SIZE 1M
10+
UNDO_BUFFER_SIZE = 1M
11+
ENGINE NDB;
12+
13+
CREATE TABLESPACE ts1
14+
ADD DATAFILE 'ts1_datafile.dat'
15+
USE LOGFILE GROUP lg1
16+
INITIAL_SIZE 16M
17+
ENGINE NDB;
18+
19+
CREATE TABLESPACE ts2
20+
ADD DATAFILE 'ts2_datafile.dat'
21+
USE LOGFILE GROUP lg1
22+
INITIAL_SIZE 16M
23+
ENGINE NDB;
24+
25+
CREATE TABLE t1 (
26+
a int PRIMARY KEY,
27+
b int
28+
) ENGINE = NDB;
29+
30+
# Adding tablespace not supported by inplace alter
31+
# i.e 'no tablespace' -> 't1'
32+
--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
33+
ALTER TABLE t1 ALGORITHM=inplace, TABLESPACE ts1;
34+
35+
# Add tablespace to t1 with copying alter
36+
ALTER TABLE t1 TABLESPACE ts1;
37+
38+
# Changing tablespace not supported by inplace alter
39+
# ie. 'ts1' -> 'ts2'
40+
--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
41+
ALTER TABLE t1 ALGORITHM=inplace, TABLESPACE=ts2;
42+
43+
# Neither changing to same name is supported by inplace alter
44+
# ie. 'ts1' -> 'ts1'
45+
--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
46+
ALTER TABLE t1 ALGORITHM=inplace, TABLESPACE=ts1;
47+
48+
# Changing tablespace to t2 with copying alter
49+
ALTER TABLE t1 TABLESPACE ts2;
50+
51+
DROP TABLE t1;
52+
ALTER TABLESPACE ts1
53+
DROP DATAFILE 'ts1_datafile.dat';
54+
DROP TABLESPACE ts1;
55+
ALTER TABLESPACE ts2
56+
DROP DATAFILE 'ts2_datafile.dat';
57+
DROP TABLESPACE ts2;
58+
DROP LOGFILE GROUP lg1
59+
ENGINE NDB;

storage/ndb/plugin/ha_ndbcluster.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15092,7 +15092,7 @@ enum_alter_inplace_result ha_ndbcluster::supported_inplace_column_change(
1509215092

1509315093
HA_CREATE_INFO *create_info = ha_alter_info->create_info;
1509415094

15095-
bool is_table_storage_changed = table_storage_changed(create_info);
15095+
const bool is_table_storage_changed = table_storage_changed(create_info);
1509615096

1509715097
DBUG_PRINT("info", ("Checking if supported column change for field %s",
1509815098
old_field->field_name));
@@ -15260,6 +15260,12 @@ enum_alter_inplace_result ha_ndbcluster::check_inplace_alter_supported(
1526015260
DBUG_PRINT("info", ("The COMMENT string changed"));
1526115261
comment_changed = true;
1526215262
}
15263+
15264+
if (create_info->used_fields & HA_CREATE_USED_TABLESPACE) {
15265+
// Changing TABLESPACE is not supported by inplace alter
15266+
return inplace_unsupported(ha_alter_info,
15267+
"Adding or changing TABLESPACE");
15268+
}
1526315269
}
1526415270

1526515271
if (alter_flags & Alter_inplace_info::ALTER_TABLE_REORG) {

storage/ndb/src/ndbapi/NdbDictionary.cpp

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License, version 2.0,
@@ -724,26 +724,6 @@ NdbDictionary::Table::setSingleUserMode(enum NdbDictionary::Table::SingleUserMod
724724
m_impl.m_single_user_mode = (Uint8)mode;
725725
}
726726

727-
#if 0
728-
int
729-
NdbDictionary::Table::setTablespaceNames(const void *data, Uint32 len)
730-
{
731-
return m_impl.setTablespaceNames(data, len);
732-
}
733-
734-
const void*
735-
NdbDictionary::Table::getTablespaceNames()
736-
{
737-
return m_impl.getTablespaceNames();
738-
}
739-
740-
Uint32
741-
NdbDictionary::Table::getTablespaceNamesLen() const
742-
{
743-
return m_impl.getTablespaceNamesLen();
744-
}
745-
#endif
746-
747727
void
748728
NdbDictionary::Table::setLinearFlag(Uint32 flag)
749729
{
@@ -4596,6 +4576,21 @@ void NdbDictionary::Dictionary::print(NdbOut& ndbout, NdbDictionary::Table const
45964576
ndbout << "HashMap: " << hashmap.getName() << endl;
45974577
}
45984578

4579+
Uint32 tablespace_id;
4580+
if (tab.getTablespace(&tablespace_id))
4581+
{
4582+
ndbout << "Tablespace id: " << tablespace_id << endl;
4583+
4584+
// Look up tablespace by id and show the name
4585+
// NOTE! The tablespace name of a table object which
4586+
// has been fetched from NDB is not assigned any value.
4587+
const NdbDictionary::Tablespace ts = getTablespace(tablespace_id);
4588+
if (getNdbError().code == 0)
4589+
{
4590+
ndbout << "Tablespace: " << ts.getName() << endl;
4591+
}
4592+
}
4593+
45994594
ndbout << "-- Attributes --" << endl;
46004595
for (int col = 0; col < tab.getNoOfColumns() ; col++)
46014596
{

0 commit comments

Comments
 (0)