Skip to content

Commit

Permalink
Introduce JSONCONS for RedisJSON and rewrite Server::GetRocksDBStatsJ…
Browse files Browse the repository at this point in the history
…son (#1366)
  • Loading branch information
PragmaTwice authored Apr 4, 2023
1 parent 115f354 commit d13dbfd
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 54 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/kvrocks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ jobs:
- name: Ubuntu Clang
os: ubuntu-20.04
compiler: clang
- name: Ubuntu 22 GCC
os: ubuntu-22.04
compiler: gcc
- name: Ubuntu 22 Clang
os: ubuntu-22.04
compiler: clang
- name: Ubuntu GCC ASan
os: ubuntu-20.04
without_jemalloc: -DDISABLE_JEMALLOC=ON
Expand Down
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ include(cmake/tbb.cmake)
include(cmake/rocksdb.cmake)
include(cmake/libevent.cmake)
include(cmake/fmt.cmake)
include(cmake/jsoncons.cmake)

if (USE_LUAJIT)
include(cmake/luajit.cmake)
Expand All @@ -148,6 +149,7 @@ if (ENABLE_OPENSSL)
list(APPEND EXTERNAL_LIBS OpenSSL::SSL)
endif()
list(APPEND EXTERNAL_LIBS tbb)
list(APPEND EXTERNAL_LIBS jsoncons)
list(APPEND EXTERNAL_LIBS Threads::Threads)

# Add git sha to version.h
Expand Down Expand Up @@ -200,6 +202,11 @@ if(ENABLE_NEW_ENCODING)
target_compile_definitions(kvrocks_objs PUBLIC ENABLE_NEW_ENCODING)
endif()

# disable LTO on GCC <= 9 due to an ICE
if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10))
set(ENABLE_IPO OFF)
endif()

if(ENABLE_IPO)
include(CheckIPOSupported)
check_ipo_supported(RESULT ipo_result OUTPUT ipo_output LANGUAGES CXX)
Expand Down
124 changes: 81 additions & 43 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -233,65 +233,103 @@ For src/common/rocksdb_crc32c.h and src/storage/batch_debugger.h are modified fr
We choose the Apache License 2.0 from the dual-licensed RocksDB code,
and have added the RocksDB license notice in each file header.

For the library LuaJIT(https://github.com/KvrocksLabs/LuaJIT) -- a Just-In-Time Compiler for Lua. https://luajit.org/
For the library LuaJIT(https://github.com/KvrocksLabs/LuaJIT):

LuaJIT is free software, released under the MIT license.
LuaJIT is a Just-In-Time Compiler for Lua, released under the MIT license.

Copyright (C) 2005-2022 Mike Pall. All rights reserved.
===============================================================================
LuaJIT -- a Just-In-Time Compiler for Lua. https://luajit.org/

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Copyright (C) 2005-2022 Mike Pall. All rights reserved.

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

[ MIT license: https://www.opensource.org/licenses/mit-license.php ]
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

===============================================================================
[ LuaJIT includes code from Lua 5.1/5.2, which has this license statement: ]
[ MIT license: https://www.opensource.org/licenses/mit-license.php ]

Copyright (C) 1994-2012 Lua.org, PUC-Rio.
===============================================================================
[ LuaJIT includes code from Lua 5.1/5.2, which has this license statement: ]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Copyright (C) 1994-2012 Lua.org, PUC-Rio.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

===============================================================================
[ LuaJIT includes code from dlmalloc, which has this license statement: ]
===============================================================================
[ LuaJIT includes code from dlmalloc, which has this license statement: ]

This is a version (aka dlmalloc) of malloc/free/realloc written by
Doug Lea and released to the public domain, as explained at
https://creativecommons.org/licenses/publicdomain
This is a version (aka dlmalloc) of malloc/free/realloc written by
Doug Lea and released to the public domain, as explained at
https://creativecommons.org/licenses/publicdomain

===============================================================================
===============================================================================

For the library oneTBB (https://github.com/oneapi-src/oneTBB):

oneAPI Threading Building Blocks (oneTBB) is a flexible C++ library that simplifies the work of adding parallelism to complex applications.
It is licensed under Apache-2.0 License, refer to LICENSE in the root directory.


For the library jsoncons (https://github.com/danielaparker/jsoncons):

jsoncons is a C++, header-only library for constructing JSON and JSON-like data formats such as CBOR.
It is released under the Boost Software License Version 1.0.

// Copyright Daniel Parker 2013 - 2020.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE or copy at
// http://www.boost.org/LICENSE_1_0.txt)

Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
29 changes: 29 additions & 0 deletions cmake/jsoncons.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

include_guard()

include(cmake/utils.cmake)

FetchContent_DeclareGitHubWithMirror(jsoncons
danielaparker/jsoncons v0.170.0
MD5=02765c8e4ce09eb744f9daacc40ca595
)

FetchContent_MakeAvailableWithArgs(jsoncons
JSONCONS_BUILD_TESTS=OFF
)
18 changes: 7 additions & 11 deletions src/server/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include <atomic>
#include <iomanip>
#include <jsoncons/json.hpp>
#include <memory>
#include <mutex>
#include <shared_mutex>
Expand Down Expand Up @@ -1154,28 +1155,23 @@ void Server::GetInfo(const std::string &ns, const std::string &section, std::str
}

std::string Server::GetRocksDBStatsJson() const {
std::string output;
jsoncons::json stats_json;

output.reserve(8 * 1024);
output.append("{");
auto stats = storage_->GetDB()->GetDBOptions().statistics;
for (const auto &iter : rocksdb::TickersNameMap) {
output.append(fmt::format(R"("{}":{},)", iter.second.c_str(), stats->getTickerCount(iter.first)));
stats_json[iter.second] = stats->getTickerCount(iter.first);
}

for (const auto &iter : rocksdb::HistogramsNameMap) {
rocksdb::HistogramData hist_data;
stats->histogramData(iter.first, &hist_data);
/* P50 P95 P99 P100 COUNT SUM */
output.append(fmt::format(R"("{}":[{},{},{},{},{},{}],)", iter.second, hist_data.median, hist_data.percentile95,
hist_data.percentile99, hist_data.max, hist_data.count, hist_data.sum));
stats_json[iter.second] =
jsoncons::json(jsoncons::json_array_arg, {hist_data.median, hist_data.percentile95, hist_data.percentile99,
hist_data.max, hist_data.count, hist_data.sum});
}

output.pop_back();
output.append("}");
output.shrink_to_fit();

return output;
return stats_json.to_string();
}

// This function is called by replication thread when finished fetching all files from its master.
Expand Down

0 comments on commit d13dbfd

Please sign in to comment.