├── .clang-format ├── .coveralls.yml ├── .gitattributes ├── .github ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .gitmodules ├── .travis.yml ├── .travis └── build.sh ├── CMakeLists.txt ├── Changelog.md ├── LICENSE ├── NOTICE ├── README.md ├── benchmarks ├── CMakeLists.txt ├── bench_common.cpp ├── bench_common.h ├── engine_benchmark.cpp └── network_benchmark.cpp ├── cmake ├── AddCXXCompilerFlag.cmake ├── CompillerSettings.cmake ├── FindJeMalloc.cmake └── config.h.cmake ├── doc ├── compression.md ├── http_api.md └── images │ ├── page.dia │ ├── page.png │ ├── read_interval.dia │ ├── read_interval.png │ ├── read_timepoint.dia │ ├── read_timepoint.png │ ├── storage.dia │ ├── storage.png │ └── time_line.dia ├── examples ├── CMakeLists.txt ├── embedded-create.cpp ├── embedded-interval.cpp ├── embedded-statistic.cpp ├── embedded-timepoint.cpp ├── embedded.cpp ├── go │ ├── showparam │ │ └── main.go │ └── writer │ │ └── main.go ├── memory-only.cpp ├── network.cpp └── shard_embedded.cpp ├── extern ├── jemalloc-cmake │ ├── .appveyor.yml │ ├── .autom4te.cfg │ ├── .gitattributes │ ├── .gitignore │ ├── .travis.yml │ ├── CMakeLists.txt │ ├── CMake_configure.cmd │ ├── COPYING │ ├── ChangeLog │ ├── GetPageSize │ │ └── .gitignore │ ├── INSTALL │ ├── Makefile.in │ ├── README │ ├── Utilities.cmake │ ├── autogen.sh │ ├── build-aux │ │ ├── config.guess │ │ ├── config.sub │ │ └── install-sh │ ├── config.stamp.in │ ├── configure.ac │ ├── coverage.sh │ ├── doc │ │ ├── html.xsl.in │ │ ├── jemalloc.xml.in │ │ ├── manpages.xsl.in │ │ └── stylesheet.xsl │ ├── include │ │ ├── jemalloc │ │ │ ├── internal │ │ │ │ ├── arena.h │ │ │ │ ├── assert.h │ │ │ │ ├── atomic.h │ │ │ │ ├── base.h │ │ │ │ ├── bitmap.h │ │ │ │ ├── chunk.h │ │ │ │ ├── chunk_dss.h │ │ │ │ ├── chunk_mmap.h │ │ │ │ ├── ckh.h │ │ │ │ ├── ctl.h │ │ │ │ ├── extent.h │ │ │ │ ├── hash.h │ │ │ │ ├── huge.h │ │ │ │ ├── jemalloc_internal.h.in │ │ │ │ ├── jemalloc_internal_decls.h │ │ │ │ ├── jemalloc_internal_defs.h.in │ │ │ │ ├── jemalloc_internal_macros.h │ │ │ │ ├── mb.h │ │ │ │ ├── mutex.h │ │ │ │ ├── nstime.h │ │ │ │ ├── pages.h │ │ │ │ ├── ph.h │ │ │ │ ├── private_namespace.sh │ │ │ │ ├── private_symbols.txt │ │ │ │ ├── private_unnamespace.sh │ │ │ │ ├── prng.h │ │ │ │ ├── prof.h │ │ │ │ ├── public_namespace.sh │ │ │ │ ├── public_unnamespace.sh │ │ │ │ ├── ql.h │ │ │ │ ├── qr.h │ │ │ │ ├── quarantine.h │ │ │ │ ├── rb.h │ │ │ │ ├── rtree.h │ │ │ │ ├── size_classes.sh │ │ │ │ ├── smoothstep.h │ │ │ │ ├── smoothstep.sh │ │ │ │ ├── spin.h │ │ │ │ ├── stats.h │ │ │ │ ├── tcache.h │ │ │ │ ├── ticker.h │ │ │ │ ├── tsd.h │ │ │ │ ├── util.h │ │ │ │ ├── valgrind.h │ │ │ │ └── witness.h │ │ │ ├── jemalloc.sh │ │ │ ├── jemalloc_defs.h.in │ │ │ ├── jemalloc_macros.h.in │ │ │ ├── jemalloc_mangle.sh │ │ │ ├── jemalloc_protos.h.in │ │ │ ├── jemalloc_rename.sh │ │ │ └── jemalloc_typedefs.h.in │ │ └── msvc_compat │ │ │ ├── C99 │ │ │ ├── stdbool.h │ │ │ └── stdint.h │ │ │ ├── strings.h │ │ │ └── windows_extra.h │ ├── jemalloc.pc.in │ ├── msvc │ │ ├── ReadMe.txt │ │ └── projects │ │ │ └── vc2015 │ │ │ └── test_threads │ │ │ ├── test_threads.cpp │ │ │ ├── test_threads.h │ │ │ └── test_threads_main.cpp │ ├── src │ │ ├── arena.c │ │ ├── atomic.c │ │ ├── base.c │ │ ├── bitmap.c │ │ ├── chunk.c │ │ ├── chunk_dss.c │ │ ├── chunk_mmap.c │ │ ├── ckh.c │ │ ├── ctl.c │ │ ├── extent.c │ │ ├── hash.c │ │ ├── huge.c │ │ ├── jemalloc.c │ │ ├── mb.c │ │ ├── mutex.c │ │ ├── nstime.c │ │ ├── pages.c │ │ ├── prng.c │ │ ├── prof.c │ │ ├── quarantine.c │ │ ├── rtree.c │ │ ├── spin.c │ │ ├── stats.c │ │ ├── tcache.c │ │ ├── ticker.c │ │ ├── tsd.c │ │ ├── util.c │ │ ├── valgrind.c │ │ ├── witness.c │ │ └── zone.c │ └── test │ │ ├── include │ │ └── test │ │ │ ├── SFMT-alti.h │ │ │ ├── SFMT-params.h │ │ │ ├── SFMT-params11213.h │ │ │ ├── SFMT-params1279.h │ │ │ ├── SFMT-params132049.h │ │ │ ├── SFMT-params19937.h │ │ │ ├── SFMT-params216091.h │ │ │ ├── SFMT-params2281.h │ │ │ ├── SFMT-params4253.h │ │ │ ├── SFMT-params44497.h │ │ │ ├── SFMT-params607.h │ │ │ ├── SFMT-params86243.h │ │ │ ├── SFMT-sse2.h │ │ │ ├── SFMT.h │ │ │ ├── btalloc.h │ │ │ ├── jemalloc_test.h.in │ │ │ ├── jemalloc_test_defs.h.in │ │ │ ├── math.h │ │ │ ├── mq.h │ │ │ ├── mtx.h │ │ │ ├── test.h │ │ │ ├── thd.h │ │ │ └── timer.h │ │ ├── integration │ │ ├── MALLOCX_ARENA.c │ │ ├── aligned_alloc.c │ │ ├── allocated.c │ │ ├── chunk.c │ │ ├── mallocx.c │ │ ├── overflow.c │ │ ├── posix_memalign.c │ │ ├── rallocx.c │ │ ├── sdallocx.c │ │ ├── thread_arena.c │ │ ├── thread_tcache_enabled.c │ │ └── xallocx.c │ │ ├── src │ │ ├── SFMT.c │ │ ├── btalloc.c │ │ ├── btalloc_0.c │ │ ├── btalloc_1.c │ │ ├── math.c │ │ ├── mq.c │ │ ├── mtx.c │ │ ├── test.c │ │ ├── thd.c │ │ └── timer.c │ │ ├── stress │ │ └── microbench.c │ │ ├── test.sh.in │ │ └── unit │ │ ├── SFMT.c │ │ ├── a0.c │ │ ├── arena_reset.c │ │ ├── atomic.c │ │ ├── bitmap.c │ │ ├── ckh.c │ │ ├── decay.c │ │ ├── fork.c │ │ ├── hash.c │ │ ├── junk.c │ │ ├── junk_alloc.c │ │ ├── junk_free.c │ │ ├── lg_chunk.c │ │ ├── mallctl.c │ │ ├── math.c │ │ ├── mq.c │ │ ├── mtx.c │ │ ├── nstime.c │ │ ├── ph.c │ │ ├── prng.c │ │ ├── prof_accum.c │ │ ├── prof_active.c │ │ ├── prof_gdump.c │ │ ├── prof_idump.c │ │ ├── prof_reset.c │ │ ├── prof_thread_name.c │ │ ├── ql.c │ │ ├── qr.c │ │ ├── quarantine.c │ │ ├── rb.c │ │ ├── rtree.c │ │ ├── run_quantize.c │ │ ├── size_classes.c │ │ ├── smoothstep.c │ │ ├── stats.c │ │ ├── ticker.c │ │ ├── tsd.c │ │ ├── util.c │ │ ├── witness.c │ │ └── zero.c └── libsqlite3 │ ├── CMakeLists.txt │ ├── cmake │ ├── FindReadline.cmake │ ├── FindSQLite3.cmake │ └── dist.cmake │ ├── depcomp │ ├── dist.info │ ├── missing │ ├── shell.c │ ├── sqlite3.1 │ ├── sqlite3.c │ ├── sqlite3.h │ ├── sqlite3.pc │ ├── sqlite3.pc.in │ └── sqlite3ext.h ├── go ├── client.go └── client_test.go ├── indent.ps1 ├── indent.sh ├── libdariadb ├── .gitignore ├── CMakeLists.txt ├── aggregate │ ├── aggregator.cpp │ ├── aggregator.h │ ├── itimer.cpp │ ├── itimer.h │ ├── timer.cpp │ └── timer.h ├── compression │ ├── base_compressor.cpp │ ├── base_compressor.h │ ├── bytebuffer.cpp │ ├── bytebuffer.h │ ├── compression.cpp │ ├── compression.h │ ├── delta.cpp │ ├── delta.h │ ├── flag.cpp │ ├── flag.h │ ├── xor.cpp │ └── xor.h ├── dariadb.cpp ├── dariadb.h ├── engines │ ├── engine.cpp │ ├── engine.h │ ├── shard.cpp │ ├── shard.h │ ├── strategy.cpp │ └── strategy.h ├── flags.h ├── interfaces │ ├── icallbacks.cpp │ ├── icallbacks.h │ ├── icompactioncontroller.h │ ├── icursor.cpp │ ├── icursor.h │ ├── idroppers.h │ ├── iengine.cpp │ ├── iengine.h │ ├── imeassource.cpp │ ├── imeassource.h │ ├── imeasstorage.cpp │ ├── imeasstorage.h │ ├── imeaswriter.cpp │ └── imeaswriter.h ├── meas.cpp ├── meas.h ├── query.cpp ├── query.h ├── scheme │ ├── helpers.cpp │ ├── helpers.h │ ├── ischeme.h │ ├── scheme.cpp │ └── scheme.h ├── stat.h ├── statistic │ ├── calculator.cpp │ ├── calculator.h │ ├── functions.cpp │ ├── functions.h │ ├── ifunction.cpp │ └── ifunction.h ├── status.cpp ├── status.h ├── storage │ ├── bloom_filter.h │ ├── callbacks.cpp │ ├── callbacks.h │ ├── chunk.cpp │ ├── chunk.h │ ├── chunkcontainer.cpp │ ├── chunkcontainer.h │ ├── cursors.cpp │ ├── cursors.h │ ├── dropper.cpp │ ├── dropper.h │ ├── dropper_description.h │ ├── engine_environment.cpp │ ├── engine_environment.h │ ├── magic.h │ ├── manifest.cpp │ ├── manifest.h │ ├── memstorage │ │ ├── allocators.cpp │ │ ├── allocators.h │ │ ├── description.h │ │ ├── memchunk.cpp │ │ ├── memchunk.h │ │ ├── memstorage.cpp │ │ ├── memstorage.h │ │ ├── timetrack.cpp │ │ └── timetrack.h │ ├── pages │ │ ├── helpers.cpp │ │ ├── helpers.h │ │ ├── index.cpp │ │ ├── index.h │ │ ├── page.cpp │ │ ├── page.h │ │ ├── page_manager.cpp │ │ └── page_manager.h │ ├── settings.cpp │ ├── settings.h │ ├── subscribe.cpp │ ├── subscribe.h │ └── wal │ │ ├── wal_manager.cpp │ │ ├── wal_manager.h │ │ ├── walfile.cpp │ │ └── walfile.h ├── timeutil.cpp ├── timeutil.h └── utils │ ├── async │ ├── locker.cpp │ ├── locker.h │ ├── thread_manager.cpp │ ├── thread_manager.h │ ├── thread_pool.cpp │ └── thread_pool.h │ ├── bitoperations.h │ ├── crc.cpp │ ├── crc.h │ ├── cz.h │ ├── exception.h │ ├── fs.cpp │ ├── fs.h │ ├── in_interval.h │ ├── jenkins_hash.h │ ├── logger.cpp │ ├── logger.h │ ├── strings.cpp │ ├── strings.h │ ├── striped_map.h │ ├── utils.cpp │ └── utils.h ├── microbenchmarks ├── CMakeLists.txt ├── common.cpp ├── common.h ├── compression.cpp ├── crc.cpp ├── cursors.cpp ├── hash.cpp ├── main.cpp ├── memstorage.cpp ├── network.cpp ├── statistic.cpp └── timeutil.cpp ├── network ├── CMakeLists.txt ├── common │ ├── .gitignore │ ├── CMakeLists.txt │ ├── async_connection.cpp │ ├── async_connection.h │ ├── http_helpers.cpp │ ├── http_helpers.h │ ├── net_common.cpp │ ├── net_common.h │ ├── net_data.cpp │ ├── net_data.h │ └── socket_ptr.h ├── dariadbd │ ├── CMakeLists.txt │ ├── main.cpp │ ├── server_logger.cpp │ └── server_logger.h ├── libclient │ ├── .gitignore │ ├── CMakeLists.txt │ ├── client.cpp │ └── client.h └── libserver │ ├── .gitignore │ ├── CMakeLists.txt │ ├── http │ ├── connection.cpp │ ├── connection.h │ ├── connection_manager.cpp │ ├── connection_manager.h │ ├── header.h │ ├── http_server.cpp │ ├── http_server.h │ ├── query_parser.cpp │ ├── query_parser.h │ ├── reply.cpp │ ├── reply.h │ ├── request.h │ ├── request_handler.cpp │ └── request_handler.h │ ├── iclientmanager.h │ ├── ioclient.cpp │ ├── ioclient.h │ ├── server.cpp │ ├── server.h │ ├── subscribecallback.cpp │ └── subscribecallback.h └── unittests ├── CMakeLists.txt ├── aggregate_test.cpp ├── compression_test.cpp ├── crc_test.cpp ├── engine_test.cpp ├── helpers.cpp ├── helpers.h ├── http_test.cpp ├── main.cpp ├── memstorage_test.cpp ├── net_test.cpp ├── pages_test.cpp ├── scheme_test.cpp ├── shard_engine_test.cpp ├── statistic_test.cpp ├── storage_common_test.cpp ├── stripped_map_test.cpp ├── timeutil_test.cpp ├── utils_test.cpp └── wal_test.cpp /.coveralls.yml: -------------------------------------------------------------------------------- 1 | service_name: travis-pro 2 | repo_token: 7VSWJleC3m9GKbZBakLFL5nBEib1CTFsb 3 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.hpp text 2 | *.h text 3 | *.cpp text 4 | *.txt text 5 | *.html text 6 | *.md text 7 | *.yml text 8 | *.xml text 9 | *.in text 10 | .gitattributes text 11 | .gitignore text 12 | 13 | *.cmd -text 14 | *.sln -text 15 | *.vcxproj -text 16 | *.vcxproj.filters -text -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | - [ ] - need update changelog. 2 | - [ ] - need update readme. 3 | - [ ] - need update protocol version. 4 | - [ ] - need update storage version. 5 | - [ ] - need update settings save/load. 6 | - [ ] - need example. 7 | - [ ] - need update papers. 8 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | --- 4 | - [ ] - need update changelog. 5 | - [ ] - need update readme. 6 | - [ ] - need update protocol version. 7 | - [ ] - need update storage version. 8 | - [ ] - need update papers. 9 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "extern/stx-btree"] 2 | path = extern/stx-btree 3 | url = https://github.com/bingmann/stx-btree.git 4 | [submodule "extern/spdlog"] 5 | path = extern/spdlog 6 | url = https://github.com/gabime/spdlog.git 7 | [submodule "extern/json"] 8 | path = extern/json 9 | url = https://github.com/nlohmann/json.git 10 | [submodule "extern/googletest"] 11 | path = extern/googletest 12 | url = https://github.com/google/googletest/ 13 | ignore = dirty 14 | [submodule "extern/benchmark"] 15 | path = extern/benchmark 16 | url = https://github.com/google/benchmark 17 | ignore = dirty 18 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2016 Sergey Lyubimov 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /benchmarks/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | INCLUDE_DIRECTORIES(${DARIADB_STORAGE_INCLUDE_DIR}) 2 | INCLUDE_DIRECTORIES(${DARIADB_NETWORK_INCLUDE_DIR}) 3 | 4 | MESSAGE(STATUS "Benchmarks: ") 5 | 6 | macro(ADD_BENCHARK name src) 7 | MESSAGE(STATUS " +" ${name}) 8 | add_executable(${name} ${src} bench_common.h bench_common.cpp) 9 | 10 | target_link_libraries(${name} ${DARIADB_STORAGE_LIBS}) 11 | set_target_properties(${name} PROPERTIES FOLDER Benchmarks) 12 | endmacro(ADD_BENCHARK) 13 | 14 | macro(ADD_PERF_TEST name) 15 | MESSAGE(STATUS " + engine_benchmark " ${name} " " ${ARGN}) 16 | add_test(${name} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/engine_benchmark --read-benchmark-runs=10 ${ARGN}) 17 | endmacro() 18 | 19 | macro(ADD_NT_PERF_TEST name) 20 | MESSAGE(STATUS " + network_benchmark " ${name} " " ${ARGN}) 21 | add_test(${name} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/network_benchmark --io-threads=5 ${ARGN}) 22 | endmacro() 23 | 24 | ADD_BENCHARK(engine_benchmark engine_benchmark.cpp) 25 | 26 | if(DARIADB_ENABLE_SERVER) 27 | ADD_BENCHARK(network_benchmark network_benchmark.cpp) 28 | TARGET_LINK_LIBRARIES(network_benchmark ${DARIADB_CLIENT_LIBS} dariadb-server) 29 | endif(DARIADB_ENABLE_SERVER) 30 | 31 | 32 | if(DARIADB_ENABLE_INTEGRATION_TESTS) 33 | MESSAGE(STATUS "Integration tests: ") 34 | ADD_PERF_TEST(WAL --strategy=WAL) 35 | ADD_PERF_TEST(COMPRESSED --strategy=COMPRESSED) 36 | ADD_PERF_TEST(MEMORY --strategy=MEMORY) 37 | ADD_PERF_TEST(CACHE --strategy=CACHE) 38 | ADD_PERF_TEST(SHARD_WAL --strategy=WAL --use-shard) 39 | ADD_PERF_TEST(SHARD_MEM --strategy=MEMORY --use-shard) 40 | ADD_PERF_TEST(MEMONLY --memory-only --ids=100 --hours=1 --freq=3) 41 | if(DARIADB_ENABLE_SERVER) 42 | ADD_NT_PERF_TEST(ONE_CLIENT --clients-count=1) 43 | ADD_NT_PERF_TEST(TEN_CLIENTS --clients-count=10) 44 | 45 | ADD_NT_PERF_TEST(HTTP_ONE_CLIENTS --clients-count=1 --http-benchmark) 46 | ADD_NT_PERF_TEST(HTTP_TEN_CLIENTS --clients-count=10 --http-benchmark) 47 | endif(DARIADB_ENABLE_SERVER) 48 | endif(DARIADB_ENABLE_INTEGRATION_TESTS) 49 | -------------------------------------------------------------------------------- /cmake/AddCXXCompilerFlag.cmake: -------------------------------------------------------------------------------- 1 | # - Adds a compiler flag if it is supported by the compiler 2 | # 3 | # This function checks that the supplied compiler flag is supported and then 4 | # adds it to the corresponding compiler flags 5 | # 6 | # add_cxx_compiler_flag( []) 7 | # 8 | # - Example 9 | # 10 | # include(AddCXXCompilerFlag) 11 | # add_cxx_compiler_flag(-Wall) 12 | # add_cxx_compiler_flag(-no-strict-aliasing RELEASE) 13 | # Requires CMake 2.6+ 14 | 15 | if(__add_cxx_compiler_flag) 16 | return() 17 | endif() 18 | set(__add_cxx_compiler_flag INCLUDED) 19 | 20 | include(CheckCXXCompilerFlag) 21 | 22 | function(add_cxx_compiler_flag FLAG) 23 | string(TOUPPER "HAVE_CXX_FLAG_${FLAG}" SANITIZED_FLAG) 24 | string(REPLACE "+" "X" SANITIZED_FLAG ${SANITIZED_FLAG}) 25 | string(REGEX REPLACE "[^A-Za-z_0-9]" "_" SANITIZED_FLAG ${SANITIZED_FLAG}) 26 | string(REGEX REPLACE "_+" "_" SANITIZED_FLAG ${SANITIZED_FLAG}) 27 | set(CMAKE_REQUIRED_FLAGS "${FLAG}") 28 | check_cxx_compiler_flag("" ${SANITIZED_FLAG}) 29 | if(${SANITIZED_FLAG}) 30 | set(VARIANT ${ARGV1}) 31 | if(ARGV1) 32 | string(TOUPPER "_${VARIANT}" VARIANT) 33 | endif() 34 | set(CMAKE_CXX_FLAGS${VARIANT} "${CMAKE_CXX_FLAGS${VARIANT}} ${FLAG}" PARENT_SCOPE) 35 | endif() 36 | endfunction() 37 | 38 | -------------------------------------------------------------------------------- /cmake/FindJeMalloc.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find jemalloc headers and libraries. 2 | # 3 | # Usage of this module as follows: 4 | # 5 | # find_package(JeMalloc) 6 | # 7 | # Variables used by this module, they can change the default behaviour and need 8 | # to be set before calling find_package: 9 | # 10 | # JEMALLOC_ROOT_DIR Set this variable to the root installation of 11 | # jemalloc if the module has problems finding 12 | # the proper installation path. 13 | # 14 | # Variables defined by this module: 15 | # 16 | # JEMALLOC_FOUND System has jemalloc libs/headers 17 | # JEMALLOC_LIBRARIES The jemalloc library/libraries 18 | # JEMALLOC_INCLUDE_DIR The location of jemalloc headers 19 | 20 | find_path(JEMALLOC_ROOT_DIR 21 | NAMES include/jemalloc/jemalloc.h 22 | ) 23 | 24 | find_library(JEMALLOC_LIBRARIES 25 | NAMES jemalloc 26 | HINTS ${JEMALLOC_ROOT_DIR}/lib 27 | ) 28 | 29 | find_path(JEMALLOC_INCLUDE_DIR 30 | NAMES jemalloc/jemalloc.h 31 | HINTS ${JEMALLOC_ROOT_DIR}/include 32 | ) 33 | 34 | include(FindPackageHandleStandardArgs) 35 | find_package_handle_standard_args(JeMalloc DEFAULT_MSG 36 | JEMALLOC_LIBRARIES 37 | JEMALLOC_INCLUDE_DIR 38 | ) 39 | 40 | mark_as_advanced( 41 | JEMALLOC_ROOT_DIR 42 | JEMALLOC_LIBRARIES 43 | JEMALLOC_INCLUDE_DIR 44 | ) -------------------------------------------------------------------------------- /cmake/config.h.cmake: -------------------------------------------------------------------------------- 1 | #ifndef CONFIG_H 2 | #define CONFIG_H 3 | 4 | #define PROJECT "@PROJECT@" 5 | #define PROJECT_VERSION "@PROJECT_VERSION@" 6 | #define PROJECT_VERSION_MAJOR @PROJECT_VERSION_MAJOR@ 7 | #define PROJECT_VERSION_MINOR @PROJECT_VERSION_MINOR@ 8 | #define PROJECT_VERSION_PATCH @PROJECT_VERSION_PATCH@ 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /doc/compression.md: -------------------------------------------------------------------------------- 1 | # Compressing time stamps 2 | 3 | 1. The block header stores the starting time stamp, 4 | 2. For subsequent time stamps, tn: 5 | * Calculate the delta of delta: D = (tn - t(n-1)) 6 | * If D is [-32:32], store '10' followed by the value. 7 | * If D is between [-4096:4096], store '1110' followed by the value. 8 | * if D is between [-524288:524287], store '1110' followed by the value. 9 | * Otherwise store '0' byte followed by D using 64 bits 10 | 11 | # Compressing values 12 | 13 | We then encode these XOR d values with the following variable length encoding scheme: 14 | 1. The first value is stored with no compression 15 | 2. If XOR with the previous is zero (same value), store single '0' byte 16 | 3. When XOR is non-zero, storing byte with count of bytes with meaningful bits. 17 | Then storing count of zeros in tail(byte), then XOR moved 18 | to the right (for example '0001010 => 0000101'). 19 | 20 | ```C++ 21 | auto lead = dariadb::utils::clz(xor_val); 22 | auto tail = dariadb::utils::ctz(xor_val); 23 | const size_t total_bits = sizeof(Value) * 8; 24 | 25 | uint8_t count_of_bytes=(total_bits - lead - tail)/8+1; //count of byte in XOR 26 | assert(count_of_bytes <= u64_buffer_size); 27 | 28 | bw->write(count_of_bytes); 29 | bw->write(tail); 30 | 31 | auto moved_value = xor_val >> tail; // 0001010 => 0000101 32 | uint8_t buff[u64_buffer_size]; 33 | *reinterpret_cast(buff) = moved_value; 34 | for (size_t i = 0; i < count_of_bytes; ++i) { 35 | bw->write(buff[i]); 36 | } 37 | ``` 38 | 39 | # Flags 40 | 41 | Using LEB128 compression; 42 | -------------------------------------------------------------------------------- /doc/images/page.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lysevi/dariadb/e9c2e34b0723ea6e040ecdcce3d57153d32b061e/doc/images/page.dia -------------------------------------------------------------------------------- /doc/images/page.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lysevi/dariadb/e9c2e34b0723ea6e040ecdcce3d57153d32b061e/doc/images/page.png -------------------------------------------------------------------------------- /doc/images/read_interval.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lysevi/dariadb/e9c2e34b0723ea6e040ecdcce3d57153d32b061e/doc/images/read_interval.dia -------------------------------------------------------------------------------- /doc/images/read_interval.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lysevi/dariadb/e9c2e34b0723ea6e040ecdcce3d57153d32b061e/doc/images/read_interval.png -------------------------------------------------------------------------------- /doc/images/read_timepoint.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lysevi/dariadb/e9c2e34b0723ea6e040ecdcce3d57153d32b061e/doc/images/read_timepoint.dia -------------------------------------------------------------------------------- /doc/images/read_timepoint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lysevi/dariadb/e9c2e34b0723ea6e040ecdcce3d57153d32b061e/doc/images/read_timepoint.png -------------------------------------------------------------------------------- /doc/images/storage.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lysevi/dariadb/e9c2e34b0723ea6e040ecdcce3d57153d32b061e/doc/images/storage.dia -------------------------------------------------------------------------------- /doc/images/storage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lysevi/dariadb/e9c2e34b0723ea6e040ecdcce3d57153d32b061e/doc/images/storage.png -------------------------------------------------------------------------------- /doc/images/time_line.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lysevi/dariadb/e9c2e34b0723ea6e040ecdcce3d57153d32b061e/doc/images/time_line.dia -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | INCLUDE_DIRECTORIES(${DARIADB_STORAGE_INCLUDE_DIR}) 2 | INCLUDE_DIRECTORIES(${DARIADB_NETWORK_INCLUDE_DIR}) 3 | 4 | LINK_DIRECTORIES(${DARIADB_LIB_PATH}) 5 | 6 | MESSAGE(STATUS "Examples") 7 | macro(EXAMPLE name src) 8 | MESSAGE(STATUS "+ example-${name}") 9 | add_executable(example-${name} ${src}) 10 | TARGET_LINK_LIBRARIES(example-${name} ${DARIADB_STORAGE_LIBS}) 11 | set_target_properties(example-${name} PROPERTIES FOLDER Examples) 12 | endmacro(EXAMPLE) 13 | 14 | 15 | EXAMPLE(embedded embedded.cpp) 16 | add_test(example-embedded ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/example-embedded) 17 | 18 | EXAMPLE(memory-only memory-only.cpp) 19 | add_test(example-memory-only ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/example-memory-only) 20 | 21 | EXAMPLE(embedded-create embedded-create.cpp) 22 | EXAMPLE(embedded-interval embedded-interval.cpp) 23 | EXAMPLE(embedded-timepoint embedded-timepoint.cpp) 24 | EXAMPLE(embedded-statistic embedded-statistic.cpp) 25 | 26 | EXAMPLE(shard-embedded shard_embedded.cpp) 27 | add_test(example-embedded ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/example-shard-embedded) 28 | 29 | EXAMPLE(network network.cpp) 30 | target_link_libraries(example-network ${DARIADB_STORAGE_LIBS} ${DARIADB_CLIENT_LIBS}) 31 | 32 | -------------------------------------------------------------------------------- /examples/embedded-create.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int, char **) { 6 | const std::string storage_path = "exampledb"; 7 | // remove 8 | if (dariadb::utils::fs::path_exists(storage_path)) { 9 | dariadb::utils::fs::rm(storage_path); 10 | } 11 | 12 | auto settings = dariadb::storage::Settings::create(storage_path); 13 | settings->save(); 14 | 15 | // create named param. p1 and p2 contain id of created timeseries. 16 | auto scheme = dariadb::scheme::Scheme::create(settings); 17 | auto p1 = scheme->addParam("group.param1"); 18 | auto p2 = scheme->addParam("group.subgroup.param2"); 19 | scheme->save(); 20 | 21 | auto storage = std::make_unique(settings); 22 | 23 | auto m = dariadb::Meas(); 24 | auto start_time = dariadb::timeutil::current_time(); 25 | 26 | // write values in interval [currentTime:currentTime+10] 27 | m.time = start_time; 28 | for (size_t i = 0; i < 10; ++i) { 29 | if (i % 2) { 30 | m.id = p1; 31 | } else { 32 | m.id = p2; 33 | } 34 | 35 | m.time++; 36 | m.value++; 37 | m.flag = 100 + i % 2; 38 | auto status = storage->append(m); 39 | if (status.writed != 1) { 40 | std::cerr << "Error: " << dariadb::to_string(status.error) << std::endl; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/.appveyor.yml: -------------------------------------------------------------------------------- 1 | version: '{build}' 2 | 3 | environment: 4 | matrix: 5 | - MSYSTEM: MINGW64 6 | CPU: x86_64 7 | MSVC: amd64 8 | - MSYSTEM: MINGW32 9 | CPU: i686 10 | MSVC: x86 11 | - MSYSTEM: MINGW64 12 | CPU: x86_64 13 | - MSYSTEM: MINGW32 14 | CPU: i686 15 | 16 | install: 17 | - set PATH=c:\msys64\%MSYSTEM%\bin;c:\msys64\usr\bin;%PATH% 18 | - if defined MSVC call "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" %MSVC% 19 | - if defined MSVC pacman --noconfirm -Rsc mingw-w64-%CPU%-gcc gcc 20 | - pacman --noconfirm -Suy mingw-w64-%CPU%-make 21 | 22 | build_script: 23 | - bash -c "autoconf" 24 | - bash -c "./configure" 25 | - mingw32-make -j3 26 | - file lib/jemalloc.dll 27 | - mingw32-make -j3 tests 28 | - mingw32-make -k check 29 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/.autom4te.cfg: -------------------------------------------------------------------------------- 1 | begin-language: "Autoconf-without-aclocal-m4" 2 | args: --no-cache 3 | end-language: "Autoconf-without-aclocal-m4" 4 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/.gitignore: -------------------------------------------------------------------------------- 1 | /*.gcov.* 2 | 3 | /bin/jemalloc-config 4 | /bin/jemalloc.sh 5 | /bin/jeprof 6 | 7 | /config.stamp 8 | /config.log 9 | /config.status 10 | /configure 11 | 12 | /doc/html.xsl 13 | /doc/manpages.xsl 14 | /doc/jemalloc.xml 15 | /doc/jemalloc.html 16 | /doc/jemalloc.3 17 | 18 | /jemalloc.pc 19 | 20 | /lib/ 21 | 22 | /Makefile 23 | 24 | /include/jemalloc/internal/jemalloc_internal.h 25 | /include/jemalloc/internal/jemalloc_internal_defs.h 26 | /include/jemalloc/internal/private_namespace.h 27 | /include/jemalloc/internal/private_unnamespace.h 28 | /include/jemalloc/internal/public_namespace.h 29 | /include/jemalloc/internal/public_symbols.txt 30 | /include/jemalloc/internal/public_unnamespace.h 31 | /include/jemalloc/internal/size_classes.h 32 | /include/jemalloc/jemalloc.h 33 | /include/jemalloc/jemalloc_defs.h 34 | /include/jemalloc/jemalloc_macros.h 35 | /include/jemalloc/jemalloc_mangle.h 36 | /include/jemalloc/jemalloc_mangle_jet.h 37 | /include/jemalloc/jemalloc_protos.h 38 | /include/jemalloc/jemalloc_protos_jet.h 39 | /include/jemalloc/jemalloc_rename.h 40 | /include/jemalloc/jemalloc_typedefs.h 41 | 42 | /src/*.[od] 43 | /src/*.gcda 44 | /src/*.gcno 45 | 46 | /test/test.sh 47 | test/include/test/jemalloc_test.h 48 | test/include/test/jemalloc_test_defs.h 49 | 50 | /test/integration/[A-Za-z]* 51 | !/test/integration/[A-Za-z]*.* 52 | /test/integration/*.[od] 53 | /test/integration/*.gcda 54 | /test/integration/*.gcno 55 | /test/integration/*.out 56 | 57 | /test/src/*.[od] 58 | /test/src/*.gcda 59 | /test/src/*.gcno 60 | 61 | /test/stress/[A-Za-z]* 62 | !/test/stress/[A-Za-z]*.* 63 | /test/stress/*.[od] 64 | /test/stress/*.gcda 65 | /test/stress/*.gcno 66 | /test/stress/*.out 67 | 68 | /test/unit/[A-Za-z]* 69 | !/test/unit/[A-Za-z]*.* 70 | /test/unit/*.[od] 71 | /test/unit/*.gcda 72 | /test/unit/*.gcno 73 | /test/unit/*.out 74 | 75 | /VERSION 76 | 77 | *.pdb 78 | *.sdf 79 | *.opendb 80 | *.opensdf 81 | *.cachefile 82 | *.suo 83 | *.user 84 | *.sln.docstates 85 | *.tmp 86 | /msvc/Win32/ 87 | /msvc/x64/ 88 | /msvc/projects/*/*/Debug*/ 89 | /msvc/projects/*/*/Release*/ 90 | /msvc/projects/*/*/Win32/ 91 | /msvc/projects/*/*/x64/ 92 | /build/ 93 | *.tcl 94 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | 3 | matrix: 4 | include: 5 | - os: linux 6 | compiler: gcc 7 | - os: linux 8 | compiler: gcc 9 | env: 10 | - EXTRA_FLAGS=-m32 11 | addons: 12 | apt: 13 | packages: 14 | - gcc-multilib 15 | - os: osx 16 | compiler: clang 17 | - os: osx 18 | compiler: clang 19 | env: 20 | - EXTRA_FLAGS=-m32 21 | 22 | before_script: 23 | - autoconf 24 | - ./configure${EXTRA_FLAGS:+ CC="$CC $EXTRA_FLAGS"} 25 | - make -j3 26 | - make -j3 tests 27 | 28 | script: 29 | - make check 30 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/CMake_configure.cmd: -------------------------------------------------------------------------------- 1 | REM Configure Jemalloc build with options 2 | 3 | CMake -G "Visual Studio 14 Win64" -Dwith-malloc-conf=purge:decay -Denable-debug=ON .. 4 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/COPYING: -------------------------------------------------------------------------------- 1 | Unless otherwise specified, files in the jemalloc source distribution are 2 | subject to the following license: 3 | -------------------------------------------------------------------------------- 4 | Copyright (C) 2002-2016 Jason Evans . 5 | All rights reserved. 6 | Copyright (C) 2007-2012 Mozilla Foundation. All rights reserved. 7 | Copyright (C) 2009-2016 Facebook, Inc. All rights reserved. 8 | 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions are met: 11 | 1. Redistributions of source code must retain the above copyright notice(s), 12 | this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright notice(s), 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS 18 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 20 | EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 25 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- 28 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/GetPageSize/.gitignore: -------------------------------------------------------------------------------- 1 | /getpagesize.c 2 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/README: -------------------------------------------------------------------------------- 1 | jemalloc is a general purpose malloc(3) implementation that emphasizes 2 | fragmentation avoidance and scalable concurrency support. jemalloc first came 3 | into use as the FreeBSD libc allocator in 2005, and since then it has found its 4 | way into numerous applications that rely on its predictable behavior. In 2010 5 | jemalloc development efforts broadened to include developer support features 6 | such as heap profiling, Valgrind integration, and extensive monitoring/tuning 7 | hooks. Modern jemalloc releases continue to be integrated back into FreeBSD, 8 | and therefore versatility remains critical. Ongoing development efforts trend 9 | toward making jemalloc among the best allocators for a broad range of demanding 10 | applications, and eliminating/mitigating weaknesses that have practical 11 | repercussions for real world applications. 12 | 13 | The COPYING file contains copyright and licensing information. 14 | 15 | The INSTALL file contains information on how to configure, build, and install 16 | jemalloc. 17 | 18 | The ChangeLog file contains a brief summary of changes for each release. 19 | 20 | URL: http://jemalloc.net/ 21 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | for i in autoconf; do 4 | echo "$i" 5 | $i 6 | if [ $? -ne 0 ]; then 7 | echo "Error $? in $i" 8 | exit 1 9 | fi 10 | done 11 | 12 | echo "./configure --enable-autogen $@" 13 | ./configure --enable-autogen $@ 14 | if [ $? -ne 0 ]; then 15 | echo "Error $? in ./configure" 16 | exit 1 17 | fi 18 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/config.stamp.in: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lysevi/dariadb/e9c2e34b0723ea6e040ecdcce3d57153d32b061e/extern/jemalloc-cmake/config.stamp.in -------------------------------------------------------------------------------- /extern/jemalloc-cmake/coverage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | objdir=$1 6 | suffix=$2 7 | shift 2 8 | objs=$@ 9 | 10 | gcov -b -p -f -o "${objdir}" ${objs} 11 | 12 | # Move gcov outputs so that subsequent gcov invocations won't clobber results 13 | # for the same sources with different compilation flags. 14 | for f in `find . -maxdepth 1 -type f -name '*.gcov'` ; do 15 | mv "${f}" "${f}.${suffix}" 16 | done 17 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/doc/html.xsl.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/doc/manpages.xsl.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/doc/stylesheet.xsl: -------------------------------------------------------------------------------- 1 | 2 | ansi 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/include/jemalloc/internal/assert.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Define a custom assert() in order to reduce the chances of deadlock during 3 | * assertion failure. 4 | */ 5 | #ifndef assert 6 | #define assert(e) do { \ 7 | if (unlikely(config_debug && !(e))) { \ 8 | malloc_printf( \ 9 | ": %s:%d: Failed assertion: \"%s\"\n", \ 10 | __FILE__, __LINE__, #e); \ 11 | abort(); \ 12 | } \ 13 | } while (0) 14 | #endif 15 | 16 | #ifndef not_reached 17 | #define not_reached() do { \ 18 | if (config_debug) { \ 19 | malloc_printf( \ 20 | ": %s:%d: Unreachable code reached\n", \ 21 | __FILE__, __LINE__); \ 22 | abort(); \ 23 | } \ 24 | unreachable(); \ 25 | } while (0) 26 | #endif 27 | 28 | #ifndef not_implemented 29 | #define not_implemented() do { \ 30 | if (config_debug) { \ 31 | malloc_printf(": %s:%d: Not implemented\n", \ 32 | __FILE__, __LINE__); \ 33 | abort(); \ 34 | } \ 35 | } while (0) 36 | #endif 37 | 38 | #ifndef assert_not_implemented 39 | #define assert_not_implemented(e) do { \ 40 | if (unlikely(config_debug && !(e))) \ 41 | not_implemented(); \ 42 | } while (0) 43 | #endif 44 | 45 | 46 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/include/jemalloc/internal/base.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | #ifdef JEMALLOC_H_TYPES 3 | 4 | #endif /* JEMALLOC_H_TYPES */ 5 | /******************************************************************************/ 6 | #ifdef JEMALLOC_H_STRUCTS 7 | 8 | #endif /* JEMALLOC_H_STRUCTS */ 9 | /******************************************************************************/ 10 | #ifdef JEMALLOC_H_EXTERNS 11 | 12 | void *base_alloc(tsdn_t *tsdn, size_t size); 13 | void base_stats_get(tsdn_t *tsdn, size_t *allocated, size_t *resident, 14 | size_t *mapped); 15 | bool base_boot(void); 16 | void base_prefork(tsdn_t *tsdn); 17 | void base_postfork_parent(tsdn_t *tsdn); 18 | void base_postfork_child(tsdn_t *tsdn); 19 | 20 | #endif /* JEMALLOC_H_EXTERNS */ 21 | /******************************************************************************/ 22 | #ifdef JEMALLOC_H_INLINES 23 | 24 | #endif /* JEMALLOC_H_INLINES */ 25 | /******************************************************************************/ 26 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/include/jemalloc/internal/chunk_dss.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | #ifdef JEMALLOC_H_TYPES 3 | 4 | typedef enum { 5 | dss_prec_disabled = 0, 6 | dss_prec_primary = 1, 7 | dss_prec_secondary = 2, 8 | 9 | dss_prec_limit = 3 10 | } dss_prec_t; 11 | #define DSS_PREC_DEFAULT dss_prec_secondary 12 | #define DSS_DEFAULT "secondary" 13 | 14 | #endif /* JEMALLOC_H_TYPES */ 15 | /******************************************************************************/ 16 | #ifdef JEMALLOC_H_STRUCTS 17 | 18 | extern const char *dss_prec_names[]; 19 | 20 | #endif /* JEMALLOC_H_STRUCTS */ 21 | /******************************************************************************/ 22 | #ifdef JEMALLOC_H_EXTERNS 23 | 24 | dss_prec_t chunk_dss_prec_get(void); 25 | bool chunk_dss_prec_set(dss_prec_t dss_prec); 26 | void *chunk_alloc_dss(tsdn_t *tsdn, arena_t *arena, void *new_addr, 27 | size_t size, size_t alignment, bool *zero, bool *commit); 28 | bool chunk_in_dss(void *chunk); 29 | bool chunk_dss_mergeable(void *chunk_a, void *chunk_b); 30 | void chunk_dss_boot(void); 31 | 32 | #endif /* JEMALLOC_H_EXTERNS */ 33 | /******************************************************************************/ 34 | #ifdef JEMALLOC_H_INLINES 35 | 36 | #endif /* JEMALLOC_H_INLINES */ 37 | /******************************************************************************/ 38 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/include/jemalloc/internal/chunk_mmap.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | #ifdef JEMALLOC_H_TYPES 3 | 4 | #endif /* JEMALLOC_H_TYPES */ 5 | /******************************************************************************/ 6 | #ifdef JEMALLOC_H_STRUCTS 7 | 8 | #endif /* JEMALLOC_H_STRUCTS */ 9 | /******************************************************************************/ 10 | #ifdef JEMALLOC_H_EXTERNS 11 | 12 | void *chunk_alloc_mmap(void *new_addr, size_t size, size_t alignment, 13 | bool *zero, bool *commit); 14 | bool chunk_dalloc_mmap(void *chunk, size_t size); 15 | 16 | #endif /* JEMALLOC_H_EXTERNS */ 17 | /******************************************************************************/ 18 | #ifdef JEMALLOC_H_INLINES 19 | 20 | #endif /* JEMALLOC_H_INLINES */ 21 | /******************************************************************************/ 22 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/include/jemalloc/internal/huge.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | #ifdef JEMALLOC_H_TYPES 3 | 4 | #endif /* JEMALLOC_H_TYPES */ 5 | /******************************************************************************/ 6 | #ifdef JEMALLOC_H_STRUCTS 7 | 8 | #endif /* JEMALLOC_H_STRUCTS */ 9 | /******************************************************************************/ 10 | #ifdef JEMALLOC_H_EXTERNS 11 | 12 | void *huge_malloc(tsdn_t *tsdn, arena_t *arena, size_t usize, bool zero); 13 | void *huge_palloc(tsdn_t *tsdn, arena_t *arena, size_t usize, 14 | size_t alignment, bool zero); 15 | bool huge_ralloc_no_move(tsdn_t *tsdn, void *ptr, size_t oldsize, 16 | size_t usize_min, size_t usize_max, bool zero); 17 | void *huge_ralloc(tsd_t *tsd, arena_t *arena, void *ptr, size_t oldsize, 18 | size_t usize, size_t alignment, bool zero, tcache_t *tcache); 19 | #ifdef JEMALLOC_JET 20 | typedef void (huge_dalloc_junk_t)(void *, size_t); 21 | extern huge_dalloc_junk_t *huge_dalloc_junk; 22 | #endif 23 | void huge_dalloc(tsdn_t *tsdn, void *ptr); 24 | arena_t *huge_aalloc(const void *ptr); 25 | size_t huge_salloc(tsdn_t *tsdn, const void *ptr); 26 | prof_tctx_t *huge_prof_tctx_get(tsdn_t *tsdn, const void *ptr); 27 | void huge_prof_tctx_set(tsdn_t *tsdn, const void *ptr, prof_tctx_t *tctx); 28 | void huge_prof_tctx_reset(tsdn_t *tsdn, const void *ptr); 29 | 30 | #endif /* JEMALLOC_H_EXTERNS */ 31 | /******************************************************************************/ 32 | #ifdef JEMALLOC_H_INLINES 33 | 34 | #endif /* JEMALLOC_H_INLINES */ 35 | /******************************************************************************/ 36 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/include/jemalloc/internal/jemalloc_internal_decls.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_DECLS_H 2 | #define JEMALLOC_INTERNAL_DECLS_H 3 | 4 | #include 5 | #ifdef _WIN32 6 | # include 7 | # include "msvc_compat/windows_extra.h" 8 | 9 | # ifdef _MSC_VER 10 | # include 11 | # define getpid _getpid 12 | # endif 13 | 14 | #else 15 | # include 16 | # include 17 | # if !defined(__pnacl__) && !defined(__native_client__) 18 | # include 19 | # if !defined(SYS_write) && defined(__NR_write) 20 | # define SYS_write __NR_write 21 | # endif 22 | # include 23 | # endif 24 | # include 25 | # ifdef JEMALLOC_OS_UNFAIR_LOCK 26 | # include 27 | # endif 28 | # ifdef JEMALLOC_GLIBC_MALLOC_HOOK 29 | # include 30 | # endif 31 | # include 32 | # include 33 | # include 34 | # ifdef JEMALLOC_HAVE_MACH_ABSOLUTE_TIME 35 | # include 36 | # endif 37 | #endif 38 | #include 39 | 40 | #include 41 | #ifndef SIZE_T_MAX 42 | # define SIZE_T_MAX SIZE_MAX 43 | #endif 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #ifndef offsetof 51 | # define offsetof(type, member) ((size_t)&(((type *)NULL)->member)) 52 | #endif 53 | #include 54 | #include 55 | #include 56 | #ifdef _MSC_VER 57 | # include 58 | typedef intptr_t ssize_t; 59 | # define PATH_MAX 1024 60 | # define STDERR_FILENO 2 61 | # define __func__ __FUNCTION__ 62 | # ifdef JEMALLOC_HAS_RESTRICT 63 | # define restrict __restrict 64 | # endif 65 | /* Disable warnings about deprecated system functions. */ 66 | # pragma warning(disable: 4996) 67 | #if _MSC_VER < 1800 68 | static int 69 | isblank(int c) 70 | { 71 | 72 | return (c == '\t' || c == ' '); 73 | } 74 | #endif 75 | #else 76 | # include 77 | #endif 78 | #include 79 | 80 | #endif /* JEMALLOC_INTERNAL_H */ 81 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/include/jemalloc/internal/jemalloc_internal_macros.h: -------------------------------------------------------------------------------- 1 | /* 2 | * JEMALLOC_ALWAYS_INLINE and JEMALLOC_INLINE are used within header files for 3 | * functions that are static inline functions if inlining is enabled, and 4 | * single-definition library-private functions if inlining is disabled. 5 | * 6 | * JEMALLOC_ALWAYS_INLINE_C and JEMALLOC_INLINE_C are for use in .c files, in 7 | * which case the denoted functions are always static, regardless of whether 8 | * inlining is enabled. 9 | */ 10 | #if defined(JEMALLOC_DEBUG) || defined(JEMALLOC_CODE_COVERAGE) 11 | /* Disable inlining to make debugging/profiling easier. */ 12 | # define JEMALLOC_ALWAYS_INLINE 13 | # define JEMALLOC_ALWAYS_INLINE_C static 14 | # define JEMALLOC_INLINE 15 | # define JEMALLOC_INLINE_C static 16 | # define inline 17 | #else 18 | # define JEMALLOC_ENABLE_INLINE 19 | # ifdef JEMALLOC_HAVE_ATTR 20 | # define JEMALLOC_ALWAYS_INLINE \ 21 | static inline JEMALLOC_ATTR(unused) JEMALLOC_ATTR(always_inline) 22 | # define JEMALLOC_ALWAYS_INLINE_C \ 23 | static inline JEMALLOC_ATTR(always_inline) 24 | # else 25 | # define JEMALLOC_ALWAYS_INLINE static inline 26 | # define JEMALLOC_ALWAYS_INLINE_C static inline 27 | # endif 28 | # define JEMALLOC_INLINE static inline 29 | # define JEMALLOC_INLINE_C static inline 30 | # ifdef _MSC_VER 31 | # define inline _inline 32 | # endif 33 | #endif 34 | 35 | #ifdef JEMALLOC_CC_SILENCE 36 | # define UNUSED JEMALLOC_ATTR(unused) 37 | #else 38 | # define UNUSED 39 | #endif 40 | 41 | #define ZU(z) ((size_t)z) 42 | #define ZI(z) ((ssize_t)z) 43 | #define QU(q) ((uint64_t)q) 44 | #define QI(q) ((int64_t)q) 45 | 46 | #define KZU(z) ZU(z##ULL) 47 | #define KZI(z) ZI(z##LL) 48 | #define KQU(q) QU(q##ULL) 49 | #define KQI(q) QI(q##LL) 50 | 51 | #ifndef __DECONST 52 | # define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var)) 53 | #endif 54 | 55 | #ifndef JEMALLOC_HAS_RESTRICT 56 | # define restrict 57 | #endif 58 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/include/jemalloc/internal/nstime.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | #ifdef JEMALLOC_H_TYPES 3 | 4 | typedef struct nstime_s nstime_t; 5 | 6 | /* Maximum supported number of seconds (~584 years). */ 7 | #define NSTIME_SEC_MAX KQU(18446744072) 8 | 9 | #endif /* JEMALLOC_H_TYPES */ 10 | /******************************************************************************/ 11 | #ifdef JEMALLOC_H_STRUCTS 12 | 13 | struct nstime_s { 14 | uint64_t ns; 15 | }; 16 | 17 | #endif /* JEMALLOC_H_STRUCTS */ 18 | /******************************************************************************/ 19 | #ifdef JEMALLOC_H_EXTERNS 20 | 21 | void nstime_init(nstime_t *time, uint64_t ns); 22 | void nstime_init2(nstime_t *time, uint64_t sec, uint64_t nsec); 23 | uint64_t nstime_ns(const nstime_t *time); 24 | uint64_t nstime_sec(const nstime_t *time); 25 | uint64_t nstime_nsec(const nstime_t *time); 26 | void nstime_copy(nstime_t *time, const nstime_t *source); 27 | int nstime_compare(const nstime_t *a, const nstime_t *b); 28 | void nstime_add(nstime_t *time, const nstime_t *addend); 29 | void nstime_subtract(nstime_t *time, const nstime_t *subtrahend); 30 | void nstime_imultiply(nstime_t *time, uint64_t multiplier); 31 | void nstime_idivide(nstime_t *time, uint64_t divisor); 32 | uint64_t nstime_divide(const nstime_t *time, const nstime_t *divisor); 33 | #ifdef JEMALLOC_JET 34 | typedef bool (nstime_monotonic_t)(void); 35 | extern nstime_monotonic_t *nstime_monotonic; 36 | typedef bool (nstime_update_t)(nstime_t *); 37 | extern nstime_update_t *nstime_update; 38 | #else 39 | bool nstime_monotonic(void); 40 | bool nstime_update(nstime_t *time); 41 | #endif 42 | 43 | #endif /* JEMALLOC_H_EXTERNS */ 44 | /******************************************************************************/ 45 | #ifdef JEMALLOC_H_INLINES 46 | 47 | #endif /* JEMALLOC_H_INLINES */ 48 | /******************************************************************************/ 49 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/include/jemalloc/internal/pages.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | #ifdef JEMALLOC_H_TYPES 3 | 4 | #endif /* JEMALLOC_H_TYPES */ 5 | /******************************************************************************/ 6 | #ifdef JEMALLOC_H_STRUCTS 7 | 8 | #endif /* JEMALLOC_H_STRUCTS */ 9 | /******************************************************************************/ 10 | #ifdef JEMALLOC_H_EXTERNS 11 | 12 | void *pages_map(void *addr, size_t size, bool *commit); 13 | void pages_unmap(void *addr, size_t size); 14 | void *pages_trim(void *addr, size_t alloc_size, size_t leadsize, 15 | size_t size, bool *commit); 16 | bool pages_commit(void *addr, size_t size); 17 | bool pages_decommit(void *addr, size_t size); 18 | bool pages_purge(void *addr, size_t size); 19 | void pages_boot(void); 20 | 21 | #endif /* JEMALLOC_H_EXTERNS */ 22 | /******************************************************************************/ 23 | #ifdef JEMALLOC_H_INLINES 24 | 25 | #endif /* JEMALLOC_H_INLINES */ 26 | /******************************************************************************/ 27 | 28 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/include/jemalloc/internal/private_namespace.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | for symbol in `cat $1` ; do 4 | echo "#define ${symbol} JEMALLOC_N(${symbol})" 5 | done 6 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/include/jemalloc/internal/private_unnamespace.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | for symbol in `cat $1` ; do 4 | echo "#undef ${symbol}" 5 | done 6 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/include/jemalloc/internal/public_namespace.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | for nm in `cat $1` ; do 4 | n=`echo ${nm} |tr ':' ' ' |awk '{print $1}'` 5 | echo "#define je_${n} JEMALLOC_N(${n})" 6 | done 7 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/include/jemalloc/internal/public_unnamespace.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | for nm in `cat $1` ; do 4 | n=`echo ${nm} |tr ':' ' ' |awk '{print $1}'` 5 | echo "#undef je_${n}" 6 | done 7 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/include/jemalloc/internal/quarantine.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | #ifdef JEMALLOC_H_TYPES 3 | 4 | typedef struct quarantine_obj_s quarantine_obj_t; 5 | typedef struct quarantine_s quarantine_t; 6 | 7 | /* Default per thread quarantine size if valgrind is enabled. */ 8 | #define JEMALLOC_VALGRIND_QUARANTINE_DEFAULT (ZU(1) << 24) 9 | 10 | #endif /* JEMALLOC_H_TYPES */ 11 | /******************************************************************************/ 12 | #ifdef JEMALLOC_H_STRUCTS 13 | 14 | struct quarantine_obj_s { 15 | void *ptr; 16 | size_t usize; 17 | }; 18 | 19 | struct quarantine_s { 20 | size_t curbytes; 21 | size_t curobjs; 22 | size_t first; 23 | #define LG_MAXOBJS_INIT 10 24 | size_t lg_maxobjs; 25 | quarantine_obj_t objs[1]; /* Dynamically sized ring buffer. */ 26 | }; 27 | 28 | #endif /* JEMALLOC_H_STRUCTS */ 29 | /******************************************************************************/ 30 | #ifdef JEMALLOC_H_EXTERNS 31 | 32 | void quarantine_alloc_hook_work(tsd_t *tsd); 33 | void quarantine(tsd_t *tsd, void *ptr); 34 | void quarantine_cleanup(tsd_t *tsd); 35 | 36 | #endif /* JEMALLOC_H_EXTERNS */ 37 | /******************************************************************************/ 38 | #ifdef JEMALLOC_H_INLINES 39 | 40 | #ifndef JEMALLOC_ENABLE_INLINE 41 | void quarantine_alloc_hook(void); 42 | #endif 43 | 44 | #if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_QUARANTINE_C_)) 45 | JEMALLOC_ALWAYS_INLINE void 46 | quarantine_alloc_hook(void) 47 | { 48 | tsd_t *tsd; 49 | 50 | assert(config_fill && opt_quarantine); 51 | 52 | tsd = tsd_fetch(); 53 | if (tsd_quarantine_get(tsd) == NULL) 54 | quarantine_alloc_hook_work(tsd); 55 | } 56 | #endif 57 | 58 | #endif /* JEMALLOC_H_INLINES */ 59 | /******************************************************************************/ 60 | 61 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/include/jemalloc/internal/spin.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | #ifdef JEMALLOC_H_TYPES 3 | 4 | typedef struct spin_s spin_t; 5 | 6 | #endif /* JEMALLOC_H_TYPES */ 7 | /******************************************************************************/ 8 | #ifdef JEMALLOC_H_STRUCTS 9 | 10 | struct spin_s { 11 | unsigned iteration; 12 | }; 13 | 14 | #endif /* JEMALLOC_H_STRUCTS */ 15 | /******************************************************************************/ 16 | #ifdef JEMALLOC_H_EXTERNS 17 | 18 | #endif /* JEMALLOC_H_EXTERNS */ 19 | /******************************************************************************/ 20 | #ifdef JEMALLOC_H_INLINES 21 | 22 | #ifndef JEMALLOC_ENABLE_INLINE 23 | void spin_init(spin_t *spin); 24 | void spin_adaptive(spin_t *spin); 25 | #endif 26 | 27 | #if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_SPIN_C_)) 28 | JEMALLOC_INLINE void 29 | spin_init(spin_t *spin) 30 | { 31 | 32 | spin->iteration = 0; 33 | } 34 | 35 | JEMALLOC_INLINE void 36 | spin_adaptive(spin_t *spin) 37 | { 38 | volatile uint64_t i; 39 | 40 | for (i = 0; i < (KQU(1) << spin->iteration); i++) 41 | CPU_SPINWAIT; 42 | 43 | if (spin->iteration < 63) 44 | spin->iteration++; 45 | } 46 | 47 | #endif 48 | 49 | #endif /* JEMALLOC_H_INLINES */ 50 | /******************************************************************************/ 51 | 52 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/include/jemalloc/internal/ticker.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | #ifdef JEMALLOC_H_TYPES 3 | 4 | typedef struct ticker_s ticker_t; 5 | 6 | #endif /* JEMALLOC_H_TYPES */ 7 | /******************************************************************************/ 8 | #ifdef JEMALLOC_H_STRUCTS 9 | 10 | struct ticker_s { 11 | int32_t tick; 12 | int32_t nticks; 13 | }; 14 | 15 | #endif /* JEMALLOC_H_STRUCTS */ 16 | /******************************************************************************/ 17 | #ifdef JEMALLOC_H_EXTERNS 18 | 19 | #endif /* JEMALLOC_H_EXTERNS */ 20 | /******************************************************************************/ 21 | #ifdef JEMALLOC_H_INLINES 22 | 23 | #ifndef JEMALLOC_ENABLE_INLINE 24 | void ticker_init(ticker_t *ticker, int32_t nticks); 25 | void ticker_copy(ticker_t *ticker, const ticker_t *other); 26 | int32_t ticker_read(const ticker_t *ticker); 27 | bool ticker_ticks(ticker_t *ticker, int32_t nticks); 28 | bool ticker_tick(ticker_t *ticker); 29 | #endif 30 | 31 | #if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_TICKER_C_)) 32 | JEMALLOC_INLINE void 33 | ticker_init(ticker_t *ticker, int32_t nticks) 34 | { 35 | 36 | ticker->tick = nticks; 37 | ticker->nticks = nticks; 38 | } 39 | 40 | JEMALLOC_INLINE void 41 | ticker_copy(ticker_t *ticker, const ticker_t *other) 42 | { 43 | 44 | *ticker = *other; 45 | } 46 | 47 | JEMALLOC_INLINE int32_t 48 | ticker_read(const ticker_t *ticker) 49 | { 50 | 51 | return (ticker->tick); 52 | } 53 | 54 | JEMALLOC_INLINE bool 55 | ticker_ticks(ticker_t *ticker, int32_t nticks) 56 | { 57 | 58 | if (unlikely(ticker->tick < nticks)) { 59 | ticker->tick = ticker->nticks; 60 | return (true); 61 | } 62 | ticker->tick -= nticks; 63 | return(false); 64 | } 65 | 66 | JEMALLOC_INLINE bool 67 | ticker_tick(ticker_t *ticker) 68 | { 69 | 70 | return (ticker_ticks(ticker, 1)); 71 | } 72 | #endif 73 | 74 | #endif /* JEMALLOC_H_INLINES */ 75 | /******************************************************************************/ 76 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/include/jemalloc/jemalloc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | objroot=$1 4 | 5 | cat < 5 | 6 | /* MSVC doesn't define _Bool or bool in C, but does have BOOL */ 7 | /* Note this doesn't pass autoconf's test because (bool) 0.5 != true */ 8 | /* Clang-cl uses MSVC headers, so needs msvc_compat, but has _Bool as 9 | * a built-in type. */ 10 | #ifndef __clang__ 11 | typedef BOOL _Bool; 12 | #endif 13 | 14 | #define bool _Bool 15 | #define true 1 16 | #define false 0 17 | 18 | #define __bool_true_false_are_defined 1 19 | 20 | #endif /* stdbool_h */ 21 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/include/msvc_compat/strings.h: -------------------------------------------------------------------------------- 1 | #ifndef strings_h 2 | #define strings_h 3 | 4 | /* MSVC doesn't define ffs/ffsl. This dummy strings.h header is provided 5 | * for both */ 6 | #ifdef _MSC_VER 7 | # include 8 | # pragma intrinsic(_BitScanForward) 9 | static __forceinline int ffsl(long x) 10 | { 11 | unsigned long i; 12 | 13 | if (_BitScanForward(&i, x)) 14 | return (i + 1); 15 | return (0); 16 | } 17 | 18 | static __forceinline int ffs(int x) 19 | { 20 | 21 | return (ffsl(x)); 22 | } 23 | 24 | # ifdef _M_X64 25 | # pragma intrinsic(_BitScanForward64) 26 | # endif 27 | 28 | static __forceinline int ffsll(unsigned __int64 x) 29 | { 30 | unsigned long i; 31 | #ifdef _M_X64 32 | if (_BitScanForward64(&i, x)) 33 | return (i + 1); 34 | return (0); 35 | #else 36 | // Fallback for 32-bit build where 64-bit version not available 37 | // assuming little endian 38 | union { 39 | unsigned __int64 ll; 40 | unsigned long l[2]; 41 | } s; 42 | 43 | s.ll = x; 44 | 45 | if (_BitScanForward(&i, s.l[0])) 46 | return (i + 1); 47 | else if(_BitScanForward(&i, s.l[1])) 48 | return (i + 33); 49 | return (0); 50 | #endif 51 | } 52 | 53 | #else 54 | # define ffsll(x) __builtin_ffsll(x) 55 | # define ffsl(x) __builtin_ffsl(x) 56 | # define ffs(x) __builtin_ffs(x) 57 | #endif 58 | 59 | #endif /* strings_h */ 60 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/include/msvc_compat/windows_extra.h: -------------------------------------------------------------------------------- 1 | #ifndef MSVC_COMPAT_WINDOWS_EXTRA_H 2 | #define MSVC_COMPAT_WINDOWS_EXTRA_H 3 | 4 | #include 5 | 6 | #endif /* MSVC_COMPAT_WINDOWS_EXTRA_H */ 7 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/jemalloc.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | install_suffix=@install_suffix@ 6 | 7 | Name: jemalloc 8 | Description: A general purpose malloc(3) implementation that emphasizes fragmentation avoidance and scalable concurrency support. 9 | URL: http://jemalloc.net/ 10 | Version: @jemalloc_version@ 11 | Cflags: -I${includedir} 12 | Libs: -L${libdir} -ljemalloc${install_suffix} 13 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/msvc/ReadMe.txt: -------------------------------------------------------------------------------- 1 | 2 | How to build jemalloc for Windows 3 | ================================= 4 | 5 | 1. Install Cygwin with at least the following packages: 6 | * autoconf 7 | * autogen 8 | * gawk 9 | * grep 10 | * sed 11 | 12 | 2. Install Visual Studio 2015 with Visual C++ 13 | 14 | 3. Add Cygwin\bin to the PATH environment variable 15 | 16 | 4. Open "VS2015 x86 Native Tools Command Prompt" 17 | (note: x86/x64 doesn't matter at this point) 18 | 19 | 5. Generate header files: 20 | sh -c "CC=cl ./autogen.sh" 21 | 22 | 6. Now the project can be opened and built in Visual Studio: 23 | msvc\jemalloc_vc2015.sln 24 | 25 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/msvc/projects/vc2015/test_threads/test_threads.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | int test_threads(); 4 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/msvc/projects/vc2015/test_threads/test_threads_main.cpp: -------------------------------------------------------------------------------- 1 | #include "test_threads.h" 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std::chrono_literals; 7 | 8 | int main(int argc, char** argv) 9 | { 10 | int rc = test_threads(); 11 | return rc; 12 | } 13 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/src/atomic.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_ATOMIC_C_ 2 | #include "jemalloc/internal/jemalloc_internal.h" 3 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/src/extent.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_EXTENT_C_ 2 | #include "jemalloc/internal/jemalloc_internal.h" 3 | 4 | /******************************************************************************/ 5 | 6 | JEMALLOC_INLINE_C size_t 7 | extent_quantize(size_t size) 8 | { 9 | 10 | /* 11 | * Round down to the nearest chunk size that can actually be requested 12 | * during normal huge allocation. 13 | */ 14 | return (index2size(size2index(size + 1) - 1)); 15 | } 16 | 17 | JEMALLOC_INLINE_C int 18 | extent_szad_comp(const extent_node_t *a, const extent_node_t *b) 19 | { 20 | int ret; 21 | size_t a_qsize = extent_quantize(extent_node_size_get(a)); 22 | size_t b_qsize = extent_quantize(extent_node_size_get(b)); 23 | 24 | /* 25 | * Compare based on quantized size rather than size, in order to sort 26 | * equally useful extents only by address. 27 | */ 28 | ret = (a_qsize > b_qsize) - (a_qsize < b_qsize); 29 | if (ret == 0) { 30 | uintptr_t a_addr = (uintptr_t)extent_node_addr_get(a); 31 | uintptr_t b_addr = (uintptr_t)extent_node_addr_get(b); 32 | 33 | ret = (a_addr > b_addr) - (a_addr < b_addr); 34 | } 35 | 36 | return (ret); 37 | } 38 | 39 | /* Generate red-black tree functions. */ 40 | rb_gen(, extent_tree_szad_, extent_tree_t, extent_node_t, szad_link, 41 | extent_szad_comp) 42 | 43 | JEMALLOC_INLINE_C int 44 | extent_ad_comp(const extent_node_t *a, const extent_node_t *b) 45 | { 46 | uintptr_t a_addr = (uintptr_t)extent_node_addr_get(a); 47 | uintptr_t b_addr = (uintptr_t)extent_node_addr_get(b); 48 | 49 | return ((a_addr > b_addr) - (a_addr < b_addr)); 50 | } 51 | 52 | /* Generate red-black tree functions. */ 53 | rb_gen(, extent_tree_ad_, extent_tree_t, extent_node_t, ad_link, extent_ad_comp) 54 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/src/hash.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_HASH_C_ 2 | #include "jemalloc/internal/jemalloc_internal.h" 3 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/src/mb.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_MB_C_ 2 | #include "jemalloc/internal/jemalloc_internal.h" 3 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/src/prng.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_PRNG_C_ 2 | #include "jemalloc/internal/jemalloc_internal.h" 3 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/src/spin.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_SPIN_C_ 2 | #include "jemalloc/internal/jemalloc_internal.h" 3 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/src/ticker.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_TICKER_C_ 2 | #include "jemalloc/internal/jemalloc_internal.h" 3 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/src/valgrind.c: -------------------------------------------------------------------------------- 1 | #include "jemalloc/internal/jemalloc_internal.h" 2 | #ifndef JEMALLOC_VALGRIND 3 | # error "This source file is for Valgrind integration." 4 | #endif 5 | 6 | #include 7 | 8 | void 9 | valgrind_make_mem_noaccess(void *ptr, size_t usize) 10 | { 11 | 12 | VALGRIND_MAKE_MEM_NOACCESS(ptr, usize); 13 | } 14 | 15 | void 16 | valgrind_make_mem_undefined(void *ptr, size_t usize) 17 | { 18 | 19 | VALGRIND_MAKE_MEM_UNDEFINED(ptr, usize); 20 | } 21 | 22 | void 23 | valgrind_make_mem_defined(void *ptr, size_t usize) 24 | { 25 | 26 | VALGRIND_MAKE_MEM_DEFINED(ptr, usize); 27 | } 28 | 29 | void 30 | valgrind_freelike_block(void *ptr, size_t usize) 31 | { 32 | 33 | VALGRIND_FREELIKE_BLOCK(ptr, usize); 34 | } 35 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/test/include/test/btalloc.h: -------------------------------------------------------------------------------- 1 | /* btalloc() provides a mechanism for allocating via permuted backtraces. */ 2 | void *btalloc(size_t size, unsigned bits); 3 | 4 | #define btalloc_n_proto(n) \ 5 | void *btalloc_##n(size_t size, unsigned bits); 6 | btalloc_n_proto(0) 7 | btalloc_n_proto(1) 8 | 9 | #define btalloc_n_gen(n) \ 10 | void * \ 11 | btalloc_##n(size_t size, unsigned bits) \ 12 | { \ 13 | void *p; \ 14 | \ 15 | if (bits == 0) \ 16 | p = mallocx(size, 0); \ 17 | else { \ 18 | switch (bits & 0x1U) { \ 19 | case 0: \ 20 | p = (btalloc_0(size, bits >> 1)); \ 21 | break; \ 22 | case 1: \ 23 | p = (btalloc_1(size, bits >> 1)); \ 24 | break; \ 25 | default: not_reached(); \ 26 | } \ 27 | } \ 28 | /* Intentionally sabotage tail call optimization. */ \ 29 | assert_ptr_not_null(p, "Unexpected mallocx() failure"); \ 30 | return (p); \ 31 | } 32 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/test/include/test/jemalloc_test_defs.h.in: -------------------------------------------------------------------------------- 1 | #include "jemalloc/internal/jemalloc_internal_defs.h" 2 | #include "jemalloc/internal/jemalloc_internal_decls.h" 3 | 4 | /* 5 | * For use by SFMT. configure.ac doesn't actually define HAVE_SSE2 because its 6 | * dependencies are notoriously unportable in practice. 7 | */ 8 | #undef HAVE_SSE2 9 | #undef HAVE_ALTIVEC 10 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/test/include/test/mtx.h: -------------------------------------------------------------------------------- 1 | /* 2 | * mtx is a slightly simplified version of malloc_mutex. This code duplication 3 | * is unfortunate, but there are allocator bootstrapping considerations that 4 | * would leak into the test infrastructure if malloc_mutex were used directly 5 | * in tests. 6 | */ 7 | 8 | typedef struct { 9 | #ifdef _WIN32 10 | CRITICAL_SECTION lock; 11 | #elif (defined(JEMALLOC_OS_UNFAIR_LOCK)) 12 | os_unfair_lock lock; 13 | #elif (defined(JEMALLOC_OSSPIN)) 14 | OSSpinLock lock; 15 | #else 16 | pthread_mutex_t lock; 17 | #endif 18 | } mtx_t; 19 | 20 | bool mtx_init(mtx_t *mtx); 21 | void mtx_fini(mtx_t *mtx); 22 | void mtx_lock(mtx_t *mtx); 23 | void mtx_unlock(mtx_t *mtx); 24 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/test/include/test/thd.h: -------------------------------------------------------------------------------- 1 | /* Abstraction layer for threading in tests. */ 2 | #ifdef _WIN32 3 | typedef HANDLE thd_t; 4 | #else 5 | typedef pthread_t thd_t; 6 | #endif 7 | 8 | void thd_create(thd_t *thd, void *(*proc)(void *), void *arg); 9 | void thd_join(thd_t thd, void **ret); 10 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/test/include/test/timer.h: -------------------------------------------------------------------------------- 1 | /* Simple timer, for use in benchmark reporting. */ 2 | 3 | typedef struct { 4 | nstime_t t0; 5 | nstime_t t1; 6 | } timedelta_t; 7 | 8 | void timer_start(timedelta_t *timer); 9 | void timer_stop(timedelta_t *timer); 10 | uint64_t timer_usec(const timedelta_t *timer); 11 | void timer_ratio(timedelta_t *a, timedelta_t *b, char *buf, size_t buflen); 12 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/test/integration/MALLOCX_ARENA.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | #define NTHREADS 10 4 | 5 | static bool have_dss = 6 | #ifdef JEMALLOC_DSS 7 | true 8 | #else 9 | false 10 | #endif 11 | ; 12 | 13 | void * 14 | thd_start(void *arg) 15 | { 16 | unsigned thread_ind = (unsigned)(uintptr_t)arg; 17 | unsigned arena_ind; 18 | void *p; 19 | size_t sz; 20 | 21 | sz = sizeof(arena_ind); 22 | assert_d_eq(mallctl("arenas.extend", &arena_ind, &sz, NULL, 0), 0, 23 | "Error in arenas.extend"); 24 | 25 | if (thread_ind % 4 != 3) { 26 | size_t mib[3]; 27 | size_t miblen = sizeof(mib) / sizeof(size_t); 28 | const char *dss_precs[] = {"disabled", "primary", "secondary"}; 29 | unsigned prec_ind = thread_ind % 30 | (sizeof(dss_precs)/sizeof(char*)); 31 | const char *dss = dss_precs[prec_ind]; 32 | int expected_err = (have_dss || prec_ind == 0) ? 0 : EFAULT; 33 | assert_d_eq(mallctlnametomib("arena.0.dss", mib, &miblen), 0, 34 | "Error in mallctlnametomib()"); 35 | mib[1] = arena_ind; 36 | assert_d_eq(mallctlbymib(mib, miblen, NULL, NULL, (void *)&dss, 37 | sizeof(const char *)), expected_err, 38 | "Error in mallctlbymib()"); 39 | } 40 | 41 | p = mallocx(1, MALLOCX_ARENA(arena_ind)); 42 | assert_ptr_not_null(p, "Unexpected mallocx() error"); 43 | dallocx(p, 0); 44 | 45 | return (NULL); 46 | } 47 | 48 | TEST_BEGIN(test_MALLOCX_ARENA) 49 | { 50 | thd_t thds[NTHREADS]; 51 | unsigned i; 52 | 53 | for (i = 0; i < NTHREADS; i++) { 54 | thd_create(&thds[i], thd_start, 55 | (void *)(uintptr_t)i); 56 | } 57 | 58 | for (i = 0; i < NTHREADS; i++) 59 | thd_join(thds[i], NULL); 60 | } 61 | TEST_END 62 | 63 | int 64 | main(void) 65 | { 66 | 67 | return (test( 68 | test_MALLOCX_ARENA)); 69 | } 70 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/test/integration/overflow.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | TEST_BEGIN(test_overflow) 4 | { 5 | unsigned nhchunks; 6 | size_t mib[4]; 7 | size_t sz, miblen, max_size_class; 8 | void *p; 9 | 10 | sz = sizeof(unsigned); 11 | assert_d_eq(mallctl("arenas.nhchunks", &nhchunks, &sz, NULL, 0), 0, 12 | "Unexpected mallctl() error"); 13 | 14 | miblen = sizeof(mib) / sizeof(size_t); 15 | assert_d_eq(mallctlnametomib("arenas.hchunk.0.size", mib, &miblen), 0, 16 | "Unexpected mallctlnametomib() error"); 17 | mib[2] = nhchunks - 1; 18 | 19 | sz = sizeof(size_t); 20 | assert_d_eq(mallctlbymib(mib, miblen, &max_size_class, &sz, NULL, 0), 0, 21 | "Unexpected mallctlbymib() error"); 22 | 23 | assert_ptr_null(malloc(max_size_class + 1), 24 | "Expected OOM due to over-sized allocation request"); 25 | assert_ptr_null(malloc(SIZE_T_MAX), 26 | "Expected OOM due to over-sized allocation request"); 27 | 28 | assert_ptr_null(calloc(1, max_size_class + 1), 29 | "Expected OOM due to over-sized allocation request"); 30 | assert_ptr_null(calloc(1, SIZE_T_MAX), 31 | "Expected OOM due to over-sized allocation request"); 32 | 33 | p = malloc(1); 34 | assert_ptr_not_null(p, "Unexpected malloc() OOM"); 35 | assert_ptr_null(realloc(p, max_size_class + 1), 36 | "Expected OOM due to over-sized allocation request"); 37 | assert_ptr_null(realloc(p, SIZE_T_MAX), 38 | "Expected OOM due to over-sized allocation request"); 39 | free(p); 40 | } 41 | TEST_END 42 | 43 | int 44 | main(void) 45 | { 46 | 47 | return (test( 48 | test_overflow)); 49 | } 50 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/test/integration/sdallocx.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | #define MAXALIGN (((size_t)1) << 25) 4 | #define NITER 4 5 | 6 | TEST_BEGIN(test_basic) 7 | { 8 | void *ptr = mallocx(64, 0); 9 | sdallocx(ptr, 64, 0); 10 | } 11 | TEST_END 12 | 13 | TEST_BEGIN(test_alignment_and_size) 14 | { 15 | size_t nsz, sz, alignment, total; 16 | unsigned i; 17 | void *ps[NITER]; 18 | 19 | for (i = 0; i < NITER; i++) 20 | ps[i] = NULL; 21 | 22 | for (alignment = 8; 23 | alignment <= MAXALIGN; 24 | alignment <<= 1) { 25 | total = 0; 26 | for (sz = 1; 27 | sz < 3 * alignment && sz < (1U << 31); 28 | sz += (alignment >> (LG_SIZEOF_PTR-1)) - 1) { 29 | for (i = 0; i < NITER; i++) { 30 | nsz = nallocx(sz, MALLOCX_ALIGN(alignment) | 31 | MALLOCX_ZERO); 32 | ps[i] = mallocx(sz, MALLOCX_ALIGN(alignment) | 33 | MALLOCX_ZERO); 34 | total += nsz; 35 | if (total >= (MAXALIGN << 1)) 36 | break; 37 | } 38 | for (i = 0; i < NITER; i++) { 39 | if (ps[i] != NULL) { 40 | sdallocx(ps[i], sz, 41 | MALLOCX_ALIGN(alignment)); 42 | ps[i] = NULL; 43 | } 44 | } 45 | } 46 | } 47 | } 48 | TEST_END 49 | 50 | int 51 | main(void) 52 | { 53 | 54 | return (test( 55 | test_basic, 56 | test_alignment_and_size)); 57 | } 58 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/test/integration/thread_arena.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | #define NTHREADS 10 4 | 5 | void * 6 | thd_start(void *arg) 7 | { 8 | unsigned main_arena_ind = *(unsigned *)arg; 9 | void *p; 10 | unsigned arena_ind; 11 | size_t size; 12 | int err; 13 | 14 | p = malloc(1); 15 | assert_ptr_not_null(p, "Error in malloc()"); 16 | free(p); 17 | 18 | size = sizeof(arena_ind); 19 | if ((err = mallctl("thread.arena", &arena_ind, &size, &main_arena_ind, 20 | sizeof(main_arena_ind)))) { 21 | char buf[BUFERROR_BUF]; 22 | 23 | buferror(err, buf, sizeof(buf)); 24 | test_fail("Error in mallctl(): %s", buf); 25 | } 26 | 27 | size = sizeof(arena_ind); 28 | if ((err = mallctl("thread.arena", &arena_ind, &size, NULL, 0))) { 29 | char buf[BUFERROR_BUF]; 30 | 31 | buferror(err, buf, sizeof(buf)); 32 | test_fail("Error in mallctl(): %s", buf); 33 | } 34 | assert_u_eq(arena_ind, main_arena_ind, 35 | "Arena index should be same as for main thread"); 36 | 37 | return (NULL); 38 | } 39 | 40 | TEST_BEGIN(test_thread_arena) 41 | { 42 | void *p; 43 | unsigned arena_ind; 44 | size_t size; 45 | int err; 46 | thd_t thds[NTHREADS]; 47 | unsigned i; 48 | 49 | p = malloc(1); 50 | assert_ptr_not_null(p, "Error in malloc()"); 51 | 52 | size = sizeof(arena_ind); 53 | if ((err = mallctl("thread.arena", &arena_ind, &size, NULL, 0))) { 54 | char buf[BUFERROR_BUF]; 55 | 56 | buferror(err, buf, sizeof(buf)); 57 | test_fail("Error in mallctl(): %s", buf); 58 | } 59 | 60 | for (i = 0; i < NTHREADS; i++) { 61 | thd_create(&thds[i], thd_start, 62 | (void *)&arena_ind); 63 | } 64 | 65 | for (i = 0; i < NTHREADS; i++) { 66 | intptr_t join_ret; 67 | thd_join(thds[i], (void *)&join_ret); 68 | assert_zd_eq(join_ret, 0, "Unexpected thread join error"); 69 | } 70 | } 71 | TEST_END 72 | 73 | int 74 | main(void) 75 | { 76 | 77 | return (test( 78 | test_thread_arena)); 79 | } 80 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/test/src/btalloc.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | void * 4 | btalloc(size_t size, unsigned bits) 5 | { 6 | 7 | return (btalloc_0(size, bits)); 8 | } 9 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/test/src/btalloc_0.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | btalloc_n_gen(0) 4 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/test/src/btalloc_1.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | btalloc_n_gen(1) 4 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/test/src/math.c: -------------------------------------------------------------------------------- 1 | #define MATH_C_ 2 | #include "test/jemalloc_test.h" 3 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/test/src/mq.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | /* 4 | * Sleep for approximately ns nanoseconds. No lower *nor* upper bound on sleep 5 | * time is guaranteed. 6 | */ 7 | void 8 | mq_nanosleep(unsigned ns) 9 | { 10 | 11 | assert(ns <= 1000*1000*1000); 12 | 13 | #ifdef _WIN32 14 | Sleep(ns / 1000); 15 | #else 16 | { 17 | struct timespec timeout; 18 | 19 | if (ns < 1000*1000*1000) { 20 | timeout.tv_sec = 0; 21 | timeout.tv_nsec = ns; 22 | } else { 23 | timeout.tv_sec = 1; 24 | timeout.tv_nsec = 0; 25 | } 26 | nanosleep(&timeout, NULL); 27 | } 28 | #endif 29 | } 30 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/test/src/mtx.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | #ifndef _CRT_SPINCOUNT 4 | #define _CRT_SPINCOUNT 4000 5 | #endif 6 | 7 | bool 8 | mtx_init(mtx_t *mtx) 9 | { 10 | 11 | #ifdef _WIN32 12 | if (!InitializeCriticalSectionAndSpinCount(&mtx->lock, _CRT_SPINCOUNT)) 13 | return (true); 14 | #elif (defined(JEMALLOC_OS_UNFAIR_LOCK)) 15 | mtx->lock = OS_UNFAIR_LOCK_INIT; 16 | #elif (defined(JEMALLOC_OSSPIN)) 17 | mtx->lock = 0; 18 | #else 19 | pthread_mutexattr_t attr; 20 | 21 | if (pthread_mutexattr_init(&attr) != 0) 22 | return (true); 23 | pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_DEFAULT); 24 | if (pthread_mutex_init(&mtx->lock, &attr) != 0) { 25 | pthread_mutexattr_destroy(&attr); 26 | return (true); 27 | } 28 | pthread_mutexattr_destroy(&attr); 29 | #endif 30 | return (false); 31 | } 32 | 33 | void 34 | mtx_fini(mtx_t *mtx) 35 | { 36 | 37 | #ifdef _WIN32 38 | #elif (defined(JEMALLOC_OS_UNFAIR_LOCK)) 39 | #elif (defined(JEMALLOC_OSSPIN)) 40 | #else 41 | pthread_mutex_destroy(&mtx->lock); 42 | #endif 43 | } 44 | 45 | void 46 | mtx_lock(mtx_t *mtx) 47 | { 48 | 49 | #ifdef _WIN32 50 | EnterCriticalSection(&mtx->lock); 51 | #elif (defined(JEMALLOC_OS_UNFAIR_LOCK)) 52 | os_unfair_lock_lock(&mtx->lock); 53 | #elif (defined(JEMALLOC_OSSPIN)) 54 | OSSpinLockLock(&mtx->lock); 55 | #else 56 | pthread_mutex_lock(&mtx->lock); 57 | #endif 58 | } 59 | 60 | void 61 | mtx_unlock(mtx_t *mtx) 62 | { 63 | 64 | #ifdef _WIN32 65 | LeaveCriticalSection(&mtx->lock); 66 | #elif (defined(JEMALLOC_OS_UNFAIR_LOCK)) 67 | os_unfair_lock_unlock(&mtx->lock); 68 | #elif (defined(JEMALLOC_OSSPIN)) 69 | OSSpinLockUnlock(&mtx->lock); 70 | #else 71 | pthread_mutex_unlock(&mtx->lock); 72 | #endif 73 | } 74 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/test/src/thd.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | #ifdef _WIN32 4 | void 5 | thd_create(thd_t *thd, void *(*proc)(void *), void *arg) 6 | { 7 | LPTHREAD_START_ROUTINE routine = (LPTHREAD_START_ROUTINE)proc; 8 | *thd = CreateThread(NULL, 0, routine, arg, 0, NULL); 9 | if (*thd == NULL) 10 | test_fail("Error in CreateThread()\n"); 11 | } 12 | 13 | void 14 | thd_join(thd_t thd, void **ret) 15 | { 16 | 17 | if (WaitForSingleObject(thd, INFINITE) == WAIT_OBJECT_0 && ret) { 18 | DWORD exit_code; 19 | GetExitCodeThread(thd, (LPDWORD) &exit_code); 20 | *ret = (void *)(uintptr_t)exit_code; 21 | } 22 | } 23 | 24 | #else 25 | void 26 | thd_create(thd_t *thd, void *(*proc)(void *), void *arg) 27 | { 28 | 29 | if (pthread_create(thd, NULL, proc, arg) != 0) 30 | test_fail("Error in pthread_create()\n"); 31 | } 32 | 33 | void 34 | thd_join(thd_t thd, void **ret) 35 | { 36 | 37 | pthread_join(thd, ret); 38 | } 39 | #endif 40 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/test/src/timer.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | void 4 | timer_start(timedelta_t *timer) 5 | { 6 | 7 | nstime_init(&timer->t0, 0); 8 | nstime_update(&timer->t0); 9 | } 10 | 11 | void 12 | timer_stop(timedelta_t *timer) 13 | { 14 | 15 | nstime_copy(&timer->t1, &timer->t0); 16 | nstime_update(&timer->t1); 17 | } 18 | 19 | uint64_t 20 | timer_usec(const timedelta_t *timer) 21 | { 22 | nstime_t delta; 23 | 24 | nstime_copy(&delta, &timer->t1); 25 | nstime_subtract(&delta, &timer->t0); 26 | return (nstime_ns(&delta) / 1000); 27 | } 28 | 29 | void 30 | timer_ratio(timedelta_t *a, timedelta_t *b, char *buf, size_t buflen) 31 | { 32 | uint64_t t0 = timer_usec(a); 33 | uint64_t t1 = timer_usec(b); 34 | uint64_t mult; 35 | size_t i = 0; 36 | size_t j, n; 37 | 38 | /* Whole. */ 39 | n = malloc_snprintf(&buf[i], buflen-i, "%"FMTu64, t0 / t1); 40 | i += n; 41 | if (i >= buflen) 42 | return; 43 | mult = 1; 44 | for (j = 0; j < n; j++) 45 | mult *= 10; 46 | 47 | /* Decimal. */ 48 | n = malloc_snprintf(&buf[i], buflen-i, "."); 49 | i += n; 50 | 51 | /* Fraction. */ 52 | while (i < buflen-1) { 53 | uint64_t round = (i+1 == buflen-1 && ((t0 * mult * 10 / t1) % 10 54 | >= 5)) ? 1 : 0; 55 | n = malloc_snprintf(&buf[i], buflen-i, 56 | "%"FMTu64, (t0 * mult / t1) % 10 + round); 57 | i += n; 58 | mult *= 10; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/test/test.sh.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | case @abi@ in 4 | macho) 5 | export DYLD_FALLBACK_LIBRARY_PATH="@objroot@lib" 6 | ;; 7 | pecoff) 8 | export PATH="${PATH}:@objroot@lib" 9 | ;; 10 | *) 11 | ;; 12 | esac 13 | 14 | # Corresponds to test_status_t. 15 | pass_code=0 16 | skip_code=1 17 | fail_code=2 18 | 19 | pass_count=0 20 | skip_count=0 21 | fail_count=0 22 | for t in $@; do 23 | if [ $pass_count -ne 0 -o $skip_count -ne 0 -o $fail_count != 0 ] ; then 24 | echo 25 | fi 26 | echo "=== ${t} ===" 27 | ${t}@exe@ @abs_srcroot@ @abs_objroot@ 28 | result_code=$? 29 | case ${result_code} in 30 | ${pass_code}) 31 | pass_count=$((pass_count+1)) 32 | ;; 33 | ${skip_code}) 34 | skip_count=$((skip_count+1)) 35 | ;; 36 | ${fail_code}) 37 | fail_count=$((fail_count+1)) 38 | ;; 39 | *) 40 | echo "Test harness error" 1>&2 41 | exit 1 42 | esac 43 | done 44 | 45 | total_count=`expr ${pass_count} + ${skip_count} + ${fail_count}` 46 | echo 47 | echo "Test suite summary: pass: ${pass_count}/${total_count}, skip: ${skip_count}/${total_count}, fail: ${fail_count}/${total_count}" 48 | 49 | if [ ${fail_count} -eq 0 ] ; then 50 | exit 0 51 | else 52 | exit 1 53 | fi 54 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/test/unit/a0.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | TEST_BEGIN(test_a0) 4 | { 5 | void *p; 6 | 7 | p = a0malloc(1); 8 | assert_ptr_not_null(p, "Unexpected a0malloc() error"); 9 | a0dalloc(p); 10 | } 11 | TEST_END 12 | 13 | int 14 | main(void) 15 | { 16 | 17 | return (test_no_malloc_init( 18 | test_a0)); 19 | } 20 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/test/unit/fork.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | #ifndef _WIN32 4 | #include 5 | #endif 6 | 7 | TEST_BEGIN(test_fork) 8 | { 9 | #ifndef _WIN32 10 | void *p; 11 | pid_t pid; 12 | 13 | p = malloc(1); 14 | assert_ptr_not_null(p, "Unexpected malloc() failure"); 15 | 16 | pid = fork(); 17 | 18 | free(p); 19 | 20 | p = malloc(64); 21 | assert_ptr_not_null(p, "Unexpected malloc() failure"); 22 | free(p); 23 | 24 | if (pid == -1) { 25 | /* Error. */ 26 | test_fail("Unexpected fork() failure"); 27 | } else if (pid == 0) { 28 | /* Child. */ 29 | _exit(0); 30 | } else { 31 | int status; 32 | 33 | /* Parent. */ 34 | while (true) { 35 | if (waitpid(pid, &status, 0) == -1) 36 | test_fail("Unexpected waitpid() failure"); 37 | if (WIFSIGNALED(status)) { 38 | test_fail("Unexpected child termination due to " 39 | "signal %d", WTERMSIG(status)); 40 | break; 41 | } 42 | if (WIFEXITED(status)) { 43 | if (WEXITSTATUS(status) != 0) { 44 | test_fail( 45 | "Unexpected child exit value %d", 46 | WEXITSTATUS(status)); 47 | } 48 | break; 49 | } 50 | } 51 | } 52 | #else 53 | test_skip("fork(2) is irrelevant to Windows"); 54 | #endif 55 | } 56 | TEST_END 57 | 58 | int 59 | main(void) 60 | { 61 | 62 | return (test( 63 | test_fork)); 64 | } 65 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/test/unit/junk_alloc.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_TEST_JUNK_OPT "junk:alloc" 2 | #include "junk.c" 3 | #undef JEMALLOC_TEST_JUNK_OPT 4 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/test/unit/junk_free.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_TEST_JUNK_OPT "junk:free" 2 | #include "junk.c" 3 | #undef JEMALLOC_TEST_JUNK_OPT 4 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/test/unit/lg_chunk.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | /* 4 | * Make sure that opt.lg_chunk clamping is sufficient. In practice, this test 5 | * program will fail a debug assertion during initialization and abort (rather 6 | * than the test soft-failing) if clamping is insufficient. 7 | */ 8 | const char *malloc_conf = "lg_chunk:0"; 9 | 10 | TEST_BEGIN(test_lg_chunk_clamp) 11 | { 12 | void *p; 13 | 14 | p = mallocx(1, 0); 15 | assert_ptr_not_null(p, "Unexpected mallocx() failure"); 16 | dallocx(p, 0); 17 | } 18 | TEST_END 19 | 20 | int 21 | main(void) 22 | { 23 | 24 | return (test( 25 | test_lg_chunk_clamp)); 26 | } 27 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/test/unit/mq.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | #define NSENDERS 3 4 | #define NMSGS 100000 5 | 6 | typedef struct mq_msg_s mq_msg_t; 7 | struct mq_msg_s { 8 | mq_msg(mq_msg_t) link; 9 | }; 10 | mq_gen(static, mq_, mq_t, mq_msg_t, link) 11 | 12 | TEST_BEGIN(test_mq_basic) 13 | { 14 | mq_t mq; 15 | mq_msg_t msg; 16 | 17 | assert_false(mq_init(&mq), "Unexpected mq_init() failure"); 18 | assert_u_eq(mq_count(&mq), 0, "mq should be empty"); 19 | assert_ptr_null(mq_tryget(&mq), 20 | "mq_tryget() should fail when the queue is empty"); 21 | 22 | mq_put(&mq, &msg); 23 | assert_u_eq(mq_count(&mq), 1, "mq should contain one message"); 24 | assert_ptr_eq(mq_tryget(&mq), &msg, "mq_tryget() should return msg"); 25 | 26 | mq_put(&mq, &msg); 27 | assert_ptr_eq(mq_get(&mq), &msg, "mq_get() should return msg"); 28 | 29 | mq_fini(&mq); 30 | } 31 | TEST_END 32 | 33 | static void * 34 | thd_receiver_start(void *arg) 35 | { 36 | mq_t *mq = (mq_t *)arg; 37 | unsigned i; 38 | 39 | for (i = 0; i < (NSENDERS * NMSGS); i++) { 40 | mq_msg_t *msg = mq_get(mq); 41 | assert_ptr_not_null(msg, "mq_get() should never return NULL"); 42 | dallocx(msg, 0); 43 | } 44 | return (NULL); 45 | } 46 | 47 | static void * 48 | thd_sender_start(void *arg) 49 | { 50 | mq_t *mq = (mq_t *)arg; 51 | unsigned i; 52 | 53 | for (i = 0; i < NMSGS; i++) { 54 | mq_msg_t *msg; 55 | void *p; 56 | p = mallocx(sizeof(mq_msg_t), 0); 57 | assert_ptr_not_null(p, "Unexpected mallocx() failure"); 58 | msg = (mq_msg_t *)p; 59 | mq_put(mq, msg); 60 | } 61 | return (NULL); 62 | } 63 | 64 | TEST_BEGIN(test_mq_threaded) 65 | { 66 | mq_t mq; 67 | thd_t receiver; 68 | thd_t senders[NSENDERS]; 69 | unsigned i; 70 | 71 | assert_false(mq_init(&mq), "Unexpected mq_init() failure"); 72 | 73 | thd_create(&receiver, thd_receiver_start, (void *)&mq); 74 | for (i = 0; i < NSENDERS; i++) 75 | thd_create(&senders[i], thd_sender_start, (void *)&mq); 76 | 77 | thd_join(receiver, NULL); 78 | for (i = 0; i < NSENDERS; i++) 79 | thd_join(senders[i], NULL); 80 | 81 | mq_fini(&mq); 82 | } 83 | TEST_END 84 | 85 | int 86 | main(void) 87 | { 88 | 89 | return (test( 90 | test_mq_basic, 91 | test_mq_threaded)); 92 | } 93 | 94 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/test/unit/mtx.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | #define NTHREADS 2 4 | #define NINCRS 2000000 5 | 6 | TEST_BEGIN(test_mtx_basic) 7 | { 8 | mtx_t mtx; 9 | 10 | assert_false(mtx_init(&mtx), "Unexpected mtx_init() failure"); 11 | mtx_lock(&mtx); 12 | mtx_unlock(&mtx); 13 | mtx_fini(&mtx); 14 | } 15 | TEST_END 16 | 17 | typedef struct { 18 | mtx_t mtx; 19 | unsigned x; 20 | } thd_start_arg_t; 21 | 22 | static void * 23 | thd_start(void *varg) 24 | { 25 | thd_start_arg_t *arg = (thd_start_arg_t *)varg; 26 | unsigned i; 27 | 28 | for (i = 0; i < NINCRS; i++) { 29 | mtx_lock(&arg->mtx); 30 | arg->x++; 31 | mtx_unlock(&arg->mtx); 32 | } 33 | return (NULL); 34 | } 35 | 36 | TEST_BEGIN(test_mtx_race) 37 | { 38 | thd_start_arg_t arg; 39 | thd_t thds[NTHREADS]; 40 | unsigned i; 41 | 42 | assert_false(mtx_init(&arg.mtx), "Unexpected mtx_init() failure"); 43 | arg.x = 0; 44 | for (i = 0; i < NTHREADS; i++) 45 | thd_create(&thds[i], thd_start, (void *)&arg); 46 | for (i = 0; i < NTHREADS; i++) 47 | thd_join(thds[i], NULL); 48 | assert_u_eq(arg.x, NTHREADS * NINCRS, 49 | "Race-related counter corruption"); 50 | } 51 | TEST_END 52 | 53 | int 54 | main(void) 55 | { 56 | 57 | return (test( 58 | test_mtx_basic, 59 | test_mtx_race)); 60 | } 61 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/test/unit/prof_idump.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | #ifdef JEMALLOC_PROF 4 | const char *malloc_conf = 5 | "prof:true,prof_accum:true,prof_active:false,lg_prof_sample:0," 6 | "lg_prof_interval:0"; 7 | #endif 8 | 9 | static bool did_prof_dump_open; 10 | 11 | static int 12 | prof_dump_open_intercept(bool propagate_err, const char *filename) 13 | { 14 | int fd; 15 | 16 | did_prof_dump_open = true; 17 | 18 | fd = open("/dev/null", O_WRONLY); 19 | assert_d_ne(fd, -1, "Unexpected open() failure"); 20 | 21 | return (fd); 22 | } 23 | 24 | TEST_BEGIN(test_idump) 25 | { 26 | bool active; 27 | void *p; 28 | 29 | test_skip_if(!config_prof); 30 | 31 | active = true; 32 | assert_d_eq(mallctl("prof.active", NULL, NULL, &active, sizeof(active)), 33 | 0, "Unexpected mallctl failure while activating profiling"); 34 | 35 | prof_dump_open = prof_dump_open_intercept; 36 | 37 | did_prof_dump_open = false; 38 | p = mallocx(1, 0); 39 | assert_ptr_not_null(p, "Unexpected mallocx() failure"); 40 | dallocx(p, 0); 41 | assert_true(did_prof_dump_open, "Expected a profile dump"); 42 | } 43 | TEST_END 44 | 45 | int 46 | main(void) 47 | { 48 | 49 | return (test( 50 | test_idump)); 51 | } 52 | -------------------------------------------------------------------------------- /extern/jemalloc-cmake/test/unit/zero.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | #ifdef JEMALLOC_FILL 4 | const char *malloc_conf = 5 | "abort:false,junk:false,zero:true,redzone:false,quarantine:0"; 6 | #endif 7 | 8 | static void 9 | test_zero(size_t sz_min, size_t sz_max) 10 | { 11 | uint8_t *s; 12 | size_t sz_prev, sz, i; 13 | #define MAGIC ((uint8_t)0x61) 14 | 15 | sz_prev = 0; 16 | s = (uint8_t *)mallocx(sz_min, 0); 17 | assert_ptr_not_null((void *)s, "Unexpected mallocx() failure"); 18 | 19 | for (sz = sallocx(s, 0); sz <= sz_max; 20 | sz_prev = sz, sz = sallocx(s, 0)) { 21 | if (sz_prev > 0) { 22 | assert_u_eq(s[0], MAGIC, 23 | "Previously allocated byte %zu/%zu is corrupted", 24 | ZU(0), sz_prev); 25 | assert_u_eq(s[sz_prev-1], MAGIC, 26 | "Previously allocated byte %zu/%zu is corrupted", 27 | sz_prev-1, sz_prev); 28 | } 29 | 30 | for (i = sz_prev; i < sz; i++) { 31 | assert_u_eq(s[i], 0x0, 32 | "Newly allocated byte %zu/%zu isn't zero-filled", 33 | i, sz); 34 | s[i] = MAGIC; 35 | } 36 | 37 | if (xallocx(s, sz+1, 0, 0) == sz) { 38 | s = (uint8_t *)rallocx(s, sz+1, 0); 39 | assert_ptr_not_null((void *)s, 40 | "Unexpected rallocx() failure"); 41 | } 42 | } 43 | 44 | dallocx(s, 0); 45 | #undef MAGIC 46 | } 47 | 48 | TEST_BEGIN(test_zero_small) 49 | { 50 | 51 | test_skip_if(!config_fill); 52 | test_zero(1, SMALL_MAXCLASS-1); 53 | } 54 | TEST_END 55 | 56 | TEST_BEGIN(test_zero_large) 57 | { 58 | 59 | test_skip_if(!config_fill); 60 | test_zero(SMALL_MAXCLASS+1, large_maxclass); 61 | } 62 | TEST_END 63 | 64 | TEST_BEGIN(test_zero_huge) 65 | { 66 | 67 | test_skip_if(!config_fill); 68 | test_zero(large_maxclass+1, chunksize*2); 69 | } 70 | TEST_END 71 | 72 | int 73 | main(void) 74 | { 75 | 76 | return (test( 77 | test_zero_small, 78 | test_zero_large, 79 | test_zero_huge)); 80 | } 81 | -------------------------------------------------------------------------------- /extern/libsqlite3/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2007-2012 LuaDist. 2 | # Created by Peter Kapec 3 | # Redistribution and use of this file is allowed according to the terms of the MIT license. 4 | # For details see the COPYRIGHT file distributed with LuaDist. 5 | # Please note that the package source code is licensed under its own license. 6 | 7 | # Project 8 | project ( sqlite3 C ) 9 | cmake_minimum_required ( VERSION 2.8 ) 10 | include ( cmake/dist.cmake ) 11 | 12 | # SQLite configuration 13 | find_package ( Threads ) 14 | if ( Threads_FOUND ) 15 | if ( CMAKE_USE_PTHREADS_INIT ) 16 | add_definitions ( -D_REENTRANT=1 -DTHREADSAFE=1 ) 17 | set ( EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ) 18 | endif ( ) 19 | endif ( ) 20 | find_package ( Readline ) 21 | if ( READLINE_FOUND ) 22 | include_directories ( ${READLINE_INCLUDE_DIRS} ) 23 | endif ( ) 24 | 25 | # Add dl on unix systems 26 | if ( UNIX ) 27 | set ( EXTRA_LIBS ${EXTRA_LIBS} dl ) 28 | endif ( ) 29 | 30 | # SQLite Library 31 | add_library ( sqlite3 STATIC sqlite3.c ) 32 | if ( CMAKE_USE_PTHREADS_INIT ) 33 | target_link_libraries ( sqlite3 ${EXTRA_LIBS} ) 34 | endif ( ) 35 | if(CMAKE_COMPILER_IS_GNUCXX) 36 | SET_TARGET_PROPERTIES(sqlite3 PROPERTIES COMPILE_FLAGS "-fPIC") 37 | endif(CMAKE_COMPILER_IS_GNUCXX) 38 | 39 | install_library ( sqlite3 ) 40 | # Install Headers 41 | install_header ( sqlite3.h sqlite3ext.h ) 42 | -------------------------------------------------------------------------------- /extern/libsqlite3/cmake/FindReadline.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find Readline 2 | # Once done this will define 3 | # READLINE_FOUND - System has readline 4 | # READLINE_INCLUDE_DIRS - The readline include directories 5 | # READLINE_LIBRARIES - The libraries needed to use readline 6 | # READLINE_DEFINITIONS - Compiler switches required for using readline 7 | 8 | find_package ( PkgConfig ) 9 | pkg_check_modules ( PC_READLINE readline ) 10 | set ( READLINE_DEFINITIONS ${PC_READLINE_CFLAGS_OTHER} ) 11 | 12 | find_path ( READLINE_INCLUDE_DIR readline/readline.h 13 | HINTS ${PC_READLINE_INCLUDEDIR} ${PC_READLINE_INCLUDE_DIRS} 14 | PATH_SUFFIXES readline ) 15 | 16 | find_library ( READLINE_LIBRARY NAMES readline 17 | HINTS ${PC_READLINE_LIBDIR} ${PC_READLINE_LIBRARY_DIRS} ) 18 | 19 | set ( READLINE_LIBRARIES ${READLINE_LIBRARY} ) 20 | set ( READLINE_INCLUDE_DIRS ${READLINE_INCLUDE_DIR} ) 21 | 22 | include ( FindPackageHandleStandardArgs ) 23 | # handle the QUIETLY and REQUIRED arguments and set READLINE_FOUND to TRUE 24 | # if all listed variables are TRUE 25 | find_package_handle_standard_args ( readline DEFAULT_MSG READLINE_LIBRARIES READLINE_INCLUDE_DIRS ) 26 | -------------------------------------------------------------------------------- /extern/libsqlite3/cmake/FindSQLite3.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2007-2009 LuaDist. 2 | # Created by Peter Kapec 3 | # Redistribution and use of this file is allowed according to the terms of the MIT license. 4 | # For details see the COPYRIGHT file distributed with LuaDist. 5 | # Note: 6 | # Searching headers and libraries is very simple and is NOT as powerful as scripts 7 | # distributed with CMake, because LuaDist defines directories to search for. 8 | # Everyone is encouraged to contact the author with improvements. Maybe this file 9 | # becomes part of CMake distribution sometimes. 10 | 11 | # - Find sqlite3 12 | # Find the native SQLITE3 headers and libraries. 13 | # 14 | # SQLITE3_INCLUDE_DIRS - where to find sqlite3.h, etc. 15 | # SQLITE3_LIBRARIES - List of libraries when using sqlite. 16 | # SQLITE3_FOUND - True if sqlite found. 17 | 18 | # Look for the header file. 19 | FIND_PATH(SQLITE3_INCLUDE_DIR NAMES sqlite3.h) 20 | 21 | # Look for the library. 22 | FIND_LIBRARY(SQLITE3_LIBRARY NAMES sqlite) 23 | 24 | # Handle the QUIETLY and REQUIRED arguments and set SQLITE3_FOUND to TRUE if all listed variables are TRUE. 25 | INCLUDE(FindPackageHandleStandardArgs) 26 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(SQLITE3 DEFAULT_MSG SQLITE3_LIBRARY SQLITE3_INCLUDE_DIR) 27 | 28 | # Copy the results to the output variables. 29 | IF(SQLITE3_FOUND) 30 | SET(SQLITE3_LIBRARIES ${SQLITE3_LIBRARY}) 31 | SET(SQLITE3_INCLUDE_DIRS ${SQLITE3_INCLUDE_DIR}) 32 | ELSE(SQLITE3_FOUND) 33 | SET(SQLITE3_LIBRARIES) 34 | SET(SQLITE3_INCLUDE_DIRS) 35 | ENDIF(SQLITE3_FOUND) 36 | 37 | MARK_AS_ADVANCED(SQLITE3_INCLUDE_DIRS SQLITE3_LIBRARIES) 38 | -------------------------------------------------------------------------------- /extern/libsqlite3/dist.info: -------------------------------------------------------------------------------- 1 | --- This file is part of LuaDist project 2 | 3 | name = "libsqlite3" 4 | version = "3.7.7.1" 5 | 6 | desc = "SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine" 7 | url = "http://www.sqlite.org/" 8 | license = "public domain" 9 | maintainer = "Peter Kapec" 10 | author = "sqlite.org" 11 | -------------------------------------------------------------------------------- /extern/libsqlite3/sqlite3.pc: -------------------------------------------------------------------------------- 1 | # Package Information for pkg-config 2 | 3 | prefix=/usr/local 4 | exec_prefix=${prefix} 5 | libdir=${exec_prefix}/lib 6 | includedir=${prefix}/include 7 | 8 | Name: SQLite 9 | Description: SQL database engine 10 | Version: 3.7.7.1 11 | Libs: -L${libdir} -lsqlite3 12 | Libs.private: -ldl -lpthread 13 | Cflags: -I${includedir} 14 | -------------------------------------------------------------------------------- /extern/libsqlite3/sqlite3.pc.in: -------------------------------------------------------------------------------- 1 | # Package Information for pkg-config 2 | 3 | prefix=@prefix@ 4 | exec_prefix=@exec_prefix@ 5 | libdir=@libdir@ 6 | includedir=@includedir@ 7 | 8 | Name: SQLite 9 | Description: SQL database engine 10 | Version: @PACKAGE_VERSION@ 11 | Libs: -L${libdir} -lsqlite3 12 | Libs.private: @LIBS@ 13 | Cflags: -I${includedir} 14 | -------------------------------------------------------------------------------- /indent.ps1: -------------------------------------------------------------------------------- 1 | Get-ChildItem . -name -recurse *.cpp | %{clang-format -style=file -i $_} 2 | Get-ChildItem . -name -recurse *.h | %{clang-format -style=file -i $_} -------------------------------------------------------------------------------- /indent.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | find . -name '*.h' -exec clang-format-3.8 --style=file -i {} \; 3 | find . -name '*.cpp' -exec clang-format-3.8 --style=file -i {} \; 4 | -------------------------------------------------------------------------------- /libdariadb/.gitignore: -------------------------------------------------------------------------------- 1 | /st_exports.h 2 | -------------------------------------------------------------------------------- /libdariadb/aggregate/aggregator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace dariadb { 9 | namespace aggregator { 10 | class Aggregator { 11 | public: 12 | EXPORT Aggregator(IEngine_Ptr storage); 13 | EXPORT Aggregator(IEngine_Ptr storage, ITimer_Ptr timer); 14 | EXPORT ~Aggregator(); 15 | EXPORT 16 | static void aggregate(const std::string &from_interval, const std::string &to_interval, 17 | IEngine_Ptr engine, Time start, Time end); 18 | 19 | protected: 20 | class Private; 21 | std::unique_ptr _Impl; 22 | }; 23 | } // namespace aggregator 24 | } // namespace dariadb -------------------------------------------------------------------------------- /libdariadb/aggregate/itimer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace dariadb; 4 | using namespace dariadb::aggregator; 5 | -------------------------------------------------------------------------------- /libdariadb/aggregate/itimer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace dariadb { 8 | namespace aggregator { 9 | class ITimer { 10 | public: 11 | class Callback { 12 | public: 13 | // return next calltime 14 | virtual Time apply(Time current_time) = 0; 15 | }; 16 | using Callback_Ptr = std::shared_ptr; 17 | 18 | virtual void addCallback(Time firstTime, Callback_Ptr clbk) = 0; 19 | virtual Time currentTime() const = 0; 20 | }; 21 | using ITimer_Ptr = std::shared_ptr; 22 | } // namespace aggregator 23 | } // namespace dariadb -------------------------------------------------------------------------------- /libdariadb/aggregate/timer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace dariadb; 6 | using namespace dariadb::aggregator; 7 | 8 | Timer::Timer() { 9 | _stop = false; 10 | _thread = std::thread{std::bind(&Timer::async_loop, this)}; 11 | } 12 | 13 | Timer::~Timer() { 14 | logger("aggregation: timer stopping..."); 15 | _stop = true; 16 | _thread.join(); 17 | logger("aggregation: timer stoped."); 18 | } 19 | 20 | void Timer::resort_queue() { 21 | if (_queue.empty()) { 22 | return; 23 | } 24 | std::sort(_queue.begin(), _queue.end(), 25 | [](const auto &r, const auto &l) { return l.target > r.target; }); 26 | ENSURE(_queue.front().target <= _queue.back().target); 27 | } 28 | 29 | void Timer::addCallback(dariadb::Time firstTime, 30 | dariadb::aggregator::ITimer::Callback_Ptr clbk) { 31 | std::unique_lock lock(_locker); 32 | QueueReccord qr; 33 | qr.target = firstTime; 34 | qr.clbk = clbk; 35 | _queue.push_back(qr); 36 | resort_queue(); 37 | } 38 | 39 | void Timer::async_loop() { 40 | while (!_stop) { 41 | std::this_thread::sleep_for(std::chrono::milliseconds(10)); 42 | std::unique_lock lock(_locker); 43 | auto ct = currentTime(); 44 | for (auto it = _queue.begin(); it != _queue.end(); ++it) { 45 | if (it->target <= ct) { 46 | it->target = it->clbk->apply(it->target); 47 | } 48 | } 49 | resort_queue(); 50 | } 51 | } -------------------------------------------------------------------------------- /libdariadb/aggregate/timer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace dariadb { 9 | namespace aggregator { 10 | class Timer : public ITimer { 11 | public: 12 | struct QueueReccord { 13 | Time target; 14 | Callback_Ptr clbk; 15 | bool operator==(const QueueReccord &other) const { return target == other.target; } 16 | 17 | bool operator<(const QueueReccord &other) const { return target < other.target; } 18 | 19 | bool operator>(const QueueReccord &other) const { return target > other.target; } 20 | }; 21 | 22 | EXPORT Timer(); 23 | EXPORT ~Timer(); 24 | EXPORT void addCallback(dariadb::Time firstTime, 25 | dariadb::aggregator::ITimer::Callback_Ptr clbk) override; 26 | 27 | dariadb::Time currentTime() const override { return timeutil::current_time(); } 28 | 29 | protected: 30 | void async_loop(); 31 | void resort_queue(); 32 | 33 | private: 34 | std::vector _queue; 35 | std::mutex _locker; 36 | std::thread _thread; 37 | bool _stop; 38 | }; 39 | } // namespace aggregator 40 | } // namespace dariadb -------------------------------------------------------------------------------- /libdariadb/compression/base_compressor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace dariadb::compression; 4 | 5 | BaseCompressor::BaseCompressor(const ByteBuffer_Ptr &bw_) : bw(bw_) {} 6 | -------------------------------------------------------------------------------- /libdariadb/compression/base_compressor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | namespace dariadb { 6 | namespace compression { 7 | 8 | struct BaseCompressor { 9 | EXPORT BaseCompressor(const ByteBuffer_Ptr &bw_); 10 | bool is_full() const { return bw->is_full(); } 11 | size_t used_space() const { return bw->cap() - bw->pos(); } 12 | 13 | ByteBuffer_Ptr bw; 14 | }; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /libdariadb/compression/bytebuffer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace dariadb; 5 | using namespace dariadb::compression; 6 | 7 | ByteBuffer::ByteBuffer(const Range &r) : _begin(r.begin), _end(r.end) { 8 | _cap = static_cast(std::distance(_begin, _end)); 9 | reset_pos(); 10 | } 11 | 12 | ByteBuffer::~ByteBuffer() {} 13 | -------------------------------------------------------------------------------- /libdariadb/compression/bytebuffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace dariadb { 11 | namespace compression { 12 | 13 | struct Range { 14 | uint8_t *begin; 15 | uint8_t *end; 16 | Range() { begin = end = nullptr; } 17 | 18 | Range(uint8_t *_begin, uint8_t *_end) { 19 | begin = _begin; 20 | end = _end; 21 | } 22 | }; 23 | 24 | class ByteBuffer; 25 | typedef std::shared_ptr ByteBuffer_Ptr; 26 | class ByteBuffer { 27 | public: 28 | EXPORT ByteBuffer(const Range &r); 29 | EXPORT ~ByteBuffer(); 30 | 31 | uint32_t pos() const { return _pos; } 32 | void set_pos(uint32_t bw_pos) { _pos = bw_pos; } 33 | size_t cap() const { return _cap; } 34 | size_t free_size() const { return _pos; } 35 | bool is_full() const { return _pos == 0; } 36 | void reset_pos() { _pos = _cap - 1; } 37 | /// return offset of value sizeof(t) relative of current pos. 38 | template T *offset_off() { 39 | static_assert(std::is_pod::value, "only POD objects."); 40 | move_pos(sizeof(T)); 41 | auto target = reinterpret_cast(_begin + _pos); 42 | return target; 43 | } 44 | 45 | template void write(T v) { 46 | auto target = offset_off(); 47 | *target = v; 48 | } 49 | 50 | template T read() { 51 | auto target = offset_off(); 52 | return *target; 53 | } 54 | 55 | Range get_range() const { return Range{_begin, _end}; } 56 | 57 | protected: 58 | inline void move_pos(int8_t count) { 59 | _pos -= count; 60 | #ifdef DEBUG 61 | if (_pos > _cap) { 62 | throw MAKE_EXCEPTION("BinaryBuffer::move_pos"); 63 | } 64 | #endif 65 | } 66 | 67 | protected: 68 | uint8_t *_begin, *_end; 69 | uint32_t _cap; 70 | uint32_t _pos; 71 | }; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /libdariadb/compression/compression.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace dariadb; 4 | using namespace dariadb::compression; 5 | 6 | CopmressedWriter::CopmressedWriter(const ByteBuffer_Ptr &bw) 7 | : _bb(bw), time_comp(bw), value_comp(bw), flag_comp(bw) { 8 | _is_first = true; 9 | _is_full = false; 10 | } 11 | 12 | CopmressedWriter::~CopmressedWriter() {} 13 | 14 | bool CopmressedWriter::append(const Meas &m) { 15 | if (_is_first) { 16 | _first = m; 17 | _is_first = false; 18 | } 19 | 20 | auto t_f = time_comp.append(m.time); 21 | auto f_f = value_comp.append(m.value); 22 | auto v_f = flag_comp.append(m.flag); 23 | 24 | if (!t_f || !f_f || !v_f) { 25 | _is_full = true; 26 | return false; 27 | } else { 28 | return true; 29 | } 30 | } 31 | 32 | CopmressedReader::CopmressedReader(const ByteBuffer_Ptr &bw, const Meas &first) 33 | : time_dcomp(bw, first.time), value_dcomp(bw, first.value), 34 | flag_dcomp(bw, first.flag) { 35 | _first = first; 36 | } 37 | 38 | CopmressedReader::~CopmressedReader() {} 39 | -------------------------------------------------------------------------------- /libdariadb/compression/compression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace dariadb { 13 | namespace compression { 14 | class CopmressedWriter { 15 | public: 16 | EXPORT CopmressedWriter(const ByteBuffer_Ptr &bw_time); 17 | EXPORT ~CopmressedWriter(); 18 | 19 | EXPORT bool append(const Meas &m); 20 | bool isFull() const { return _is_full; } 21 | 22 | size_t usedSpace() const { return time_comp.used_space(); } 23 | 24 | ByteBuffer_Ptr getBinaryBuffer() const { return _bb; } 25 | 26 | protected: 27 | ByteBuffer_Ptr _bb; 28 | Meas _first; 29 | bool _is_first; 30 | bool _is_full; 31 | DeltaCompressor time_comp; 32 | XorCompressor value_comp; 33 | FlagCompressor flag_comp; 34 | }; 35 | 36 | class CopmressedReader { 37 | public: 38 | CopmressedReader() = default; 39 | EXPORT CopmressedReader(const ByteBuffer_Ptr &bw_time, const Meas &first); 40 | EXPORT ~CopmressedReader(); 41 | 42 | dariadb::Meas read() { 43 | Meas result{}; 44 | result.id = _first.id; 45 | result.time = time_dcomp.read(); 46 | result.value = value_dcomp.read(); 47 | result.flag = flag_dcomp.read(); 48 | return result; 49 | } 50 | 51 | protected: 52 | dariadb::Meas _first; 53 | DeltaDeCompressor time_dcomp; 54 | XorDeCompressor value_dcomp; 55 | FlagDeCompressor flag_dcomp; 56 | }; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /libdariadb/compression/delta.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace dariadb { 7 | namespace compression { 8 | struct DeltaCompressor : public BaseCompressor { 9 | EXPORT DeltaCompressor(const ByteBuffer_Ptr &bw); 10 | 11 | EXPORT bool append(Time t); 12 | 13 | bool is_first; 14 | Time first; 15 | int64_t prev_delta; 16 | Time prev_time; 17 | }; 18 | 19 | struct DeltaDeCompressor : public BaseCompressor { 20 | EXPORT DeltaDeCompressor(const ByteBuffer_Ptr &bw, Time first); 21 | 22 | EXPORT Time read(); 23 | 24 | int64_t prev_delta; 25 | Time prev_time; 26 | }; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /libdariadb/compression/flag.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | using namespace dariadb::compression; 6 | 7 | FlagCompressor::FlagCompressor(const ByteBuffer_Ptr &bw_) : BaseCompressor(bw_) { 8 | _is_first = true; 9 | } 10 | 11 | bool FlagCompressor::append(dariadb::Flag v) { 12 | static_assert(sizeof(dariadb::Flag) == 4, "Flag no x32 value"); 13 | if (_is_first) { 14 | _first = v; 15 | _is_first = false; 16 | return true; 17 | } 18 | 19 | // LEB128 20 | auto x = v; 21 | do { 22 | if (bw->free_size() < 1) { 23 | return false; 24 | } 25 | auto sub_res = x & 0x7fU; 26 | if (x >>= 7) 27 | sub_res |= 0x80U; 28 | bw->write(static_cast(sub_res)); 29 | } while (x); 30 | 31 | return true; 32 | } 33 | 34 | FlagDeCompressor::FlagDeCompressor(const ByteBuffer_Ptr &bw_, dariadb::Flag first) 35 | : BaseCompressor(bw_) { 36 | _first = first; 37 | _is_first = true; 38 | ; 39 | } 40 | 41 | dariadb::Flag FlagDeCompressor::read() { 42 | static_assert(sizeof(dariadb::Flag) == 4, "Flag no x32 value"); 43 | dariadb::Flag result(0); 44 | 45 | size_t bytes = 0; 46 | while (true) { 47 | auto readed = bw->read(); 48 | result |= (readed & 0x7fULL) << (7 * bytes++); 49 | if (!(readed & 0x80U)) 50 | break; 51 | } 52 | return result; 53 | } 54 | -------------------------------------------------------------------------------- /libdariadb/compression/flag.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace dariadb { 7 | namespace compression { 8 | struct FlagCompressor : public BaseCompressor { 9 | EXPORT FlagCompressor(const ByteBuffer_Ptr &bw); 10 | 11 | EXPORT bool append(Flag v); 12 | Flag _first; 13 | bool _is_first; 14 | }; 15 | 16 | struct FlagDeCompressor : public BaseCompressor { 17 | EXPORT FlagDeCompressor(const ByteBuffer_Ptr &bw, Flag first); 18 | 19 | EXPORT Flag read(); 20 | Flag _first; 21 | bool _is_first; 22 | }; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /libdariadb/compression/xor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace dariadb { 7 | namespace compression { 8 | namespace inner { 9 | 10 | inline int64_t flat_double_to_int(dariadb::Value v) { 11 | static_assert(sizeof(dariadb::Value) == sizeof(int64_t), "size not equal"); 12 | auto result = reinterpret_cast(&v); 13 | return *result; 14 | } 15 | inline dariadb::Value flat_int_to_double(int64_t i) { 16 | auto result = reinterpret_cast(&i); 17 | return *result; 18 | } 19 | } 20 | 21 | struct XorCompressor : public BaseCompressor { 22 | public: 23 | EXPORT XorCompressor(const ByteBuffer_Ptr &bw_); 24 | 25 | EXPORT bool append(Value v); 26 | 27 | bool _is_first; 28 | uint64_t _first; 29 | uint64_t _prev_value; 30 | }; 31 | 32 | struct XorDeCompressor : public BaseCompressor { 33 | public: 34 | EXPORT XorDeCompressor(const ByteBuffer_Ptr &bw, Value first); 35 | 36 | EXPORT Value read(); 37 | 38 | uint64_t _prev_value; 39 | }; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /libdariadb/dariadb.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | namespace dariadb { 6 | 7 | IEngine_Ptr open_storage(const std::string &path, bool force_unlock) { 8 | if (utils::fs::file_exists(utils::fs::append_path(path, SHARD_FILE_NAME))) { 9 | return ShardEngine::create(path, force_unlock); 10 | } else { 11 | auto settings = dariadb::storage::Settings::create(path); 12 | IEngine_Ptr result{new Engine(settings, true, force_unlock)}; 13 | return result; 14 | } 15 | } 16 | 17 | IEngine_Ptr memory_only_storage() { 18 | auto settings = dariadb::storage::Settings::create(); 19 | IEngine_Ptr result{new Engine(settings)}; 20 | return result; 21 | } 22 | } // namespace dariadb -------------------------------------------------------------------------------- /libdariadb/dariadb.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | namespace dariadb { 17 | /** 18 | autodetect engine type in folder and return instance. 19 | */ 20 | EXPORT IEngine_Ptr open_storage(const std::string &path, bool force_unlock = false); 21 | /** 22 | create memory only storage. 23 | */ 24 | EXPORT IEngine_Ptr memory_only_storage(); 25 | } // namespace dariadb 26 | -------------------------------------------------------------------------------- /libdariadb/engines/strategy.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | std::istream &dariadb::operator>>(std::istream &in, STRATEGY &strat) { 7 | std::string token; 8 | in >> token; 9 | 10 | token = utils::strings::to_upper(token); 11 | 12 | if (token == "WAL") { 13 | strat = dariadb::STRATEGY::WAL; 14 | return in; 15 | } 16 | if (token == "COMPRESSED") { 17 | strat = dariadb::STRATEGY::COMPRESSED; 18 | return in; 19 | } 20 | 21 | if (token == "MEMORY") { 22 | strat = dariadb::STRATEGY::MEMORY; 23 | return in; 24 | } 25 | 26 | if (token == "CACHE") { 27 | strat = dariadb::STRATEGY::CACHE; 28 | return in; 29 | } 30 | if (token == "SHARD") { 31 | strat = dariadb::STRATEGY::SHARD; 32 | return in; 33 | } 34 | THROW_EXCEPTION("engine: bad strategy name - ", token); 35 | } 36 | 37 | std::ostream &dariadb::operator<<(std::ostream &stream, const STRATEGY &strat) { 38 | switch (strat) { 39 | case STRATEGY::COMPRESSED: 40 | stream << "COMPRESSED"; 41 | break; 42 | case STRATEGY::WAL: 43 | stream << "WAL"; 44 | break; 45 | case STRATEGY::MEMORY: 46 | stream << "MEMORY"; 47 | break; 48 | case STRATEGY::CACHE: 49 | stream << "CACHE"; 50 | break; 51 | case STRATEGY::SHARD: 52 | stream << "SHARD"; 53 | break; 54 | default: 55 | THROW_EXCEPTION("engine: bad strategy - ", (uint16_t)strat); 56 | break; 57 | }; 58 | return stream; 59 | } 60 | 61 | std::string dariadb::to_string(const STRATEGY &strat) { 62 | std::stringstream ss; 63 | ss << strat; 64 | return ss.str(); 65 | } -------------------------------------------------------------------------------- /libdariadb/engines/strategy.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace dariadb { 8 | enum class STRATEGY : uint16_t { WAL = 0, COMPRESSED, MEMORY, CACHE, SHARD }; 9 | 10 | EXPORT std::istream &operator>>(std::istream &in, STRATEGY &strat); 11 | EXPORT std::ostream &operator<<(std::ostream &stream, const STRATEGY &strat); 12 | 13 | EXPORT std::string to_string(const STRATEGY &strat); 14 | } // namespace dariadb 15 | -------------------------------------------------------------------------------- /libdariadb/flags.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | namespace dariadb { 6 | namespace FLAGS { 7 | 8 | const Flag _NO_DATA = MAX_FLAG; // {1111 1111, 1111 1111, 1111 1111, 1111 1111} 9 | const Flag _STATS = 0x80000000; // {1000 0000, 0000 0000, 0000 0000, 0000 0000} 10 | 11 | } // namespace FLAGS 12 | } // namespace dariadb 13 | -------------------------------------------------------------------------------- /libdariadb/interfaces/icallbacks.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace dariadb; 5 | 6 | IReadCallback::IReadCallback() { 7 | is_end_called = false; 8 | is_cancel = false; 9 | } 10 | 11 | IReadCallback::~IReadCallback() {} 12 | 13 | void IReadCallback::is_end() { 14 | is_end_called = true; 15 | } 16 | 17 | void IReadCallback::wait() { 18 | while (!is_end_called) { 19 | utils::sleep_mls(300); 20 | } 21 | } 22 | 23 | void IReadCallback::cancel() { 24 | is_cancel = true; 25 | } 26 | 27 | bool IReadCallback::is_canceled() const { 28 | return is_cancel; 29 | } -------------------------------------------------------------------------------- /libdariadb/interfaces/icallbacks.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace dariadb { 8 | 9 | class IReadCallback; 10 | typedef std::shared_ptr ReaderCallback_ptr; 11 | class IReadCallback { 12 | public: 13 | EXPORT IReadCallback(); 14 | EXPORT virtual void is_end(); // called, when all data readed. 15 | EXPORT virtual ~IReadCallback(); 16 | EXPORT void wait(); 17 | EXPORT void cancel(); // called by user if want to stop operation. 18 | EXPORT bool is_canceled() const; // true - if `cancel` was called. 19 | virtual void apply(const Meas &m) = 0; // must be thread safety. 20 | protected: 21 | bool is_end_called; 22 | bool is_cancel; 23 | }; 24 | } 25 | -------------------------------------------------------------------------------- /libdariadb/interfaces/icompactioncontroller.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace dariadb { 6 | 7 | class ICompactionController { 8 | public: 9 | ICompactionController(Id id, Time _eraseOlderThan, Time _from, Time _to) { 10 | targetId = id; 11 | eraseOlderThan = _eraseOlderThan; 12 | from = _from; 13 | to = _to; 14 | } 15 | /** 16 | method to control compaction process. 17 | values - input vector of values. you can replace needed items 18 | filter - if filter[i]==0 values be ignored. 19 | */ 20 | virtual void compact(dariadb::MeasArray &values, std::vector &filter) = 0; 21 | 22 | Id targetId; 23 | Time eraseOlderThan; 24 | Time from; 25 | Time to; 26 | }; 27 | } // namespace dariadb 28 | -------------------------------------------------------------------------------- /libdariadb/interfaces/icursor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace dariadb; 5 | 6 | void dariadb::ICursor::apply(IReadCallback *clbk) { 7 | while (!this->is_end()) { 8 | if (clbk->is_canceled()) { 9 | break; 10 | } 11 | auto v = readNext(); 12 | clbk->apply(v); 13 | } 14 | } 15 | 16 | void dariadb::ICursor::apply(IReadCallback *clbk, const dariadb::QueryInterval &q) { 17 | while (!this->is_end()) { 18 | if (clbk->is_canceled()) { 19 | break; 20 | } 21 | auto v = readNext(); 22 | if (v.inQuery(q.ids, q.flag, q.from, q.to)) { 23 | clbk->apply(v); 24 | } 25 | } 26 | } 27 | 28 | Meas dariadb::ICursor::read_time_point(const QueryTimePoint &q) { 29 | bool result_set = false; 30 | Meas result; 31 | while (!is_end()) { 32 | auto m = readNext(); 33 | if (m.time <= q.time_point && m.inQuery(q.ids, q.flag)) { 34 | if (!result_set) { 35 | result = m; 36 | } else { 37 | if (m.time > result.time) { 38 | result = m; 39 | } 40 | } 41 | } 42 | } 43 | return result; 44 | } -------------------------------------------------------------------------------- /libdariadb/interfaces/icursor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | namespace dariadb { 12 | class ICursor; 13 | using Cursor_Ptr = std::shared_ptr; 14 | 15 | class ICursor : public utils::NonCopy { 16 | public: 17 | virtual Meas readNext() = 0; 18 | virtual Meas top() = 0; /// null if isEnd==true 19 | virtual bool is_end() const = 0; 20 | virtual ~ICursor() {} 21 | 22 | virtual Time minTime() = 0; 23 | virtual Time maxTime() = 0; 24 | 25 | /** 26 | maximum count of stored values. with duplicates. 27 | */ 28 | virtual size_t count() const = 0; 29 | 30 | EXPORT virtual void apply(IReadCallback *clbk); 31 | EXPORT virtual void apply(IReadCallback *clbk, const QueryInterval &q); 32 | EXPORT virtual Meas read_time_point(const QueryTimePoint &q); 33 | }; 34 | 35 | using Id2Cursor = std::unordered_map; 36 | using CursorsList = std::list; 37 | using Id2CursorsList = std::unordered_map; 38 | } 39 | -------------------------------------------------------------------------------- /libdariadb/interfaces/idroppers.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace dariadb { 6 | 7 | class IWALDropper { 8 | public: 9 | virtual void dropWAL(const std::string &fname) = 0; 10 | virtual ~IWALDropper() {} 11 | }; 12 | } 13 | -------------------------------------------------------------------------------- /libdariadb/interfaces/iengine.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace dariadb; 5 | using namespace dariadb::utils::async; 6 | 7 | void IEngine::foreach (const QueryInterval &q, IReadCallback * clbk) { 8 | auto params = std::make_shared(q, clbk); 9 | 10 | AsyncTask at_t = [this, params](const ThreadInfo &ti) { 11 | TKIND_CHECK(THREAD_KINDS::COMMON, ti.kind); 12 | 13 | if (params->next_id_pos < params->q.ids.size()) { 14 | if (!params->clbk->is_canceled()) { 15 | // auto start_time = clock(); 16 | 17 | QueryInterval local_q = params->q; 18 | local_q.ids.resize(1); 19 | auto id = params->q.ids[params->next_id_pos++]; 20 | 21 | local_q.ids[0] = id; 22 | auto r = intervalReader(local_q); 23 | auto fres = r.find(id); 24 | if (fres != r.end()) { 25 | fres->second->apply(params->clbk, local_q); 26 | } 27 | /*auto elapsed_time = (((float)clock() - start_time) / CLOCKS_PER_SEC); 28 | logger("foreach: #", id, ": elapsed ", elapsed_time, "s");*/ 29 | 30 | if (params->next_id_pos < params->q.ids.size()) { 31 | return true; 32 | } 33 | } 34 | } 35 | params->clbk->is_end(); 36 | return false; 37 | }; 38 | 39 | ThreadManager::instance()->post(THREAD_KINDS::COMMON, AT(at_t)); 40 | } 41 | 42 | void IEngine::foreach (const QueryTimePoint &q, IReadCallback * clbk) { 43 | auto values = this->readTimePoint(q); 44 | for (auto &kv : values) { 45 | if (clbk->is_canceled()) { 46 | break; 47 | } 48 | clbk->apply(kv.second); 49 | } 50 | clbk->is_end(); 51 | } 52 | 53 | void IEngine::setScheme(const scheme::IScheme_Ptr &scheme) { 54 | _scheme = scheme; 55 | } 56 | 57 | scheme::IScheme_Ptr IEngine::getScheme() { 58 | return _scheme; 59 | } 60 | 61 | void IEngine::repack(const scheme::IScheme_Ptr s) { 62 | logger_info("engine: all repack..."); 63 | if (s == nullptr) { 64 | dariadb::logger_fatal("engine: repack. scheme==nullptr"); 65 | return; 66 | } else { 67 | auto datamap = s->ls(); 68 | for (auto kv : datamap) { 69 | this->repack(kv.first); 70 | } 71 | } 72 | } -------------------------------------------------------------------------------- /libdariadb/interfaces/imeassource.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace dariadb; 8 | using namespace dariadb::storage; 9 | 10 | void IMeasSource::foreach (const QueryTimePoint &q, IReadCallback * clbk) { 11 | auto values = this->readTimePoint(q); 12 | for (auto &kv : values) { 13 | clbk->apply(kv.second); 14 | } 15 | } 16 | 17 | MeasArray IMeasSource::readInterval(const QueryInterval &q) { 18 | size_t max_count = 0; 19 | auto r = this->intervalReader(q); 20 | for (auto &kv : r) { 21 | max_count += kv.second->count(); 22 | } 23 | MeasArray result; 24 | result.reserve(max_count); 25 | auto clbk = std::make_unique(&result); 26 | 27 | for (auto id : q.ids) { 28 | auto fres = r.find(id); 29 | if (fres != r.end()) { 30 | fres->second->apply(clbk.get(), q); 31 | } 32 | } 33 | clbk->is_end(); 34 | return result; 35 | } 36 | -------------------------------------------------------------------------------- /libdariadb/interfaces/imeassource.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace dariadb { 13 | 14 | class IMeasSource { 15 | public: 16 | virtual Time minTime() = 0; 17 | virtual Time maxTime() = 0; 18 | 19 | virtual bool minMaxTime(Id id, Time *minResult, Time *maxResult) = 0; 20 | virtual void foreach (const QueryInterval &q, IReadCallback * clbk) = 0; 21 | virtual void foreach (const QueryTimePoint &q, IReadCallback * clbk); 22 | virtual Id2Cursor intervalReader(const QueryInterval &query) = 0; 23 | virtual Id2Meas readTimePoint(const QueryTimePoint &q) = 0; 24 | virtual Id2Meas currentValue(const IdArray &ids, const Flag &flag) = 0; 25 | virtual Statistic stat(const Id id, Time from, Time to) = 0; 26 | EXPORT virtual Id2MinMax_Ptr loadMinMax() = 0; 27 | EXPORT virtual MeasArray readInterval(const QueryInterval &q); 28 | virtual ~IMeasSource() {} 29 | }; 30 | 31 | typedef std::shared_ptr IMeasSource_ptr; 32 | } 33 | -------------------------------------------------------------------------------- /libdariadb/interfaces/imeasstorage.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace dariadb; 4 | 5 | IMeasStorage::~IMeasStorage() {} 6 | -------------------------------------------------------------------------------- /libdariadb/interfaces/imeasstorage.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace dariadb { 9 | 10 | class IMeasStorage : public utils::NonCopy, public IMeasSource, public IMeasWriter { 11 | public: 12 | EXPORT ~IMeasStorage(); 13 | }; 14 | 15 | typedef std::shared_ptr IMeasStorage_ptr; 16 | } 17 | -------------------------------------------------------------------------------- /libdariadb/interfaces/imeaswriter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace dariadb; 4 | 5 | void IMeasWriter::flush() {} 6 | 7 | void IMeasWriter::flush(Id) {} 8 | 9 | Status IMeasWriter::append(const MeasArray::const_iterator &begin, 10 | const MeasArray::const_iterator &end) { 11 | dariadb::Status ar{}; 12 | 13 | for (auto it = begin; it != end; ++it) { 14 | ar = ar + this->append(*it); 15 | } 16 | return ar; 17 | } 18 | 19 | IMeasWriter::~IMeasWriter() {} 20 | -------------------------------------------------------------------------------- /libdariadb/interfaces/imeaswriter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace dariadb { 10 | class IMeasWriter { 11 | public: 12 | EXPORT Status append(Id i, Time t, Flag f, Value v) { 13 | Meas m; 14 | m.id = i; 15 | m.time = t; 16 | m.flag = f; 17 | m.value = v; 18 | return append(m); 19 | } 20 | 21 | EXPORT Status append(Id i, Time t, Value v) { return append(i, t, Flag(), v); } 22 | 23 | EXPORT virtual Status append(const Meas &value) = 0; 24 | EXPORT virtual void flush(); 25 | EXPORT virtual void flush(Id id); 26 | EXPORT virtual Status append(const MeasArray::const_iterator &begin, 27 | const MeasArray::const_iterator &end); 28 | EXPORT virtual ~IMeasWriter(); 29 | }; 30 | 31 | typedef std::shared_ptr IMeasWriter_ptr; 32 | } // namespace dariadb 33 | -------------------------------------------------------------------------------- /libdariadb/meas.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace dariadb; 10 | 11 | Meas::Meas() { 12 | id = Id(); 13 | flag = Flag(); 14 | value = Value(); 15 | time = Time(); 16 | } 17 | 18 | Meas::Meas(Id i) : Meas() { 19 | id = i; 20 | } 21 | 22 | Meas::Meas(const Meas &other) { 23 | id = other.id; 24 | time = other.time; 25 | value = other.value; 26 | flag = other.flag; 27 | } 28 | 29 | bool dariadb::areSame(Value a, Value b, const Value EPSILON) { 30 | return std::fabs(a - b) < EPSILON; 31 | } 32 | 33 | void dariadb::minmax_append(Id2MinMax_Ptr &out, const Id2MinMax_Ptr &source) { 34 | auto f = [&out](const Id2MinMax::value_type &v) { 35 | auto fres = out->find_bucket(v.first); 36 | fres.v->second.updateMax(v.second.max); 37 | fres.v->second.updateMin(v.second.min); 38 | }; 39 | source->apply(f); 40 | } 41 | 42 | void MeasMinMax::updateMax(const Meas &m) { 43 | if (m.time > this->max.time) { 44 | this->max = m; 45 | } 46 | } 47 | 48 | void MeasMinMax::updateMin(const Meas &m) { 49 | if (m.time < this->min.time) { 50 | this->min = m; 51 | } 52 | } -------------------------------------------------------------------------------- /libdariadb/query.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace dariadb { 4 | namespace query_inner { 5 | void empty_func_to_disable_warnings() {} 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /libdariadb/query.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace dariadb { 8 | 9 | struct QueryParam { 10 | IdArray ids; 11 | Flag flag; 12 | QueryParam(const IdArray &_ids, Flag _flag) : ids(_ids), flag(_flag) {} 13 | }; 14 | 15 | struct QueryInterval : public QueryParam { 16 | Time from; 17 | Time to; 18 | Time step; /// ignored in disk operations 19 | QueryInterval(const IdArray &_ids, Flag _flag, Time _from, Time _to) 20 | : QueryParam(_ids, _flag), from(_from), to(_to), step(0) {} 21 | 22 | QueryInterval(const IdArray &_ids, Flag _flag, Time _from, Time _to, Time _step) 23 | : QueryParam(_ids, _flag), from(_from), to(_to), step(_step) {} 24 | }; 25 | 26 | struct QueryTimePoint : public QueryParam { 27 | Time time_point; 28 | 29 | QueryTimePoint(const IdArray &_ids, Flag _flag, Time _time_point) 30 | : QueryParam(_ids, _flag), time_point(_time_point) {} 31 | }; 32 | } 33 | -------------------------------------------------------------------------------- /libdariadb/scheme/helpers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace dariadb { 4 | namespace scheme { 5 | 6 | std::ostream &operator<<(std::ostream &stream, const MeasurementDescription &d) { 7 | stream << "{ name:" << d.name << ", id:" << d.id; 8 | 9 | if (!d.interval.empty()) { 10 | stream << ", interval:" << d.interval; 11 | } 12 | 13 | if (!d.aggregation_func.empty()) { 14 | stream << ", func:" << d.aggregation_func; 15 | } 16 | 17 | stream << "}"; 18 | return stream; 19 | } 20 | } // namespace scheme 21 | } // namespace dariadb -------------------------------------------------------------------------------- /libdariadb/scheme/helpers.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace dariadb { 8 | namespace scheme { 9 | 10 | EXPORT std::ostream &operator<<(std::ostream &stream, const MeasurementDescription &d); 11 | } 12 | } -------------------------------------------------------------------------------- /libdariadb/scheme/ischeme.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace dariadb { 9 | namespace scheme { 10 | struct MeasurementDescription { 11 | std::string name; 12 | Id id; 13 | std::string interval; 14 | std::string aggregation_func; 15 | 16 | // return value without interval. 17 | std::string prefix() const { 18 | if (interval == "") { 19 | return name; 20 | } 21 | auto interval_pos = name.find(interval); 22 | if (interval_pos == std::string::npos) { 23 | return name; 24 | } 25 | return name.substr(0, interval_pos); 26 | } 27 | }; 28 | 29 | class DescriptionMap : public std::unordered_map { 30 | public: 31 | Id idByParam(const std::string ¶m) { 32 | auto fres = std::find_if(begin(), end(), 33 | [¶m](auto kv) { return kv.second.name == param; }); 34 | if (fres == end()) { 35 | return MAX_ID; 36 | } else { 37 | return fres->first; 38 | } 39 | } 40 | }; 41 | 42 | class IScheme { 43 | public: 44 | virtual Id addParam(const std::string ¶m) = 0; 45 | virtual DescriptionMap ls() = 0; 46 | virtual MeasurementDescription descriptionFor(dariadb::Id id) = 0; 47 | virtual DescriptionMap lsInterval(const std::string &interval) = 0; 48 | virtual DescriptionMap linkedForValue(const MeasurementDescription ¶m) = 0; 49 | virtual void save() = 0; 50 | }; 51 | 52 | using IScheme_Ptr = std::shared_ptr; 53 | } // namespace scheme 54 | } // namespace dariadb 55 | -------------------------------------------------------------------------------- /libdariadb/scheme/scheme.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace dariadb { 10 | namespace scheme { 11 | 12 | /*** 13 | example: 14 | * memory.raw 15 | * memory.median.hour 16 | * memory.sigma.hour 17 | * memory.sigma.'T\d{19}' 18 | * memory.median.day 19 | * memory.median.month 20 | */ 21 | class Scheme : public IScheme { 22 | public: 23 | EXPORT static IScheme_Ptr create(const storage::Settings_ptr s); 24 | 25 | EXPORT Id addParam(const std::string ¶m) override; 26 | EXPORT DescriptionMap ls() override; 27 | EXPORT MeasurementDescription descriptionFor(dariadb::Id id) override; 28 | EXPORT DescriptionMap lsInterval(const std::string &interval) override; 29 | EXPORT DescriptionMap linkedForValue(const MeasurementDescription ¶m) override; 30 | EXPORT void save(); 31 | 32 | protected: 33 | EXPORT Scheme(const storage::Settings_ptr s); 34 | struct Private; 35 | std::unique_ptr _impl; 36 | }; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /libdariadb/stat.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace dariadb { 7 | #pragma pack(push, 1) 8 | struct Statistic { 9 | Time minTime; 10 | Time maxTime; 11 | 12 | uint32_t count; /// count of stored values. 13 | 14 | uint64_t flag_bloom; 15 | 16 | Value minValue; 17 | 18 | Value maxValue; 19 | 20 | Value sum; 21 | 22 | Statistic() { 23 | flag_bloom = storage::bloom_empty(); 24 | count = uint32_t(0); 25 | minTime = MAX_TIME; 26 | maxTime = MIN_TIME; 27 | 28 | minValue = MAX_VALUE; 29 | maxValue = MIN_VALUE; 30 | 31 | sum = Value(0); 32 | } 33 | 34 | void update(const Meas &m) { 35 | count++; 36 | 37 | minTime = std::min(m.time, minTime); 38 | maxTime = std::max(m.time, maxTime); 39 | 40 | flag_bloom = storage::bloom_add(flag_bloom, m.flag); 41 | 42 | minValue = std::min(m.value, minValue); 43 | maxValue = std::max(m.value, maxValue); 44 | 45 | sum += m.value; 46 | } 47 | 48 | void update(const Statistic &st) { 49 | count += st.count; 50 | 51 | minTime = std::min(st.minTime, minTime); 52 | maxTime = std::max(st.maxTime, maxTime); 53 | 54 | flag_bloom = storage::bloom_combine(flag_bloom, st.flag_bloom); 55 | 56 | minValue = std::min(st.minValue, minValue); 57 | maxValue = std::max(st.maxValue, maxValue); 58 | 59 | sum += st.sum; 60 | } 61 | }; 62 | #pragma pack(pop) 63 | } -------------------------------------------------------------------------------- /libdariadb/statistic/calculator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace dariadb { 10 | namespace statistic { 11 | 12 | class FunctionFactory { 13 | public: 14 | EXPORT static IFunction_ptr make_one(const std::string &k); 15 | EXPORT static std::vector make(const std::vector &kinds); 16 | /*** 17 | return vector of available functions. 18 | */ 19 | EXPORT static std::vector functions(); 20 | }; 21 | 22 | class Calculator { 23 | public: 24 | EXPORT Calculator(const IEngine_Ptr &storage); 25 | EXPORT MeasArray apply(const Id id, Time from, Time to, Flag f, 26 | const std::vector &functions); 27 | 28 | protected: 29 | IEngine_Ptr _storage; 30 | }; 31 | } // namespace statistic 32 | } // namespace dariadb -------------------------------------------------------------------------------- /libdariadb/statistic/functions.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace dariadb { 7 | namespace statistic { 8 | 9 | class Average : public IFunction { 10 | public: 11 | EXPORT Average(const std::string &s); 12 | EXPORT Meas apply(const MeasArray &ma) override; 13 | }; 14 | 15 | class Minimum : public IFunction { 16 | public: 17 | EXPORT Minimum(const std::string &s); 18 | EXPORT Meas apply(const MeasArray &ma) override; 19 | }; 20 | 21 | class Maximum : public IFunction { 22 | public: 23 | EXPORT Maximum(const std::string &s); 24 | EXPORT Meas apply(const MeasArray &ma) override; 25 | }; 26 | 27 | class Count : public IFunction { 28 | public: 29 | EXPORT Count(const std::string &s); 30 | EXPORT Meas apply(const MeasArray &ma) override; 31 | }; 32 | 33 | class StandartDeviation : public IFunction { 34 | public: 35 | EXPORT StandartDeviation(const std::string &s); 36 | EXPORT Meas apply(const MeasArray &ma) override; 37 | }; 38 | 39 | template class Percentile : public IFunction { 40 | public: 41 | Percentile(const std::string &s) : IFunction(s) {} 42 | 43 | EXPORT Meas apply(const MeasArray &ma) override { 44 | if (ma.empty()) { 45 | return Meas(); 46 | } 47 | 48 | if (ma.size() == 1) { 49 | return ma.front(); 50 | } 51 | 52 | if (ma.size() == 2) { 53 | Meas m = ma[0]; 54 | m.value += ma[1].value; 55 | m.value /= 2; 56 | m.time = std::max(ma[0].time, ma[1].time); 57 | return m; 58 | } 59 | MeasArray _result(ma); 60 | std::sort(_result.begin(), _result.end(), meas_value_compare_less()); 61 | auto perc_float = percentile * 0.01; 62 | auto index = (size_t)(perc_float * _result.size()); 63 | return _result.at(index); 64 | } 65 | }; // namespace statistic 66 | 67 | using Median = Percentile<50>; 68 | using Percentile90 = Percentile<90>; 69 | using Percentile99 = Percentile<99>; 70 | } // namespace statistic 71 | } // namespace dariadb 72 | -------------------------------------------------------------------------------- /libdariadb/statistic/ifunction.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /libdariadb/statistic/ifunction.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace dariadb { 8 | namespace statistic { 9 | class IFunction { 10 | public: 11 | IFunction(const std::string &s) : _kindname(s) {} 12 | virtual Meas apply(const MeasArray &ma) = 0; 13 | std::string kind() const { return _kindname; }; 14 | 15 | protected: 16 | std::string _kindname; 17 | }; 18 | using IFunction_ptr = std::shared_ptr; 19 | } // namespace statistic 20 | } // namespace dariadb -------------------------------------------------------------------------------- /libdariadb/status.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | namespace dariadb { 5 | std::string to_string(const APPEND_ERROR st) { 6 | switch (st) { 7 | case APPEND_ERROR::OK: 8 | return "OK"; 9 | break; 10 | case APPEND_ERROR::bad_alloc: 11 | return "memory allocation error"; 12 | break; 13 | case APPEND_ERROR::bad_shard: 14 | return "shard not found"; 15 | break; 16 | case APPEND_ERROR::wal_file_limit: 17 | return "wall file is full"; 18 | break; 19 | } 20 | THROW_EXCEPTION("std::string to_string(const APPEND_ERROR st) - ", (int)st); 21 | } 22 | } -------------------------------------------------------------------------------- /libdariadb/status.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace dariadb { 8 | 9 | enum class APPEND_ERROR : int { OK, bad_alloc, bad_shard, wal_file_limit }; 10 | 11 | struct Status { 12 | static Status empty() { return Status(); } 13 | Status() { 14 | writed = ignored = 0; 15 | error = APPEND_ERROR::OK; 16 | } 17 | Status(size_t wr) { 18 | writed = wr; 19 | ignored = size_t(0); 20 | error = APPEND_ERROR::OK; 21 | } 22 | 23 | Status(size_t ig, APPEND_ERROR err) { 24 | ignored = ig; 25 | error = err; 26 | } 27 | 28 | Status(const Status &other) { 29 | this->writed = other.writed; 30 | this->ignored = other.ignored; 31 | this->error = other.error; 32 | } 33 | 34 | Status operator+(const Status &other) const { 35 | Status res; 36 | res.writed = writed + other.writed; 37 | res.ignored = ignored + other.ignored; 38 | return res; 39 | } 40 | 41 | Status &operator=(const Status &other) { 42 | if (this != &other) { 43 | this->writed = other.writed; 44 | this->ignored = other.ignored; 45 | this->error = other.error; 46 | } 47 | return *this; 48 | } 49 | 50 | bool operator==(const Status &other) { 51 | if (this != &other) { 52 | return this->ignored == other.ignored && this->writed == other.writed; 53 | } 54 | return true; 55 | } 56 | 57 | bool operator!=(const Status &other) { 58 | if (this != &other) { 59 | return !(*this == other); 60 | } 61 | return true; 62 | } 63 | size_t writed; 64 | size_t ignored; 65 | APPEND_ERROR error; 66 | }; 67 | 68 | EXPORT std::string to_string(const APPEND_ERROR strat); 69 | } 70 | -------------------------------------------------------------------------------- /libdariadb/storage/bloom_filter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace dariadb { 6 | namespace storage { 7 | 8 | template static uint64_t bloom_empty() { 9 | return uint64_t(0); 10 | } 11 | 12 | template static uint64_t bloom_add(const uint64_t fltr, const T &val) { 13 | auto h = utils::jenkins_one_at_a_time_hash(val); 14 | return fltr | h; 15 | } 16 | 17 | template static bool bloom_check(const uint64_t fltr, const T &val) { 18 | auto h = utils::jenkins_one_at_a_time_hash(val); 19 | return (fltr & h) == h; 20 | } 21 | 22 | static uint64_t bloom_combine(const uint64_t fltr_a, const uint64_t fltr_b) { 23 | return fltr_a | fltr_b; 24 | } 25 | } // namespace storage 26 | } // namespace dariadb 27 | -------------------------------------------------------------------------------- /libdariadb/storage/callbacks.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace dariadb; 4 | using namespace dariadb::storage; 5 | 6 | MArray_ReaderClb::MArray_ReaderClb(size_t count) { 7 | this->marray.reserve(count); 8 | } 9 | 10 | void MArray_ReaderClb::apply(const Meas &m) { 11 | std::lock_guard lg(_locker); 12 | marray.push_back(m); 13 | } 14 | 15 | MArrayPtr_ReaderClb::MArrayPtr_ReaderClb(MeasArray *output) { 16 | this->marray = output; 17 | } 18 | 19 | void MArrayPtr_ReaderClb::apply(const Meas &m) { 20 | std::lock_guard lg(_locker); 21 | marray->push_back(m); 22 | } 23 | 24 | FunctorCallback::FunctorCallback(FunctorCallback::FunctorType &ft) : functor(ft) {} 25 | 26 | void FunctorCallback::apply(const Meas &m) { 27 | is_cancel = this->functor(m); 28 | } -------------------------------------------------------------------------------- /libdariadb/storage/callbacks.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace dariadb { 11 | namespace storage { 12 | 13 | struct MArray_ReaderClb : public IReadCallback { 14 | EXPORT MArray_ReaderClb(size_t count); 15 | EXPORT void apply(const Meas &m) override; 16 | 17 | MeasArray marray; 18 | utils::async::Locker _locker; 19 | }; 20 | 21 | struct MArrayPtr_ReaderClb : public IReadCallback { 22 | EXPORT MArrayPtr_ReaderClb(MeasArray *output); 23 | EXPORT void apply(const Meas &m) override; 24 | 25 | MeasArray *marray; 26 | utils::async::Locker _locker; 27 | }; 28 | 29 | struct FunctorCallback : public IReadCallback { 30 | /// return true to cancel; 31 | typedef std::function FunctorType; 32 | EXPORT FunctorCallback(FunctorType &ft); 33 | EXPORT void apply(const Meas &m) override; 34 | FunctorType functor; 35 | }; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /libdariadb/storage/chunkcontainer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace dariadb; 4 | 5 | IChunkStorage::~IChunkStorage() {} 6 | 7 | ChunkContainer::ChunkContainer() {} 8 | ChunkContainer::~ChunkContainer() {} 9 | 10 | void ChunkContainer::foreach (const QueryInterval &query, IReadCallback * clb) { 11 | auto readers = intervalReader(query); 12 | for (auto kv : readers) { 13 | kv.second->apply(clb, query); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /libdariadb/storage/chunkcontainer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace dariadb { 11 | 12 | struct ChunkLink { 13 | uint64_t id; 14 | uint64_t meas_id; 15 | dariadb::Time minTime; 16 | dariadb::Time maxTime; 17 | std::string page_name; 18 | uint64_t index_rec_number; 19 | }; 20 | 21 | using ChunkLinkList = std::list; 22 | 23 | class IChunkStorage { 24 | public: 25 | virtual void appendChunks(const std::vector &a) = 0; 26 | EXPORT ~IChunkStorage(); 27 | }; 28 | 29 | class ChunkContainer : public IChunkStorage { 30 | public: 31 | virtual bool minMaxTime(dariadb::Id id, dariadb::Time *minResult, 32 | dariadb::Time *maxResult) = 0; 33 | virtual Id2Meas valuesBeforeTimePoint(const QueryTimePoint &q) = 0; 34 | virtual Id2Cursor intervalReader(const QueryInterval &query) = 0; 35 | virtual Statistic stat(const Id id, Time from, Time to) = 0; 36 | EXPORT virtual void foreach (const QueryInterval &query, IReadCallback * clb); 37 | EXPORT ChunkContainer(); 38 | EXPORT virtual ~ChunkContainer(); 39 | }; 40 | } 41 | -------------------------------------------------------------------------------- /libdariadb/storage/cursors.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace dariadb { 8 | namespace storage { 9 | 10 | /** 11 | Store all values in memory. 12 | */ 13 | class FullCursor : public ICursor { 14 | public: 15 | EXPORT FullCursor(MeasArray &ma); 16 | EXPORT virtual Meas readNext() override; 17 | 18 | EXPORT bool is_end() const override; 19 | 20 | EXPORT Meas top() override; 21 | EXPORT Time minTime() override; 22 | EXPORT Time maxTime() override; 23 | 24 | EXPORT size_t count() const override; 25 | MeasArray _ma; 26 | size_t _index; 27 | 28 | Time _minTime; 29 | Time _maxTime; 30 | }; 31 | 32 | /** 33 | Merge sort. 34 | */ 35 | class MergeSortCursor : public ICursor { 36 | public: 37 | EXPORT MergeSortCursor(const CursorsList &readers); 38 | EXPORT virtual Meas readNext() override; 39 | EXPORT bool is_end() const override; 40 | EXPORT Meas top() override; 41 | EXPORT Time minTime() override; 42 | EXPORT Time maxTime() override; 43 | EXPORT size_t count() const override; 44 | 45 | size_t _values_count; 46 | std::vector _readers; 47 | std::vector