From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id C39276EC41; Thu, 19 Aug 2021 05:56:58 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org C39276EC41 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1629341818; bh=9AjsP5ciJYOQeESm9OUBCpmCV0pddm6DrCbeJ4xMXkY=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=jvMAMUUNUgXgFqz9FvDxfTyGHL2keDa2YhYHg9ySJc48XPuiZ2EBPkdc4Yt3BuFJM TPJnnFNxRm2AUdrND9CjXAIPrZfUtIcIk6yPS4A86PELXLGzwUFaStkTXfNwAMumGy iwzMg6Sli7dgtOoodscg/mrOl7JAiVv19U5M/hLU= Received: from smtp33.i.mail.ru (smtp33.i.mail.ru [94.100.177.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 5B6D06EC40 for ; Thu, 19 Aug 2021 05:56:57 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 5B6D06EC40 Received: by smtp33.i.mail.ru with esmtpa (envelope-from ) id 1mGYEg-00022X-G2; Thu, 19 Aug 2021 05:56:55 +0300 To: vdavydov@tarantool.org, sergepetrenko@tarantool.org, tarantool-patches@dev.tarantool.org Date: Thu, 19 Aug 2021 05:56:28 +0300 Message-Id: X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD906AB4890CDABF0C5CB76CEE71D3E4007182A05F538085040618008E934DD8651F03A2AB0CC75DA3D8AB8953FAECC83EC57F044C52CEEEBDF X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE745C0EDBD94D46193EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637103BD9D8542B9C568638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D86CDBC4B109546193ECEC904AC9E89564117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC60CDF180582EB8FBA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735201E561CDFBCA1751F28451B159A507268D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE1B544F03EFBC4D57D94E105876FE7799D8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE3B28C6475D0D323302D242C3BD2E3F4C6C4224003CC836476EA7A3FFF5B025636E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F7900637427B078F297B269AEFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458F0AFF96BAACF4158235E5A14AD4A4A4625E192CAD1D9E79D0B18DC6AC13D9A1C1E263BC4259BED1A X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CF160826E4E1956AE46E4454309653AE0FED946CBDCF1446B9C2B6934AE262D3EE7EAB7254005DCEDF10D2BF6470C20F61E0A4E2319210D9B64D260DF9561598F01A9E91200F654B08D1F0E447259586B93EDB24507CE13387DFF0A840B692CF8 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34738A88CA0C70A558EAF431A258A073219716C6D105683C175997D14C49F9543B3BA6F43873479D371D7E09C32AA3244CF900ED8E56202D303BBEA8010082D38D97FE24653F78E668AD832FF50B3043B1 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojGSxK+6r6oBGjsggAOZF2Zg== X-Mailru-Sender: 6CA451E36783D721CBEA96CEA26D325D02A58AA77E4B1A9062502ADD110D39E5B7CBEF92542CD7C82F97C478340294DCC77752E0C033A69E0F0C7111264B8915FF1320A92A5534336C18EFA0BB12DBB0 X-Mras: Ok Subject: [Tarantool-patches] [PATCH v6 0/5] Initial datetime implementation X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Timur Safin via Tarantool-patches Reply-To: Timur Safin Cc: v.shpilevoy@tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" * Version #6 changes: Massive changes and reshuffles to the patches in patchset, now we consolidated them to 3 major parts: - creation of a Lua module; - serialization to MessagePack and other formats; - Box storage support; As a result of yesterday discussion we significantly simplified datetime.lua API. We have dropped interval support, and made implementation as immutable, as possible. Now object have these major methods: - add{} - sub{} - totable() - set{} Interface for constructors kept the same, but performance improved due to removed loops over keys in hash. We got rid of ctime()/asctime() methods, as they are useless. strftime() is good enough for majority of similar cases. In addition to these massive datetime.lua changes we have reshuffled code for indices support - we have moved part introducing new field type from serialization patch, to the more appropriate box indices patch. datetime_to_string() has been reimplemented using SNPRINT facilities. As a bonus part - mp_utils.h has been introduced to simiplify work with integer values when they need to be encoded/decoded to/from MesagePack. This API works regardless of a values signedness. | I'm planning to resend updated datetime.lua patch as it's not yet | feature-complete - there is no working set{} method | | Also we need to extend tests with a new API methods usage. Stay tuned! * Version #5 changes: - After performance evaluations it was decided to switch data type used by `datetime.secs` from `int64_t` (which is boxed in LuaJIT) to `double` (which is unboxed number). - please see perf/datetime*.cc perf test as a benchmark we used for comparison of 2 veriants of C implementation. Results are here - https://gist.github.com/tsafin/618fbf847d258f6e7f5a75fdf9ea945b * Version #4 changes: A lot. - Got rid of closures usage here and there. Benchmarks revealed there is 20x speed difference of hash with closure handlers to the case when we check keys using sequence of simple ifs. And despite the fact that it looks ugler, we have updated all places which used to use closures - so much performance impact does not worth it; - c-dt library now is accompanied with corresponding unit-tests; - due to a new (old) way of exporting public symbols, which is now used by Tarantool build, we have modified c-dt sources to use approach similar to that used by xxhash (or ICU) - "namespaces" for public symbols. If there is DT_NAMESPACE macro (e.g. DT_NAMESPACE=tnt_) defined at the moment of compilation we rename all relevant public symbols to use that "namespace" as prefix #define dt_from_rdn DT_NAME(DT_NAMESPACE, dt_from_rdn) C sources continue to use original name (now as a macro), but in Lua ffi we have to use renamed symbol - `tnt_dt_from_rdn`. - We have separated code which implement MessagePack related funcionality from generic (i.e. stringization) support for datetime types. Stringization is in `src/core/datetime.c`, but MessagePack support is in `src/core/mp_datetime.c`. - `ctime` and `asctime` now use reentrant versions (i.e. `ctime_r` instead of `ctime`, and `asctime_r` instead of `asctime`). This allows us to avoid nasty problem with GC where it was possible to corrupt returned static buffer regardless the fact that it was immediately passed to `ffi.string`. `test/app-tap/gh-5632-6050-6259-gc-buf-reuse.test.lua` updated to check our new api `datetime.ctime`, and `datetime.asctime`. - Introduced MessagePack unit-test which check C implementation (mp encode/decode, mp_snprint, mp_fprint) - Some special efforts have been taken to make sure we deal correctly with datetime stamps which were before Unix Epoch (1970-01-01), i.e. for negative stamps or timezones against epoch. - And last, but not the least: in addition to usual getters like `timestamp`, `nanoseconds`, `epoch`, we have introduced function modifiers `to_utc()` or `to_tz(offset)` which allow to manipulate with datetime timezone `.offset` field. Actually it does not do much now (only reattributing object with different offset, but not changed actual timestamp, which is UTC normalized). But different timestamp modifies textual representation, which simplify debugging. * Version #3 changes: - renamed `struct datetime_t` to `struct datetime`, and `struct datetime_interval_t` to `struct datetime_interval`; - significantly reworked arguments checks in module api entries; - fixed datetime comparisons; - changed hints calculation to take into account fractional part; - provided more comments here and there; NB! There are MacOSX problems due to GLIBC specific code used (as Vlad has already pointed out) - so additional patch, making it more cross-compatible coming here soon... * Version #2 changes: - fixed problem with overloaded '-' and '+' operations for datetime arguments; - fixed messagepack serialization problems; - heavily documented MessagePack serialization schema in the code; - introduced working implementation of datetime hints for storage engines; - made interval related names be more consistent, renamed durations and period to intervals, i.e. t_datetime_duration to datetime_interval_t, duration_* to interval_*, period to interval; - properly implemented all reasonable cases of datetime+interval arithmetic; - moved all initialization code to utils.c; - renamed core/mp_datetime.c to core/datetime.c because it makes more sense now; * Version #1 - initial RFC In brief -------- This patchset implements datetime lua support in box, with serialization to messagepack, yaml, json and lua mode. Also it contains storage engines' indices implementation for datetime type introduced. * Current implementation is heavily influenced by Sci-Lua lua-time module https://github.com/stepelu/lua-time e.g. you could find very similar approach for handling of operations with year or month long intervals (which should be handled differently than usual intervals of seconds, or days). * But internally we actually use Christian Hanson' c-dt module https://github.com/chansen/c-dt (though it has been modified slightly for cleaner integration into our cmake-based build process). Datetime Module API ------------------- Small draft of documentation for our `datetime` module API has been extracted to the discussion topic there - https://github.com/tarantool/tarantool/discussions/6244#discussioncomment-1043988 We try to update documentation there once any relevant change introdcued to the implementaton. Messagepack serialization schema -------------------------------- In short it looks like: - now we introduce new MP_EXT extension type #4; - we may save 1 required and 2 optional fields for datetime field; In all gory details it's explained in MessagePack serialization schema depicted here: https://github.com/tarantool/tarantool/discussions/6244#discussioncomment-1043990 https://github.com/tarantool/tarantool/issues/5941 https://github.com/tarantool/tarantool/issues/5946 https://github.com/tarantool/tarantool/tree/tsafin/gh-5941-datetime-v5 Timur Safin (5): build, lua: built-in module datetime box, datetime: messagepack support for datetime box, datetime: datetime comparison for indices datetime: perf test for datetime parser datetime: changelog for datetime module .gitmodules | 3 + CMakeLists.txt | 8 + .../gh-5941-datetime-type-support.md | 6 + cmake/BuildCDT.cmake | 10 + extra/exports | 35 ++ perf/CMakeLists.txt | 3 + perf/datetime-common.h | 105 ++++ perf/datetime-compare.cc | 213 +++++++ perf/datetime-parser.cc | 105 ++++ src/CMakeLists.txt | 5 +- src/box/field_def.c | 35 +- src/box/field_def.h | 1 + src/box/lua/serialize_lua.c | 8 +- src/box/msgpack.c | 7 +- src/box/tuple_compare.cc | 77 +++ src/lib/core/CMakeLists.txt | 5 +- src/lib/core/datetime.c | 134 +++++ src/lib/core/datetime.h | 121 ++++ src/lib/core/mp_datetime.c | 171 ++++++ src/lib/core/mp_datetime.h | 64 ++ src/lib/core/mp_extension_types.h | 1 + src/lib/core/mp_utils.h | 64 ++ src/lib/mpstream/mpstream.c | 11 + src/lib/mpstream/mpstream.h | 4 + src/lua/datetime.lua | 567 ++++++++++++++++++ src/lua/init.c | 4 +- src/lua/msgpack.c | 12 + src/lua/msgpackffi.lua | 18 + src/lua/serializer.c | 4 + src/lua/serializer.h | 2 + src/lua/utils.c | 27 + src/lua/utils.h | 12 + test/app-tap/datetime.test.lua | 213 +++++++ test/engine/datetime.result | 77 +++ test/engine/datetime.test.lua | 35 ++ test/unit/CMakeLists.txt | 3 +- test/unit/datetime.c | 383 ++++++++++++ test/unit/datetime.result | 471 +++++++++++++++ third_party/c-dt | 1 + third_party/lua-cjson/lua_cjson.c | 8 + third_party/lua-yaml/lyaml.cc | 6 +- 41 files changed, 3017 insertions(+), 22 deletions(-) create mode 100644 changelogs/unreleased/gh-5941-datetime-type-support.md create mode 100644 cmake/BuildCDT.cmake create mode 100644 perf/datetime-common.h create mode 100644 perf/datetime-compare.cc create mode 100644 perf/datetime-parser.cc create mode 100644 src/lib/core/datetime.c create mode 100644 src/lib/core/datetime.h create mode 100644 src/lib/core/mp_datetime.c create mode 100644 src/lib/core/mp_datetime.h create mode 100644 src/lib/core/mp_utils.h create mode 100644 src/lua/datetime.lua create mode 100755 test/app-tap/datetime.test.lua create mode 100644 test/engine/datetime.result create mode 100644 test/engine/datetime.test.lua create mode 100644 test/unit/datetime.c create mode 100644 test/unit/datetime.result create mode 160000 third_party/c-dt -- 2.29.2