Merge lp:~tjoneslo/akiban-server/fix-bug-1167541 into lp:~akiban-technologies/akiban-server/trunk

Proposed by Thomas Jones-Low
Status: Merged
Approved by: Nathan Williams
Approved revision: 2626
Merged at revision: 2630
Proposed branch: lp:~tjoneslo/akiban-server/fix-bug-1167541
Merge into: lp:~akiban-technologies/akiban-server/trunk
Diff against target: 123 lines (+52/-2)
6 files modified
src/main/java/com/akiban/server/error/DropSequenceNotAllowedException.java (+26/-0)
src/main/java/com/akiban/server/error/ErrorCode.java (+2/-1)
src/main/java/com/akiban/server/service/dxl/BasicDDLFunctions.java (+7/-1)
src/main/java/com/akiban/sql/aisddl/SequenceDDL.java (+2/-0)
src/main/resources/com/akiban/server/error/error_code.properties (+1/-0)
src/test/resources/com/akiban/sql/pg/yaml/bugs/test-bug-1167451.yaml (+14/-0)
To merge this branch: bzr merge lp:~tjoneslo/akiban-server/fix-bug-1167541
Reviewer Review Type Date Requested Status
Nathan Williams Approve
Thomas Jones-Low Needs Resubmitting
Review via email: mp+159496@code.launchpad.net

Description of the change

Fix bug 1167451 - Have the SequenceDDL process check if the sequence in question is begin used as a identity column for a table and reject the drop with an error message.

To post a comment you must log in.
Revision history for this message
Thomas Jones-Low (tjoneslo) wrote :

Now with fewer merge conflicts.

review: Needs Resubmitting
Revision history for this message
Nathan Williams (nwilliams) wrote :

Would you be opposed to moving the usage check into BasicDDLFunctions? That way other consumers get in on the action and other things (transaction, locking) come along for free.

review: Needs Fixing
Revision history for this message
Thomas Jones-Low (tjoneslo) wrote :

Not at all, moved check as requested.

review: Needs Resubmitting
Revision history for this message
Thomas Jones-Low (tjoneslo) wrote :

One thing I thought about doing, but didn't to keep this simple, was to have the Sequence contain a link back to the UserTable if the Sequence was being used as a identity column for the table. Makes the check simpler at the expense of maintaining an extra field in the Sequence.

Revision history for this message
Nathan Williams (nwilliams) wrote :

Thanks for the tweak. Looks good to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'src/main/java/com/akiban/server/error/DropSequenceNotAllowedException.java'
2--- src/main/java/com/akiban/server/error/DropSequenceNotAllowedException.java 1970-01-01 00:00:00 +0000
3+++ src/main/java/com/akiban/server/error/DropSequenceNotAllowedException.java 2013-04-17 22:41:30 +0000
4@@ -0,0 +1,26 @@
5+/**
6+ * Copyright (C) 2009-2013 Akiban Technologies, Inc.
7+ *
8+ * This program is free software: you can redistribute it and/or modify
9+ * it under the terms of the GNU Affero General Public License as published by
10+ * the Free Software Foundation, either version 3 of the License, or
11+ * (at your option) any later version.
12+ *
13+ * This program is distributed in the hope that it will be useful,
14+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+ * GNU Affero General Public License for more details.
17+ *
18+ * You should have received a copy of the GNU Affero General Public License
19+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
20+ */
21+package com.akiban.server.error;
22+
23+import com.akiban.ais.model.TableName;
24+
25+public class DropSequenceNotAllowedException extends InvalidOperationException {
26+
27+ public DropSequenceNotAllowedException(String sequenceName, TableName table) {
28+ super(ErrorCode.DROP_SEQUENCE_NOT_ALLOWED, sequenceName, table.getSchemaName(), table.getTableName());
29+ }
30+}
31
32=== modified file 'src/main/java/com/akiban/server/error/ErrorCode.java'
33--- src/main/java/com/akiban/server/error/ErrorCode.java 2013-04-15 16:02:52 +0000
34+++ src/main/java/com/akiban/server/error/ErrorCode.java 2013-04-17 22:41:30 +0000
35@@ -14,7 +14,7 @@
36 * You should have received a copy of the GNU Affero General Public License
37 * along with this program. If not, see <http://www.gnu.org/licenses/>.
38 */
39-
40+
41 package com.akiban.server.error;
42
43 import org.slf4j.Logger;
44@@ -375,6 +375,7 @@
45 MODEL_BUILDER_ERROR ("50", "026", Importance.DEBUG, ModelBuilderException.class),
46 COLUMN_NOT_GENERATED ("50", "027", Importance.DEBUG, ColumnNotGeneratedException.class),
47 COLUMN_ALREADY_GENERATED ("50", "028", Importance.DEBUG, ColumnAlreadyGeneratedException.class),
48+ DROP_SEQUENCE_NOT_ALLOWED ("50", "029", Importance.DEBUG, DropSequenceNotAllowedException.class),
49
50 // Class 51 - Internal problems created by user configuration
51 STALE_AIS ("51", "001", Importance.TRACE, OldAISException.class),
52
53=== modified file 'src/main/java/com/akiban/server/service/dxl/BasicDDLFunctions.java'
54--- src/main/java/com/akiban/server/service/dxl/BasicDDLFunctions.java 2013-04-15 19:20:36 +0000
55+++ src/main/java/com/akiban/server/service/dxl/BasicDDLFunctions.java 2013-04-17 22:41:30 +0000
56@@ -83,6 +83,7 @@
57 import com.akiban.server.api.dml.scan.Cursor;
58 import com.akiban.server.api.dml.scan.CursorId;
59 import com.akiban.server.api.dml.scan.ScanRequest;
60+import com.akiban.server.error.DropSequenceNotAllowedException;
61 import com.akiban.server.error.ForeignConstraintDDLException;
62 import com.akiban.server.error.InvalidOperationException;
63 import com.akiban.server.error.NoSuchGroupException;
64@@ -1300,7 +1301,12 @@
65 if (sequence == null) {
66 throw new NoSuchSequenceException (sequenceName);
67 }
68-
69+
70+ for (UserTable table : getAIS(session).getUserTables().values()) {
71+ if (table.getIdentityColumn() != null && table.getIdentityColumn().getIdentityGenerator().equals(sequence)) {
72+ throw new DropSequenceNotAllowedException(sequence.getSequenceName().getTableName(), table.getName());
73+ }
74+ }
75 store().deleteSequences(session, Collections.singleton(sequence));
76 schemaManager().dropSequence(session, sequence);
77 }
78
79=== modified file 'src/main/java/com/akiban/sql/aisddl/SequenceDDL.java'
80--- src/main/java/com/akiban/sql/aisddl/SequenceDDL.java 2013-03-22 20:05:57 +0000
81+++ src/main/java/com/akiban/sql/aisddl/SequenceDDL.java 2013-04-17 22:41:30 +0000
82@@ -19,7 +19,9 @@
83 import com.akiban.ais.model.AISBuilder;
84 import com.akiban.ais.model.Sequence;
85 import com.akiban.ais.model.TableName;
86+import com.akiban.ais.model.UserTable;
87 import com.akiban.server.api.DDLFunctions;
88+import com.akiban.server.error.DropSequenceNotAllowedException;
89 import com.akiban.server.error.NoSuchSequenceException;
90 import com.akiban.server.service.session.Session;
91 import com.akiban.sql.parser.CreateSequenceNode;
92
93=== modified file 'src/main/resources/com/akiban/server/error/error_code.properties'
94--- src/main/resources/com/akiban/server/error/error_code.properties 2013-04-15 16:02:52 +0000
95+++ src/main/resources/com/akiban/server/error/error_code.properties 2013-04-17 22:41:30 +0000
96@@ -251,6 +251,7 @@
97 MODEL_BUILDER_ERROR = Error building model for `{0}`.`{1}`: {2}
98 COLUMN_NOT_GENERATED = Column `{0}`.`{1}`.`{2}` is not generated
99 COLUMN_ALREADY_GENERATED = Column `{0}`.`{1}`.`{2}` already generated by sequence `{3}`.`{4}`
100+DROP_SEQUENCE_NOT_ALLOWED = Sequence `{0}` is in use by table `{1}`.`{2}` and can not be dropped
101 #
102 # Class 51 - Internal problems created by user configuration
103 #
104
105=== added file 'src/test/resources/com/akiban/sql/pg/yaml/bugs/test-bug-1167451.yaml'
106--- src/test/resources/com/akiban/sql/pg/yaml/bugs/test-bug-1167451.yaml 1970-01-01 00:00:00 +0000
107+++ src/test/resources/com/akiban/sql/pg/yaml/bugs/test-bug-1167451.yaml 2013-04-17 22:41:30 +0000
108@@ -0,0 +1,14 @@
109+---
110+- Properties: sys-mysql
111+- suppressed: true
112+---
113+- CreateTable: t_sequence (c1 integer not null generated by default as identity)
114+---
115+- Statement: insert into t_sequence (c1) values (null)
116+---
117+- Statement: select * from t_sequence
118+- output: [[1]]
119+---
120+- Statement: drop sequence `test`.`_sequence-122892222` restrict
121+- error: [50029]
122+...
123\ No newline at end of file

Subscribers

People subscribed via source and target branches