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 2DFD26EC42; Fri, 13 Aug 2021 01:34:19 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 2DFD26EC42 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1628807659; bh=fO4s8Ahf2y6F7UkbWNfbKbFGnJipBMP5zOm1Egumwdg=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Guy8APUn62DUdKgtWZ35/lYq/fq1KWchXU+Tulp0pojidLiO+ZRnOy8DYJBtcBH/d uqDttWWvDPhBkN9Kh/eZQ/P697zBD3jTW8edKIQq2wy5JJS/hdne0nt4RCHhIUcicG feNwpJ5jJIpUPi6hZTYKdSoZt7HbShA+ekiFgxT0= Received: from smtp52.i.mail.ru (smtp52.i.mail.ru [94.100.177.112]) (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 7AD566EC40 for ; Fri, 13 Aug 2021 01:34:17 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 7AD566EC40 Received: by smtp52.i.mail.ru with esmtpa (envelope-from ) id 1mEJHD-0003Mm-On; Fri, 13 Aug 2021 01:34:16 +0300 To: imun@tarantool.org, v.shpilevoy@tarantool.org Date: Fri, 13 Aug 2021 01:33:39 +0300 Message-Id: X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD906AB4890CDABF0C5CB76CEE71D3E4007182A05F538085040A94674C193444B79FF3EF9EB5EFD3E61561ACE5C93A9D17B75EC6C283748A5A4 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7FEAC828D2BF6EC3CEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637F7C2A16C2A438FE58638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D88C84C6FEB0F52FCCC69EC07169C83C20117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCECADA55FE5B58BB7A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735201E561CDFBCA1751F618001F51B5FD3F9D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE38D4DC57D478E688A9D86F9317F2E7ACD8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE30085B890FD2717DA6136E347CC761E07C4224003CC836476EA7A3FFF5B025636E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F790063788B3B24285A3CD0EEFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458F0AFF96BAACF4158235E5A14AD4A4A4625E192CAD1D9E79D94463893BF8742D05D8CD140D131CC4D X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C69415AB31670C86C3B4C67B1A9D963226E2D9BE95C4830D39C2B6934AE262D3EE7EAB7254005DCED41D154D92A01BDF11E0A4E2319210D9B64D260DF9561598FCFFBF5018520E39865218196CFC280F58E8E86DC7131B365E7726E8460B7C23C X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D348F343DA43F62289FC019383C675D135EE1D586F89200D1831C63F522037F8F086F8005BA30B3E4241D7E09C32AA3244CCF3EFD24962A46F7FCE2C50212A082864DBEAD0ED6C55A808D5DD81C2BAB7D1D X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojbL9S8ysBdXiF5utLcPtgORuvWH503Z6/ X-Mailru-Sender: B5B6A6EBBD94DAD86A422A53D9D37A7D23E429C30DF02D8ECFAB1352DD208AEFF735632FA06710BD1EC9E4A2C82A33BC8C24925A86E657CE0C70AEE3C9A96FBAB3D7EE8ED63280BE112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: [Tarantool-patches] [PATCH v4 0/7] Initial datetime support 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: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" * 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-v4 Timur Safin (7): build: add Christian Hansen c-dt to the build lua: built-in module datetime lua, datetime: display datetime box, datetime: messagepack support for datetime box, datetime: datetime comparison for indices lua, datetime: time intervals support datetime: changelog for datetime module .gitmodules | 3 + CMakeLists.txt | 8 + .../gh-5941-datetime-type-support.md | 4 + cmake/BuildCDT.cmake | 10 + extra/exports | 34 + src/CMakeLists.txt | 5 +- src/box/field_def.c | 53 +- src/box/field_def.h | 4 + src/box/lua/serialize_lua.c | 7 +- src/box/memtx_space.c | 3 +- src/box/msgpack.c | 7 +- src/box/tuple_compare.cc | 77 ++ src/box/vinyl.c | 3 +- src/lib/core/CMakeLists.txt | 5 +- src/lib/core/datetime.c | 176 ++++ src/lib/core/datetime.h | 115 +++ src/lib/core/mp_datetime.c | 189 ++++ src/lib/core/mp_datetime.h | 89 ++ src/lib/core/mp_extension_types.h | 1 + src/lib/mpstream/mpstream.c | 11 + src/lib/mpstream/mpstream.h | 4 + src/lua/datetime.lua | 880 ++++++++++++++++++ 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 | 28 +- src/lua/utils.h | 12 + test/app-tap/datetime.test.lua | 370 ++++++++ .../gh-5632-6050-6259-gc-buf-reuse.test.lua | 74 +- test/engine/datetime.result | 77 ++ test/engine/datetime.test.lua | 35 + test/unit/CMakeLists.txt | 3 +- test/unit/datetime.c | 379 ++++++++ test/unit/datetime.result | 358 +++++++ third_party/c-dt | 1 + third_party/lua-cjson/lua_cjson.c | 8 + third_party/lua-yaml/lyaml.cc | 6 +- 39 files changed, 3051 insertions(+), 28 deletions(-) create mode 100644 changelogs/unreleased/gh-5941-datetime-type-support.md create mode 100644 cmake/BuildCDT.cmake 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/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