iproto: generate iproto_type_strs from IPROTO_TYPES
Currently, we fill iproto_type_strs only for command codes exported to box.stat while for the rest of command codes we have a switch-case in the iproto_type_name function. This is ugly and error-prone because we can easily forget to update iproto_type_name when we add a new command code. Let's generate iproto_type_strs automatically just like we generate iproto_key_strs. There are a few things that should be noted here: - We don't generate strings for IPROTO_TYPE_ERROR and IPROTO_UNKNOWN because the former has a big code while the latter has a negative code. The only place where we need the strings is exporting IPROTO constants to Lua so now we just export these special codes explicitly there. - We don't generate strings for IPROTO codes reserved for vinyl because they aren't exported to Lua and use a different naming convention. As before, we have a switch-case in iproto_type_name for them. - We remove IPROTO_RESERVED_TYPE_STAT_MAX because it isn't a reserved code. Instead we define IPROTO_TYPE_STAT_MAX explicitly in the iproto_type enum as IPROTO_ROLLBACK + 1. This allows us to remove the condition that skips "RESERVED" constants from the code that exports IPROTO constants to Lua. - Before this change iproto_type_strs didn't have names for OK, CALL_16, and NOP, because they aren't shown in box.stat. After this change the names are present so we have to filter out the stat items explicitly in the rmean_foreach callback. Generating iproto_type_strs makes iproto_type_constants useless so we drop it in the scope of this patch and start using iproto_type_strs to populate box.iproto.type. Follow-up #8443 Follow-up commit b3fb883b ("iproto: export IPROTO constants to Lua automatically") NO_DOC=refactoring NO_TEST=refactoring NO_CHANGELOG=refactoring
Showing
- src/box/iproto_constants.c 5 additions, 25 deletionssrc/box/iproto_constants.c
- src/box/iproto_constants.h 17 additions, 53 deletionssrc/box/iproto_constants.h
- src/box/lua/iproto.c 13 additions, 4 deletionssrc/box/lua/iproto.c
- src/box/lua/stat.c 27 additions, 2 deletionssrc/box/lua/stat.c
- src/rmean.c 0 additions, 2 deletionssrc/rmean.c
- test/unit/xrow.cc 1 addition, 1 deletiontest/unit/xrow.cc
Loading
Please register or sign in to comment