alter: rewrite space truncation using alter infrastructure
Truncation of a space is equivalent to recreation of all space indexes with the same definition. The reason why we use a special system space to trigger space truncation (_truncate) is that we don't have transactional DDL while space truncation has to be done atomically. However, apart from the new system space, implementation of truncation entailed a new vylog record (VY_LOG_TRUNCATE_INDEX) and quite a few lines of code to handle it. So why couldn't we just invoke ALTER that would recreate all indexes? To answer this question, one needs to recall that back then vinyl used LSN to identify indexes in vylog. As a result, we couldn't recreate more than one index in one operation - if we did that, they would all have the same LSN and hence wouldn't be distinguishable in vylog. So we had to introduce a special vylog operation (VY_LOG_TRUNCATE_INDEX) that bump the truncation counter of an index instead of just dropping and recreating it. We also had to introduce a pair of new virtual space methods, prepare_truncate and commit_truncate so that we could write this new command to vylog in vinyl. Putting it all together, it becomes obvious why we couldn't reuse ALTER code for space truncation. Fortunately, things have changed since then. Now, vylog identifies indexes by space_id/index_id. That means that now we can simplify space truncation implementation a great deal by - reusing alter_space_do() for space truncation, - dropping space_vtab::prepare_truncate and commit_truncate, - removing truncate_count from space, index, and vylog.
Showing
- src/box/alter.cc 13 additions, 94 deletionssrc/box/alter.cc
- src/box/memtx_space.c 7 additions, 22 deletionssrc/box/memtx_space.c
- src/box/space.h 0 additions, 44 deletionssrc/box/space.h
- src/box/sysview_engine.c 0 additions, 17 deletionssrc/box/sysview_engine.c
- src/box/vinyl.c 12 additions, 148 deletionssrc/box/vinyl.c
- src/box/vy_index.c 2 additions, 23 deletionssrc/box/vy_index.c
- src/box/vy_index.h 0 additions, 22 deletionssrc/box/vy_index.h
- src/box/vy_log.c 3 additions, 53 deletionssrc/box/vy_log.c
- src/box/vy_log.h 11 additions, 18 deletionssrc/box/vy_log.h
Loading
Please register or sign in to comment