]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#444,!229] Switched back to second precision in MySQL CB.
authorMarcin Siodelski <marcin@isc.org>
Thu, 7 Feb 2019 11:59:44 +0000 (12:59 +0100)
committerMarcin Siodelski <marcin@isc.org>
Fri, 8 Feb 2019 08:46:21 +0000 (09:46 +0100)
src/lib/cc/stamped_element.cc
src/lib/mysql/mysql_binding.cc
src/lib/mysql/tests/mysql_binding_unittest.cc
src/lib/mysql/tests/mysql_connection_unittest.cc
src/share/database/scripts/mysql/dhcpdb_create.mysql
src/share/database/scripts/mysql/upgrade_7.0_to_8.0.sh.in

index c1ce7a3924f4580e622a22f5254244a3c6bee0e9..32bf59588ea0cb9f15d0cfe135dd20068aed8d62 100644 (file)
@@ -10,12 +10,16 @@ namespace isc {
 namespace data {
 
 StampedElement::StampedElement()
-    : timestamp_(boost::posix_time::microsec_clock::local_time()) {
+    /// @todo Change it to microsec_clock once we transition to subsecond
+    /// precision.
+    : timestamp_(boost::posix_time::second_clock::local_time()) {
 }
 
 void
 StampedElement::updateModificationTime() {
-    setModificationTime(boost::posix_time::microsec_clock::local_time());
+    /// @todo Change it to microsec_clock once we transition to subsecond
+    /// precision.
+    setModificationTime(boost::posix_time::second_clock::local_time());
 }
 
 } // end of namespace isc::data
index ff23a290c3326ac5801a5736876dd4b98f5bea0f..737623011ffd2b47bd2236ce7628862b5e79906e 100644 (file)
@@ -158,8 +158,11 @@ MySqlBinding::convertToDatabaseTime(const boost::posix_time::ptime& input_time,
     output_time.hour = input_time.time_of_day().hours();
     output_time.minute = input_time.time_of_day().minutes();
     output_time.second = input_time.time_of_day().seconds();
-    output_time.second_part = input_time.time_of_day().fractional_seconds()
-        *1000000/time_duration::ticks_per_second();
+    /// @todo Use fractional seconds instead of 0 when minimum supported
+    /// MySQL version has it.
+    output_time.second_part = 0;
+/*    output_time.second_part = input_time.time_of_day().fractional_seconds()
+        *1000000/time_duration::ticks_per_second(); */
     output_time.neg = my_bool(0);
 }
 
@@ -218,7 +221,10 @@ MySqlBinding::convertFromDatabaseTime(const MYSQL_TIME& expire,
 
 ptime
 MySqlBinding::convertFromDatabaseTime(const MYSQL_TIME& database_time) {
-    long fractional = database_time.second_part * time_duration::ticks_per_second()/1000000;
+    /// @todo Use fractional seconds instead of 0 when minimum supported
+    /// MySQL version has it.
+    long fractional = 0;
+    // long fractional = database_time.second_part * time_duration::ticks_per_second()/1000000;
     ptime pt(boost::gregorian::date(database_time.year,
                                     boost::gregorian::greg_month(database_time.month),
                                     database_time.day),
index 55f63b0deba0ae20ae33571673aa1c29c0ef33d3..776b0ef4326f5c52a3f1fed2009075dc7d9532a0 100644 (file)
@@ -96,7 +96,9 @@ TEST(MySqlBindingTest, defaultTimestamp) {
 
 // This test verifies that the binding preserves fractional seconds in
 // millisecond precision.
-TEST(MySqlBindingTest, millisecondTimestampPrecision) {
+/// @todo This test is disabled until we decide that the minimum
+/// supported MySQL version has a fractional seconds precision.
+TEST(MySqlBindingTest, DISABLED_millisecondTimestampPrecision) {
     // Set timestamp of 2019-01-28 01:12:10.123
 
     // Fractional part depends on the clock resolution.
index 3299698748397a78040b2ce33b02354e32289b46..6d54857b6b5bea234679dd0795a0a89eda5f1d4a 100644 (file)
@@ -99,13 +99,19 @@ public:
     /// The new table contains 6 columns of various data types. All of
     /// the columns accept null values.
     void createTestTable() {
+        /// @todo TIMESTAMP value lacks sub second precision because
+        /// it is supported since MySQL 5.6.4, which is still not a
+        /// default version on some OSes. When the subsecond precision
+        /// is available on all OSes that Kea supports, the timestamp
+        /// column should be turned to TIMESTAMP(6). Until then, it
+        /// must remain TIMESTAMP.
         runQuery("CREATE TABLE IF NOT EXISTS mysql_connection_test ("
                  "tinyint_value TINYINT NULL,"
                  "int_value INT NULL,"
                  "bigint_value BIGINT NULL,"
                  "string_value TEXT NULL,"
                  "blob_value BLOB NULL,"
-                 "timestamp_value TIMESTAMP(6) NULL"
+                 "timestamp_value TIMESTAMP NULL"
                  ")");
     }
 
@@ -236,7 +242,9 @@ TEST_F(MySqlConnectionTest, select) {
         MySqlBinding::createInteger<int64_t>(-4096),
         MySqlBinding::createString("shellfish"),
         MySqlBinding::createBlob(blob.begin(), blob.end()),
-        MySqlBinding::createTimestamp(boost::posix_time::microsec_clock::local_time())
+        /// @todo Change it to microsec_clock once we transition to subsecond
+        /// precision.
+        MySqlBinding::createTimestamp(boost::posix_time::second_clock::local_time())
     };
 
     testInsertSelect(in_bindings);
@@ -252,7 +260,9 @@ TEST_F(MySqlConnectionTest, selectNullInteger) {
         MySqlBinding::createInteger<int64_t>(-4096),
         MySqlBinding::createString("shellfish"),
         MySqlBinding::createBlob(blob.begin(), blob.end()),
-        MySqlBinding::createTimestamp(boost::posix_time::microsec_clock::local_time())
+        /// @todo Change it to microsec_clock once we transition to subsecond
+        /// precision.
+        MySqlBinding::createTimestamp(boost::posix_time::second_clock::local_time())
     };
 
     testInsertSelect(in_bindings);
@@ -269,7 +279,9 @@ TEST_F(MySqlConnectionTest, selectNullString) {
         MySqlBinding::createInteger<int64_t>(-4096),
         MySqlBinding::createNull(),
         MySqlBinding::createBlob(blob.begin(), blob.end()),
-        MySqlBinding::createTimestamp(boost::posix_time::microsec_clock::local_time())
+        /// @todo Change it to microsec_clock once we transition to subsecond
+        /// precision.
+        MySqlBinding::createTimestamp(boost::posix_time::second_clock::local_time())
     };
 
     testInsertSelect(in_bindings);
@@ -284,7 +296,9 @@ TEST_F(MySqlConnectionTest, selectNullBlob) {
         MySqlBinding::createInteger<int64_t>(-4096),
         MySqlBinding::createString("shellfish"),
         MySqlBinding::createNull(),
-        MySqlBinding::createTimestamp(boost::posix_time::microsec_clock::local_time())
+        /// @todo Change it to microsec_clock once we transition to subsecond
+        /// precision.
+        MySqlBinding::createTimestamp(boost::posix_time::second_clock::local_time())
     };
 
     testInsertSelect(in_bindings);
@@ -315,7 +329,9 @@ TEST_F(MySqlConnectionTest, selectEmptyStringBlob) {
         MySqlBinding::createInteger<int64_t>(-4096),
         MySqlBinding::createString(""),
         MySqlBinding::createBlob(blob.begin(), blob.end()),
-        MySqlBinding::createTimestamp(boost::posix_time::microsec_clock::local_time())
+        /// @todo Change it to microsec_clock once we transition to subsecond
+        /// precision.
+        MySqlBinding::createTimestamp(boost::posix_time::second_clock::local_time())
     };
 
     testInsertSelect(in_bindings);
index 5fb00b5021ca0799bb8356ef9fa0fa988e87e49b..eacd182f2a45e986fb7b25c462445905c02259d9 100644 (file)
@@ -1334,91 +1334,13 @@ SET version = '7', minor = '0';
 
 # This line concludes database upgrade to version 7.0.
 
--- -----------------------------------------------------
--- Modify timestamps in the Configuration Backend
--- specific tables to use fractional seconds with
--- 6 decimal places precision.
--- -----------------------------------------------------
-
-ALTER TABLE dhcp4_server
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp4_audit
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp4_global_parameter
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp4_global_parameter_server
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp4_option_def
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp4_option_def_server
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp4_shared_network
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp4_shared_network_server
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp4_subnet
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp4_pool
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp4_subnet_server
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
 
 ALTER TABLE dhcp4_options
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL
-    DEFAULT CURRENT_TIMESTAMP(6);
-
-ALTER TABLE dhcp4_options_server
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp6_server
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp6_audit
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp6_global_parameter
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp6_global_parameter_server
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp6_option_def
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp6_option_def_server
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp6_shared_network
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp6_shared_network_server
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp6_subnet
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp6_pool
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp6_subnet_server
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
+        MODIFY COLUMN modification_ts TIMESTAMP NOT NULL
+    DEFAULT CURRENT_TIMESTAMP;
 ALTER TABLE dhcp6_options
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL
-    DEFAULT CURRENT_TIMESTAMP(6);
-
-ALTER TABLE dhcp6_options_server
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
+        MODIFY COLUMN modification_ts TIMESTAMP NOT NULL
+    DEFAULT CURRENT_TIMESTAMP;
 
 -- -----------------------------------------------------
 -- Make sure that constraints on the 7.0 schema tables
@@ -1522,7 +1444,7 @@ ALTER TABLE dhcp6_options_server
 -- -----------------------------------------------------
 CREATE TABLE IF NOT EXISTS dhcp4_audit_revision (
     id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
-    modification_ts TIMESTAMP(6) NOT NULL,
+    modification_ts TIMESTAMP NOT NULL,
     log_message TEXT,
     server_id BIGINT(10) UNSIGNED,
     PRIMARY KEY (id),
@@ -1579,7 +1501,7 @@ ALTER TABLE dhcp4_audit
 -- -----------------------------------------------------
 DROP PROCEDURE IF EXISTS createAuditRevisionDHCP4;
 DELIMITER $$
-CREATE PROCEDURE createAuditRevisionDHCP4(IN audit_ts TIMESTAMP(6),
+CREATE PROCEDURE createAuditRevisionDHCP4(IN audit_ts TIMESTAMP,
                                           IN server_tag VARCHAR(256),
                                           IN audit_log_message TEXT,
                                           IN cascade_transaction TINYINT(1))
index d43cc5fab972bd6c9660d5a053a8a3aad68d4163..3a3446fd6e13bc0a4ed1f6c73d643e822f7803c7 100644 (file)
@@ -17,91 +17,14 @@ fi
 
 mysql "$@" <<EOF
 
--- -----------------------------------------------------
--- Modify timestamps in the Configuration Backend
--- specific tables to use fractional seconds with
--- 6 decimal places precision.
--- -----------------------------------------------------
-
-ALTER TABLE dhcp4_server
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp4_audit
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp4_global_parameter
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp4_global_parameter_server
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp4_option_def
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp4_option_def_server
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp4_shared_network
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp4_shared_network_server
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp4_subnet
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp4_pool
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp4_subnet_server
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
 
 ALTER TABLE dhcp4_options
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL
-    DEFAULT CURRENT_TIMESTAMP(6);
-
-ALTER TABLE dhcp4_options_server
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp6_server
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp6_audit
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp6_global_parameter
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp6_global_parameter_server
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp6_option_def
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp6_option_def_server
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp6_shared_network
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp6_shared_network_server
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp6_subnet
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp6_pool
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
-
-ALTER TABLE dhcp6_subnet_server
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
+    MODIFY COLUMN modification_ts TIMESTAMP NOT NULL
+    DEFAULT CURRENT_TIMESTAMP;
 
 ALTER TABLE dhcp6_options
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL
-    DEFAULT CURRENT_TIMESTAMP(6);
-
-ALTER TABLE dhcp6_options_server
-    MODIFY COLUMN modification_ts TIMESTAMP(6) NOT NULL;
+    MODIFY COLUMN modification_ts TIMESTAMP NOT NULL
+    DEFAULT CURRENT_TIMESTAMP;
 
 -- -----------------------------------------------------
 -- Make sure that constraints on the 7.0 schema tables
@@ -205,7 +128,7 @@ ALTER TABLE dhcp6_options_server
 -- -----------------------------------------------------
 CREATE TABLE IF NOT EXISTS dhcp4_audit_revision (
     id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
-    modification_ts TIMESTAMP(6) NOT NULL,
+    modification_ts TIMESTAMP NOT NULL,
     log_message TEXT,
     server_id BIGINT(10) UNSIGNED,
     PRIMARY KEY (id),
@@ -262,7 +185,7 @@ ALTER TABLE dhcp4_audit
 -- -----------------------------------------------------
 DROP PROCEDURE IF EXISTS createAuditRevisionDHCP4;
 DELIMITER $$
-CREATE PROCEDURE createAuditRevisionDHCP4(IN audit_ts TIMESTAMP(6),
+CREATE PROCEDURE createAuditRevisionDHCP4(IN audit_ts TIMESTAMP,
                                           IN server_tag VARCHAR(256),
                                           IN audit_log_message TEXT,
                                           IN cascade_transaction TINYINT(1))