Browse Source

[4237] Added MySQL ENGINE to all table creates, fixed hosts table not dropping

All MySQL text to create tables sets ENGINE to INNODB
MySQL unit tests now reliably drop the "hosts" table

src/bin/admin/scripts/mysql/dhcpdb_create.mysql
    Added "ENGINE = INNODB" table creates where needed

src/bin/admin/scripts/mysql/upgrade_1.0_to_2.0.sh.in
src/bin/admin/scripts/mysql/upgrade_2.0_to_3.0.sh.in
    Added "ENGINE = INNODB" table creates where needed

src/bin/admin/tests/data/mysql.lease6_dump_test.reference.csv
    Reversed order of reference file to match INNODB result

src/bin/admin/tests/dhcpdb_create_1.0.mysql
    Added "ENGINE = INNODB" table creates where needed

src/bin/admin/tests/mysql_tests.sh.in
    Removed unnecessary explicit drop of ipv6_reservations

src/lib/dhcpsrv/tests/mysql_schema.cc
    Added MySQL error output on statement failures

src/lib/dhcpsrv/tests/schema_mysql_copy.h
    const char* destroy_statement[]
        Added statement to turn off referential integrity checks, so all
        tables will get dropped.  "hosts" table was being left behind.

    const char* create_statement[]
        Added "ENGINE = INNODB" table creates where needed
Thomas Markwalder 9 years ago
parent
commit
6bd7ac72bc

+ 4 - 3
src/bin/admin/scripts/mysql/dhcpdb_create.mysql

@@ -92,7 +92,8 @@ CREATE INDEX lease6_by_iaid_subnet_id_duid ON lease6 (iaid, subnet_id, duid);
 CREATE TABLE lease6_types (
     lease_type TINYINT PRIMARY KEY NOT NULL,    # Lease type code.
     name VARCHAR(5)                             # Name of the lease type
-    );
+    ) ENGINE = INNODB;
+
 START TRANSACTION;
 INSERT INTO lease6_types VALUES (0, "IA_NA");   # Non-temporary v6 addresses
 INSERT INTO lease6_types VALUES (1, "IA_TA");   # Temporary v6 addresses
@@ -111,7 +112,7 @@ COMMIT;
 CREATE TABLE schema_version (
     version INT PRIMARY KEY NOT NULL,       # Major version number
     minor INT                               # Minor version number
-    );
+    ) ENGINE = INNODB;
 START TRANSACTION;
 INSERT INTO schema_version VALUES (1, 0);
 COMMIT;
@@ -136,7 +137,7 @@ ALTER TABLE lease6
 CREATE TABLE lease_hwaddr_source (
     hwaddr_source INT PRIMARY KEY NOT NULL,
     name VARCHAR(40)
-);
+) ENGINE = INNODB;
 
 # Hardware address obtained from raw sockets
 INSERT INTO lease_hwaddr_source VALUES (1, "HWADDR_SOURCE_RAW");

+ 1 - 1
src/bin/admin/scripts/mysql/upgrade_1.0_to_2.0.sh.in

@@ -24,7 +24,7 @@ ALTER TABLE lease6
 CREATE TABLE lease_hwaddr_source (
     hwaddr_source INT PRIMARY KEY NOT NULL,
     name VARCHAR(40)
-);
+) ENGINE = INNODB;
 
 -- See src/lib/dhcp/dhcp/pkt.h for detailed explanation
 INSERT INTO lease_hwaddr_source VALUES (1, "HWADDR_SOURCE_RAW");

+ 8 - 4
src/bin/admin/scripts/mysql/upgrade_2.0_to_3.0.sh.in

@@ -28,7 +28,8 @@ dhcp4_client_classes VARCHAR(255) NULL ,
 dhcp6_client_classes VARCHAR(255) NULL ,
 PRIMARY KEY (host_id) ,
 INDEX key_dhcp4_identifier_subnet_id (dhcp_identifier ASC, dhcp_identifier_type ASC) ,
-INDEX key_dhcp6_identifier_subnet_id (dhcp_identifier ASC, dhcp_identifier_type ASC, dhcp6_subnet_id ASC) );
+INDEX key_dhcp6_identifier_subnet_id (dhcp_identifier ASC, dhcp_identifier_type ASC, dhcp6_subnet_id ASC) 
+) ENGINE = INNODB;
 
 CREATE TABLE IF NOT EXISTS ipv6_reservations (
 reservation_id INT NOT NULL AUTO_INCREMENT ,
@@ -43,7 +44,8 @@ CONSTRAINT fk_ipv6_reservations_Host
 FOREIGN KEY (host_id )
 REFERENCES hosts (host_id )
 ON DELETE NO ACTION
-ON UPDATE NO ACTION);
+ON UPDATE NO ACTION
+) ENGINE = INNODB;
 
 CREATE TABLE IF NOT EXISTS dhcp4_options (
 option_id INT UNSIGNED NOT NULL AUTO_INCREMENT ,
@@ -62,7 +64,8 @@ CONSTRAINT fk_options_host1
 FOREIGN KEY (host_id )
 REFERENCES hosts (host_id )
 ON DELETE NO ACTION
-ON UPDATE NO ACTION);
+ON UPDATE NO ACTION
+) ENGINE = INNODB;
 
 CREATE TABLE IF NOT EXISTS dhcp6_options (
 option_id INT UNSIGNED NOT NULL AUTO_INCREMENT ,
@@ -81,7 +84,8 @@ CONSTRAINT fk_options_host10
 FOREIGN KEY (host_id )
 REFERENCES hosts (host_id )
 ON DELETE NO ACTION
-ON UPDATE NO ACTION);
+ON UPDATE NO ACTION
+) ENGINE = INNODB;
 
 DELIMITER $$
 CREATE TRIGGER host_BDEL BEFORE DELETE ON hosts FOR EACH ROW

+ 1 - 1
src/bin/admin/tests/data/mysql.lease6_dump_test.reference.csv

@@ -1,4 +1,4 @@
 address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,hwtype,hwaddr_source,state
+10,3230,30,2015-04-04 01:15:30,40,50,IA_TA,60,70,1,1,one.example.com,3830,90,HWADDR_SOURCE_REMOTE_ID,default
 11,,30,2015-05-05 02:30:45,40,50,IA_TA,60,70,1,1,,3830,90,HWADDR_SOURCE_RAW,declined
 12,3231,30,2015-06-06 11:01:07,40,50,IA_TA,60,70,1,1,three.example.com,3830,90,HWADDR_SOURCE_DUID,expired-reclaimed
-10,3230,30,2015-04-04 01:15:30,40,50,IA_TA,60,70,1,1,one.example.com,3830,90,HWADDR_SOURCE_REMOTE_ID,default

+ 2 - 2
src/bin/admin/tests/dhcpdb_create_1.0.mysql

@@ -84,7 +84,7 @@ CREATE INDEX lease6_by_iaid_subnet_id_duid ON lease6 (iaid, subnet_id, duid);
 CREATE TABLE lease6_types (
     lease_type TINYINT PRIMARY KEY NOT NULL,    # Lease type code.
     name VARCHAR(5)                             # Name of the lease type
-    );
+    ) ENGINE = INNODB;
 START TRANSACTION;
 INSERT INTO lease6_types VALUES (0, "IA_NA");   # Non-temporary v6 addresses
 INSERT INTO lease6_types VALUES (1, "IA_TA");   # Temporary v6 addresses
@@ -103,7 +103,7 @@ COMMIT;
 CREATE TABLE schema_version (
     version INT PRIMARY KEY NOT NULL,       # Major version number
     minor INT                               # Minor version number
-    );
+    ) ENGINE = INNODB;
 START TRANSACTION;
 INSERT INTO schema_version VALUES (1, 0);
 COMMIT;

+ 0 - 5
src/bin/admin/tests/mysql_tests.sh.in

@@ -38,11 +38,6 @@ keaadmin=@abs_top_builddir@/src/bin/admin/kea-admin
 mysql_wipe() {
     printf "Wiping whole database %s\n" $db_name
 
-    # ipv6_reservations table must be deleted first, as it has contraints that
-    # are dependent on hosts. Therefore hosts table cannot be deleted before
-    # ipv6_reservations.
-    mysql_execute "DROP TABLE IF EXISTS ipv6_reservations;"
-
     # First we build the list of drop table commands
     # We don't bother with "cascade" because as of MySQL
     # 5.1 it is only there to ease porting, it doesn't

+ 3 - 1
src/lib/dhcpsrv/tests/mysql_schema.cc

@@ -122,7 +122,9 @@ void createMySQLSchema() {
     // Execute creation statements.
     for (int i = 0; create_statement[i] != NULL; ++i) {
         ASSERT_EQ(0, mysql_query(mysql, create_statement[i]))
-            << "Failed on statement " << i << ": " << create_statement[i];
+            << "Failed on statement " << i << ": " << create_statement[i]
+            << " error: " << mysql_error(mysql) << " (error code "
+            << mysql_errno(mysql) << ")";
     }
 }
 

+ 4 - 6
src/lib/dhcpsrv/tests/schema_mysql_copy.h

@@ -32,15 +32,13 @@ namespace {
 // Deletion of existing tables.
 
 const char* destroy_statement[] = {
+    // Turning off referential integrity checks ensures tables get dropped
+    "SET SESSION FOREIGN_KEY_CHECKS = 0",
     "DROP TABLE lease4",
     "DROP TABLE lease6",
     "DROP TABLE lease6_types",
     "DROP TABLE lease_hwaddr_source",
     "DROP TABLE schema_version",
-
-    // We need to drop ipv6_reservations before hosts, as it has constrains
-    // that depend on hosts. Therefore hosts table cannot be deleted while
-    // ipv6_reservations exists.
     "DROP TABLE ipv6_reservations",
     "DROP TABLE hosts",
     "DROP TABLE dhcp4_options",
@@ -92,7 +90,7 @@ const char* create_statement[] = {
     "CREATE TABLE lease6_types ("
         "lease_type TINYINT PRIMARY KEY NOT NULL,"
         "name VARCHAR(5)"
-        ")",
+        ") ENGINE = INNODB",
 
     "INSERT INTO lease6_types VALUES (0, \"IA_NA\")",
     "INSERT INTO lease6_types VALUES (1, \"IA_TA\")",
@@ -101,7 +99,7 @@ const char* create_statement[] = {
     "CREATE TABLE schema_version ("
         "version INT PRIMARY KEY NOT NULL,"
         "minor INT"
-        ")",
+        ") ENGINE = INNODB",
 
     "INSERT INTO schema_version VALUES (1, 0)",
     "COMMIT",