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
=== added file 'src/main/java/com/akiban/server/error/DropSequenceNotAllowedException.java'
--- src/main/java/com/akiban/server/error/DropSequenceNotAllowedException.java 1970-01-01 00:00:00 +0000
+++ src/main/java/com/akiban/server/error/DropSequenceNotAllowedException.java 2013-04-17 22:41:30 +0000
@@ -0,0 +1,26 @@
1/**
2 * Copyright (C) 2009-2013 Akiban Technologies, Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
13 *
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17package com.akiban.server.error;
18
19import com.akiban.ais.model.TableName;
20
21public class DropSequenceNotAllowedException extends InvalidOperationException {
22
23 public DropSequenceNotAllowedException(String sequenceName, TableName table) {
24 super(ErrorCode.DROP_SEQUENCE_NOT_ALLOWED, sequenceName, table.getSchemaName(), table.getTableName());
25 }
26}
027
=== modified file 'src/main/java/com/akiban/server/error/ErrorCode.java'
--- src/main/java/com/akiban/server/error/ErrorCode.java 2013-04-15 16:02:52 +0000
+++ src/main/java/com/akiban/server/error/ErrorCode.java 2013-04-17 22:41:30 +0000
@@ -14,7 +14,7 @@
14 * You should have received a copy of the GNU Affero General Public License14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */16 */
1717
18package com.akiban.server.error;18package com.akiban.server.error;
1919
20import org.slf4j.Logger;20import org.slf4j.Logger;
@@ -375,6 +375,7 @@
375 MODEL_BUILDER_ERROR ("50", "026", Importance.DEBUG, ModelBuilderException.class),375 MODEL_BUILDER_ERROR ("50", "026", Importance.DEBUG, ModelBuilderException.class),
376 COLUMN_NOT_GENERATED ("50", "027", Importance.DEBUG, ColumnNotGeneratedException.class),376 COLUMN_NOT_GENERATED ("50", "027", Importance.DEBUG, ColumnNotGeneratedException.class),
377 COLUMN_ALREADY_GENERATED ("50", "028", Importance.DEBUG, ColumnAlreadyGeneratedException.class),377 COLUMN_ALREADY_GENERATED ("50", "028", Importance.DEBUG, ColumnAlreadyGeneratedException.class),
378 DROP_SEQUENCE_NOT_ALLOWED ("50", "029", Importance.DEBUG, DropSequenceNotAllowedException.class),
378379
379 // Class 51 - Internal problems created by user configuration380 // Class 51 - Internal problems created by user configuration
380 STALE_AIS ("51", "001", Importance.TRACE, OldAISException.class),381 STALE_AIS ("51", "001", Importance.TRACE, OldAISException.class),
381382
=== modified file 'src/main/java/com/akiban/server/service/dxl/BasicDDLFunctions.java'
--- src/main/java/com/akiban/server/service/dxl/BasicDDLFunctions.java 2013-04-15 19:20:36 +0000
+++ src/main/java/com/akiban/server/service/dxl/BasicDDLFunctions.java 2013-04-17 22:41:30 +0000
@@ -83,6 +83,7 @@
83import com.akiban.server.api.dml.scan.Cursor;83import com.akiban.server.api.dml.scan.Cursor;
84import com.akiban.server.api.dml.scan.CursorId;84import com.akiban.server.api.dml.scan.CursorId;
85import com.akiban.server.api.dml.scan.ScanRequest;85import com.akiban.server.api.dml.scan.ScanRequest;
86import com.akiban.server.error.DropSequenceNotAllowedException;
86import com.akiban.server.error.ForeignConstraintDDLException;87import com.akiban.server.error.ForeignConstraintDDLException;
87import com.akiban.server.error.InvalidOperationException;88import com.akiban.server.error.InvalidOperationException;
88import com.akiban.server.error.NoSuchGroupException;89import com.akiban.server.error.NoSuchGroupException;
@@ -1300,7 +1301,12 @@
1300 if (sequence == null) {1301 if (sequence == null) {
1301 throw new NoSuchSequenceException (sequenceName);1302 throw new NoSuchSequenceException (sequenceName);
1302 }1303 }
1303 1304
1305 for (UserTable table : getAIS(session).getUserTables().values()) {
1306 if (table.getIdentityColumn() != null && table.getIdentityColumn().getIdentityGenerator().equals(sequence)) {
1307 throw new DropSequenceNotAllowedException(sequence.getSequenceName().getTableName(), table.getName());
1308 }
1309 }
1304 store().deleteSequences(session, Collections.singleton(sequence));1310 store().deleteSequences(session, Collections.singleton(sequence));
1305 schemaManager().dropSequence(session, sequence);1311 schemaManager().dropSequence(session, sequence);
1306 }1312 }
13071313
=== modified file 'src/main/java/com/akiban/sql/aisddl/SequenceDDL.java'
--- src/main/java/com/akiban/sql/aisddl/SequenceDDL.java 2013-03-22 20:05:57 +0000
+++ src/main/java/com/akiban/sql/aisddl/SequenceDDL.java 2013-04-17 22:41:30 +0000
@@ -19,7 +19,9 @@
19import com.akiban.ais.model.AISBuilder;19import com.akiban.ais.model.AISBuilder;
20import com.akiban.ais.model.Sequence;20import com.akiban.ais.model.Sequence;
21import com.akiban.ais.model.TableName;21import com.akiban.ais.model.TableName;
22import com.akiban.ais.model.UserTable;
22import com.akiban.server.api.DDLFunctions;23import com.akiban.server.api.DDLFunctions;
24import com.akiban.server.error.DropSequenceNotAllowedException;
23import com.akiban.server.error.NoSuchSequenceException;25import com.akiban.server.error.NoSuchSequenceException;
24import com.akiban.server.service.session.Session;26import com.akiban.server.service.session.Session;
25import com.akiban.sql.parser.CreateSequenceNode;27import com.akiban.sql.parser.CreateSequenceNode;
2628
=== modified file 'src/main/resources/com/akiban/server/error/error_code.properties'
--- src/main/resources/com/akiban/server/error/error_code.properties 2013-04-15 16:02:52 +0000
+++ src/main/resources/com/akiban/server/error/error_code.properties 2013-04-17 22:41:30 +0000
@@ -251,6 +251,7 @@
251MODEL_BUILDER_ERROR = Error building model for `{0}`.`{1}`: {2}251MODEL_BUILDER_ERROR = Error building model for `{0}`.`{1}`: {2}
252COLUMN_NOT_GENERATED = Column `{0}`.`{1}`.`{2}` is not generated252COLUMN_NOT_GENERATED = Column `{0}`.`{1}`.`{2}` is not generated
253COLUMN_ALREADY_GENERATED = Column `{0}`.`{1}`.`{2}` already generated by sequence `{3}`.`{4}`253COLUMN_ALREADY_GENERATED = Column `{0}`.`{1}`.`{2}` already generated by sequence `{3}`.`{4}`
254DROP_SEQUENCE_NOT_ALLOWED = Sequence `{0}` is in use by table `{1}`.`{2}` and can not be dropped
254#255#
255# Class 51 - Internal problems created by user configuration256# Class 51 - Internal problems created by user configuration
256#257#
257258
=== added file 'src/test/resources/com/akiban/sql/pg/yaml/bugs/test-bug-1167451.yaml'
--- src/test/resources/com/akiban/sql/pg/yaml/bugs/test-bug-1167451.yaml 1970-01-01 00:00:00 +0000
+++ src/test/resources/com/akiban/sql/pg/yaml/bugs/test-bug-1167451.yaml 2013-04-17 22:41:30 +0000
@@ -0,0 +1,14 @@
1---
2- Properties: sys-mysql
3- suppressed: true
4---
5- CreateTable: t_sequence (c1 integer not null generated by default as identity)
6---
7- Statement: insert into t_sequence (c1) values (null)
8---
9- Statement: select * from t_sequence
10- output: [[1]]
11---
12- Statement: drop sequence `test`.`_sequence-122892222` restrict
13- error: [50029]
14...
0\ No newline at end of file15\ No newline at end of file

Subscribers

People subscribed via source and target branches