BIND 10 trac1330, updated. 132e0b02edf9a0cebccd64a183eb56839f42606f [1330] Make "diff iterator" exceptions subclasses of DataSourceError

BIND 10 source code commits bind10-changes at lists.isc.org
Thu Nov 10 18:54:20 UTC 2011


The branch, trac1330 has been updated
       via  132e0b02edf9a0cebccd64a183eb56839f42606f (commit)
       via  2aac7b891f4ee43fa29bbd41ee3bd48c4a849010 (commit)
      from  f94f5bc089b09a77b34138bbf19ea71921a7950d (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 132e0b02edf9a0cebccd64a183eb56839f42606f
Author: Stephen Morris <stephen at isc.org>
Date:   Thu Nov 10 18:42:27 2011 +0000

    [1330] Make "diff iterator" exceptions subclasses of DataSourceError

commit 2aac7b891f4ee43fa29bbd41ee3bd48c4a849010
Author: Stephen Morris <stephen at isc.org>
Date:   Thu Nov 10 15:48:08 2011 +0000

    [1330] Update after review
    
    Resolved confusion over "operation" values for adding and deleting
    records.  Added ORDER BY clause to SQL statement and removed
    redundant variable declaration.

-----------------------------------------------------------------------

Summary of changes:
 src/lib/datasrc/sqlite3_accessor.cc            |   20 +++++++-----
 src/lib/datasrc/sqlite3_accessor.h             |   17 +++++-----
 src/lib/datasrc/tests/testdata/diffs.sqlite3   |  Bin 16384 -> 16384 bytes
 src/lib/datasrc/tests/testdata/diffs_table.sql |   38 ++++++++++++------------
 4 files changed, 40 insertions(+), 35 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/sqlite3_accessor.cc b/src/lib/datasrc/sqlite3_accessor.cc
index 0149587..42ad53f 100644
--- a/src/lib/datasrc/sqlite3_accessor.cc
+++ b/src/lib/datasrc/sqlite3_accessor.cc
@@ -23,6 +23,7 @@
 #include <datasrc/logger.h>
 #include <datasrc/data_source.h>
 #include <datasrc/factory.h>
+#include <datasrc/database.h>
 #include <util/filename.h>
 
 using namespace std;
@@ -96,16 +97,17 @@ const char* const text_statements[NUM_STATEMENTS] = {
     // Two statements to select the lowest ID and highest ID in a set of
     // differences.
     "SELECT id FROM diffs "     // LOW_DIFF_ID
-        "WHERE zone_id=?1 AND version=?2 and OPERATION=0 "
+        "WHERE zone_id=?1 AND version=?2 and OPERATION=?3 "
         "ORDER BY id ASC LIMIT 1",
     "SELECT id FROM diffs "     // HIGH_DIFF_ID
-        "WHERE zone_id=?1 AND version=?2 and OPERATION=1 "
+        "WHERE zone_id=?1 AND version=?2 and OPERATION=?3 "
         "ORDER BY id DESC LIMIT 1",
 
     // In the next statement, note the redundant ID.  This is to ensure
     // that the columns match the column IDs passed to the iterator
     "SELECT rrtype, ttl, id, rdata, name FROM diffs "   // DIFF_RECS
-        "WHERE zone_id=?1 AND id>=?2 and id<=?3"
+        "WHERE zone_id=?1 AND id>=?2 and id<=?3 "
+        "ORDER BY id ASC"
 };
 
 struct SQLite3Parameters {
@@ -622,8 +624,8 @@ public:
         last_status_(SQLITE_ROW)
     {
         try {
-            int low_id = findIndex(LOW_DIFF_ID, zone_id, start);
-            int high_id = findIndex(HIGH_DIFF_ID, zone_id, end);
+            int low_id = findIndex(LOW_DIFF_ID, zone_id, start, DIFF_DELETE);
+            int high_id = findIndex(HIGH_DIFF_ID, zone_id, end, DIFF_ADD);
 
             // Prepare the statement that will return data values
             reset(DIFF_RECS);
@@ -743,7 +745,7 @@ private:
 
             // Got some data, extract the value
             result = sqlite3_column_int(stmt, 0);
-            int rc = sqlite3_step(stmt);
+            rc = sqlite3_step(stmt);
             if (rc == SQLITE_DONE) {
 
                 // All OK, exit with the value.
@@ -777,6 +779,7 @@ private:
     /// \param stmt_id Index of the prepared statement to execute
     /// \param zone_id ID of the zone for which the index is being sought
     /// \param serial Zone serial number for which an index is being sought.
+    /// \param diff Code to delete record additions or deletions
     ///
     /// \return int ID of the row in the difss table corresponding to the
     ///         statement.
@@ -785,19 +788,20 @@ private:
     ///            was expected.
     /// \exception NoSuchSerial Serial number not found.
     /// \exception NoDiffsData No data for this zone found in diffs table
-    int findIndex(StatementID stindex, int zone_id, uint32_t serial) {
+    int findIndex(StatementID stindex, int zone_id, uint32_t serial, int diff) {
 
         // Set up the statement
         reset(stindex);
         bindInt(stindex, 1, zone_id);
         bindInt(stindex, 2, serial);
+        bindInt(stindex, 3, diff);
 
         // Execute the statement
         int result = -1;
         try {
             result = getSingleValue(stindex);
 
-        } catch (TooLittleData) {
+        } catch (const TooLittleData&) {
 
             // No data returned but the SQL query succeeded.  Only possibility
             // is that there is no entry in the differences table for the given
diff --git a/src/lib/datasrc/sqlite3_accessor.h b/src/lib/datasrc/sqlite3_accessor.h
index 79078d3..be998fa 100644
--- a/src/lib/datasrc/sqlite3_accessor.h
+++ b/src/lib/datasrc/sqlite3_accessor.h
@@ -17,6 +17,7 @@
 #define __DATASRC_SQLITE3_ACCESSOR_H
 
 #include <datasrc/database.h>
+#include <datasrc/data_source.h>
 
 #include <exceptions/exceptions.h>
 
@@ -40,10 +41,10 @@ namespace datasrc {
  * It might mean corrupt database file, invalid request or that something is
  * rotten in the library.
  */
-class SQLite3Error : public Exception {
+class SQLite3Error : public DataSourceError {
 public:
     SQLite3Error(const char* file, size_t line, const char* what) :
-        isc::Exception(file, line, what) {}
+        DataSourceError(file, line, what) {}
 };
 
 /**
@@ -52,10 +53,10 @@ public:
  * Thrown if a query expecting a certain number of rows back returned too
  * many rows.
  */
-class TooMuchData : public Exception {
+class TooMuchData : public DataSourceError {
 public:
     TooMuchData(const char* file, size_t line, const char* what) :
-        isc::Exception(file, line, what) {}
+        DataSourceError(file, line, what) {}
 };
 
 /**
@@ -64,10 +65,10 @@ public:
  * Thrown if a query expecting a certain number of rows back returned too
  * few rows (including none).
  */
-class TooLittleData : public Exception {
+class TooLittleData : public DataSourceError {
 public:
     TooLittleData(const char* file, size_t line, const char* what) :
-        isc::Exception(file, line, what) {}
+        DataSourceError(file, line, what) {}
 };
 
 /**
@@ -76,10 +77,10 @@ public:
  * Thrown if either the zone/start version or zone/end version combination
  * does not exist in the differences table.
  */
-class NoSuchSerial : public Exception {
+class NoSuchSerial : public DataSourceError {
 public:
     NoSuchSerial(const char* file, size_t line, const char* what) :
-        isc::Exception(file, line, what) {}
+        DataSourceError(file, line, what) {}
 };
 
 
diff --git a/src/lib/datasrc/tests/testdata/diffs.sqlite3 b/src/lib/datasrc/tests/testdata/diffs.sqlite3
index d3c9b3b..3820563 100644
Binary files a/src/lib/datasrc/tests/testdata/diffs.sqlite3 and b/src/lib/datasrc/tests/testdata/diffs.sqlite3 differ
diff --git a/src/lib/datasrc/tests/testdata/diffs_table.sql b/src/lib/datasrc/tests/testdata/diffs_table.sql
index 336d79a..0e05207 100644
--- a/src/lib/datasrc/tests/testdata/diffs_table.sql
+++ b/src/lib/datasrc/tests/testdata/diffs_table.sql
@@ -45,77 +45,77 @@ CREATE TABLE diffs (id INTEGER PRIMARY KEY,
 -- Change from 4294967280 (0xfffffff0) to 1230 to show serial rollover
 -- Update one record in the zone.
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
-    VALUES(1, 4294967280,  0, "example.org.", "SOA", 3600,
+    VALUES(1, 4294967280,  1, "example.org.", "SOA", 3600,
            "ns1.example.org. admin.example.org. 4294967280 3600 1800 2419200 7200");
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
-    VALUES(1, 4294967280, 0, "www.example.org.", "A", 3600, "192.0.2.31");
+    VALUES(1, 4294967280, 1, "www.example.org.", "A", 3600, "192.0.2.31");
 
 -- Records added in version 1230 of the zone
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
-    VALUES(1, 1230, 1, "example.org.", "SOA", 1800,
+    VALUES(1, 1230, 0, "example.org.", "SOA", 1800,
            "ns1.example.org. admin.example.org. 1230 3600 1800 2419200 7200");
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
-    VALUES(1, 1230, 1, "www.example.org.", "A", 3600, "192.0.2.21");
+    VALUES(1, 1230, 0, "www.example.org.", "A", 3600, "192.0.2.21");
 
 -- Change 1230 to 1231: Change change a parameter of the SOA record
 -- Records removed from version 1230 of the zone
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
-    VALUES(1, 1230, 0, "example.org.", "SOA", 1800,
+    VALUES(1, 1230, 1, "example.org.", "SOA", 1800,
            "ns1.example.org. admin.example.org. 1230 3600 1800 2419200 7200");
 
 -- Records added in version 1231 of the zone
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
-    VALUES(1, 1231, 1, "example.org.", "SOA", 3600,
+    VALUES(1, 1231, 0, "example.org.", "SOA", 3600,
            "ns1.example.org. admin.example.org. 1231 3600 1800 2419200 7200");
 
 
 -- Change 1231 to 1232: Remove one record, don't add anything.
 -- Records removed from version 1231 of the zone
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
-    VALUES(1, 1231, 0, "example.org.", "SOA", 3600,
+    VALUES(1, 1231, 1, "example.org.", "SOA", 3600,
            "ns1.example.org. admin.example.org. 1231 3600 1800 2419200 7200");
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
-    VALUES(1, 1231, 0, "unused.example.org.", "A", 3600, "192.0.2.102");
+    VALUES(1, 1231, 1, "unused.example.org.", "A", 3600, "192.0.2.102");
 
 -- Records added in version 1232 of the zone
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
-    VALUES(1, 1232, 1, "example.org.", "SOA", 3600,
+    VALUES(1, 1232, 0, "example.org.", "SOA", 3600,
            "ns1.example.org. admin.example.org. 1232 3600 1800 2419200 7200");
 
 -- Change 1232 to 1233: Add two, don't remove anything.
 -- Records removed from version 1232 of the zone
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
-    VALUES(1, 1232, 0, "example.org.", "SOA", 3600,
+    VALUES(1, 1232, 1, "example.org.", "SOA", 3600,
            "ns1.example.org. admin.example.org. 1232 3600 1800 2419200 7200");
 
 -- Records added in version 1233 of the zone
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
-    VALUES(1, 1233, 1, "example.org.", "SOA", 3600,
+    VALUES(1, 1233, 0, "example.org.", "SOA", 3600,
            "ns1.example.org. admin.example.org. 1233 3600 1800 2419200 7200");
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
-    VALUES(1, 1233, 1, "sub.example.org.", "NS", 3600, "ns.sub.example.org.");
+    VALUES(1, 1233, 0, "sub.example.org.", "NS", 3600, "ns.sub.example.org.");
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
-    VALUES(1, 1233, 1, "ns.sub.example.org.", "A", 3600, "192.0.2.101");
+    VALUES(1, 1233, 0, "ns.sub.example.org.", "A", 3600, "192.0.2.101");
 
 
 -- Change 1233 to 1234: change addresses of two A records
 -- Records removed from version 1233 of the zone
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
-    VALUES(1, 1233, 0, "example.org.", "SOA", 3600,
+    VALUES(1, 1233, 1, "example.org.", "SOA", 3600,
            "ns1.example.org. admin.example.org. 1233 3600 1800 2419200 7200");
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
-    VALUES(1, 1233, 0, "www.example.org.", "A", 3600, "192.0.2.21");
+    VALUES(1, 1233, 1, "www.example.org.", "A", 3600, "192.0.2.21");
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
-    VALUES(1, 1233, 0, "mail.example.org.", "A", 3600, "192.0.2.210");
+    VALUES(1, 1233, 1, "mail.example.org.", "A", 3600, "192.0.2.210");
 
 -- Records added in version 1234 of the zone
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
-    VALUES(1, 1234, 1, "example.org.", "SOA", 3600,
+    VALUES(1, 1234, 0, "example.org.", "SOA", 3600,
            "ns1.example.org. admin.example.org. 1234 3600 1800 2419200 7200");
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
-    VALUES(1, 1234, 1, "www.example.org.", "A", 3600, "192.0.2.1");
+    VALUES(1, 1234, 0, "www.example.org.", "A", 3600, "192.0.2.1");
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
-    VALUES(1, 1234, 1, "mail.example.org.", "A", 3600, "192.0.2.10");
+    VALUES(1, 1234, 0, "mail.example.org.", "A", 3600, "192.0.2.10");
 
 -- Finally, update the zone_id in the diffs table with what is actually
 -- in the zone table.




More information about the bind10-changes mailing list