Uploaded image for project: 'Derby'
  1. Derby
  2. DERBY-6670

Rollback to savepoint allows violation of deferrable constraints

    XMLWordPrintableJSON

    Details

    • Urgency:
      Blocker
    • Issue & fix info:
      Repro attached
    • Bug behavior facts:
      Data corruption

      Description

      The bug is illustrated by the following code snippet:

              Connection c = DriverManager.getConnection("jdbc:derby:memory:db;create=true");
              c.setAutoCommit(false);
              Statement s = c.createStatement();
              s.execute("create table t1(x int primary key initially deferred)");
              s.execute("insert into t1 values 1,1,1,1");
      
              Savepoint sp = c.setSavepoint();
              s.execute("drop table t1");
              c.rollback(sp);
      
              // Since there are four identical rows in T1, this call should have
              // failed because the primary key was violated.
              c.commit();
      
              // Instead, it succeeds, and all four rows are committed, as can
              // be seen here:
              ResultSet rs = s.executeQuery("select * from t1");
              while (rs.next()) {
                  System.out.println(rs.getInt(1));
              }
      
              // Insert yet another row, so that we have five identical rows ...
              s.execute("insert into t1 values 1");
              // ... and now commit complains ...
              c.commit();
      

      With auto-commit off, add duplicates into a deferred primary key. Then set a savepoint, drop the table, and roll back to the savepoint.

      Apparently, when you drop the table, information about any constraint violations seen on that table is lost, and that information is not restored when the drop table operation is undone by the rollback to savepoint.

      So when you commit the transaction after having rolled back the drop operation, no deferred checking of constraints happens, and the duplicates you have inserted are committed.

        Attachments

        1. derby-6670-01-aa-forbidSavepointsWithDeferredConstraints.diff
          9 kB
          Richard N. Hillegas
        2. derby-6670-2-a.diff
          94 kB
          Dag H. Wanvik
        3. derby-6670-2-a.status
          3 kB
          Dag H. Wanvik
        4. derby-6670-2-b.diff
          94 kB
          Dag H. Wanvik
        5. derby-6670-2-b.status
          3 kB
          Dag H. Wanvik
        6. derby-6670-2-c.diff
          104 kB
          Dag H. Wanvik

          Issue Links

            Activity

              People

              • Assignee:
                dagw Dag H. Wanvik
                Reporter:
                knutanders Knut Anders Hatlen
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: