diff --git a/src/box/alter.cc b/src/box/alter.cc index 7530aff1dd61b31928d50547a2155213cca683d1..04c02a377d4390774dfb0e3c3d01c5805c4cac94 100644 --- a/src/box/alter.cc +++ b/src/box/alter.cc @@ -1422,6 +1422,15 @@ on_replace_dd_truncate(struct trigger * /* trigger */, void *event) 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. */ diff --git a/src/box/errcode.h b/src/box/errcode.h index 8fb1fa8c2659d35484508d9fc6458c12a2e4c498..ce7078b6fc9edb2e134919857ecf7b551096936d 100644 --- a/src/box/errcode.h +++ b/src/box/errcode.h @@ -189,6 +189,7 @@ struct errcode_record { /*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") \ /*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 diff --git a/test/box/misc.result b/test/box/misc.result index cf56fd4750b201663fc02c67673e97758b78c94e..1db87035e1521fac6c623f1a8e802c2c07f7ac7a 100644 --- a/test/box/misc.result +++ b/test/box/misc.result @@ -377,6 +377,7 @@ t; - 'box.error.SYSTEM : 115' - 'box.error.KEY_PART_IS_TOO_LONG : 118' - 'box.error.injection : table: <address> + - 'box.error.TRUNCATE_SYSTEM_SPACE : 137' - 'box.error.VY_QUOTA_TIMEOUT : 135' - 'box.error.USER_MAX : 56' - 'box.error.INVALID_XLOG_TYPE : 125' diff --git a/test/engine/truncate.result b/test/engine/truncate.result index ace1cd2cdd21ab8258f759bece2634c636e4acea..ea8a2c05b73ff030d7094d629dd3d45c42c66db9 100644 --- a/test/engine/truncate.result +++ b/test/engine/truncate.result @@ -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. -- s = box.schema.create_space('test', {engine = engine}) diff --git a/test/engine/truncate.test.lua b/test/engine/truncate.test.lua index 7cef3ba225875c5650c69978dbede1ec614e1b49..65b2a9fc78f0dcafc0552a165b112d62a073310f 100644 --- a/test/engine/truncate.test.lua +++ b/test/engine/truncate.test.lua @@ -27,6 +27,12 @@ box.space.test:truncate() box.space.test:select() 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. --