Skip to content
Snippets Groups Projects
Commit 3e1b734b authored by Vladimir Davydov's avatar Vladimir Davydov Committed by Roman Tsisyk
Browse files

alter: disallow truncation of system spaces

It is unsafe, because system spaces use triggers to keep records in sync
with internal objects while space truncation doesn't invoke triggers.

Closes #2523
parent 1f0b74e4
No related branches found
No related tags found
No related merge requests found
...@@ -1422,6 +1422,15 @@ on_replace_dd_truncate(struct trigger * /* trigger */, void *event) ...@@ -1422,6 +1422,15 @@ on_replace_dd_truncate(struct trigger * /* trigger */, void *event)
return; return;
} }
/*
* System spaces use triggers to keep records in sync
* with internal objects. Since space truncation doesn't
* invoke triggers, we don't permit it for system spaces.
*/
if (space_is_system(old_space))
tnt_raise(ClientError, ER_TRUNCATE_SYSTEM_SPACE,
space_name(old_space));
/* /*
* Truncate counter is updated - truncate the space. * Truncate counter is updated - truncate the space.
*/ */
......
...@@ -189,6 +189,7 @@ struct errcode_record { ...@@ -189,6 +189,7 @@ struct errcode_record {
/*134 */_(ER_CHECKPOINT_ROLLBACK, "Can't start a checkpoint while in cascading rollback") \ /*134 */_(ER_CHECKPOINT_ROLLBACK, "Can't start a checkpoint while in cascading rollback") \
/*135 */_(ER_VY_QUOTA_TIMEOUT, "Timed out waiting for Vinyl memory quota") \ /*135 */_(ER_VY_QUOTA_TIMEOUT, "Timed out waiting for Vinyl memory quota") \
/*136 */_(ER_PARTIAL_KEY, "%s index does not support selects via a partial key (expected %u parts, got %u). Please Consider changing index type to TREE.") \ /*136 */_(ER_PARTIAL_KEY, "%s index does not support selects via a partial key (expected %u parts, got %u). Please Consider changing index type to TREE.") \
/*137 */_(ER_TRUNCATE_SYSTEM_SPACE, "Can't truncate a system space, space '%s'") \
/* /*
* !IMPORTANT! Please follow instructions at start of the file * !IMPORTANT! Please follow instructions at start of the file
......
...@@ -377,6 +377,7 @@ t; ...@@ -377,6 +377,7 @@ t;
- 'box.error.SYSTEM : 115' - 'box.error.SYSTEM : 115'
- 'box.error.KEY_PART_IS_TOO_LONG : 118' - 'box.error.KEY_PART_IS_TOO_LONG : 118'
- 'box.error.injection : table: <address> - 'box.error.injection : table: <address>
- 'box.error.TRUNCATE_SYSTEM_SPACE : 137'
- 'box.error.VY_QUOTA_TIMEOUT : 135' - 'box.error.VY_QUOTA_TIMEOUT : 135'
- 'box.error.USER_MAX : 56' - 'box.error.USER_MAX : 56'
- 'box.error.INVALID_XLOG_TYPE : 125' - 'box.error.INVALID_XLOG_TYPE : 125'
......
...@@ -64,6 +64,17 @@ box.space.test:drop() ...@@ -64,6 +64,17 @@ box.space.test:drop()
--- ---
... ...
-- --
-- Check that truncation of system spaces is not permitted.
--
box.space._space:truncate()
---
- error: Can't truncate a system space, space '_space'
...
box.space._index:truncate()
---
- error: Can't truncate a system space, space '_index'
...
--
-- Truncate space with no indexes. -- Truncate space with no indexes.
-- --
s = box.schema.create_space('test', {engine = engine}) s = box.schema.create_space('test', {engine = engine})
......
...@@ -27,6 +27,12 @@ box.space.test:truncate() ...@@ -27,6 +27,12 @@ box.space.test:truncate()
box.space.test:select() box.space.test:select()
box.space.test:drop() box.space.test:drop()
--
-- Check that truncation of system spaces is not permitted.
--
box.space._space:truncate()
box.space._index:truncate()
-- --
-- Truncate space with no indexes. -- Truncate space with no indexes.
-- --
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment