mirror of
https://github.com/XRPLF/clio.git
synced 2026-02-08 07:52:31 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c35649eb6e | ||
|
|
4da4b49eda |
@@ -2,6 +2,15 @@ _help_parse: Options affecting listfile parsing
|
|||||||
parse:
|
parse:
|
||||||
_help_additional_commands:
|
_help_additional_commands:
|
||||||
- Specify structure for custom cmake functions
|
- Specify structure for custom cmake functions
|
||||||
|
additional_commands:
|
||||||
|
foo:
|
||||||
|
flags:
|
||||||
|
- BAR
|
||||||
|
- BAZ
|
||||||
|
kwargs:
|
||||||
|
HEADERS: "*"
|
||||||
|
SOURCES: "*"
|
||||||
|
DEPENDS: "*"
|
||||||
_help_override_spec:
|
_help_override_spec:
|
||||||
- Override configurations per-command where available
|
- Override configurations per-command where available
|
||||||
override_spec: {}
|
override_spec: {}
|
||||||
@@ -21,7 +30,7 @@ format:
|
|||||||
line_width: 120
|
line_width: 120
|
||||||
_help_tab_size:
|
_help_tab_size:
|
||||||
- How many spaces to tab for indent
|
- How many spaces to tab for indent
|
||||||
tab_size: 4
|
tab_size: 2
|
||||||
_help_use_tabchars:
|
_help_use_tabchars:
|
||||||
- If true, lines are indented using tab characters (utf-8
|
- If true, lines are indented using tab characters (utf-8
|
||||||
- 0x09) instead of <tab_size> space characters (utf-8 0x20).
|
- 0x09) instead of <tab_size> space characters (utf-8 0x20).
|
||||||
@@ -61,19 +70,19 @@ format:
|
|||||||
_help_dangle_parens:
|
_help_dangle_parens:
|
||||||
- If a statement is wrapped to more than one line, than dangle
|
- If a statement is wrapped to more than one line, than dangle
|
||||||
- the closing parenthesis on its own line.
|
- the closing parenthesis on its own line.
|
||||||
dangle_parens: false
|
dangle_parens: true
|
||||||
_help_dangle_align:
|
_help_dangle_align:
|
||||||
- If the trailing parenthesis must be 'dangled' on its on
|
- If the trailing parenthesis must be 'dangled' on its on
|
||||||
- "line, then align it to this reference: `prefix`: the start"
|
- "line, then align it to this reference: `prefix`: the start"
|
||||||
- "of the statement, `prefix-indent`: the start of the"
|
- "of the statement, `prefix-indent`: the start of the"
|
||||||
- "statement, plus one indentation level, `child`: align to"
|
- "statement, plus one indentation level, `child`: align to"
|
||||||
- the column of the arguments
|
- the column of the arguments
|
||||||
dangle_align: prefix
|
dangle_align: prefix
|
||||||
_help_min_prefix_chars:
|
_help_min_prefix_chars:
|
||||||
- If the statement spelling length (including space and
|
- If the statement spelling length (including space and
|
||||||
- parenthesis) is smaller than this amount, then force reject
|
- parenthesis) is smaller than this amount, then force reject
|
||||||
- nested layouts.
|
- nested layouts.
|
||||||
min_prefix_chars: 18
|
min_prefix_chars: 4
|
||||||
_help_max_prefix_chars:
|
_help_max_prefix_chars:
|
||||||
- If the statement spelling length (including space and
|
- If the statement spelling length (including space and
|
||||||
- parenthesis) is larger than the tab width by more than this
|
- parenthesis) is larger than the tab width by more than this
|
||||||
@@ -118,7 +127,7 @@ _help_markup: Options affecting comment reflow and formatting.
|
|||||||
markup:
|
markup:
|
||||||
_help_bullet_char:
|
_help_bullet_char:
|
||||||
- What character to use for bulleted lists
|
- What character to use for bulleted lists
|
||||||
bullet_char: "-"
|
bullet_char: "*"
|
||||||
_help_enum_char:
|
_help_enum_char:
|
||||||
- What character to use as punctuation after numerals in an
|
- What character to use as punctuation after numerals in an
|
||||||
- enumerated list
|
- enumerated list
|
||||||
|
|||||||
2
.github/actions/build-clio/action.yml
vendored
2
.github/actions/build-clio/action.yml
vendored
@@ -14,7 +14,7 @@ runs:
|
|||||||
using: composite
|
using: composite
|
||||||
steps:
|
steps:
|
||||||
- name: Get number of processors
|
- name: Get number of processors
|
||||||
uses: XRPLF/actions/get-nproc@cf0433aa74563aead044a1e395610c96d65a37cf
|
uses: XRPLF/actions/.github/actions/get-nproc@046b1620f6bfd6cd0985dc82c3df02786801fe0a
|
||||||
id: nproc
|
id: nproc
|
||||||
with:
|
with:
|
||||||
subtract: ${{ inputs.nproc_subtract }}
|
subtract: ${{ inputs.nproc_subtract }}
|
||||||
|
|||||||
@@ -34,14 +34,14 @@ runs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Login to DockerHub
|
- name: Login to DockerHub
|
||||||
if: ${{ inputs.push_image == 'true' && inputs.dockerhub_repo != '' }}
|
if: ${{ inputs.push_image == 'true' && inputs.dockerhub_repo != '' }}
|
||||||
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
|
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
|
||||||
with:
|
with:
|
||||||
username: ${{ env.DOCKERHUB_USER }}
|
username: ${{ env.DOCKERHUB_USER }}
|
||||||
password: ${{ env.DOCKERHUB_PW }}
|
password: ${{ env.DOCKERHUB_PW }}
|
||||||
|
|
||||||
- name: Login to GitHub Container Registry
|
- name: Login to GitHub Container Registry
|
||||||
if: ${{ inputs.push_image == 'true' }}
|
if: ${{ inputs.push_image == 'true' }}
|
||||||
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
|
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.repository_owner }}
|
username: ${{ github.repository_owner }}
|
||||||
@@ -50,7 +50,7 @@ runs:
|
|||||||
- uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
|
- uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
|
||||||
with:
|
with:
|
||||||
cache-image: false
|
cache-image: false
|
||||||
- uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
|
- uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
|
||||||
|
|
||||||
- uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0
|
- uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0
|
||||||
id: meta
|
id: meta
|
||||||
|
|||||||
17
.github/actions/cmake/action.yml
vendored
17
.github/actions/cmake/action.yml
vendored
@@ -37,10 +37,6 @@ inputs:
|
|||||||
description: Whether to generate Debian package
|
description: Whether to generate Debian package
|
||||||
required: true
|
required: true
|
||||||
default: "false"
|
default: "false"
|
||||||
version:
|
|
||||||
description: Version of the clio_server binary
|
|
||||||
required: false
|
|
||||||
default: ""
|
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: composite
|
using: composite
|
||||||
@@ -61,19 +57,6 @@ runs:
|
|||||||
STATIC: "${{ inputs.static == 'true' && 'ON' || 'OFF' }}"
|
STATIC: "${{ inputs.static == 'true' && 'ON' || 'OFF' }}"
|
||||||
TIME_TRACE: "${{ inputs.time_trace == 'true' && 'ON' || 'OFF' }}"
|
TIME_TRACE: "${{ inputs.time_trace == 'true' && 'ON' || 'OFF' }}"
|
||||||
PACKAGE: "${{ inputs.package == 'true' && 'ON' || 'OFF' }}"
|
PACKAGE: "${{ inputs.package == 'true' && 'ON' || 'OFF' }}"
|
||||||
# GitHub creates a merge commit for a PR
|
|
||||||
# https://www.kenmuse.com/blog/the-many-shas-of-a-github-pull-request/
|
|
||||||
#
|
|
||||||
# We:
|
|
||||||
# - explicitly provide branch name
|
|
||||||
# - use `github.head_ref` to get the SHA of last commit in the PR branch
|
|
||||||
#
|
|
||||||
# This way it works both for PRs and pushes to branches.
|
|
||||||
GITHUB_BRANCH_NAME: "${{ github.head_ref || github.ref_name }}"
|
|
||||||
GITHUB_HEAD_SHA: "${{ github.event.pull_request.head.sha || github.sha }}"
|
|
||||||
#
|
|
||||||
# If tag is being pushed, or it's a nightly release, we use that version.
|
|
||||||
FORCE_CLIO_VERSION: ${{ inputs.version }}
|
|
||||||
run: |
|
run: |
|
||||||
cmake \
|
cmake \
|
||||||
-B "${BUILD_DIR}" \
|
-B "${BUILD_DIR}" \
|
||||||
|
|||||||
2
.github/actions/code-coverage/action.yml
vendored
2
.github/actions/code-coverage/action.yml
vendored
@@ -24,7 +24,7 @@ runs:
|
|||||||
-j8 --exclude-throw-branches
|
-j8 --exclude-throw-branches
|
||||||
|
|
||||||
- name: Archive coverage report
|
- name: Archive coverage report
|
||||||
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
|
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||||
with:
|
with:
|
||||||
name: coverage-report.xml
|
name: coverage-report.xml
|
||||||
path: build/coverage_report.xml
|
path: build/coverage_report.xml
|
||||||
|
|||||||
4
.github/actions/conan/action.yml
vendored
4
.github/actions/conan/action.yml
vendored
@@ -21,6 +21,10 @@ inputs:
|
|||||||
runs:
|
runs:
|
||||||
using: composite
|
using: composite
|
||||||
steps:
|
steps:
|
||||||
|
- name: Create build directory
|
||||||
|
shell: bash
|
||||||
|
run: mkdir -p "${{ inputs.build_dir }}"
|
||||||
|
|
||||||
- name: Run conan
|
- name: Run conan
|
||||||
shell: bash
|
shell: bash
|
||||||
env:
|
env:
|
||||||
|
|||||||
2
.github/scripts/conan/generate_matrix.py
vendored
2
.github/scripts/conan/generate_matrix.py
vendored
@@ -4,7 +4,7 @@ import json
|
|||||||
|
|
||||||
LINUX_OS = ["heavy", "heavy-arm64"]
|
LINUX_OS = ["heavy", "heavy-arm64"]
|
||||||
LINUX_CONTAINERS = [
|
LINUX_CONTAINERS = [
|
||||||
'{ "image": "ghcr.io/xrplf/clio-ci:14342e087ceb8b593027198bf9ef06a43833c696" }'
|
'{ "image": "ghcr.io/xrplf/clio-ci:067449c3f8ae6755ea84752ea2962b589fe56c8f" }'
|
||||||
]
|
]
|
||||||
LINUX_COMPILERS = ["gcc", "clang"]
|
LINUX_COMPILERS = ["gcc", "clang"]
|
||||||
|
|
||||||
|
|||||||
25
.github/scripts/conan/regenerate_lockfile.sh
vendored
25
.github/scripts/conan/regenerate_lockfile.sh
vendored
@@ -1,25 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
set -ex
|
|
||||||
|
|
||||||
TEMP_DIR=$(mktemp -d)
|
|
||||||
trap "rm -rf $TEMP_DIR" EXIT
|
|
||||||
|
|
||||||
echo "Using temporary CONAN_HOME: $TEMP_DIR"
|
|
||||||
|
|
||||||
# We use a temporary Conan home to avoid polluting the user's existing Conan
|
|
||||||
# configuration and to not use local cache (which leads to non-reproducible lockfiles).
|
|
||||||
export CONAN_HOME="$TEMP_DIR"
|
|
||||||
|
|
||||||
# Ensure that the xrplf remote is the first to be consulted, so any recipes we
|
|
||||||
# patched are used. We also add it there to not created huge diff when the
|
|
||||||
# official Conan Center Index is updated.
|
|
||||||
conan remote add --force --index 0 xrplf https://conan.ripplex.io
|
|
||||||
|
|
||||||
# Delete any existing lockfile.
|
|
||||||
rm -f conan.lock
|
|
||||||
|
|
||||||
# Create a new lockfile that is compatible with macOS.
|
|
||||||
# It should also work on Linux.
|
|
||||||
conan lock create . \
|
|
||||||
--profile:all=.github/scripts/conan/apple-clang-17.profile
|
|
||||||
46
.github/scripts/execute-tests-under-sanitizer.sh
vendored
Executable file
46
.github/scripts/execute-tests-under-sanitizer.sh
vendored
Executable file
@@ -0,0 +1,46 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
|
# Note: This script is intended to be run from the root of the repository.
|
||||||
|
#
|
||||||
|
# This script runs each unit-test separately and generates reports from the currently active sanitizer.
|
||||||
|
# Output is saved in ./.sanitizer-report in the root of the repository
|
||||||
|
|
||||||
|
if [[ -z "$1" ]]; then
|
||||||
|
cat <<EOF
|
||||||
|
|
||||||
|
ERROR
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
Path to clio_tests should be passed as first argument to the script.
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
EOF
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
TEST_BINARY=$1
|
||||||
|
|
||||||
|
if [[ ! -f "$TEST_BINARY" ]]; then
|
||||||
|
echo "Test binary not found: $TEST_BINARY"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
TESTS=$($TEST_BINARY --gtest_list_tests | awk '/^ / {print suite $1} !/^ / {suite=$1}')
|
||||||
|
|
||||||
|
OUTPUT_DIR="./.sanitizer-report"
|
||||||
|
mkdir -p "$OUTPUT_DIR"
|
||||||
|
|
||||||
|
export TSAN_OPTIONS="die_after_fork=0"
|
||||||
|
export MallocNanoZone='0' # for MacOSX
|
||||||
|
|
||||||
|
for TEST in $TESTS; do
|
||||||
|
OUTPUT_FILE="$OUTPUT_DIR/${TEST//\//_}.log"
|
||||||
|
$TEST_BINARY --gtest_filter="$TEST" >"$OUTPUT_FILE" 2>&1
|
||||||
|
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "'$TEST' failed a sanitizer check."
|
||||||
|
else
|
||||||
|
rm "$OUTPUT_FILE"
|
||||||
|
fi
|
||||||
|
done
|
||||||
@@ -48,11 +48,11 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||||
|
|
||||||
- name: Download Clio binary from artifact
|
- name: Download Clio binary from artifact
|
||||||
if: ${{ inputs.artifact_name != null }}
|
if: ${{ inputs.artifact_name != null }}
|
||||||
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
|
uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
|
||||||
with:
|
with:
|
||||||
name: ${{ inputs.artifact_name }}
|
name: ${{ inputs.artifact_name }}
|
||||||
path: ./docker/clio/artifact/
|
path: ./docker/clio/artifact/
|
||||||
|
|||||||
29
.github/workflows/build.yml
vendored
29
.github/workflows/build.yml
vendored
@@ -23,7 +23,6 @@ on:
|
|||||||
- "cmake/**"
|
- "cmake/**"
|
||||||
- "src/**"
|
- "src/**"
|
||||||
- "tests/**"
|
- "tests/**"
|
||||||
- "benchmarks/**"
|
|
||||||
|
|
||||||
- docs/config-description.md
|
- docs/config-description.md
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
@@ -50,7 +49,7 @@ jobs:
|
|||||||
build_type: [Release, Debug]
|
build_type: [Release, Debug]
|
||||||
container:
|
container:
|
||||||
[
|
[
|
||||||
'{ "image": "ghcr.io/xrplf/clio-ci:14342e087ceb8b593027198bf9ef06a43833c696" }',
|
'{ "image": "ghcr.io/xrplf/clio-ci:067449c3f8ae6755ea84752ea2962b589fe56c8f" }',
|
||||||
]
|
]
|
||||||
static: [true]
|
static: [true]
|
||||||
|
|
||||||
@@ -80,7 +79,7 @@ jobs:
|
|||||||
uses: ./.github/workflows/reusable-build.yml
|
uses: ./.github/workflows/reusable-build.yml
|
||||||
with:
|
with:
|
||||||
runs_on: heavy
|
runs_on: heavy
|
||||||
container: '{ "image": "ghcr.io/xrplf/clio-ci:14342e087ceb8b593027198bf9ef06a43833c696" }'
|
container: '{ "image": "ghcr.io/xrplf/clio-ci:067449c3f8ae6755ea84752ea2962b589fe56c8f" }'
|
||||||
conan_profile: gcc
|
conan_profile: gcc
|
||||||
build_type: Debug
|
build_type: Debug
|
||||||
download_ccache: true
|
download_ccache: true
|
||||||
@@ -93,17 +92,35 @@ jobs:
|
|||||||
secrets:
|
secrets:
|
||||||
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
|
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
|
||||||
|
|
||||||
|
package:
|
||||||
|
name: Build packages
|
||||||
|
|
||||||
|
uses: ./.github/workflows/reusable-build.yml
|
||||||
|
with:
|
||||||
|
runs_on: heavy
|
||||||
|
container: '{ "image": "ghcr.io/xrplf/clio-ci:067449c3f8ae6755ea84752ea2962b589fe56c8f" }'
|
||||||
|
conan_profile: gcc
|
||||||
|
build_type: Release
|
||||||
|
download_ccache: true
|
||||||
|
upload_ccache: false
|
||||||
|
code_coverage: false
|
||||||
|
static: true
|
||||||
|
upload_clio_server: false
|
||||||
|
package: true
|
||||||
|
targets: package
|
||||||
|
analyze_build_time: false
|
||||||
|
|
||||||
check_config:
|
check_config:
|
||||||
name: Check Config Description
|
name: Check Config Description
|
||||||
needs: build-and-test
|
needs: build-and-test
|
||||||
runs-on: heavy
|
runs-on: heavy
|
||||||
container:
|
container:
|
||||||
image: ghcr.io/xrplf/clio-ci:14342e087ceb8b593027198bf9ef06a43833c696
|
image: ghcr.io/xrplf/clio-ci:067449c3f8ae6755ea84752ea2962b589fe56c8f
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||||
|
|
||||||
- uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
|
- uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
|
||||||
with:
|
with:
|
||||||
name: clio_server_Linux_Release_gcc
|
name: clio_server_Linux_Release_gcc
|
||||||
|
|
||||||
|
|||||||
16
.github/workflows/check-libxrpl.yml
vendored
16
.github/workflows/check-libxrpl.yml
vendored
@@ -21,17 +21,17 @@ jobs:
|
|||||||
name: Build Clio / `libXRPL ${{ github.event.client_payload.version }}`
|
name: Build Clio / `libXRPL ${{ github.event.client_payload.version }}`
|
||||||
runs-on: heavy
|
runs-on: heavy
|
||||||
container:
|
container:
|
||||||
image: ghcr.io/xrplf/clio-ci:14342e087ceb8b593027198bf9ef06a43833c696
|
image: ghcr.io/xrplf/clio-ci:067449c3f8ae6755ea84752ea2962b589fe56c8f
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Prepare runner
|
- name: Prepare runner
|
||||||
uses: XRPLF/actions/prepare-runner@2cbf481018d930656e9276fcc20dc0e3a0be5b6d
|
uses: XRPLF/actions/.github/actions/prepare-runner@8abb0722cbff83a9a2dc7d06c473f7a4964b7382
|
||||||
with:
|
with:
|
||||||
enable_ccache: false
|
disable_ccache: true
|
||||||
|
|
||||||
- name: Update libXRPL version requirement
|
- name: Update libXRPL version requirement
|
||||||
run: |
|
run: |
|
||||||
@@ -59,7 +59,7 @@ jobs:
|
|||||||
run: strip build/clio_tests
|
run: strip build/clio_tests
|
||||||
|
|
||||||
- name: Upload clio_tests
|
- name: Upload clio_tests
|
||||||
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
|
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||||
with:
|
with:
|
||||||
name: clio_tests_check_libxrpl
|
name: clio_tests_check_libxrpl
|
||||||
path: build/clio_tests
|
path: build/clio_tests
|
||||||
@@ -69,10 +69,10 @@ jobs:
|
|||||||
needs: build
|
needs: build
|
||||||
runs-on: heavy
|
runs-on: heavy
|
||||||
container:
|
container:
|
||||||
image: ghcr.io/xrplf/clio-ci:14342e087ceb8b593027198bf9ef06a43833c696
|
image: ghcr.io/xrplf/clio-ci:067449c3f8ae6755ea84752ea2962b589fe56c8f
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
|
- uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
|
||||||
with:
|
with:
|
||||||
name: clio_tests_check_libxrpl
|
name: clio_tests_check_libxrpl
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ jobs:
|
|||||||
issues: write
|
issues: write
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||||
|
|
||||||
- name: Create an issue
|
- name: Create an issue
|
||||||
uses: ./.github/actions/create-issue
|
uses: ./.github/actions/create-issue
|
||||||
|
|||||||
12
.github/workflows/clang-tidy.yml
vendored
12
.github/workflows/clang-tidy.yml
vendored
@@ -31,7 +31,7 @@ jobs:
|
|||||||
if: github.event_name != 'push' || contains(github.event.head_commit.message, 'clang-tidy auto fixes')
|
if: github.event_name != 'push' || contains(github.event.head_commit.message, 'clang-tidy auto fixes')
|
||||||
runs-on: heavy
|
runs-on: heavy
|
||||||
container:
|
container:
|
||||||
image: ghcr.io/xrplf/clio-ci:14342e087ceb8b593027198bf9ef06a43833c696
|
image: ghcr.io/xrplf/clio-ci:067449c3f8ae6755ea84752ea2962b589fe56c8f
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
@@ -39,14 +39,14 @@ jobs:
|
|||||||
pull-requests: write
|
pull-requests: write
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Prepare runner
|
- name: Prepare runner
|
||||||
uses: XRPLF/actions/prepare-runner@2cbf481018d930656e9276fcc20dc0e3a0be5b6d
|
uses: XRPLF/actions/.github/actions/prepare-runner@8abb0722cbff83a9a2dc7d06c473f7a4964b7382
|
||||||
with:
|
with:
|
||||||
enable_ccache: false
|
disable_ccache: true
|
||||||
|
|
||||||
- name: Run conan
|
- name: Run conan
|
||||||
uses: ./.github/actions/conan
|
uses: ./.github/actions/conan
|
||||||
@@ -59,7 +59,7 @@ jobs:
|
|||||||
conan_profile: ${{ env.CONAN_PROFILE }}
|
conan_profile: ${{ env.CONAN_PROFILE }}
|
||||||
|
|
||||||
- name: Get number of processors
|
- name: Get number of processors
|
||||||
uses: XRPLF/actions/get-nproc@cf0433aa74563aead044a1e395610c96d65a37cf
|
uses: XRPLF/actions/.github/actions/get-nproc@046b1620f6bfd6cd0985dc82c3df02786801fe0a
|
||||||
id: nproc
|
id: nproc
|
||||||
|
|
||||||
- name: Run clang-tidy (several times)
|
- name: Run clang-tidy (several times)
|
||||||
@@ -107,7 +107,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Create PR with fixes
|
- name: Create PR with fixes
|
||||||
if: ${{ steps.files_changed.outcome != 'success' && github.event_name != 'pull_request' }}
|
if: ${{ steps.files_changed.outcome != 'success' && github.event_name != 'pull_request' }}
|
||||||
uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8.1.0
|
uses: peter-evans/create-pull-request@22a9089034f40e5a961c8808d113e2c98fb63676 # v7.0.11
|
||||||
env:
|
env:
|
||||||
GH_REPO: ${{ github.repository }}
|
GH_REPO: ${{ github.repository }}
|
||||||
GH_TOKEN: ${{ github.token }}
|
GH_TOKEN: ${{ github.token }}
|
||||||
|
|||||||
8
.github/workflows/docs.yml
vendored
8
.github/workflows/docs.yml
vendored
@@ -18,18 +18,18 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container:
|
container:
|
||||||
image: ghcr.io/xrplf/clio-ci:14342e087ceb8b593027198bf9ef06a43833c696
|
image: ghcr.io/xrplf/clio-ci:067449c3f8ae6755ea84752ea2962b589fe56c8f
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||||
with:
|
with:
|
||||||
lfs: true
|
lfs: true
|
||||||
|
|
||||||
- name: Prepare runner
|
- name: Prepare runner
|
||||||
uses: XRPLF/actions/prepare-runner@2cbf481018d930656e9276fcc20dc0e3a0be5b6d
|
uses: XRPLF/actions/.github/actions/prepare-runner@8abb0722cbff83a9a2dc7d06c473f7a4964b7382
|
||||||
with:
|
with:
|
||||||
enable_ccache: false
|
disable_ccache: true
|
||||||
|
|
||||||
- name: Create build directory
|
- name: Create build directory
|
||||||
run: mkdir build_docs
|
run: mkdir build_docs
|
||||||
|
|||||||
58
.github/workflows/nightly.yml
vendored
58
.github/workflows/nightly.yml
vendored
@@ -28,20 +28,8 @@ defaults:
|
|||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
get_date:
|
|
||||||
name: Get Date
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
outputs:
|
|
||||||
date: ${{ steps.get_date.outputs.date }}
|
|
||||||
steps:
|
|
||||||
- name: Get current date
|
|
||||||
id: get_date
|
|
||||||
run: |
|
|
||||||
echo "date=$(date +'%Y%m%d')" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
build-and-test:
|
build-and-test:
|
||||||
name: Build and Test
|
name: Build and Test
|
||||||
needs: get_date
|
|
||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
@@ -55,17 +43,17 @@ jobs:
|
|||||||
conan_profile: gcc
|
conan_profile: gcc
|
||||||
build_type: Release
|
build_type: Release
|
||||||
static: true
|
static: true
|
||||||
container: '{ "image": "ghcr.io/xrplf/clio-ci:14342e087ceb8b593027198bf9ef06a43833c696" }'
|
container: '{ "image": "ghcr.io/xrplf/clio-ci:067449c3f8ae6755ea84752ea2962b589fe56c8f" }'
|
||||||
- os: heavy
|
- os: heavy
|
||||||
conan_profile: gcc
|
conan_profile: gcc
|
||||||
build_type: Debug
|
build_type: Debug
|
||||||
static: true
|
static: true
|
||||||
container: '{ "image": "ghcr.io/xrplf/clio-ci:14342e087ceb8b593027198bf9ef06a43833c696" }'
|
container: '{ "image": "ghcr.io/xrplf/clio-ci:067449c3f8ae6755ea84752ea2962b589fe56c8f" }'
|
||||||
- os: heavy
|
- os: heavy
|
||||||
conan_profile: gcc.ubsan
|
conan_profile: gcc.ubsan
|
||||||
build_type: Release
|
build_type: Release
|
||||||
static: false
|
static: false
|
||||||
container: '{ "image": "ghcr.io/xrplf/clio-ci:14342e087ceb8b593027198bf9ef06a43833c696" }'
|
container: '{ "image": "ghcr.io/xrplf/clio-ci:067449c3f8ae6755ea84752ea2962b589fe56c8f" }'
|
||||||
|
|
||||||
uses: ./.github/workflows/reusable-build-test.yml
|
uses: ./.github/workflows/reusable-build-test.yml
|
||||||
with:
|
with:
|
||||||
@@ -79,31 +67,9 @@ jobs:
|
|||||||
upload_clio_server: true
|
upload_clio_server: true
|
||||||
download_ccache: false
|
download_ccache: false
|
||||||
upload_ccache: false
|
upload_ccache: false
|
||||||
version: nightly-${{ needs.get_date.outputs.date }}
|
|
||||||
|
|
||||||
package:
|
|
||||||
name: Build debian package
|
|
||||||
needs: get_date
|
|
||||||
|
|
||||||
uses: ./.github/workflows/reusable-build.yml
|
|
||||||
with:
|
|
||||||
runs_on: heavy
|
|
||||||
container: '{ "image": "ghcr.io/xrplf/clio-ci:14342e087ceb8b593027198bf9ef06a43833c696" }'
|
|
||||||
conan_profile: gcc
|
|
||||||
build_type: Release
|
|
||||||
download_ccache: false
|
|
||||||
upload_ccache: false
|
|
||||||
code_coverage: false
|
|
||||||
static: true
|
|
||||||
upload_clio_server: false
|
|
||||||
package: true
|
|
||||||
version: nightly-${{ needs.get_date.outputs.date }}
|
|
||||||
targets: package
|
|
||||||
analyze_build_time: false
|
|
||||||
|
|
||||||
analyze_build_time:
|
analyze_build_time:
|
||||||
name: Analyze Build Time
|
name: Analyze Build Time
|
||||||
needs: get_date
|
|
||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
@@ -111,7 +77,7 @@ jobs:
|
|||||||
include:
|
include:
|
||||||
- os: heavy
|
- os: heavy
|
||||||
conan_profile: clang
|
conan_profile: clang
|
||||||
container: '{ "image": "ghcr.io/xrplf/clio-ci:14342e087ceb8b593027198bf9ef06a43833c696" }'
|
container: '{ "image": "ghcr.io/xrplf/clio-ci:067449c3f8ae6755ea84752ea2962b589fe56c8f" }'
|
||||||
static: true
|
static: true
|
||||||
- os: macos15
|
- os: macos15
|
||||||
conan_profile: apple-clang
|
conan_profile: apple-clang
|
||||||
@@ -130,10 +96,20 @@ jobs:
|
|||||||
upload_clio_server: false
|
upload_clio_server: false
|
||||||
targets: all
|
targets: all
|
||||||
analyze_build_time: true
|
analyze_build_time: true
|
||||||
version: nightly-${{ needs.get_date.outputs.date }}
|
|
||||||
|
get_date:
|
||||||
|
name: Get Date
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
date: ${{ steps.get_date.outputs.date }}
|
||||||
|
steps:
|
||||||
|
- name: Get current date
|
||||||
|
id: get_date
|
||||||
|
run: |
|
||||||
|
echo "date=$(date +'%Y%m%d')" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
nightly_release:
|
nightly_release:
|
||||||
needs: [build-and-test, package, get_date]
|
needs: [build-and-test, get_date]
|
||||||
uses: ./.github/workflows/reusable-release.yml
|
uses: ./.github/workflows/reusable-release.yml
|
||||||
with:
|
with:
|
||||||
delete_pattern: "nightly-*"
|
delete_pattern: "nightly-*"
|
||||||
@@ -169,7 +145,7 @@ jobs:
|
|||||||
issues: write
|
issues: write
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||||
|
|
||||||
- name: Create an issue
|
- name: Create an issue
|
||||||
uses: ./.github/actions/create-issue
|
uses: ./.github/actions/create-issue
|
||||||
|
|||||||
2
.github/workflows/pre-commit-autoupdate.yml
vendored
2
.github/workflows/pre-commit-autoupdate.yml
vendored
@@ -12,7 +12,7 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
auto-update:
|
auto-update:
|
||||||
uses: XRPLF/actions/.github/workflows/pre-commit-autoupdate.yml@8b19d3462e52cd8ea4d76b4c8d0f7533e7469c15
|
uses: XRPLF/actions/.github/workflows/pre-commit-autoupdate.yml@afbcbdafbe0ce5439492fb87eda6441371086386
|
||||||
with:
|
with:
|
||||||
sign_commit: true
|
sign_commit: true
|
||||||
committer: "Clio CI <skuznetsov@ripple.com>"
|
committer: "Clio CI <skuznetsov@ripple.com>"
|
||||||
|
|||||||
4
.github/workflows/pre-commit.yml
vendored
4
.github/workflows/pre-commit.yml
vendored
@@ -8,7 +8,7 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
run-hooks:
|
run-hooks:
|
||||||
uses: XRPLF/actions/.github/workflows/pre-commit.yml@320be44621ca2a080f05aeb15817c44b84518108
|
uses: XRPLF/actions/.github/workflows/pre-commit.yml@34790936fae4c6c751f62ec8c06696f9c1a5753a
|
||||||
with:
|
with:
|
||||||
runs_on: heavy
|
runs_on: heavy
|
||||||
container: '{ "image": "ghcr.io/xrplf/clio-pre-commit:14342e087ceb8b593027198bf9ef06a43833c696" }'
|
container: '{ "image": "ghcr.io/xrplf/clio-pre-commit:067449c3f8ae6755ea84752ea2962b589fe56c8f" }'
|
||||||
|
|||||||
25
.github/workflows/release.yml
vendored
25
.github/workflows/release.yml
vendored
@@ -29,7 +29,7 @@ jobs:
|
|||||||
conan_profile: gcc
|
conan_profile: gcc
|
||||||
build_type: Release
|
build_type: Release
|
||||||
static: true
|
static: true
|
||||||
container: '{ "image": "ghcr.io/xrplf/clio-ci:14342e087ceb8b593027198bf9ef06a43833c696" }'
|
container: '{ "image": "ghcr.io/xrplf/clio-ci:067449c3f8ae6755ea84752ea2962b589fe56c8f" }'
|
||||||
|
|
||||||
uses: ./.github/workflows/reusable-build-test.yml
|
uses: ./.github/workflows/reusable-build-test.yml
|
||||||
with:
|
with:
|
||||||
@@ -43,29 +43,10 @@ jobs:
|
|||||||
upload_clio_server: true
|
upload_clio_server: true
|
||||||
download_ccache: false
|
download_ccache: false
|
||||||
upload_ccache: false
|
upload_ccache: false
|
||||||
version: ${{ github.event_name == 'push' && github.ref_name || '' }}
|
expected_version: ${{ github.event_name == 'push' && github.ref_name || '' }}
|
||||||
|
|
||||||
package:
|
|
||||||
name: Build debian package
|
|
||||||
|
|
||||||
uses: ./.github/workflows/reusable-build.yml
|
|
||||||
with:
|
|
||||||
runs_on: heavy
|
|
||||||
container: '{ "image": "ghcr.io/xrplf/clio-ci:14342e087ceb8b593027198bf9ef06a43833c696" }'
|
|
||||||
conan_profile: gcc
|
|
||||||
build_type: Release
|
|
||||||
download_ccache: false
|
|
||||||
upload_ccache: false
|
|
||||||
code_coverage: false
|
|
||||||
static: true
|
|
||||||
upload_clio_server: false
|
|
||||||
package: true
|
|
||||||
version: ${{ github.event_name == 'push' && github.ref_name || '' }}
|
|
||||||
targets: package
|
|
||||||
analyze_build_time: false
|
|
||||||
|
|
||||||
release:
|
release:
|
||||||
needs: [build-and-test, package]
|
needs: build-and-test
|
||||||
uses: ./.github/workflows/reusable-release.yml
|
uses: ./.github/workflows/reusable-release.yml
|
||||||
with:
|
with:
|
||||||
delete_pattern: ""
|
delete_pattern: ""
|
||||||
|
|||||||
14
.github/workflows/reusable-build-test.yml
vendored
14
.github/workflows/reusable-build-test.yml
vendored
@@ -63,18 +63,18 @@ on:
|
|||||||
type: string
|
type: string
|
||||||
default: all
|
default: all
|
||||||
|
|
||||||
|
expected_version:
|
||||||
|
description: Expected version of the clio_server binary
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
|
default: ""
|
||||||
|
|
||||||
package:
|
package:
|
||||||
description: Whether to generate Debian package
|
description: Whether to generate Debian package
|
||||||
required: false
|
required: false
|
||||||
type: boolean
|
type: boolean
|
||||||
default: false
|
default: false
|
||||||
|
|
||||||
version:
|
|
||||||
description: Version of the clio_server binary
|
|
||||||
required: false
|
|
||||||
type: string
|
|
||||||
default: ""
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
uses: ./.github/workflows/reusable-build.yml
|
uses: ./.github/workflows/reusable-build.yml
|
||||||
@@ -90,8 +90,8 @@ jobs:
|
|||||||
upload_clio_server: ${{ inputs.upload_clio_server }}
|
upload_clio_server: ${{ inputs.upload_clio_server }}
|
||||||
targets: ${{ inputs.targets }}
|
targets: ${{ inputs.targets }}
|
||||||
analyze_build_time: false
|
analyze_build_time: false
|
||||||
|
expected_version: ${{ inputs.expected_version }}
|
||||||
package: ${{ inputs.package }}
|
package: ${{ inputs.package }}
|
||||||
version: ${{ inputs.version }}
|
|
||||||
|
|
||||||
test:
|
test:
|
||||||
needs: build
|
needs: build
|
||||||
|
|||||||
58
.github/workflows/reusable-build.yml
vendored
58
.github/workflows/reusable-build.yml
vendored
@@ -60,17 +60,17 @@ on:
|
|||||||
required: true
|
required: true
|
||||||
type: boolean
|
type: boolean
|
||||||
|
|
||||||
|
expected_version:
|
||||||
|
description: Expected version of the clio_server binary
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
|
default: ""
|
||||||
|
|
||||||
package:
|
package:
|
||||||
description: Whether to generate Debian package
|
description: Whether to generate Debian package
|
||||||
required: false
|
required: false
|
||||||
type: boolean
|
type: boolean
|
||||||
|
|
||||||
version:
|
|
||||||
description: Version of the clio_server binary
|
|
||||||
required: false
|
|
||||||
type: string
|
|
||||||
default: ""
|
|
||||||
|
|
||||||
secrets:
|
secrets:
|
||||||
CODECOV_TOKEN:
|
CODECOV_TOKEN:
|
||||||
required: false
|
required: false
|
||||||
@@ -88,16 +88,20 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Cleanup workspace
|
- name: Cleanup workspace
|
||||||
if: ${{ runner.os == 'macOS' }}
|
if: ${{ runner.os == 'macOS' }}
|
||||||
uses: XRPLF/actions/cleanup-workspace@cf0433aa74563aead044a1e395610c96d65a37cf
|
uses: XRPLF/actions/.github/actions/cleanup-workspace@ea9970b7c211b18f4c8bcdb28c29f5711752029f
|
||||||
|
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
# We need to fetch tags to have correct version in the release
|
||||||
|
# The workaround is based on https://github.com/actions/checkout/issues/1467
|
||||||
|
fetch-tags: true
|
||||||
|
ref: ${{ github.ref }}
|
||||||
|
|
||||||
- name: Prepare runner
|
- name: Prepare runner
|
||||||
uses: XRPLF/actions/prepare-runner@2cbf481018d930656e9276fcc20dc0e3a0be5b6d
|
uses: XRPLF/actions/.github/actions/prepare-runner@8abb0722cbff83a9a2dc7d06c473f7a4964b7382
|
||||||
with:
|
with:
|
||||||
enable_ccache: ${{ inputs.download_ccache }}
|
disable_ccache: ${{ !inputs.download_ccache }}
|
||||||
|
|
||||||
- name: Setup conan on macOS
|
- name: Setup conan on macOS
|
||||||
if: ${{ runner.os == 'macOS' }}
|
if: ${{ runner.os == 'macOS' }}
|
||||||
@@ -113,7 +117,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Restore ccache cache
|
- name: Restore ccache cache
|
||||||
if: ${{ inputs.download_ccache && github.ref != 'refs/heads/develop' }}
|
if: ${{ inputs.download_ccache && github.ref != 'refs/heads/develop' }}
|
||||||
uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
|
uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
|
||||||
with:
|
with:
|
||||||
path: ${{ env.CCACHE_DIR }}
|
path: ${{ env.CCACHE_DIR }}
|
||||||
key: ${{ steps.cache_key.outputs.key }}
|
key: ${{ steps.cache_key.outputs.key }}
|
||||||
@@ -135,7 +139,6 @@ jobs:
|
|||||||
static: ${{ inputs.static }}
|
static: ${{ inputs.static }}
|
||||||
time_trace: ${{ inputs.analyze_build_time }}
|
time_trace: ${{ inputs.analyze_build_time }}
|
||||||
package: ${{ inputs.package }}
|
package: ${{ inputs.package }}
|
||||||
version: ${{ inputs.version }}
|
|
||||||
|
|
||||||
- name: Build Clio
|
- name: Build Clio
|
||||||
uses: ./.github/actions/build-clio
|
uses: ./.github/actions/build-clio
|
||||||
@@ -151,7 +154,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Upload build time analyze report
|
- name: Upload build time analyze report
|
||||||
if: ${{ inputs.analyze_build_time }}
|
if: ${{ inputs.analyze_build_time }}
|
||||||
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
|
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||||
with:
|
with:
|
||||||
name: build_time_report_${{ runner.os }}_${{ inputs.build_type }}_${{ inputs.conan_profile }}
|
name: build_time_report_${{ runner.os }}_${{ inputs.build_type }}_${{ inputs.conan_profile }}
|
||||||
path: build_time_report.txt
|
path: build_time_report.txt
|
||||||
@@ -159,12 +162,12 @@ jobs:
|
|||||||
- name: Show ccache's statistics and zero it
|
- name: Show ccache's statistics and zero it
|
||||||
if: ${{ inputs.download_ccache }}
|
if: ${{ inputs.download_ccache }}
|
||||||
run: |
|
run: |
|
||||||
ccache --show-stats -vv
|
ccache --show-stats
|
||||||
ccache --zero-stats
|
ccache --zero-stats
|
||||||
|
|
||||||
- name: Save ccache cache
|
- name: Save ccache cache
|
||||||
if: ${{ inputs.upload_ccache && github.ref == 'refs/heads/develop' }}
|
if: ${{ inputs.upload_ccache && github.ref == 'refs/heads/develop' }}
|
||||||
uses: actions/cache/save@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
|
uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
|
||||||
with:
|
with:
|
||||||
path: ${{ env.CCACHE_DIR }}
|
path: ${{ env.CCACHE_DIR }}
|
||||||
key: ${{ steps.cache_key.outputs.key }}
|
key: ${{ steps.cache_key.outputs.key }}
|
||||||
@@ -179,28 +182,28 @@ jobs:
|
|||||||
|
|
||||||
- name: Upload clio_server
|
- name: Upload clio_server
|
||||||
if: ${{ inputs.upload_clio_server && !inputs.code_coverage && !inputs.analyze_build_time }}
|
if: ${{ inputs.upload_clio_server && !inputs.code_coverage && !inputs.analyze_build_time }}
|
||||||
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
|
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||||
with:
|
with:
|
||||||
name: clio_server_${{ runner.os }}_${{ inputs.build_type }}_${{ inputs.conan_profile }}
|
name: clio_server_${{ runner.os }}_${{ inputs.build_type }}_${{ inputs.conan_profile }}
|
||||||
path: build/clio_server
|
path: build/clio_server
|
||||||
|
|
||||||
- name: Upload clio_tests
|
- name: Upload clio_tests
|
||||||
if: ${{ !inputs.code_coverage && !inputs.analyze_build_time && !inputs.package }}
|
if: ${{ !inputs.code_coverage && !inputs.analyze_build_time && !inputs.package }}
|
||||||
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
|
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||||
with:
|
with:
|
||||||
name: clio_tests_${{ runner.os }}_${{ inputs.build_type }}_${{ inputs.conan_profile }}
|
name: clio_tests_${{ runner.os }}_${{ inputs.build_type }}_${{ inputs.conan_profile }}
|
||||||
path: build/clio_tests
|
path: build/clio_tests
|
||||||
|
|
||||||
- name: Upload clio_integration_tests
|
- name: Upload clio_integration_tests
|
||||||
if: ${{ !inputs.code_coverage && !inputs.analyze_build_time && !inputs.package }}
|
if: ${{ !inputs.code_coverage && !inputs.analyze_build_time && !inputs.package }}
|
||||||
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
|
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||||
with:
|
with:
|
||||||
name: clio_integration_tests_${{ runner.os }}_${{ inputs.build_type }}_${{ inputs.conan_profile }}
|
name: clio_integration_tests_${{ runner.os }}_${{ inputs.build_type }}_${{ inputs.conan_profile }}
|
||||||
path: build/clio_integration_tests
|
path: build/clio_integration_tests
|
||||||
|
|
||||||
- name: Upload Clio Linux package
|
- name: Upload Clio Linux package
|
||||||
if: ${{ inputs.package }}
|
if: ${{ inputs.package }}
|
||||||
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
|
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||||
with:
|
with:
|
||||||
name: clio_deb_package_${{ runner.os }}_${{ inputs.build_type }}_${{ inputs.conan_profile }}
|
name: clio_deb_package_${{ runner.os }}_${{ inputs.build_type }}_${{ inputs.conan_profile }}
|
||||||
path: build/*.deb
|
path: build/*.deb
|
||||||
@@ -215,20 +218,15 @@ jobs:
|
|||||||
if: ${{ inputs.code_coverage }}
|
if: ${{ inputs.code_coverage }}
|
||||||
uses: ./.github/actions/code-coverage
|
uses: ./.github/actions/code-coverage
|
||||||
|
|
||||||
- name: Verify version is expected
|
- name: Verify expected version
|
||||||
if: ${{ inputs.version != '' }}
|
if: ${{ inputs.expected_version != '' }}
|
||||||
env:
|
env:
|
||||||
INPUT_VERSION: ${{ inputs.version }}
|
INPUT_EXPECTED_VERSION: ${{ inputs.expected_version }}
|
||||||
BUILD_TYPE: ${{ inputs.build_type }}
|
|
||||||
run: |
|
run: |
|
||||||
set -e
|
set -e
|
||||||
EXPECTED_VERSION="clio-${INPUT_VERSION}"
|
EXPECTED_VERSION="clio-${INPUT_EXPECTED_VERSION}"
|
||||||
if [[ "${BUILD_TYPE}" == "Debug" ]]; then
|
actual_version=$(./build/clio_server --version)
|
||||||
EXPECTED_VERSION="${EXPECTED_VERSION}+DEBUG"
|
if [[ "$actual_version" != "$EXPECTED_VERSION" ]]; then
|
||||||
fi
|
|
||||||
|
|
||||||
actual_version=$(./build/clio_server --version | head -n 1)
|
|
||||||
if [[ "${actual_version}" != "${EXPECTED_VERSION}" ]]; then
|
|
||||||
echo "Expected version '${EXPECTED_VERSION}', but got '${actual_version}'"
|
echo "Expected version '${EXPECTED_VERSION}', but got '${actual_version}'"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|||||||
28
.github/workflows/reusable-release.yml
vendored
28
.github/workflows/reusable-release.yml
vendored
@@ -46,7 +46,7 @@ jobs:
|
|||||||
release:
|
release:
|
||||||
runs-on: heavy
|
runs-on: heavy
|
||||||
container:
|
container:
|
||||||
image: ghcr.io/xrplf/clio-ci:14342e087ceb8b593027198bf9ef06a43833c696
|
image: ghcr.io/xrplf/clio-ci:067449c3f8ae6755ea84752ea2962b589fe56c8f
|
||||||
env:
|
env:
|
||||||
GH_REPO: ${{ github.repository }}
|
GH_REPO: ${{ github.repository }}
|
||||||
GH_TOKEN: ${{ github.token }}
|
GH_TOKEN: ${{ github.token }}
|
||||||
@@ -55,28 +55,20 @@ jobs:
|
|||||||
contents: write
|
contents: write
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Prepare runner
|
- name: Prepare runner
|
||||||
uses: XRPLF/actions/prepare-runner@2cbf481018d930656e9276fcc20dc0e3a0be5b6d
|
uses: XRPLF/actions/.github/actions/prepare-runner@8abb0722cbff83a9a2dc7d06c473f7a4964b7382
|
||||||
with:
|
with:
|
||||||
enable_ccache: false
|
disable_ccache: true
|
||||||
|
|
||||||
- uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
|
- uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
|
||||||
with:
|
with:
|
||||||
path: release_artifacts
|
path: release_artifacts
|
||||||
pattern: clio_server_*
|
pattern: clio_server_*
|
||||||
|
|
||||||
- name: Prepare release artifacts
|
|
||||||
run: .github/scripts/prepare-release-artifacts.sh release_artifacts
|
|
||||||
|
|
||||||
- uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
|
|
||||||
with:
|
|
||||||
path: release_artifacts
|
|
||||||
pattern: clio_deb_package_*
|
|
||||||
|
|
||||||
- name: Create release notes
|
- name: Create release notes
|
||||||
env:
|
env:
|
||||||
RELEASE_HEADER: ${{ inputs.header }}
|
RELEASE_HEADER: ${{ inputs.header }}
|
||||||
@@ -91,10 +83,14 @@ jobs:
|
|||||||
LAST_TAG="$(gh release view --json tagName -q .tagName --repo XRPLF/clio)"
|
LAST_TAG="$(gh release view --json tagName -q .tagName --repo XRPLF/clio)"
|
||||||
LAST_TAG_COMMIT="$(git rev-parse $LAST_TAG)"
|
LAST_TAG_COMMIT="$(git rev-parse $LAST_TAG)"
|
||||||
BASE_COMMIT="$(git merge-base HEAD $LAST_TAG_COMMIT)"
|
BASE_COMMIT="$(git merge-base HEAD $LAST_TAG_COMMIT)"
|
||||||
git-cliff "${BASE_COMMIT}..HEAD" --ignore-tags "nightly|-b|-rc" >> "${RUNNER_TEMP}/release_notes.md"
|
git-cliff "${BASE_COMMIT}..HEAD" --ignore-tags "nightly|-b|-rc"
|
||||||
|
cat CHANGELOG.md >> "${RUNNER_TEMP}/release_notes.md"
|
||||||
|
|
||||||
|
- name: Prepare release artifacts
|
||||||
|
run: .github/scripts/prepare-release-artifacts.sh release_artifacts
|
||||||
|
|
||||||
- name: Upload release notes
|
- name: Upload release notes
|
||||||
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
|
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||||
with:
|
with:
|
||||||
name: release_notes_${{ inputs.version }}
|
name: release_notes_${{ inputs.version }}
|
||||||
path: "${RUNNER_TEMP}/release_notes.md"
|
path: "${RUNNER_TEMP}/release_notes.md"
|
||||||
@@ -126,4 +122,4 @@ jobs:
|
|||||||
--target "${GITHUB_SHA}" \
|
--target "${GITHUB_SHA}" \
|
||||||
${DRAFT_OPTION} \
|
${DRAFT_OPTION} \
|
||||||
--notes-file "${RUNNER_TEMP}/release_notes.md" \
|
--notes-file "${RUNNER_TEMP}/release_notes.md" \
|
||||||
./release_artifacts/clio_*
|
./release_artifacts/clio_server*
|
||||||
|
|||||||
68
.github/workflows/reusable-test.yml
vendored
68
.github/workflows/reusable-test.yml
vendored
@@ -45,29 +45,54 @@ jobs:
|
|||||||
|
|
||||||
if: ${{ inputs.run_unit_tests }}
|
if: ${{ inputs.run_unit_tests }}
|
||||||
|
|
||||||
|
env:
|
||||||
|
# TODO: remove completely when we have fixed all currently existing issues with sanitizers
|
||||||
|
SANITIZER_IGNORE_ERRORS: ${{ endsWith(inputs.conan_profile, '.tsan') }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Cleanup workspace
|
- name: Cleanup workspace
|
||||||
if: ${{ runner.os == 'macOS' }}
|
if: ${{ runner.os == 'macOS' }}
|
||||||
uses: XRPLF/actions/cleanup-workspace@cf0433aa74563aead044a1e395610c96d65a37cf
|
uses: XRPLF/actions/.github/actions/cleanup-workspace@ea9970b7c211b18f4c8bcdb28c29f5711752029f
|
||||||
|
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
|
- uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
|
||||||
with:
|
with:
|
||||||
name: clio_tests_${{ runner.os }}_${{ inputs.build_type }}_${{ inputs.conan_profile }}
|
name: clio_tests_${{ runner.os }}_${{ inputs.build_type }}_${{ inputs.conan_profile }}
|
||||||
|
|
||||||
- name: Make clio_tests executable
|
- name: Make clio_tests executable
|
||||||
run: chmod +x ./clio_tests
|
run: chmod +x ./clio_tests
|
||||||
|
|
||||||
- name: Run clio_tests
|
- name: Run clio_tests (regular)
|
||||||
continue-on-error: true
|
if: ${{ env.SANITIZER_IGNORE_ERRORS == 'false' }}
|
||||||
id: run_clio_tests
|
|
||||||
run: ./clio_tests
|
run: ./clio_tests
|
||||||
|
|
||||||
|
- name: Run clio_tests (sanitizer errors ignored)
|
||||||
|
if: ${{ env.SANITIZER_IGNORE_ERRORS == 'true' }}
|
||||||
|
run: ./.github/scripts/execute-tests-under-sanitizer.sh ./clio_tests
|
||||||
|
|
||||||
|
- name: Check for sanitizer report
|
||||||
|
if: ${{ env.SANITIZER_IGNORE_ERRORS == 'true' }}
|
||||||
|
id: check_report
|
||||||
|
run: |
|
||||||
|
if ls .sanitizer-report/* 1> /dev/null 2>&1; then
|
||||||
|
echo "found_report=true" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
echo "found_report=false" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Upload sanitizer report
|
||||||
|
if: ${{ env.SANITIZER_IGNORE_ERRORS == 'true' && steps.check_report.outputs.found_report == 'true' }}
|
||||||
|
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||||
|
with:
|
||||||
|
name: sanitizer_report_${{ runner.os }}_${{ inputs.build_type }}_${{ inputs.conan_profile }}
|
||||||
|
path: .sanitizer-report/*
|
||||||
|
include-hidden-files: true
|
||||||
|
|
||||||
- name: Create an issue
|
- name: Create an issue
|
||||||
if: ${{ steps.run_clio_tests.outcome == 'failure' && endsWith(inputs.conan_profile, 'san') }}
|
if: ${{ false && env.SANITIZER_IGNORE_ERRORS == 'true' && steps.check_report.outputs.found_report == 'true' }}
|
||||||
uses: ./.github/actions/create-issue
|
uses: ./.github/actions/create-issue
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ github.token }}
|
GH_TOKEN: ${{ github.token }}
|
||||||
@@ -75,13 +100,10 @@ jobs:
|
|||||||
labels: "bug"
|
labels: "bug"
|
||||||
title: "[${{ inputs.conan_profile }}] reported issues"
|
title: "[${{ inputs.conan_profile }}] reported issues"
|
||||||
body: >
|
body: >
|
||||||
Clio tests failed one or more sanitizer checks when built with `${{ inputs.conan_profile }}`.
|
Clio tests failed one or more sanitizer checks when built with ${{ inputs.conan_profile }}`.
|
||||||
|
|
||||||
Workflow: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/
|
Workflow: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/
|
||||||
|
Reports are available as artifacts.
|
||||||
- name: Fail the job if clio_tests failed
|
|
||||||
if: ${{ steps.run_clio_tests.outcome == 'failure' }}
|
|
||||||
run: exit 1
|
|
||||||
|
|
||||||
integration_tests:
|
integration_tests:
|
||||||
name: Integration testing
|
name: Integration testing
|
||||||
@@ -102,19 +124,13 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Cleanup workspace
|
- name: Cleanup workspace
|
||||||
if: ${{ runner.os == 'macOS' }}
|
if: ${{ runner.os == 'macOS' }}
|
||||||
uses: XRPLF/actions/cleanup-workspace@cf0433aa74563aead044a1e395610c96d65a37cf
|
uses: XRPLF/actions/.github/actions/cleanup-workspace@ea9970b7c211b18f4c8bcdb28c29f5711752029f
|
||||||
|
|
||||||
- name: Delete and start colima (macOS)
|
- name: Spin up scylladb
|
||||||
# This is a temporary workaround for colima issues on macOS runners
|
|
||||||
if: ${{ runner.os == 'macOS' }}
|
if: ${{ runner.os == 'macOS' }}
|
||||||
|
timeout-minutes: 3
|
||||||
run: |
|
run: |
|
||||||
colima delete --force
|
docker rm --force scylladb || true
|
||||||
colima start
|
|
||||||
|
|
||||||
- name: Spin up scylladb (macOS)
|
|
||||||
if: ${{ runner.os == 'macOS' }}
|
|
||||||
timeout-minutes: 1
|
|
||||||
run: |
|
|
||||||
docker run \
|
docker run \
|
||||||
--detach \
|
--detach \
|
||||||
--name scylladb \
|
--name scylladb \
|
||||||
@@ -126,15 +142,11 @@ jobs:
|
|||||||
--memory 16G \
|
--memory 16G \
|
||||||
scylladb/scylla
|
scylladb/scylla
|
||||||
|
|
||||||
- name: Wait for scylladb container to be healthy (macOS)
|
|
||||||
if: ${{ runner.os == 'macOS' }}
|
|
||||||
timeout-minutes: 1
|
|
||||||
run: |
|
|
||||||
until [ "$(docker inspect -f '{{.State.Health.Status}}' scylladb)" == "healthy" ]; do
|
until [ "$(docker inspect -f '{{.State.Health.Status}}' scylladb)" == "healthy" ]; do
|
||||||
sleep 1
|
sleep 5
|
||||||
done
|
done
|
||||||
|
|
||||||
- uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
|
- uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
|
||||||
with:
|
with:
|
||||||
name: clio_integration_tests_${{ runner.os }}_${{ inputs.build_type }}_${{ inputs.conan_profile }}
|
name: clio_integration_tests_${{ runner.os }}_${{ inputs.build_type }}_${{ inputs.conan_profile }}
|
||||||
|
|
||||||
|
|||||||
@@ -16,19 +16,19 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Download report artifact
|
- name: Download report artifact
|
||||||
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
|
uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
|
||||||
with:
|
with:
|
||||||
name: coverage-report.xml
|
name: coverage-report.xml
|
||||||
path: build
|
path: build
|
||||||
|
|
||||||
- name: Upload coverage report
|
- name: Upload coverage report
|
||||||
if: ${{ hashFiles('build/coverage_report.xml') != '' }}
|
if: ${{ hashFiles('build/coverage_report.xml') != '' }}
|
||||||
uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5.5.2
|
uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1
|
||||||
with:
|
with:
|
||||||
files: build/coverage_report.xml
|
files: build/coverage_report.xml
|
||||||
fail_ci_if_error: true
|
fail_ci_if_error: true
|
||||||
|
|||||||
3
.github/workflows/sanitizers.yml
vendored
3
.github/workflows/sanitizers.yml
vendored
@@ -15,6 +15,7 @@ on:
|
|||||||
- ".github/actions/**"
|
- ".github/actions/**"
|
||||||
- "!.github/actions/build-docker-image/**"
|
- "!.github/actions/build-docker-image/**"
|
||||||
- "!.github/actions/create-issue/**"
|
- "!.github/actions/create-issue/**"
|
||||||
|
- .github/scripts/execute-tests-under-sanitizer.sh
|
||||||
|
|
||||||
- CMakeLists.txt
|
- CMakeLists.txt
|
||||||
- conanfile.py
|
- conanfile.py
|
||||||
@@ -43,7 +44,7 @@ jobs:
|
|||||||
uses: ./.github/workflows/reusable-build-test.yml
|
uses: ./.github/workflows/reusable-build-test.yml
|
||||||
with:
|
with:
|
||||||
runs_on: heavy
|
runs_on: heavy
|
||||||
container: '{ "image": "ghcr.io/xrplf/clio-ci:14342e087ceb8b593027198bf9ef06a43833c696" }'
|
container: '{ "image": "ghcr.io/xrplf/clio-ci:067449c3f8ae6755ea84752ea2962b589fe56c8f" }'
|
||||||
download_ccache: false
|
download_ccache: false
|
||||||
upload_ccache: false
|
upload_ccache: false
|
||||||
conan_profile: ${{ matrix.compiler }}${{ matrix.sanitizer_ext }}
|
conan_profile: ${{ matrix.compiler }}${{ matrix.sanitizer_ext }}
|
||||||
|
|||||||
42
.github/workflows/update-docker-ci.yml
vendored
42
.github/workflows/update-docker-ci.yml
vendored
@@ -56,11 +56,11 @@ jobs:
|
|||||||
needs: repo
|
needs: repo
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||||
|
|
||||||
- name: Get changed files
|
- name: Get changed files
|
||||||
id: changed-files
|
id: changed-files
|
||||||
uses: tj-actions/changed-files@e0021407031f5be11a464abee9a0776171c79891 # v47.0.1
|
uses: tj-actions/changed-files@24d32ffd492484c1d75e0c0b894501ddb9d30d62 # v47.0.0
|
||||||
with:
|
with:
|
||||||
files: "docker/compilers/gcc/**"
|
files: "docker/compilers/gcc/**"
|
||||||
|
|
||||||
@@ -94,11 +94,11 @@ jobs:
|
|||||||
needs: repo
|
needs: repo
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||||
|
|
||||||
- name: Get changed files
|
- name: Get changed files
|
||||||
id: changed-files
|
id: changed-files
|
||||||
uses: tj-actions/changed-files@e0021407031f5be11a464abee9a0776171c79891 # v47.0.1
|
uses: tj-actions/changed-files@ed68ef82c095e0d48ec87eccea555d944a631a4c # v46.0.5
|
||||||
with:
|
with:
|
||||||
files: "docker/compilers/gcc/**"
|
files: "docker/compilers/gcc/**"
|
||||||
|
|
||||||
@@ -132,20 +132,20 @@ jobs:
|
|||||||
needs: [repo, gcc-amd64, gcc-arm64]
|
needs: [repo, gcc-amd64, gcc-arm64]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||||
|
|
||||||
- name: Get changed files
|
- name: Get changed files
|
||||||
id: changed-files
|
id: changed-files
|
||||||
uses: tj-actions/changed-files@e0021407031f5be11a464abee9a0776171c79891 # v47.0.1
|
uses: tj-actions/changed-files@24d32ffd492484c1d75e0c0b894501ddb9d30d62 # v47.0.0
|
||||||
with:
|
with:
|
||||||
files: "docker/compilers/gcc/**"
|
files: "docker/compilers/gcc/**"
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
|
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
|
||||||
|
|
||||||
- name: Login to GitHub Container Registry
|
- name: Login to GitHub Container Registry
|
||||||
if: ${{ github.event_name != 'pull_request' }}
|
if: ${{ github.event_name != 'pull_request' }}
|
||||||
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
|
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.repository_owner }}
|
username: ${{ github.repository_owner }}
|
||||||
@@ -153,7 +153,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Login to DockerHub
|
- name: Login to DockerHub
|
||||||
if: ${{ github.repository_owner == 'XRPLF' && github.event_name != 'pull_request' }}
|
if: ${{ github.repository_owner == 'XRPLF' && github.event_name != 'pull_request' }}
|
||||||
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
|
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKERHUB_USER }}
|
username: ${{ secrets.DOCKERHUB_USER }}
|
||||||
password: ${{ secrets.DOCKERHUB_PW }}
|
password: ${{ secrets.DOCKERHUB_PW }}
|
||||||
@@ -183,11 +183,11 @@ jobs:
|
|||||||
needs: repo
|
needs: repo
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||||
|
|
||||||
- name: Get changed files
|
- name: Get changed files
|
||||||
id: changed-files
|
id: changed-files
|
||||||
uses: tj-actions/changed-files@e0021407031f5be11a464abee9a0776171c79891 # v47.0.1
|
uses: tj-actions/changed-files@24d32ffd492484c1d75e0c0b894501ddb9d30d62 # v47.0.0
|
||||||
with:
|
with:
|
||||||
files: "docker/compilers/clang/**"
|
files: "docker/compilers/clang/**"
|
||||||
|
|
||||||
@@ -219,11 +219,11 @@ jobs:
|
|||||||
needs: [repo, gcc-merge]
|
needs: [repo, gcc-merge]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||||
|
|
||||||
- name: Get changed files
|
- name: Get changed files
|
||||||
id: changed-files
|
id: changed-files
|
||||||
uses: tj-actions/changed-files@e0021407031f5be11a464abee9a0776171c79891 # v47.0.1
|
uses: tj-actions/changed-files@24d32ffd492484c1d75e0c0b894501ddb9d30d62 # v47.0.0
|
||||||
with:
|
with:
|
||||||
files: "docker/tools/**"
|
files: "docker/tools/**"
|
||||||
|
|
||||||
@@ -250,11 +250,11 @@ jobs:
|
|||||||
needs: [repo, gcc-merge]
|
needs: [repo, gcc-merge]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||||
|
|
||||||
- name: Get changed files
|
- name: Get changed files
|
||||||
id: changed-files
|
id: changed-files
|
||||||
uses: tj-actions/changed-files@e0021407031f5be11a464abee9a0776171c79891 # v47.0.1
|
uses: tj-actions/changed-files@ed68ef82c095e0d48ec87eccea555d944a631a4c # v46.0.5
|
||||||
with:
|
with:
|
||||||
files: "docker/tools/**"
|
files: "docker/tools/**"
|
||||||
|
|
||||||
@@ -281,20 +281,20 @@ jobs:
|
|||||||
needs: [repo, tools-amd64, tools-arm64]
|
needs: [repo, tools-amd64, tools-arm64]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||||
|
|
||||||
- name: Get changed files
|
- name: Get changed files
|
||||||
id: changed-files
|
id: changed-files
|
||||||
uses: tj-actions/changed-files@e0021407031f5be11a464abee9a0776171c79891 # v47.0.1
|
uses: tj-actions/changed-files@24d32ffd492484c1d75e0c0b894501ddb9d30d62 # v47.0.0
|
||||||
with:
|
with:
|
||||||
files: "docker/tools/**"
|
files: "docker/tools/**"
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
|
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
|
||||||
|
|
||||||
- name: Login to GitHub Container Registry
|
- name: Login to GitHub Container Registry
|
||||||
if: ${{ github.event_name != 'pull_request' }}
|
if: ${{ github.event_name != 'pull_request' }}
|
||||||
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
|
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.repository_owner }}
|
username: ${{ github.repository_owner }}
|
||||||
@@ -316,7 +316,7 @@ jobs:
|
|||||||
needs: [repo, tools-merge]
|
needs: [repo, tools-merge]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||||
- uses: ./.github/actions/build-docker-image
|
- uses: ./.github/actions/build-docker-image
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
@@ -338,7 +338,7 @@ jobs:
|
|||||||
needs: [repo, gcc-merge, clang, tools-merge]
|
needs: [repo, gcc-merge, clang, tools-merge]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||||
- uses: ./.github/actions/build-docker-image
|
- uses: ./.github/actions/build-docker-image
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|||||||
10
.github/workflows/upload-conan-deps.yml
vendored
10
.github/workflows/upload-conan-deps.yml
vendored
@@ -22,7 +22,6 @@ on:
|
|||||||
|
|
||||||
- .github/actions/conan/action.yml
|
- .github/actions/conan/action.yml
|
||||||
- ".github/scripts/conan/**"
|
- ".github/scripts/conan/**"
|
||||||
- "!.github/scripts/conan/regenerate_lockfile.sh"
|
|
||||||
|
|
||||||
- conanfile.py
|
- conanfile.py
|
||||||
- conan.lock
|
- conan.lock
|
||||||
@@ -33,7 +32,6 @@ on:
|
|||||||
|
|
||||||
- .github/actions/conan/action.yml
|
- .github/actions/conan/action.yml
|
||||||
- ".github/scripts/conan/**"
|
- ".github/scripts/conan/**"
|
||||||
- "!.github/scripts/conan/regenerate_lockfile.sh"
|
|
||||||
|
|
||||||
- conanfile.py
|
- conanfile.py
|
||||||
- conan.lock
|
- conan.lock
|
||||||
@@ -52,7 +50,7 @@ jobs:
|
|||||||
outputs:
|
outputs:
|
||||||
matrix: ${{ steps.set-matrix.outputs.matrix }}
|
matrix: ${{ steps.set-matrix.outputs.matrix }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||||
|
|
||||||
- name: Calculate conan matrix
|
- name: Calculate conan matrix
|
||||||
id: set-matrix
|
id: set-matrix
|
||||||
@@ -75,12 +73,12 @@ jobs:
|
|||||||
CONAN_PROFILE: ${{ matrix.compiler }}${{ matrix.sanitizer_ext }}
|
CONAN_PROFILE: ${{ matrix.compiler }}${{ matrix.sanitizer_ext }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||||
|
|
||||||
- name: Prepare runner
|
- name: Prepare runner
|
||||||
uses: XRPLF/actions/prepare-runner@2cbf481018d930656e9276fcc20dc0e3a0be5b6d
|
uses: XRPLF/actions/.github/actions/prepare-runner@8abb0722cbff83a9a2dc7d06c473f7a4964b7382
|
||||||
with:
|
with:
|
||||||
enable_ccache: false
|
disable_ccache: true
|
||||||
|
|
||||||
- name: Setup conan on macOS
|
- name: Setup conan on macOS
|
||||||
if: ${{ runner.os == 'macOS' }}
|
if: ${{ runner.os == 'macOS' }}
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,7 +4,6 @@
|
|||||||
.build
|
.build
|
||||||
.cache
|
.cache
|
||||||
.vscode
|
.vscode
|
||||||
.zed
|
|
||||||
.python-version
|
.python-version
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.sanitizer-report
|
.sanitizer-report
|
||||||
|
|||||||
@@ -29,12 +29,12 @@ repos:
|
|||||||
|
|
||||||
# Autoformat: YAML, JSON, Markdown, etc.
|
# Autoformat: YAML, JSON, Markdown, etc.
|
||||||
- repo: https://github.com/rbubley/mirrors-prettier
|
- repo: https://github.com/rbubley/mirrors-prettier
|
||||||
rev: c2bc67fe8f8f549cc489e00ba8b45aa18ee713b1 # frozen: v3.8.1
|
rev: 3c603eae8faac85303ae675fd33325cff699a797 # frozen: v3.7.3
|
||||||
hooks:
|
hooks:
|
||||||
- id: prettier
|
- id: prettier
|
||||||
|
|
||||||
- repo: https://github.com/igorshubovych/markdownlint-cli
|
- repo: https://github.com/igorshubovych/markdownlint-cli
|
||||||
rev: 76b3d32d3f4b965e1d6425253c59407420ae2c43 # frozen: v0.47.0
|
rev: c8fd5003603dd6f12447314ecd935ba87c09aff5 # frozen: v0.46.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: markdownlint-fix
|
- id: markdownlint-fix
|
||||||
exclude: LICENSE.md
|
exclude: LICENSE.md
|
||||||
@@ -59,7 +59,7 @@ repos:
|
|||||||
]
|
]
|
||||||
|
|
||||||
- repo: https://github.com/psf/black-pre-commit-mirror
|
- repo: https://github.com/psf/black-pre-commit-mirror
|
||||||
rev: ea488cebbfd88a5f50b8bd95d5c829d0bb76feb8 # frozen: 26.1.0
|
rev: 2892f1f81088477370d4fbc56545c05d33d2493f # frozen: 25.11.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: black
|
- id: black
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ repos:
|
|||||||
language: script
|
language: script
|
||||||
|
|
||||||
- repo: https://github.com/pre-commit/mirrors-clang-format
|
- repo: https://github.com/pre-commit/mirrors-clang-format
|
||||||
rev: 75ca4ad908dc4a99f57921f29b7e6c1521e10b26 # frozen: v21.1.8
|
rev: 4c26f99731e7c22a047c35224150ee9e43d7c03e # frozen: v21.1.6
|
||||||
hooks:
|
hooks:
|
||||||
- id: clang-format
|
- id: clang-format
|
||||||
args: [--style=file]
|
args: [--style=file]
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
cmake_minimum_required(VERSION 3.20)
|
cmake_minimum_required(VERSION 3.20)
|
||||||
|
|
||||||
project(clio VERSION ${CLIO_VERSION} HOMEPAGE_URL "https://github.com/XRPLF/clio"
|
project(clio VERSION ${CLIO_VERSION} HOMEPAGE_URL "https://github.com/XRPLF/clio"
|
||||||
DESCRIPTION "An XRP Ledger API Server")
|
DESCRIPTION "An XRP Ledger API Server"
|
||||||
|
)
|
||||||
|
|
||||||
# =========================== Options ====================================== #
|
# =========================== Options ====================================== #
|
||||||
option(verbose "Verbose build" FALSE)
|
option(verbose "Verbose build" FALSE)
|
||||||
@@ -35,7 +36,7 @@ target_compile_features(clio_options INTERFACE cxx_std_23) # Clio needs c++23 bu
|
|||||||
target_include_directories(clio_options INTERFACE ${CMAKE_SOURCE_DIR}/src)
|
target_include_directories(clio_options INTERFACE ${CMAKE_SOURCE_DIR}/src)
|
||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
set(CMAKE_VERBOSE_MAKEFILE TRUE)
|
set(CMAKE_VERBOSE_MAKEFILE TRUE)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
# Clio tweaks and checks
|
# Clio tweaks and checks
|
||||||
@@ -57,36 +58,36 @@ add_subdirectory(src)
|
|||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
|
|
||||||
if (benchmark)
|
if (benchmark)
|
||||||
add_subdirectory(benchmarks)
|
add_subdirectory(benchmarks)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
# Enable selected sanitizer if enabled via `san`
|
# Enable selected sanitizer if enabled via `san`
|
||||||
if (san)
|
if (san)
|
||||||
set(SUPPORTED_SANITIZERS "address" "thread" "memory" "undefined")
|
set(SUPPORTED_SANITIZERS "address" "thread" "memory" "undefined")
|
||||||
if (NOT san IN_LIST SUPPORTED_SANITIZERS)
|
if (NOT san IN_LIST SUPPORTED_SANITIZERS)
|
||||||
message(FATAL_ERROR "Error: Unsupported sanitizer '${san}'. Supported values are: ${SUPPORTED_SANITIZERS}.")
|
message(FATAL_ERROR "Error: Unsupported sanitizer '${san}'. Supported values are: ${SUPPORTED_SANITIZERS}.")
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
# Sanitizers recommend minimum of -O1 for reasonable performance so we enable it for debug builds
|
# Sanitizers recommend minimum of -O1 for reasonable performance so we enable it for debug builds
|
||||||
set(SAN_OPTIMIZATION_FLAG "")
|
set(SAN_OPTIMIZATION_FLAG "")
|
||||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||||
set(SAN_OPTIMIZATION_FLAG -O1)
|
set(SAN_OPTIMIZATION_FLAG -O1)
|
||||||
endif ()
|
endif ()
|
||||||
target_compile_options(clio_options INTERFACE ${SAN_OPTIMIZATION_FLAG} ${SAN_FLAG} -fno-omit-frame-pointer)
|
target_compile_options(clio_options INTERFACE ${SAN_OPTIMIZATION_FLAG} ${SAN_FLAG} -fno-omit-frame-pointer)
|
||||||
|
|
||||||
target_link_libraries(clio_options INTERFACE ${SAN_FLAG} ${SAN_LIB})
|
target_link_libraries(clio_options INTERFACE ${SAN_FLAG} ${SAN_LIB})
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
# Generate `docs` target for doxygen documentation if enabled Note: use `make docs` to generate the documentation
|
# Generate `docs` target for doxygen documentation if enabled Note: use `make docs` to generate the documentation
|
||||||
if (docs)
|
if (docs)
|
||||||
add_subdirectory(docs)
|
add_subdirectory(docs)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
include(install/install)
|
include(install/install)
|
||||||
if (package)
|
if (package)
|
||||||
include(ClioPackage)
|
include(ClioPackage)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (snapshot)
|
if (snapshot)
|
||||||
add_subdirectory(tools/snapshot)
|
add_subdirectory(tools/snapshot)
|
||||||
endif ()
|
endif ()
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
add_executable(clio_benchmark)
|
add_executable(clio_benchmark)
|
||||||
|
|
||||||
target_sources(clio_benchmark
|
target_sources(
|
||||||
PRIVATE # Common
|
clio_benchmark
|
||||||
Main.cpp
|
PRIVATE # Common
|
||||||
Playground.cpp
|
Main.cpp
|
||||||
# ExecutionContext
|
Playground.cpp
|
||||||
util/async/ExecutionContextBenchmarks.cpp
|
# ExecutionContext
|
||||||
# Logger
|
util/async/ExecutionContextBenchmarks.cpp
|
||||||
util/log/LoggerBenchmark.cpp
|
# Logger
|
||||||
# WorkQueue
|
util/log/LoggerBenchmark.cpp
|
||||||
rpc/WorkQueueBenchmarks.cpp)
|
)
|
||||||
|
|
||||||
include(deps/gbench)
|
include(deps/gbench)
|
||||||
|
|
||||||
target_include_directories(clio_benchmark PRIVATE .)
|
target_include_directories(clio_benchmark PRIVATE .)
|
||||||
target_link_libraries(clio_benchmark PRIVATE clio_rpc clio_util benchmark::benchmark_main spdlog::spdlog)
|
target_link_libraries(clio_benchmark PUBLIC clio_util benchmark::benchmark_main spdlog::spdlog)
|
||||||
set_target_properties(clio_benchmark PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
|
set_target_properties(clio_benchmark PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||||
|
|||||||
@@ -1,145 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
/*
|
|
||||||
This file is part of clio: https://github.com/XRPLF/clio
|
|
||||||
Copyright (c) 2025, the clio developers.
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
//==============================================================================
|
|
||||||
|
|
||||||
#include "rpc/WorkQueue.hpp"
|
|
||||||
#include "util/Assert.hpp"
|
|
||||||
#include "util/config/Array.hpp"
|
|
||||||
#include "util/config/ConfigConstraints.hpp"
|
|
||||||
#include "util/config/ConfigDefinition.hpp"
|
|
||||||
#include "util/config/ConfigValue.hpp"
|
|
||||||
#include "util/config/Types.hpp"
|
|
||||||
#include "util/log/Logger.hpp"
|
|
||||||
#include "util/prometheus/Prometheus.hpp"
|
|
||||||
|
|
||||||
#include <benchmark/benchmark.h>
|
|
||||||
#include <boost/asio/steady_timer.hpp>
|
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <atomic>
|
|
||||||
#include <cassert>
|
|
||||||
#include <chrono>
|
|
||||||
#include <cstddef>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <mutex>
|
|
||||||
#include <thread>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
using namespace rpc;
|
|
||||||
using namespace util::config;
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
auto const kCONFIG = ClioConfigDefinition{
|
|
||||||
{"prometheus.compress_reply", ConfigValue{ConfigType::Boolean}.defaultValue(true)},
|
|
||||||
{"prometheus.enabled", ConfigValue{ConfigType::Boolean}.defaultValue(true)},
|
|
||||||
{"log.channels.[].channel", Array{ConfigValue{ConfigType::String}}},
|
|
||||||
{"log.channels.[].level", Array{ConfigValue{ConfigType::String}}},
|
|
||||||
{"log.level", ConfigValue{ConfigType::String}.defaultValue("info")},
|
|
||||||
{"log.format", ConfigValue{ConfigType::String}.defaultValue(R"(%Y-%m-%d %H:%M:%S.%f %^%3!l:%n%$ - %v)")},
|
|
||||||
{"log.is_async", ConfigValue{ConfigType::Boolean}.defaultValue(false)},
|
|
||||||
{"log.enable_console", ConfigValue{ConfigType::Boolean}.defaultValue(false)},
|
|
||||||
{"log.directory", ConfigValue{ConfigType::String}.optional()},
|
|
||||||
{"log.rotation_size", ConfigValue{ConfigType::Integer}.defaultValue(2048).withConstraint(gValidateUint32)},
|
|
||||||
{"log.directory_max_files", ConfigValue{ConfigType::Integer}.defaultValue(25).withConstraint(gValidateUint32)},
|
|
||||||
{"log.tag_style", ConfigValue{ConfigType::String}.defaultValue("none")},
|
|
||||||
};
|
|
||||||
|
|
||||||
// this should be a fixture but it did not work with Args very well
|
|
||||||
void
|
|
||||||
init()
|
|
||||||
{
|
|
||||||
static std::once_flag kONCE;
|
|
||||||
std::call_once(kONCE, [] {
|
|
||||||
PrometheusService::init(kCONFIG);
|
|
||||||
(void)util::LogService::init(kCONFIG);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
static void
|
|
||||||
benchmarkWorkQueue(benchmark::State& state)
|
|
||||||
{
|
|
||||||
init();
|
|
||||||
|
|
||||||
auto const wqThreads = static_cast<uint32_t>(state.range(0));
|
|
||||||
auto const maxQueueSize = static_cast<uint32_t>(state.range(1));
|
|
||||||
auto const clientThreads = static_cast<uint32_t>(state.range(2));
|
|
||||||
auto const itemsPerClient = static_cast<uint32_t>(state.range(3));
|
|
||||||
auto const clientProcessingMs = static_cast<uint32_t>(state.range(4));
|
|
||||||
|
|
||||||
for (auto _ : state) {
|
|
||||||
std::atomic_size_t totalExecuted = 0uz;
|
|
||||||
std::atomic_size_t totalQueued = 0uz;
|
|
||||||
|
|
||||||
state.PauseTiming();
|
|
||||||
WorkQueue queue(wqThreads, maxQueueSize);
|
|
||||||
state.ResumeTiming();
|
|
||||||
|
|
||||||
std::vector<std::thread> threads;
|
|
||||||
threads.reserve(clientThreads);
|
|
||||||
|
|
||||||
for (auto t = 0uz; t < clientThreads; ++t) {
|
|
||||||
threads.emplace_back([&] {
|
|
||||||
for (auto i = 0uz; i < itemsPerClient; ++i) {
|
|
||||||
totalQueued += static_cast<std::size_t>(queue.postCoro(
|
|
||||||
[&clientProcessingMs, &totalExecuted](auto yield) {
|
|
||||||
++totalExecuted;
|
|
||||||
|
|
||||||
boost::asio::steady_timer timer(
|
|
||||||
yield.get_executor(), std::chrono::milliseconds{clientProcessingMs}
|
|
||||||
);
|
|
||||||
timer.async_wait(yield);
|
|
||||||
|
|
||||||
std::this_thread::sleep_for(std::chrono::microseconds{10});
|
|
||||||
},
|
|
||||||
/* isWhiteListed = */ false
|
|
||||||
));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto& t : threads)
|
|
||||||
t.join();
|
|
||||||
|
|
||||||
queue.stop();
|
|
||||||
|
|
||||||
ASSERT(totalExecuted == totalQueued, "Totals don't match");
|
|
||||||
ASSERT(totalQueued <= itemsPerClient * clientThreads, "Queued more than requested");
|
|
||||||
|
|
||||||
if (maxQueueSize == 0) {
|
|
||||||
ASSERT(totalQueued == itemsPerClient * clientThreads, "Queued exactly the expected amount");
|
|
||||||
} else {
|
|
||||||
ASSERT(totalQueued >= std::min(maxQueueSize, itemsPerClient * clientThreads), "Queued less than expected");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Usage example:
|
|
||||||
/*
|
|
||||||
./clio_benchmark \
|
|
||||||
--benchmark_repetitions=10 \
|
|
||||||
--benchmark_display_aggregates_only=true \
|
|
||||||
--benchmark_min_time=1x \
|
|
||||||
--benchmark_filter="WorkQueue"
|
|
||||||
*/
|
|
||||||
// TODO: figure out what happens on 1 thread
|
|
||||||
BENCHMARK(benchmarkWorkQueue)
|
|
||||||
->ArgsProduct({{2, 4, 8, 16}, {0, 5'000}, {4, 8, 16}, {1'000, 10'000}, {10, 100, 250}})
|
|
||||||
->Unit(benchmark::kMillisecond);
|
|
||||||
@@ -49,6 +49,8 @@ postprocessors = [
|
|||||||
]
|
]
|
||||||
# render body even when there are no releases to process
|
# render body even when there are no releases to process
|
||||||
# render_always = true
|
# render_always = true
|
||||||
|
# output file path
|
||||||
|
output = "CHANGELOG.md"
|
||||||
|
|
||||||
[git]
|
[git]
|
||||||
# parse the commits based on https://www.conventionalcommits.org
|
# parse the commits based on https://www.conventionalcommits.org
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
find_program(CCACHE_PATH "ccache")
|
find_program(CCACHE_PATH "ccache")
|
||||||
if (CCACHE_PATH)
|
if (CCACHE_PATH)
|
||||||
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PATH}")
|
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PATH}")
|
||||||
message(STATUS "Using ccache: ${CCACHE_PATH}")
|
message(STATUS "Using ccache: ${CCACHE_PATH}")
|
||||||
endif ()
|
endif ()
|
||||||
|
|||||||
@@ -1,42 +1,42 @@
|
|||||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||||
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16)
|
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16)
|
||||||
message(FATAL_ERROR "Clang 16+ required for building clio")
|
message(FATAL_ERROR "Clang 16+ required for building clio")
|
||||||
endif ()
|
endif ()
|
||||||
set(is_clang TRUE)
|
set(is_clang TRUE)
|
||||||
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
|
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
|
||||||
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15)
|
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15)
|
||||||
message(FATAL_ERROR "AppleClang 15+ required for building clio")
|
message(FATAL_ERROR "AppleClang 15+ required for building clio")
|
||||||
endif ()
|
endif ()
|
||||||
set(is_appleclang TRUE)
|
set(is_appleclang TRUE)
|
||||||
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||||
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12)
|
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12)
|
||||||
message(FATAL_ERROR "GCC 12+ required for building clio")
|
message(FATAL_ERROR "GCC 12+ required for building clio")
|
||||||
endif ()
|
endif ()
|
||||||
set(is_gcc TRUE)
|
set(is_gcc TRUE)
|
||||||
else ()
|
else ()
|
||||||
message(FATAL_ERROR "Supported compilers: AppleClang 15+, Clang 16+, GCC 12+")
|
message(FATAL_ERROR "Supported compilers: AppleClang 15+, Clang 16+, GCC 12+")
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (san)
|
if (san)
|
||||||
string(TOLOWER ${san} san)
|
string(TOLOWER ${san} san)
|
||||||
set(SAN_FLAG "-fsanitize=${san}")
|
set(SAN_FLAG "-fsanitize=${san}")
|
||||||
set(SAN_LIB "")
|
set(SAN_LIB "")
|
||||||
if (is_gcc)
|
if (is_gcc)
|
||||||
if (san STREQUAL "address")
|
if (san STREQUAL "address")
|
||||||
set(SAN_LIB "asan")
|
set(SAN_LIB "asan")
|
||||||
elseif (san STREQUAL "thread")
|
elseif (san STREQUAL "thread")
|
||||||
set(SAN_LIB "tsan")
|
set(SAN_LIB "tsan")
|
||||||
elseif (san STREQUAL "memory")
|
elseif (san STREQUAL "memory")
|
||||||
set(SAN_LIB "msan")
|
set(SAN_LIB "msan")
|
||||||
elseif (san STREQUAL "undefined")
|
elseif (san STREQUAL "undefined")
|
||||||
set(SAN_LIB "ubsan")
|
set(SAN_LIB "ubsan")
|
||||||
endif ()
|
|
||||||
endif ()
|
|
||||||
set(_saved_CRL ${CMAKE_REQUIRED_LIBRARIES})
|
|
||||||
set(CMAKE_REQUIRED_LIBRARIES "${SAN_FLAG};${SAN_LIB}")
|
|
||||||
check_cxx_compiler_flag(${SAN_FLAG} COMPILER_SUPPORTS_SAN)
|
|
||||||
set(CMAKE_REQUIRED_LIBRARIES ${_saved_CRL})
|
|
||||||
if (NOT COMPILER_SUPPORTS_SAN)
|
|
||||||
message(FATAL_ERROR "${san} sanitizer does not seem to be supported by your compiler")
|
|
||||||
endif ()
|
endif ()
|
||||||
|
endif ()
|
||||||
|
set(_saved_CRL ${CMAKE_REQUIRED_LIBRARIES})
|
||||||
|
set(CMAKE_REQUIRED_LIBRARIES "${SAN_FLAG};${SAN_LIB}")
|
||||||
|
check_cxx_compiler_flag(${SAN_FLAG} COMPILER_SUPPORTS_SAN)
|
||||||
|
set(CMAKE_REQUIRED_LIBRARIES ${_saved_CRL})
|
||||||
|
if (NOT COMPILER_SUPPORTS_SAN)
|
||||||
|
message(FATAL_ERROR "${san} sanitizer does not seem to be supported by your compiler")
|
||||||
|
endif ()
|
||||||
endif ()
|
endif ()
|
||||||
|
|||||||
@@ -1,30 +1,33 @@
|
|||||||
if (lint)
|
if (lint)
|
||||||
|
|
||||||
# Find clang-tidy binary
|
# Find clang-tidy binary
|
||||||
if (DEFINED ENV{CLIO_CLANG_TIDY_BIN})
|
if (DEFINED ENV{CLIO_CLANG_TIDY_BIN})
|
||||||
set(_CLANG_TIDY_BIN $ENV{CLIO_CLANG_TIDY_BIN})
|
set(_CLANG_TIDY_BIN $ENV{CLIO_CLANG_TIDY_BIN})
|
||||||
if ((NOT EXISTS ${_CLANG_TIDY_BIN}) OR IS_DIRECTORY ${_CLANG_TIDY_BIN})
|
if ((NOT EXISTS ${_CLANG_TIDY_BIN}) OR IS_DIRECTORY ${_CLANG_TIDY_BIN})
|
||||||
message(FATAL_ERROR "$ENV{CLIO_CLANG_TIDY_BIN} no such file. Check CLIO_CLANG_TIDY_BIN env variable")
|
message(FATAL_ERROR "$ENV{CLIO_CLANG_TIDY_BIN} no such file. Check CLIO_CLANG_TIDY_BIN env variable")
|
||||||
endif ()
|
|
||||||
message(STATUS "Using clang-tidy from CLIO_CLANG_TIDY_BIN")
|
|
||||||
else ()
|
|
||||||
find_program(_CLANG_TIDY_BIN NAMES "clang-tidy-20" "clang-tidy" REQUIRED)
|
|
||||||
endif ()
|
endif ()
|
||||||
|
message(STATUS "Using clang-tidy from CLIO_CLANG_TIDY_BIN")
|
||||||
|
else ()
|
||||||
|
find_program(_CLANG_TIDY_BIN NAMES "clang-tidy-20" "clang-tidy" REQUIRED)
|
||||||
|
endif ()
|
||||||
|
|
||||||
if (NOT _CLANG_TIDY_BIN)
|
if (NOT _CLANG_TIDY_BIN)
|
||||||
message(FATAL_ERROR "clang-tidy binary not found. Please set the CLIO_CLANG_TIDY_BIN environment variable or install clang-tidy."
|
message(
|
||||||
)
|
FATAL_ERROR
|
||||||
endif ()
|
"clang-tidy binary not found. Please set the CLIO_CLANG_TIDY_BIN environment variable or install clang-tidy."
|
||||||
|
)
|
||||||
|
endif ()
|
||||||
|
|
||||||
# Support for https://github.com/matus-chochlik/ctcache
|
# Support for https://github.com/matus-chochlik/ctcache
|
||||||
find_program(CLANG_TIDY_CACHE_PATH NAMES "clang-tidy-cache")
|
find_program(CLANG_TIDY_CACHE_PATH NAMES "clang-tidy-cache")
|
||||||
if (CLANG_TIDY_CACHE_PATH)
|
if (CLANG_TIDY_CACHE_PATH)
|
||||||
set(_CLANG_TIDY_CMD "${CLANG_TIDY_CACHE_PATH};${_CLANG_TIDY_BIN}"
|
set(_CLANG_TIDY_CMD "${CLANG_TIDY_CACHE_PATH};${_CLANG_TIDY_BIN}"
|
||||||
CACHE STRING "A combined command to run clang-tidy with caching wrapper")
|
CACHE STRING "A combined command to run clang-tidy with caching wrapper"
|
||||||
else ()
|
)
|
||||||
set(_CLANG_TIDY_CMD "${_CLANG_TIDY_BIN}")
|
else ()
|
||||||
endif ()
|
set(_CLANG_TIDY_CMD "${_CLANG_TIDY_BIN}")
|
||||||
|
endif ()
|
||||||
|
|
||||||
set(CMAKE_CXX_CLANG_TIDY "${_CLANG_TIDY_CMD};--quiet")
|
set(CMAKE_CXX_CLANG_TIDY "${_CLANG_TIDY_CMD};--quiet")
|
||||||
message(STATUS "Using clang-tidy: ${CMAKE_CXX_CLANG_TIDY}")
|
message(STATUS "Using clang-tidy: ${CMAKE_CXX_CLANG_TIDY}")
|
||||||
endif ()
|
endif ()
|
||||||
|
|||||||
@@ -1,41 +1,47 @@
|
|||||||
find_package(Git REQUIRED)
|
find_package(Git REQUIRED)
|
||||||
|
|
||||||
if (DEFINED ENV{GITHUB_BRANCH_NAME})
|
set(GIT_COMMAND describe --tags --exact-match)
|
||||||
set(GIT_BUILD_BRANCH $ENV{GITHUB_BRANCH_NAME})
|
execute_process(
|
||||||
set(GIT_COMMIT_HASH $ENV{GITHUB_HEAD_SHA})
|
COMMAND ${GIT_EXECUTABLE} ${GIT_COMMAND}
|
||||||
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||||
|
OUTPUT_VARIABLE TAG
|
||||||
|
RESULT_VARIABLE RC
|
||||||
|
ERROR_VARIABLE ERR
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE
|
||||||
|
)
|
||||||
|
|
||||||
|
if (RC EQUAL 0)
|
||||||
|
message(STATUS "Found tag '${TAG}' in git. Will use it as Clio version")
|
||||||
|
set(CLIO_VERSION "${TAG}")
|
||||||
|
set(DOC_CLIO_VERSION "${TAG}")
|
||||||
else ()
|
else ()
|
||||||
set(GIT_COMMAND branch --show-current)
|
message(STATUS "Error finding tag in git: ${ERR}")
|
||||||
execute_process(COMMAND ${GIT_EXECUTABLE} ${GIT_COMMAND} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
message(STATUS "Will use 'YYYYMMDDHMS-<branch>-<git-rev>' as Clio version")
|
||||||
OUTPUT_VARIABLE GIT_BUILD_BRANCH OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ERROR_IS_FATAL ANY)
|
|
||||||
|
|
||||||
set(GIT_COMMAND rev-parse HEAD)
|
set(GIT_COMMAND show -s --date=format:%Y%m%d%H%M%S --format=%cd)
|
||||||
execute_process(COMMAND ${GIT_EXECUTABLE} ${GIT_COMMAND} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
execute_process(
|
||||||
OUTPUT_VARIABLE GIT_COMMIT_HASH OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ERROR_IS_FATAL ANY)
|
COMMAND ${GIT_EXECUTABLE} ${GIT_COMMAND} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE DATE
|
||||||
endif ()
|
OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ERROR_IS_FATAL ANY
|
||||||
|
)
|
||||||
|
|
||||||
execute_process(COMMAND date +%Y%m%d%H%M%S WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE BUILD_DATE
|
set(GIT_COMMAND branch --show-current)
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ERROR_IS_FATAL ANY)
|
execute_process(
|
||||||
|
COMMAND ${GIT_EXECUTABLE} ${GIT_COMMAND} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE BRANCH
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ERROR_IS_FATAL ANY
|
||||||
|
)
|
||||||
|
|
||||||
message(STATUS "Git branch: ${GIT_BUILD_BRANCH}")
|
set(GIT_COMMAND rev-parse --short HEAD)
|
||||||
message(STATUS "Git commit hash: ${GIT_COMMIT_HASH}")
|
execute_process(
|
||||||
message(STATUS "Build date: ${BUILD_DATE}")
|
COMMAND ${GIT_EXECUTABLE} ${GIT_COMMAND} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE REV
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ERROR_IS_FATAL ANY
|
||||||
|
)
|
||||||
|
|
||||||
if (DEFINED ENV{FORCE_CLIO_VERSION} AND NOT "$ENV{FORCE_CLIO_VERSION}" STREQUAL "")
|
set(CLIO_VERSION "${DATE}-${BRANCH}-${REV}")
|
||||||
message(STATUS "Using explicitly provided '${FORCE_CLIO_VERSION}' as Clio version")
|
set(DOC_CLIO_VERSION "develop")
|
||||||
|
|
||||||
set(CLIO_VERSION "$ENV{FORCE_CLIO_VERSION}")
|
|
||||||
set(DOC_CLIO_VERSION "$ENV{FORCE_CLIO_VERSION}")
|
|
||||||
else ()
|
|
||||||
message(STATUS "Using 'YYYYMMDDHMS-<branch>-<git short rev>' as Clio version")
|
|
||||||
|
|
||||||
string(SUBSTRING ${GIT_COMMIT_HASH} 0 7 GIT_COMMIT_HASH_SHORT)
|
|
||||||
|
|
||||||
set(CLIO_VERSION "${BUILD_DATE}-${GIT_BUILD_BRANCH}-${GIT_COMMIT_HASH_SHORT}")
|
|
||||||
set(DOC_CLIO_VERSION "develop")
|
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (CMAKE_BUILD_TYPE MATCHES Debug)
|
if (CMAKE_BUILD_TYPE MATCHES Debug)
|
||||||
set(CLIO_VERSION "${CLIO_VERSION}+DEBUG")
|
set(CLIO_VERSION "${CLIO_VERSION}+DEBUG")
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
message(STATUS "Build version: ${CLIO_VERSION}")
|
message(STATUS "Build version: ${CLIO_VERSION}")
|
||||||
|
|||||||
@@ -107,69 +107,76 @@ option(CODE_COVERAGE_VERBOSE "Verbose information" FALSE)
|
|||||||
find_program(GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/scripts/test)
|
find_program(GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/scripts/test)
|
||||||
|
|
||||||
if (DEFINED CODE_COVERAGE_GCOV_TOOL)
|
if (DEFINED CODE_COVERAGE_GCOV_TOOL)
|
||||||
set(GCOV_TOOL "${CODE_COVERAGE_GCOV_TOOL}")
|
set(GCOV_TOOL "${CODE_COVERAGE_GCOV_TOOL}")
|
||||||
elseif (DEFINED ENV{CODE_COVERAGE_GCOV_TOOL})
|
elseif (DEFINED ENV{CODE_COVERAGE_GCOV_TOOL})
|
||||||
set(GCOV_TOOL "$ENV{CODE_COVERAGE_GCOV_TOOL}")
|
set(GCOV_TOOL "$ENV{CODE_COVERAGE_GCOV_TOOL}")
|
||||||
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang")
|
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang")
|
||||||
if (APPLE)
|
if (APPLE)
|
||||||
execute_process(COMMAND xcrun -f llvm-cov OUTPUT_VARIABLE LLVMCOV_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
|
execute_process(COMMAND xcrun -f llvm-cov OUTPUT_VARIABLE LLVMCOV_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
else ()
|
else ()
|
||||||
find_program(LLVMCOV_PATH llvm-cov)
|
find_program(LLVMCOV_PATH llvm-cov)
|
||||||
endif ()
|
endif ()
|
||||||
if (LLVMCOV_PATH)
|
if (LLVMCOV_PATH)
|
||||||
set(GCOV_TOOL "${LLVMCOV_PATH} gcov")
|
set(GCOV_TOOL "${LLVMCOV_PATH} gcov")
|
||||||
endif ()
|
endif ()
|
||||||
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
|
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
|
||||||
find_program(GCOV_PATH gcov)
|
find_program(GCOV_PATH gcov)
|
||||||
set(GCOV_TOOL "${GCOV_PATH}")
|
set(GCOV_TOOL "${GCOV_PATH}")
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
# Check supported compiler (Clang, GNU and Flang)
|
# Check supported compiler (Clang, GNU and Flang)
|
||||||
get_property(LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES)
|
get_property(LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES)
|
||||||
foreach (LANG ${LANGUAGES})
|
foreach (LANG ${LANGUAGES})
|
||||||
if ("${CMAKE_${LANG}_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang")
|
if ("${CMAKE_${LANG}_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang")
|
||||||
if ("${CMAKE_${LANG}_COMPILER_VERSION}" VERSION_LESS 3)
|
if ("${CMAKE_${LANG}_COMPILER_VERSION}" VERSION_LESS 3)
|
||||||
message(FATAL_ERROR "Clang version must be 3.0.0 or greater! Aborting...")
|
message(FATAL_ERROR "Clang version must be 3.0.0 or greater! Aborting...")
|
||||||
endif ()
|
|
||||||
elseif (NOT "${CMAKE_${LANG}_COMPILER_ID}" MATCHES "GNU" AND NOT "${CMAKE_${LANG}_COMPILER_ID}" MATCHES
|
|
||||||
"(LLVM)?[Ff]lang")
|
|
||||||
message(FATAL_ERROR "Compiler is not GNU or Flang! Aborting...")
|
|
||||||
endif ()
|
endif ()
|
||||||
|
elseif (NOT "${CMAKE_${LANG}_COMPILER_ID}" MATCHES "GNU" AND NOT "${CMAKE_${LANG}_COMPILER_ID}" MATCHES
|
||||||
|
"(LLVM)?[Ff]lang"
|
||||||
|
)
|
||||||
|
message(FATAL_ERROR "Compiler is not GNU or Flang! Aborting...")
|
||||||
|
endif ()
|
||||||
endforeach ()
|
endforeach ()
|
||||||
|
|
||||||
set(COVERAGE_COMPILER_FLAGS "-g --coverage" CACHE INTERNAL "")
|
set(COVERAGE_COMPILER_FLAGS "-g --coverage" CACHE INTERNAL "")
|
||||||
if (CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
|
if (CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
|
||||||
include(CheckCXXCompilerFlag)
|
include(CheckCXXCompilerFlag)
|
||||||
check_cxx_compiler_flag(-fprofile-abs-path HAVE_cxx_fprofile_abs_path)
|
check_cxx_compiler_flag(-fprofile-abs-path HAVE_cxx_fprofile_abs_path)
|
||||||
if (HAVE_cxx_fprofile_abs_path)
|
if (HAVE_cxx_fprofile_abs_path)
|
||||||
set(COVERAGE_CXX_COMPILER_FLAGS "${COVERAGE_COMPILER_FLAGS} -fprofile-abs-path")
|
set(COVERAGE_CXX_COMPILER_FLAGS "${COVERAGE_COMPILER_FLAGS} -fprofile-abs-path")
|
||||||
endif ()
|
endif ()
|
||||||
include(CheckCCompilerFlag)
|
include(CheckCCompilerFlag)
|
||||||
check_c_compiler_flag(-fprofile-abs-path HAVE_c_fprofile_abs_path)
|
check_c_compiler_flag(-fprofile-abs-path HAVE_c_fprofile_abs_path)
|
||||||
if (HAVE_c_fprofile_abs_path)
|
if (HAVE_c_fprofile_abs_path)
|
||||||
set(COVERAGE_C_COMPILER_FLAGS "${COVERAGE_COMPILER_FLAGS} -fprofile-abs-path")
|
set(COVERAGE_C_COMPILER_FLAGS "${COVERAGE_COMPILER_FLAGS} -fprofile-abs-path")
|
||||||
endif ()
|
endif ()
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
set(CMAKE_Fortran_FLAGS_COVERAGE ${COVERAGE_COMPILER_FLAGS}
|
set(CMAKE_Fortran_FLAGS_COVERAGE ${COVERAGE_COMPILER_FLAGS}
|
||||||
CACHE STRING "Flags used by the Fortran compiler during coverage builds." FORCE)
|
CACHE STRING "Flags used by the Fortran compiler during coverage builds." FORCE
|
||||||
|
)
|
||||||
set(CMAKE_CXX_FLAGS_COVERAGE ${COVERAGE_COMPILER_FLAGS}
|
set(CMAKE_CXX_FLAGS_COVERAGE ${COVERAGE_COMPILER_FLAGS}
|
||||||
CACHE STRING "Flags used by the C++ compiler during coverage builds." FORCE)
|
CACHE STRING "Flags used by the C++ compiler during coverage builds." FORCE
|
||||||
|
)
|
||||||
set(CMAKE_C_FLAGS_COVERAGE ${COVERAGE_COMPILER_FLAGS}
|
set(CMAKE_C_FLAGS_COVERAGE ${COVERAGE_COMPILER_FLAGS}
|
||||||
CACHE STRING "Flags used by the C compiler during coverage builds." FORCE)
|
CACHE STRING "Flags used by the C compiler during coverage builds." FORCE
|
||||||
|
)
|
||||||
set(CMAKE_EXE_LINKER_FLAGS_COVERAGE "" CACHE STRING "Flags used for linking binaries during coverage builds." FORCE)
|
set(CMAKE_EXE_LINKER_FLAGS_COVERAGE "" CACHE STRING "Flags used for linking binaries during coverage builds." FORCE)
|
||||||
set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE ""
|
set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE ""
|
||||||
CACHE STRING "Flags used by the shared libraries linker during coverage builds." FORCE)
|
CACHE STRING "Flags used by the shared libraries linker during coverage builds." FORCE
|
||||||
mark_as_advanced(CMAKE_Fortran_FLAGS_COVERAGE CMAKE_CXX_FLAGS_COVERAGE CMAKE_C_FLAGS_COVERAGE
|
)
|
||||||
CMAKE_EXE_LINKER_FLAGS_COVERAGE CMAKE_SHARED_LINKER_FLAGS_COVERAGE)
|
mark_as_advanced(
|
||||||
|
CMAKE_Fortran_FLAGS_COVERAGE CMAKE_CXX_FLAGS_COVERAGE CMAKE_C_FLAGS_COVERAGE CMAKE_EXE_LINKER_FLAGS_COVERAGE
|
||||||
|
CMAKE_SHARED_LINKER_FLAGS_COVERAGE
|
||||||
|
)
|
||||||
|
|
||||||
get_property(GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
|
get_property(GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
|
||||||
if (NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR GENERATOR_IS_MULTI_CONFIG))
|
if (NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR GENERATOR_IS_MULTI_CONFIG))
|
||||||
message(WARNING "Code coverage results with an optimised (non-Debug) build may be misleading")
|
message(WARNING "Code coverage results with an optimised (non-Debug) build may be misleading")
|
||||||
endif () # NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR GENERATOR_IS_MULTI_CONFIG)
|
endif () # NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR GENERATOR_IS_MULTI_CONFIG)
|
||||||
|
|
||||||
if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
|
if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
|
||||||
link_libraries(gcov)
|
link_libraries(gcov)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
# Defines a target for running and collection code coverage information Builds dependencies, runs the given executable
|
# Defines a target for running and collection code coverage information Builds dependencies, runs the given executable
|
||||||
@@ -185,164 +192,170 @@ endif ()
|
|||||||
# with CMake 3.4+) ) The user can set the variable GCOVR_ADDITIONAL_ARGS to supply additional flags to the GCVOR
|
# with CMake 3.4+) ) The user can set the variable GCOVR_ADDITIONAL_ARGS to supply additional flags to the GCVOR
|
||||||
# command.
|
# command.
|
||||||
function (setup_target_for_coverage_gcovr)
|
function (setup_target_for_coverage_gcovr)
|
||||||
set(options NONE)
|
set(options NONE)
|
||||||
set(oneValueArgs BASE_DIRECTORY NAME FORMAT)
|
set(oneValueArgs BASE_DIRECTORY NAME FORMAT)
|
||||||
set(multiValueArgs EXCLUDE EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES)
|
set(multiValueArgs EXCLUDE EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES)
|
||||||
cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||||
|
|
||||||
if (NOT GCOV_TOOL)
|
if (NOT GCOV_TOOL)
|
||||||
message(FATAL_ERROR "Could not find gcov or llvm-cov tool! Aborting...")
|
message(FATAL_ERROR "Could not find gcov or llvm-cov tool! Aborting...")
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (NOT GCOVR_PATH)
|
if (NOT GCOVR_PATH)
|
||||||
message(FATAL_ERROR "Could not find gcovr tool! Aborting...")
|
message(FATAL_ERROR "Could not find gcovr tool! Aborting...")
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
# Set base directory (as absolute path), or default to PROJECT_SOURCE_DIR
|
# Set base directory (as absolute path), or default to PROJECT_SOURCE_DIR
|
||||||
if (DEFINED Coverage_BASE_DIRECTORY)
|
if (DEFINED Coverage_BASE_DIRECTORY)
|
||||||
get_filename_component(BASEDIR ${Coverage_BASE_DIRECTORY} ABSOLUTE)
|
get_filename_component(BASEDIR ${Coverage_BASE_DIRECTORY} ABSOLUTE)
|
||||||
else ()
|
else ()
|
||||||
set(BASEDIR ${PROJECT_SOURCE_DIR})
|
set(BASEDIR ${PROJECT_SOURCE_DIR})
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (NOT DEFINED Coverage_FORMAT)
|
if (NOT DEFINED Coverage_FORMAT)
|
||||||
set(Coverage_FORMAT xml)
|
set(Coverage_FORMAT xml)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if ("--output" IN_LIST GCOVR_ADDITIONAL_ARGS)
|
if ("--output" IN_LIST GCOVR_ADDITIONAL_ARGS)
|
||||||
message(FATAL_ERROR "Unsupported --output option detected in GCOVR_ADDITIONAL_ARGS! Aborting...")
|
message(FATAL_ERROR "Unsupported --output option detected in GCOVR_ADDITIONAL_ARGS! Aborting...")
|
||||||
else ()
|
else ()
|
||||||
if ((Coverage_FORMAT STREQUAL "html-details") OR (Coverage_FORMAT STREQUAL "html-nested"))
|
if ((Coverage_FORMAT STREQUAL "html-details") OR (Coverage_FORMAT STREQUAL "html-nested"))
|
||||||
set(GCOVR_OUTPUT_FILE ${PROJECT_BINARY_DIR}/${Coverage_NAME}/index.html)
|
set(GCOVR_OUTPUT_FILE ${PROJECT_BINARY_DIR}/${Coverage_NAME}/index.html)
|
||||||
set(GCOVR_CREATE_FOLDER ${PROJECT_BINARY_DIR}/${Coverage_NAME})
|
set(GCOVR_CREATE_FOLDER ${PROJECT_BINARY_DIR}/${Coverage_NAME})
|
||||||
elseif (Coverage_FORMAT STREQUAL "html-single")
|
|
||||||
set(GCOVR_OUTPUT_FILE ${Coverage_NAME}.html)
|
|
||||||
elseif ((Coverage_FORMAT STREQUAL "json-summary") OR (Coverage_FORMAT STREQUAL "json-details")
|
|
||||||
OR (Coverage_FORMAT STREQUAL "coveralls"))
|
|
||||||
set(GCOVR_OUTPUT_FILE ${Coverage_NAME}.json)
|
|
||||||
elseif (Coverage_FORMAT STREQUAL "txt")
|
|
||||||
set(GCOVR_OUTPUT_FILE ${Coverage_NAME}.txt)
|
|
||||||
elseif (Coverage_FORMAT STREQUAL "csv")
|
|
||||||
set(GCOVR_OUTPUT_FILE ${Coverage_NAME}.csv)
|
|
||||||
else ()
|
|
||||||
set(GCOVR_OUTPUT_FILE ${Coverage_NAME}.xml)
|
|
||||||
endif ()
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
if ((Coverage_FORMAT STREQUAL "cobertura") OR (Coverage_FORMAT STREQUAL "xml"))
|
|
||||||
list(APPEND GCOVR_ADDITIONAL_ARGS --cobertura "${GCOVR_OUTPUT_FILE}")
|
|
||||||
list(APPEND GCOVR_ADDITIONAL_ARGS --cobertura-pretty)
|
|
||||||
set(Coverage_FORMAT cobertura) # overwrite xml
|
|
||||||
elseif (Coverage_FORMAT STREQUAL "sonarqube")
|
|
||||||
list(APPEND GCOVR_ADDITIONAL_ARGS --sonarqube "${GCOVR_OUTPUT_FILE}")
|
|
||||||
elseif (Coverage_FORMAT STREQUAL "json-summary")
|
|
||||||
list(APPEND GCOVR_ADDITIONAL_ARGS --json-summary "${GCOVR_OUTPUT_FILE}")
|
|
||||||
list(APPEND GCOVR_ADDITIONAL_ARGS --json-summary-pretty)
|
|
||||||
elseif (Coverage_FORMAT STREQUAL "json-details")
|
|
||||||
list(APPEND GCOVR_ADDITIONAL_ARGS --json "${GCOVR_OUTPUT_FILE}")
|
|
||||||
list(APPEND GCOVR_ADDITIONAL_ARGS --json-pretty)
|
|
||||||
elseif (Coverage_FORMAT STREQUAL "coveralls")
|
|
||||||
list(APPEND GCOVR_ADDITIONAL_ARGS --coveralls "${GCOVR_OUTPUT_FILE}")
|
|
||||||
list(APPEND GCOVR_ADDITIONAL_ARGS --coveralls-pretty)
|
|
||||||
elseif (Coverage_FORMAT STREQUAL "csv")
|
|
||||||
list(APPEND GCOVR_ADDITIONAL_ARGS --csv "${GCOVR_OUTPUT_FILE}")
|
|
||||||
elseif (Coverage_FORMAT STREQUAL "txt")
|
|
||||||
list(APPEND GCOVR_ADDITIONAL_ARGS --txt "${GCOVR_OUTPUT_FILE}")
|
|
||||||
elseif (Coverage_FORMAT STREQUAL "html-single")
|
elseif (Coverage_FORMAT STREQUAL "html-single")
|
||||||
list(APPEND GCOVR_ADDITIONAL_ARGS --html "${GCOVR_OUTPUT_FILE}")
|
set(GCOVR_OUTPUT_FILE ${Coverage_NAME}.html)
|
||||||
list(APPEND GCOVR_ADDITIONAL_ARGS --html-self-contained)
|
elseif ((Coverage_FORMAT STREQUAL "json-summary") OR (Coverage_FORMAT STREQUAL "json-details")
|
||||||
elseif (Coverage_FORMAT STREQUAL "html-nested")
|
OR (Coverage_FORMAT STREQUAL "coveralls")
|
||||||
list(APPEND GCOVR_ADDITIONAL_ARGS --html-nested "${GCOVR_OUTPUT_FILE}")
|
)
|
||||||
elseif (Coverage_FORMAT STREQUAL "html-details")
|
set(GCOVR_OUTPUT_FILE ${Coverage_NAME}.json)
|
||||||
list(APPEND GCOVR_ADDITIONAL_ARGS --html-details "${GCOVR_OUTPUT_FILE}")
|
elseif (Coverage_FORMAT STREQUAL "txt")
|
||||||
|
set(GCOVR_OUTPUT_FILE ${Coverage_NAME}.txt)
|
||||||
|
elseif (Coverage_FORMAT STREQUAL "csv")
|
||||||
|
set(GCOVR_OUTPUT_FILE ${Coverage_NAME}.csv)
|
||||||
else ()
|
else ()
|
||||||
message(FATAL_ERROR "Unsupported output style ${Coverage_FORMAT}! Aborting...")
|
set(GCOVR_OUTPUT_FILE ${Coverage_NAME}.xml)
|
||||||
|
endif ()
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
if ((Coverage_FORMAT STREQUAL "cobertura") OR (Coverage_FORMAT STREQUAL "xml"))
|
||||||
|
list(APPEND GCOVR_ADDITIONAL_ARGS --cobertura "${GCOVR_OUTPUT_FILE}")
|
||||||
|
list(APPEND GCOVR_ADDITIONAL_ARGS --cobertura-pretty)
|
||||||
|
set(Coverage_FORMAT cobertura) # overwrite xml
|
||||||
|
elseif (Coverage_FORMAT STREQUAL "sonarqube")
|
||||||
|
list(APPEND GCOVR_ADDITIONAL_ARGS --sonarqube "${GCOVR_OUTPUT_FILE}")
|
||||||
|
elseif (Coverage_FORMAT STREQUAL "json-summary")
|
||||||
|
list(APPEND GCOVR_ADDITIONAL_ARGS --json-summary "${GCOVR_OUTPUT_FILE}")
|
||||||
|
list(APPEND GCOVR_ADDITIONAL_ARGS --json-summary-pretty)
|
||||||
|
elseif (Coverage_FORMAT STREQUAL "json-details")
|
||||||
|
list(APPEND GCOVR_ADDITIONAL_ARGS --json "${GCOVR_OUTPUT_FILE}")
|
||||||
|
list(APPEND GCOVR_ADDITIONAL_ARGS --json-pretty)
|
||||||
|
elseif (Coverage_FORMAT STREQUAL "coveralls")
|
||||||
|
list(APPEND GCOVR_ADDITIONAL_ARGS --coveralls "${GCOVR_OUTPUT_FILE}")
|
||||||
|
list(APPEND GCOVR_ADDITIONAL_ARGS --coveralls-pretty)
|
||||||
|
elseif (Coverage_FORMAT STREQUAL "csv")
|
||||||
|
list(APPEND GCOVR_ADDITIONAL_ARGS --csv "${GCOVR_OUTPUT_FILE}")
|
||||||
|
elseif (Coverage_FORMAT STREQUAL "txt")
|
||||||
|
list(APPEND GCOVR_ADDITIONAL_ARGS --txt "${GCOVR_OUTPUT_FILE}")
|
||||||
|
elseif (Coverage_FORMAT STREQUAL "html-single")
|
||||||
|
list(APPEND GCOVR_ADDITIONAL_ARGS --html "${GCOVR_OUTPUT_FILE}")
|
||||||
|
list(APPEND GCOVR_ADDITIONAL_ARGS --html-self-contained)
|
||||||
|
elseif (Coverage_FORMAT STREQUAL "html-nested")
|
||||||
|
list(APPEND GCOVR_ADDITIONAL_ARGS --html-nested "${GCOVR_OUTPUT_FILE}")
|
||||||
|
elseif (Coverage_FORMAT STREQUAL "html-details")
|
||||||
|
list(APPEND GCOVR_ADDITIONAL_ARGS --html-details "${GCOVR_OUTPUT_FILE}")
|
||||||
|
else ()
|
||||||
|
message(FATAL_ERROR "Unsupported output style ${Coverage_FORMAT}! Aborting...")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
# Collect excludes (CMake 3.4+: Also compute absolute paths)
|
||||||
|
set(GCOVR_EXCLUDES "")
|
||||||
|
foreach (EXCLUDE ${Coverage_EXCLUDE} ${COVERAGE_EXCLUDES} ${COVERAGE_GCOVR_EXCLUDES})
|
||||||
|
if (CMAKE_VERSION VERSION_GREATER 3.4)
|
||||||
|
get_filename_component(EXCLUDE ${EXCLUDE} ABSOLUTE BASE_DIR ${BASEDIR})
|
||||||
|
endif ()
|
||||||
|
list(APPEND GCOVR_EXCLUDES "${EXCLUDE}")
|
||||||
|
endforeach ()
|
||||||
|
list(REMOVE_DUPLICATES GCOVR_EXCLUDES)
|
||||||
|
|
||||||
|
# Combine excludes to several -e arguments
|
||||||
|
set(GCOVR_EXCLUDE_ARGS "")
|
||||||
|
foreach (EXCLUDE ${GCOVR_EXCLUDES})
|
||||||
|
list(APPEND GCOVR_EXCLUDE_ARGS "-e")
|
||||||
|
list(APPEND GCOVR_EXCLUDE_ARGS "${EXCLUDE}")
|
||||||
|
endforeach ()
|
||||||
|
|
||||||
|
# Set up commands which will be run to generate coverage data Run tests
|
||||||
|
set(GCOVR_EXEC_TESTS_CMD ${Coverage_EXECUTABLE} ${Coverage_EXECUTABLE_ARGS})
|
||||||
|
|
||||||
|
# Create folder
|
||||||
|
if (DEFINED GCOVR_CREATE_FOLDER)
|
||||||
|
set(GCOVR_FOLDER_CMD ${CMAKE_COMMAND} -E make_directory ${GCOVR_CREATE_FOLDER})
|
||||||
|
else ()
|
||||||
|
set(GCOVR_FOLDER_CMD echo) # dummy
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
# Running gcovr
|
||||||
|
set(GCOVR_CMD
|
||||||
|
${GCOVR_PATH}
|
||||||
|
--gcov-executable
|
||||||
|
${GCOV_TOOL}
|
||||||
|
--gcov-ignore-parse-errors=negative_hits.warn_once_per_file
|
||||||
|
-r
|
||||||
|
${BASEDIR}
|
||||||
|
${GCOVR_ADDITIONAL_ARGS}
|
||||||
|
${GCOVR_EXCLUDE_ARGS}
|
||||||
|
--object-directory=${PROJECT_BINARY_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
if (CODE_COVERAGE_VERBOSE)
|
||||||
|
message(STATUS "Executed command report")
|
||||||
|
|
||||||
|
message(STATUS "Command to run tests: ")
|
||||||
|
string(REPLACE ";" " " GCOVR_EXEC_TESTS_CMD_SPACED "${GCOVR_EXEC_TESTS_CMD}")
|
||||||
|
message(STATUS "${GCOVR_EXEC_TESTS_CMD_SPACED}")
|
||||||
|
|
||||||
|
if (NOT GCOVR_FOLDER_CMD STREQUAL "echo")
|
||||||
|
message(STATUS "Command to create a folder: ")
|
||||||
|
string(REPLACE ";" " " GCOVR_FOLDER_CMD_SPACED "${GCOVR_FOLDER_CMD}")
|
||||||
|
message(STATUS "${GCOVR_FOLDER_CMD_SPACED}")
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
# Collect excludes (CMake 3.4+: Also compute absolute paths)
|
message(STATUS "Command to generate gcovr coverage data: ")
|
||||||
set(GCOVR_EXCLUDES "")
|
string(REPLACE ";" " " GCOVR_CMD_SPACED "${GCOVR_CMD}")
|
||||||
foreach (EXCLUDE ${Coverage_EXCLUDE} ${COVERAGE_EXCLUDES} ${COVERAGE_GCOVR_EXCLUDES})
|
message(STATUS "${GCOVR_CMD_SPACED}")
|
||||||
if (CMAKE_VERSION VERSION_GREATER 3.4)
|
endif ()
|
||||||
get_filename_component(EXCLUDE ${EXCLUDE} ABSOLUTE BASE_DIR ${BASEDIR})
|
|
||||||
endif ()
|
|
||||||
list(APPEND GCOVR_EXCLUDES "${EXCLUDE}")
|
|
||||||
endforeach ()
|
|
||||||
list(REMOVE_DUPLICATES GCOVR_EXCLUDES)
|
|
||||||
|
|
||||||
# Combine excludes to several -e arguments
|
add_custom_target(
|
||||||
set(GCOVR_EXCLUDE_ARGS "")
|
${Coverage_NAME}
|
||||||
foreach (EXCLUDE ${GCOVR_EXCLUDES})
|
COMMAND ${GCOVR_EXEC_TESTS_CMD}
|
||||||
list(APPEND GCOVR_EXCLUDE_ARGS "-e")
|
COMMAND ${GCOVR_FOLDER_CMD}
|
||||||
list(APPEND GCOVR_EXCLUDE_ARGS "${EXCLUDE}")
|
COMMAND ${GCOVR_CMD}
|
||||||
endforeach ()
|
BYPRODUCTS ${GCOVR_OUTPUT_FILE}
|
||||||
|
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
||||||
|
DEPENDS ${Coverage_DEPENDENCIES}
|
||||||
|
VERBATIM # Protect arguments to commands
|
||||||
|
COMMENT "Running gcovr to produce code coverage report."
|
||||||
|
)
|
||||||
|
|
||||||
# Set up commands which will be run to generate coverage data Run tests
|
# Show info where to find the report
|
||||||
set(GCOVR_EXEC_TESTS_CMD ${Coverage_EXECUTABLE} ${Coverage_EXECUTABLE_ARGS})
|
add_custom_command(
|
||||||
|
TARGET ${Coverage_NAME} POST_BUILD COMMAND ;
|
||||||
# Create folder
|
COMMENT "Code coverage report saved in ${GCOVR_OUTPUT_FILE} formatted as ${Coverage_FORMAT}"
|
||||||
if (DEFINED GCOVR_CREATE_FOLDER)
|
)
|
||||||
set(GCOVR_FOLDER_CMD ${CMAKE_COMMAND} -E make_directory ${GCOVR_CREATE_FOLDER})
|
|
||||||
else ()
|
|
||||||
set(GCOVR_FOLDER_CMD echo) # dummy
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
# Running gcovr
|
|
||||||
set(GCOVR_CMD
|
|
||||||
${GCOVR_PATH}
|
|
||||||
--gcov-executable
|
|
||||||
${GCOV_TOOL}
|
|
||||||
--gcov-ignore-parse-errors=negative_hits.warn_once_per_file
|
|
||||||
-r
|
|
||||||
${BASEDIR}
|
|
||||||
${GCOVR_ADDITIONAL_ARGS}
|
|
||||||
${GCOVR_EXCLUDE_ARGS}
|
|
||||||
--object-directory=${PROJECT_BINARY_DIR})
|
|
||||||
|
|
||||||
if (CODE_COVERAGE_VERBOSE)
|
|
||||||
message(STATUS "Executed command report")
|
|
||||||
|
|
||||||
message(STATUS "Command to run tests: ")
|
|
||||||
string(REPLACE ";" " " GCOVR_EXEC_TESTS_CMD_SPACED "${GCOVR_EXEC_TESTS_CMD}")
|
|
||||||
message(STATUS "${GCOVR_EXEC_TESTS_CMD_SPACED}")
|
|
||||||
|
|
||||||
if (NOT GCOVR_FOLDER_CMD STREQUAL "echo")
|
|
||||||
message(STATUS "Command to create a folder: ")
|
|
||||||
string(REPLACE ";" " " GCOVR_FOLDER_CMD_SPACED "${GCOVR_FOLDER_CMD}")
|
|
||||||
message(STATUS "${GCOVR_FOLDER_CMD_SPACED}")
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
message(STATUS "Command to generate gcovr coverage data: ")
|
|
||||||
string(REPLACE ";" " " GCOVR_CMD_SPACED "${GCOVR_CMD}")
|
|
||||||
message(STATUS "${GCOVR_CMD_SPACED}")
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
add_custom_target(${Coverage_NAME}
|
|
||||||
COMMAND ${GCOVR_EXEC_TESTS_CMD}
|
|
||||||
COMMAND ${GCOVR_FOLDER_CMD}
|
|
||||||
COMMAND ${GCOVR_CMD}
|
|
||||||
BYPRODUCTS ${GCOVR_OUTPUT_FILE}
|
|
||||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
|
||||||
DEPENDS ${Coverage_DEPENDENCIES}
|
|
||||||
VERBATIM # Protect arguments to commands
|
|
||||||
COMMENT "Running gcovr to produce code coverage report.")
|
|
||||||
|
|
||||||
# Show info where to find the report
|
|
||||||
add_custom_command(TARGET ${Coverage_NAME} POST_BUILD COMMAND ;
|
|
||||||
COMMENT "Code coverage report saved in ${GCOVR_OUTPUT_FILE} formatted as ${Coverage_FORMAT}")
|
|
||||||
endfunction () # setup_target_for_coverage_gcovr
|
endfunction () # setup_target_for_coverage_gcovr
|
||||||
|
|
||||||
function (append_coverage_compiler_flags)
|
function (append_coverage_compiler_flags)
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE)
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE)
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE)
|
||||||
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE)
|
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE)
|
||||||
message(STATUS "Appending code coverage compiler flags: ${COVERAGE_COMPILER_FLAGS}")
|
message(STATUS "Appending code coverage compiler flags: ${COVERAGE_COMPILER_FLAGS}")
|
||||||
endfunction () # append_coverage_compiler_flags
|
endfunction () # append_coverage_compiler_flags
|
||||||
|
|
||||||
# Setup coverage for specific library
|
# Setup coverage for specific library
|
||||||
function (append_coverage_compiler_flags_to_target name mode)
|
function (append_coverage_compiler_flags_to_target name mode)
|
||||||
separate_arguments(_flag_list NATIVE_COMMAND "${COVERAGE_COMPILER_FLAGS}")
|
separate_arguments(_flag_list NATIVE_COMMAND "${COVERAGE_COMPILER_FLAGS}")
|
||||||
target_compile_options(${name} ${mode} ${_flag_list})
|
target_compile_options(${name} ${mode} ${_flag_list})
|
||||||
if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
|
if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
|
||||||
target_link_libraries(${name} ${mode} gcov)
|
target_link_libraries(${name} ${mode} gcov)
|
||||||
endif ()
|
endif ()
|
||||||
endfunction ()
|
endfunction ()
|
||||||
|
|||||||
@@ -11,8 +11,10 @@ set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile)
|
|||||||
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
|
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
|
||||||
|
|
||||||
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT})
|
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT})
|
||||||
add_custom_target(docs
|
add_custom_target(
|
||||||
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
|
docs
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
|
||||||
COMMENT "Generating API documentation with Doxygen"
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
VERBATIM)
|
COMMENT "Generating API documentation with Doxygen"
|
||||||
|
VERBATIM
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
if (DEFINED CMAKE_LINKER_TYPE)
|
if (DEFINED CMAKE_LINKER_TYPE)
|
||||||
message(STATUS "Custom linker is already set: ${CMAKE_LINKER_TYPE}")
|
message(STATUS "Custom linker is already set: ${CMAKE_LINKER_TYPE}")
|
||||||
return()
|
return()
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
find_program(MOLD_PATH mold)
|
find_program(MOLD_PATH mold)
|
||||||
|
|
||||||
if (MOLD_PATH AND CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
if (MOLD_PATH AND CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||||
message(STATUS "Using Mold linker: ${MOLD_PATH}")
|
message(STATUS "Using Mold linker: ${MOLD_PATH}")
|
||||||
set(CMAKE_LINKER_TYPE MOLD)
|
set(CMAKE_LINKER_TYPE MOLD)
|
||||||
endif ()
|
endif ()
|
||||||
|
|||||||
@@ -31,51 +31,52 @@ set(COMPILER_FLAGS
|
|||||||
# -Wduplicated-cond -Wlogical-op -Wuseless-cast ) endif ()
|
# -Wduplicated-cond -Wlogical-op -Wuseless-cast ) endif ()
|
||||||
|
|
||||||
if (is_clang)
|
if (is_clang)
|
||||||
list(APPEND COMPILER_FLAGS -Wshadow # gcc is to aggressive with shadowing
|
list(APPEND COMPILER_FLAGS -Wshadow # gcc is to aggressive with shadowing
|
||||||
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78147
|
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78147
|
||||||
)
|
)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (is_appleclang)
|
if (is_appleclang)
|
||||||
list(APPEND COMPILER_FLAGS -Wreorder-init-list)
|
list(APPEND COMPILER_FLAGS -Wreorder-init-list)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (san)
|
if (san)
|
||||||
# When building with sanitizers some compilers will actually produce extra warnings/errors. We don't want this yet,
|
# When building with sanitizers some compilers will actually produce extra warnings/errors. We don't want this yet, at
|
||||||
# at least not until we have fixed all runtime issues reported by the sanitizers. Once that is done we can start
|
# least not until we have fixed all runtime issues reported by the sanitizers. Once that is done we can start removing
|
||||||
# removing some of these and trying to fix it in our codebase. We can never remove all of below because most of them
|
# some of these and trying to fix it in our codebase. We can never remove all of below because most of them are
|
||||||
# are reported from deep inside libraries like boost or libxrpl.
|
# reported from deep inside libraries like boost or libxrpl.
|
||||||
#
|
#
|
||||||
# TODO: Address in https://github.com/XRPLF/clio/issues/1885
|
# TODO: Address in https://github.com/XRPLF/clio/issues/1885
|
||||||
list(APPEND
|
list(
|
||||||
COMPILER_FLAGS
|
APPEND
|
||||||
-Wno-error=tsan # Disables treating TSAN warnings as errors
|
COMPILER_FLAGS
|
||||||
-Wno-tsan # Disables TSAN warnings (thread-safety analysis)
|
-Wno-error=tsan # Disables treating TSAN warnings as errors
|
||||||
-Wno-uninitialized # Disables warnings about uninitialized variables (AddressSanitizer,
|
-Wno-tsan # Disables TSAN warnings (thread-safety analysis)
|
||||||
# UndefinedBehaviorSanitizer, etc.)
|
-Wno-uninitialized # Disables warnings about uninitialized variables (AddressSanitizer, UndefinedBehaviorSanitizer,
|
||||||
-Wno-stringop-overflow # Disables warnings about potential string operation overflows (AddressSanitizer)
|
# etc.)
|
||||||
-Wno-unsafe-buffer-usage # Disables warnings about unsafe memory operations (AddressSanitizer)
|
-Wno-stringop-overflow # Disables warnings about potential string operation overflows (AddressSanitizer)
|
||||||
-Wno-frame-larger-than # Disables warnings about stack frame size being too large (AddressSanitizer)
|
-Wno-unsafe-buffer-usage # Disables warnings about unsafe memory operations (AddressSanitizer)
|
||||||
-Wno-unused-function # Disables warnings about unused functions (LeakSanitizer, memory-related issues)
|
-Wno-frame-larger-than # Disables warnings about stack frame size being too large (AddressSanitizer)
|
||||||
-Wno-unused-but-set-variable # Disables warnings about unused variables (MemorySanitizer)
|
-Wno-unused-function # Disables warnings about unused functions (LeakSanitizer, memory-related issues)
|
||||||
-Wno-thread-safety-analysis # Disables warnings related to thread safety usage (ThreadSanitizer)
|
-Wno-unused-but-set-variable # Disables warnings about unused variables (MemorySanitizer)
|
||||||
-Wno-thread-safety # Disables warnings related to thread safety usage (ThreadSanitizer)
|
-Wno-thread-safety-analysis # Disables warnings related to thread safety usage (ThreadSanitizer)
|
||||||
-Wno-sign-compare # Disables warnings about signed/unsigned comparison (UndefinedBehaviorSanitizer)
|
-Wno-thread-safety # Disables warnings related to thread safety usage (ThreadSanitizer)
|
||||||
-Wno-nonnull # Disables warnings related to null pointer dereferencing (UndefinedBehaviorSanitizer)
|
-Wno-sign-compare # Disables warnings about signed/unsigned comparison (UndefinedBehaviorSanitizer)
|
||||||
-Wno-address # Disables warnings about address-related issues (UndefinedBehaviorSanitizer)
|
-Wno-nonnull # Disables warnings related to null pointer dereferencing (UndefinedBehaviorSanitizer)
|
||||||
-Wno-array-bounds # Disables array bounds checks (UndefinedBehaviorSanitizer)
|
-Wno-address # Disables warnings about address-related issues (UndefinedBehaviorSanitizer)
|
||||||
)
|
-Wno-array-bounds # Disables array bounds checks (UndefinedBehaviorSanitizer)
|
||||||
|
)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
# See https://github.com/cpp-best-practices/cppbestpractices/blob/master/02-Use_the_Tools_Available.md#gcc--clang for
|
# See https://github.com/cpp-best-practices/cppbestpractices/blob/master/02-Use_the_Tools_Available.md#gcc--clang for
|
||||||
# the flags description
|
# the flags description
|
||||||
|
|
||||||
if (time_trace)
|
if (time_trace)
|
||||||
if (is_clang OR is_appleclang)
|
if (is_clang OR is_appleclang)
|
||||||
list(APPEND COMPILER_FLAGS -ftime-trace)
|
list(APPEND COMPILER_FLAGS -ftime-trace)
|
||||||
else ()
|
else ()
|
||||||
message(FATAL_ERROR "Clang or AppleClang is required to use `-ftime-trace`")
|
message(FATAL_ERROR "Clang or AppleClang is required to use `-ftime-trace`")
|
||||||
endif ()
|
endif ()
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
target_compile_options(clio_options INTERFACE ${COMPILER_FLAGS})
|
target_compile_options(clio_options INTERFACE ${COMPILER_FLAGS})
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ include(CheckIncludeFileCXX)
|
|||||||
|
|
||||||
check_include_file_cxx("source_location" SOURCE_LOCATION_AVAILABLE)
|
check_include_file_cxx("source_location" SOURCE_LOCATION_AVAILABLE)
|
||||||
if (SOURCE_LOCATION_AVAILABLE)
|
if (SOURCE_LOCATION_AVAILABLE)
|
||||||
target_compile_definitions(clio_options INTERFACE "HAS_SOURCE_LOCATION")
|
target_compile_definitions(clio_options INTERFACE "HAS_SOURCE_LOCATION")
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
check_include_file_cxx("experimental/source_location" EXPERIMENTAL_SOURCE_LOCATION_AVAILABLE)
|
check_include_file_cxx("experimental/source_location" EXPERIMENTAL_SOURCE_LOCATION_AVAILABLE)
|
||||||
if (EXPERIMENTAL_SOURCE_LOCATION_AVAILABLE)
|
if (EXPERIMENTAL_SOURCE_LOCATION_AVAILABLE)
|
||||||
target_compile_definitions(clio_options INTERFACE "HAS_EXPERIMENTAL_SOURCE_LOCATION")
|
target_compile_definitions(clio_options INTERFACE "HAS_EXPERIMENTAL_SOURCE_LOCATION")
|
||||||
endif ()
|
endif ()
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
if ("${san}" STREQUAL "")
|
if ("${san}" STREQUAL "")
|
||||||
target_compile_definitions(clio_options INTERFACE BOOST_STACKTRACE_LINK)
|
target_compile_definitions(clio_options INTERFACE BOOST_STACKTRACE_LINK)
|
||||||
target_compile_definitions(clio_options INTERFACE BOOST_STACKTRACE_USE_BACKTRACE)
|
target_compile_definitions(clio_options INTERFACE BOOST_STACKTRACE_USE_BACKTRACE)
|
||||||
find_package(libbacktrace REQUIRED CONFIG)
|
find_package(libbacktrace REQUIRED CONFIG)
|
||||||
else ()
|
else ()
|
||||||
# Some sanitizers (TSAN and ASAN for sure) can't be used with libbacktrace because they have their own backtracing
|
# Some sanitizers (TSAN and ASAN for sure) can't be used with libbacktrace because they have their own backtracing
|
||||||
# capabilities and there are conflicts. In any case, this makes sure Clio code knows that backtrace is not
|
# capabilities and there are conflicts. In any case, this makes sure Clio code knows that backtrace is not available.
|
||||||
# available. See relevant conan profiles for sanitizers where we disable stacktrace in Boost explicitly.
|
# See relevant conan profiles for sanitizers where we disable stacktrace in Boost explicitly.
|
||||||
target_compile_definitions(clio_options INTERFACE CLIO_WITHOUT_STACKTRACE)
|
target_compile_definitions(clio_options INTERFACE CLIO_WITHOUT_STACKTRACE)
|
||||||
message(STATUS "Sanitizer enabled, disabling stacktrace")
|
message(STATUS "Sanitizer enabled, disabling stacktrace")
|
||||||
endif ()
|
endif ()
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
find_package(spdlog REQUIRED)
|
find_package(spdlog REQUIRED)
|
||||||
|
|
||||||
if (NOT TARGET spdlog::spdlog)
|
if (NOT TARGET spdlog::spdlog)
|
||||||
message(FATAL_ERROR "spdlog::spdlog target not found")
|
message(FATAL_ERROR "spdlog::spdlog target not found")
|
||||||
endif ()
|
endif ()
|
||||||
|
|||||||
41
conan.lock
41
conan.lock
@@ -1,42 +1,42 @@
|
|||||||
{
|
{
|
||||||
"version": "0.5",
|
"version": "0.5",
|
||||||
"requires": [
|
"requires": [
|
||||||
"zlib/1.3.1#b8bc2603263cf7eccbd6e17e66b0ed76%1765850150.075",
|
"zlib/1.3.1#b8bc2603263cf7eccbd6e17e66b0ed76%1756234269.497",
|
||||||
"xxhash/0.8.3#681d36a0a6111fc56e5e45ea182c19cc%1765850149.987",
|
"xxhash/0.8.3#681d36a0a6111fc56e5e45ea182c19cc%1756234289.683",
|
||||||
"xrpl/3.0.0#534d3f65a336109eee929b88962bae4e%1765375071.547",
|
"xrpl/3.0.0#534d3f65a336109eee929b88962bae4e%1765375071.547",
|
||||||
"sqlite3/3.49.1#8631739a4c9b93bd3d6b753bac548a63%1765850149.926",
|
"sqlite3/3.49.1#8631739a4c9b93bd3d6b753bac548a63%1756234266.869",
|
||||||
"spdlog/1.17.0#bcbaaf7147bda6ad24ffbd1ac3d7142c%1767636069.964",
|
"spdlog/1.16.0#942c2c39562ae25ba575d9c8e2bdf3b6%1763984117.108",
|
||||||
"soci/4.0.3#a9f8d773cd33e356b5879a4b0564f287%1765850149.46",
|
"soci/4.0.3#a9f8d773cd33e356b5879a4b0564f287%1756234262.318",
|
||||||
"re2/20230301#ca3b241baec15bd31ea9187150e0b333%1765850148.103",
|
"re2/20230301#ca3b241baec15bd31ea9187150e0b333%1764175362.029",
|
||||||
"rapidjson/cci.20220822#1b9d8c2256876a154172dc5cfbe447c6%1754325007.656",
|
"rapidjson/cci.20220822#1b9d8c2256876a154172dc5cfbe447c6%1754325007.656",
|
||||||
"protobuf/3.21.12#44ee56c0a6eea0c19aeeaca680370b88%1764175361.456",
|
"protobuf/3.21.12#44ee56c0a6eea0c19aeeaca680370b88%1764175361.456",
|
||||||
"openssl/1.1.1w#a8f0792d7c5121b954578a7149d23e03%1756223730.729",
|
"openssl/1.1.1w#a8f0792d7c5121b954578a7149d23e03%1756223730.729",
|
||||||
"nudb/2.0.9#fb8dfd1a5557f5e0528114c2da17721e%1765850143.957",
|
"nudb/2.0.9#fb8dfd1a5557f5e0528114c2da17721e%1763150366.909",
|
||||||
"minizip/1.2.13#9e87d57804bd372d6d1e32b1871517a3%1754325004.374",
|
"minizip/1.2.13#9e87d57804bd372d6d1e32b1871517a3%1754325004.374",
|
||||||
"lz4/1.10.0#59fc63cac7f10fbe8e05c7e62c2f3504%1765850143.914",
|
"lz4/1.10.0#59fc63cac7f10fbe8e05c7e62c2f3504%1756234228.999",
|
||||||
"libuv/1.46.0#dc28c1f653fa197f00db5b577a6f6011%1754325003.592",
|
"libuv/1.46.0#dc28c1f653fa197f00db5b577a6f6011%1754325003.592",
|
||||||
"libiconv/1.17#1e65319e945f2d31941a9d28cc13c058%1765842973.492",
|
"libiconv/1.17#1e65319e945f2d31941a9d28cc13c058%1756223727.64",
|
||||||
"libbacktrace/cci.20210118#a7691bfccd8caaf66309df196790a5a1%1765842973.03",
|
"libbacktrace/cci.20210118#a7691bfccd8caaf66309df196790a5a1%1756230911.03",
|
||||||
"libarchive/3.8.1#ffee18995c706e02bf96e7a2f7042e0d%1765850144.736",
|
"libarchive/3.8.1#ffee18995c706e02bf96e7a2f7042e0d%1764175360.142",
|
||||||
"http_parser/2.9.4#98d91690d6fd021e9e624218a85d9d97%1754325001.385",
|
"http_parser/2.9.4#98d91690d6fd021e9e624218a85d9d97%1754325001.385",
|
||||||
"gtest/1.17.0#5224b3b3ff3b4ce1133cbdd27d53ee7d%1755784855.585",
|
"gtest/1.14.0#f8f0757a574a8dd747d16af62d6eb1b7%1754325000.842",
|
||||||
"grpc/1.50.1#02291451d1e17200293a409410d1c4e1%1756234248.958",
|
"grpc/1.50.1#02291451d1e17200293a409410d1c4e1%1756234248.958",
|
||||||
"fmt/12.1.0#50abab23274d56bb8f42c94b3b9a40c7%1763984116.926",
|
"fmt/12.1.0#50abab23274d56bb8f42c94b3b9a40c7%1763984116.926",
|
||||||
"doctest/2.4.11#a4211dfc329a16ba9f280f9574025659%1756234220.819",
|
"doctest/2.4.11#a4211dfc329a16ba9f280f9574025659%1756234220.819",
|
||||||
"date/3.0.4#862e11e80030356b53c2c38599ceb32b%1765850143.772",
|
"date/3.0.4#862e11e80030356b53c2c38599ceb32b%1763584497.32",
|
||||||
"cassandra-cpp-driver/2.17.0#bd3934138689482102c265d01288a316%1764175359.611",
|
"cassandra-cpp-driver/2.17.0#bd3934138689482102c265d01288a316%1764175359.611",
|
||||||
"c-ares/1.34.5#5581c2b62a608b40bb85d965ab3ec7c8%1765850144.336",
|
"c-ares/1.34.5#5581c2b62a608b40bb85d965ab3ec7c8%1764175359.429",
|
||||||
"bzip2/1.0.8#c470882369c2d95c5c77e970c0c7e321%1765850143.837",
|
"bzip2/1.0.8#c470882369c2d95c5c77e970c0c7e321%1764175359.429",
|
||||||
"boost/1.83.0#91d8b1572534d2c334d6790e3c34d0c1%1764175359.61",
|
"boost/1.83.0#91d8b1572534d2c334d6790e3c34d0c1%1764175359.61",
|
||||||
"benchmark/1.9.4#ce4403f7a24d3e1f907cd9da4b678be4%1754578869.672",
|
"benchmark/1.9.4#ce4403f7a24d3e1f907cd9da4b678be4%1754578869.672",
|
||||||
"abseil/20230802.1#90ba607d4ee8fb5fb157c3db540671fc%1764175359.429"
|
"abseil/20230802.1#90ba607d4ee8fb5fb157c3db540671fc%1764175359.429"
|
||||||
],
|
],
|
||||||
"build_requires": [
|
"build_requires": [
|
||||||
"zlib/1.3.1#b8bc2603263cf7eccbd6e17e66b0ed76%1765850150.075",
|
"zlib/1.3.1#b8bc2603263cf7eccbd6e17e66b0ed76%1756234269.497",
|
||||||
"protobuf/3.21.12#44ee56c0a6eea0c19aeeaca680370b88%1764175361.456",
|
"protobuf/3.21.12#44ee56c0a6eea0c19aeeaca680370b88%1764175361.456",
|
||||||
"cmake/4.2.0#ae0a44f44a1ef9ab68fd4b3e9a1f8671%1765850153.937",
|
"cmake/4.2.0#ae0a44f44a1ef9ab68fd4b3e9a1f8671%1764175359.44",
|
||||||
"cmake/3.31.10#313d16a1aa16bbdb2ca0792467214b76%1765850153.479",
|
"cmake/3.31.10#313d16a1aa16bbdb2ca0792467214b76%1764175359.429",
|
||||||
"b2/5.3.3#107c15377719889654eb9a162a673975%1765850144.355"
|
"b2/5.3.3#107c15377719889654eb9a162a673975%1756234226.28"
|
||||||
],
|
],
|
||||||
"python_requires": [],
|
"python_requires": [],
|
||||||
"overrides": {
|
"overrides": {
|
||||||
@@ -53,6 +53,9 @@
|
|||||||
],
|
],
|
||||||
"sqlite3/3.44.2": [
|
"sqlite3/3.44.2": [
|
||||||
"sqlite3/3.49.1"
|
"sqlite3/3.49.1"
|
||||||
|
],
|
||||||
|
"fmt/12.0.0": [
|
||||||
|
"fmt/12.1.0"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"config_requires": []
|
"config_requires": []
|
||||||
|
|||||||
20
conanfile.py
20
conanfile.py
@@ -14,37 +14,37 @@ class ClioConan(ConanFile):
|
|||||||
requires = [
|
requires = [
|
||||||
"boost/1.83.0",
|
"boost/1.83.0",
|
||||||
"cassandra-cpp-driver/2.17.0",
|
"cassandra-cpp-driver/2.17.0",
|
||||||
"fmt/12.1.0",
|
|
||||||
"grpc/1.50.1",
|
|
||||||
"libbacktrace/cci.20210118",
|
|
||||||
"openssl/1.1.1w",
|
|
||||||
"protobuf/3.21.12",
|
"protobuf/3.21.12",
|
||||||
"spdlog/1.17.0",
|
"grpc/1.50.1",
|
||||||
|
"openssl/1.1.1w",
|
||||||
"xrpl/3.0.0",
|
"xrpl/3.0.0",
|
||||||
"zlib/1.3.1",
|
"zlib/1.3.1",
|
||||||
|
"libbacktrace/cci.20210118",
|
||||||
|
"spdlog/1.16.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
default_options = {
|
default_options = {
|
||||||
|
"xrpl/*:tests": False,
|
||||||
|
"xrpl/*:rocksdb": False,
|
||||||
"cassandra-cpp-driver/*:shared": False,
|
"cassandra-cpp-driver/*:shared": False,
|
||||||
"date/*:header_only": True,
|
"date/*:header_only": True,
|
||||||
"grpc/*:secure": True,
|
|
||||||
"grpc/*:shared": False,
|
"grpc/*:shared": False,
|
||||||
"gtest/*:no_main": True,
|
"grpc/*:secure": True,
|
||||||
"libpq/*:shared": False,
|
"libpq/*:shared": False,
|
||||||
"lz4/*:shared": False,
|
"lz4/*:shared": False,
|
||||||
"openssl/*:shared": False,
|
"openssl/*:shared": False,
|
||||||
"protobuf/*:shared": False,
|
"protobuf/*:shared": False,
|
||||||
"protobuf/*:with_zlib": True,
|
"protobuf/*:with_zlib": True,
|
||||||
"snappy/*:shared": False,
|
"snappy/*:shared": False,
|
||||||
"xrpl/*:rocksdb": False,
|
"gtest/*:no_main": True,
|
||||||
"xrpl/*:tests": False,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports_sources = ("CMakeLists.txt", "cmake/*", "src/*")
|
exports_sources = ("CMakeLists.txt", "cmake/*", "src/*")
|
||||||
|
|
||||||
def requirements(self):
|
def requirements(self):
|
||||||
self.requires("gtest/1.17.0")
|
self.requires("gtest/1.14.0")
|
||||||
self.requires("benchmark/1.9.4")
|
self.requires("benchmark/1.9.4")
|
||||||
|
self.requires("fmt/12.1.0", force=True)
|
||||||
|
|
||||||
def configure(self):
|
def configure(self):
|
||||||
if self.settings.compiler == "apple-clang":
|
if self.settings.compiler == "apple-clang":
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ RUN pip install -q --no-cache-dir \
|
|||||||
# lxml 6.0.0 is not compatible with our image
|
# lxml 6.0.0 is not compatible with our image
|
||||||
'lxml<6.0.0' \
|
'lxml<6.0.0' \
|
||||||
cmake \
|
cmake \
|
||||||
conan==2.24.0 \
|
conan==2.22.1 \
|
||||||
gcovr \
|
gcovr \
|
||||||
# We're adding pre-commit to this image as well,
|
# We're adding pre-commit to this image as well,
|
||||||
# because clang-tidy workflow requires it
|
# because clang-tidy workflow requires it
|
||||||
|
|||||||
@@ -5,15 +5,15 @@ It is used in [Clio Github Actions](https://github.com/XRPLF/clio/actions) but c
|
|||||||
|
|
||||||
The image is based on Ubuntu 20.04 and contains:
|
The image is based on Ubuntu 20.04 and contains:
|
||||||
|
|
||||||
- ccache 4.12.2
|
- ccache 4.12.1
|
||||||
- Clang 19
|
- Clang 19
|
||||||
- ClangBuildAnalyzer 1.6.0
|
- ClangBuildAnalyzer 1.6.0
|
||||||
- Conan 2.24.0
|
- Conan 2.22.1
|
||||||
- Doxygen 1.16.1
|
- Doxygen 1.15.0
|
||||||
- GCC 15.2.0
|
- GCC 15.2.0
|
||||||
- GDB 17.1
|
- GDB 16.3
|
||||||
- gh 2.83.2
|
- gh 2.82.1
|
||||||
- git-cliff 2.11.0
|
- git-cliff 2.10.1
|
||||||
- mold 2.40.4
|
- mold 2.40.4
|
||||||
- Ninja 1.13.2
|
- Ninja 1.13.2
|
||||||
- Python 3.8
|
- Python 3.8
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
services:
|
services:
|
||||||
clio_develop:
|
clio_develop:
|
||||||
image: ghcr.io/xrplf/clio-ci:14342e087ceb8b593027198bf9ef06a43833c696
|
image: ghcr.io/xrplf/clio-ci:067449c3f8ae6755ea84752ea2962b589fe56c8f
|
||||||
volumes:
|
volumes:
|
||||||
- clio_develop_conan_data:/root/.conan2/p
|
- clio_develop_conan_data:/root/.conan2/p
|
||||||
- clio_develop_ccache:/root/.ccache
|
- clio_develop_ccache:/root/.ccache
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ RUN wget --progress=dot:giga "https://github.com/rui314/mold/archive/refs/tags/v
|
|||||||
&& ninja install \
|
&& ninja install \
|
||||||
&& rm -rf /tmp/* /var/tmp/*
|
&& rm -rf /tmp/* /var/tmp/*
|
||||||
|
|
||||||
ARG CCACHE_VERSION=4.12.2
|
ARG CCACHE_VERSION=4.12.1
|
||||||
RUN wget --progress=dot:giga "https://github.com/ccache/ccache/releases/download/v${CCACHE_VERSION}/ccache-${CCACHE_VERSION}.tar.gz" \
|
RUN wget --progress=dot:giga "https://github.com/ccache/ccache/releases/download/v${CCACHE_VERSION}/ccache-${CCACHE_VERSION}.tar.gz" \
|
||||||
&& tar xf "ccache-${CCACHE_VERSION}.tar.gz" \
|
&& tar xf "ccache-${CCACHE_VERSION}.tar.gz" \
|
||||||
&& cd "ccache-${CCACHE_VERSION}" \
|
&& cd "ccache-${CCACHE_VERSION}" \
|
||||||
@@ -59,7 +59,7 @@ RUN apt-get update \
|
|||||||
&& apt-get clean \
|
&& apt-get clean \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
ARG DOXYGEN_VERSION=1.16.1
|
ARG DOXYGEN_VERSION=1.15.0
|
||||||
RUN wget --progress=dot:giga "https://github.com/doxygen/doxygen/releases/download/Release_${DOXYGEN_VERSION//./_}/doxygen-${DOXYGEN_VERSION}.src.tar.gz" \
|
RUN wget --progress=dot:giga "https://github.com/doxygen/doxygen/releases/download/Release_${DOXYGEN_VERSION//./_}/doxygen-${DOXYGEN_VERSION}.src.tar.gz" \
|
||||||
&& tar xf "doxygen-${DOXYGEN_VERSION}.src.tar.gz" \
|
&& tar xf "doxygen-${DOXYGEN_VERSION}.src.tar.gz" \
|
||||||
&& cd "doxygen-${DOXYGEN_VERSION}" \
|
&& cd "doxygen-${DOXYGEN_VERSION}" \
|
||||||
@@ -79,13 +79,13 @@ RUN wget --progress=dot:giga "https://github.com/aras-p/ClangBuildAnalyzer/archi
|
|||||||
&& ninja install \
|
&& ninja install \
|
||||||
&& rm -rf /tmp/* /var/tmp/*
|
&& rm -rf /tmp/* /var/tmp/*
|
||||||
|
|
||||||
ARG GIT_CLIFF_VERSION=2.11.0
|
ARG GIT_CLIFF_VERSION=2.10.1
|
||||||
RUN wget --progress=dot:giga "https://github.com/orhun/git-cliff/releases/download/v${GIT_CLIFF_VERSION}/git-cliff-${GIT_CLIFF_VERSION}-x86_64-unknown-linux-musl.tar.gz" \
|
RUN wget --progress=dot:giga "https://github.com/orhun/git-cliff/releases/download/v${GIT_CLIFF_VERSION}/git-cliff-${GIT_CLIFF_VERSION}-x86_64-unknown-linux-musl.tar.gz" \
|
||||||
&& tar xf git-cliff-${GIT_CLIFF_VERSION}-x86_64-unknown-linux-musl.tar.gz \
|
&& tar xf git-cliff-${GIT_CLIFF_VERSION}-x86_64-unknown-linux-musl.tar.gz \
|
||||||
&& mv git-cliff-${GIT_CLIFF_VERSION}/git-cliff /usr/local/bin/git-cliff \
|
&& mv git-cliff-${GIT_CLIFF_VERSION}/git-cliff /usr/local/bin/git-cliff \
|
||||||
&& rm -rf /tmp/* /var/tmp/*
|
&& rm -rf /tmp/* /var/tmp/*
|
||||||
|
|
||||||
ARG GH_VERSION=2.83.2
|
ARG GH_VERSION=2.82.1
|
||||||
RUN wget --progress=dot:giga "https://github.com/cli/cli/releases/download/v${GH_VERSION}/gh_${GH_VERSION}_linux_${TARGETARCH}.tar.gz" \
|
RUN wget --progress=dot:giga "https://github.com/cli/cli/releases/download/v${GH_VERSION}/gh_${GH_VERSION}_linux_${TARGETARCH}.tar.gz" \
|
||||||
&& tar xf gh_${GH_VERSION}_linux_${TARGETARCH}.tar.gz \
|
&& tar xf gh_${GH_VERSION}_linux_${TARGETARCH}.tar.gz \
|
||||||
&& mv gh_${GH_VERSION}_linux_${TARGETARCH}/bin/gh /usr/local/bin/gh \
|
&& mv gh_${GH_VERSION}_linux_${TARGETARCH}/bin/gh /usr/local/bin/gh \
|
||||||
@@ -100,7 +100,7 @@ RUN apt-get update \
|
|||||||
&& apt-get clean \
|
&& apt-get clean \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
ARG GDB_VERSION=17.1
|
ARG GDB_VERSION=16.3
|
||||||
RUN wget --progress=dot:giga "https://sourceware.org/pub/gdb/releases/gdb-${GDB_VERSION}.tar.gz" \
|
RUN wget --progress=dot:giga "https://sourceware.org/pub/gdb/releases/gdb-${GDB_VERSION}.tar.gz" \
|
||||||
&& tar xf "gdb-${GDB_VERSION}.tar.gz" \
|
&& tar xf "gdb-${GDB_VERSION}.tar.gz" \
|
||||||
&& cd "gdb-${GDB_VERSION}" \
|
&& cd "gdb-${GDB_VERSION}" \
|
||||||
|
|||||||
@@ -97,14 +97,30 @@ Now you should be able to download the prebuilt dependencies (including `xrpl` p
|
|||||||
|
|
||||||
#### Conan lockfile
|
#### Conan lockfile
|
||||||
|
|
||||||
To achieve reproducible dependencies, we use a [Conan lockfile](https://docs.conan.io/2/tutorial/versioning/lockfiles.html).
|
To achieve reproducible dependencies, we use [Conan lockfile](https://docs.conan.io/2/tutorial/versioning/lockfiles.html).
|
||||||
|
|
||||||
The `conan.lock` file in the repository contains a "snapshot" of the current dependencies.
|
The `conan.lock` file in the repository contains a "snapshot" of the current dependencies.
|
||||||
It is implicitly used when running `conan` commands, you don't need to specify it.
|
It is implicitly used when running `conan` commands, you don't need to specify it.
|
||||||
|
|
||||||
You have to update this file every time you add a new dependency or change a revision or version of an existing dependency.
|
You have to update this file every time you add a new dependency or change a revision or version of an existing dependency.
|
||||||
|
|
||||||
To update a lockfile, run from the repository root: `./.github/scripts/conan/regenerate_lockfile.sh`
|
> [!NOTE]
|
||||||
|
> Conan uses local cache by default when creating a lockfile.
|
||||||
|
>
|
||||||
|
> To ensure, that lockfile creation works the same way on all developer machines, you should clear the local cache before creating a new lockfile.
|
||||||
|
|
||||||
|
To create a new lockfile, run the following commands in the repository root:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
conan remove '*' --confirm
|
||||||
|
rm conan.lock
|
||||||
|
# This ensure that xrplf remote is the first to be consulted
|
||||||
|
conan remote add --force --index 0 xrplf https://conan.ripplex.io
|
||||||
|
conan lock create .
|
||||||
|
```
|
||||||
|
|
||||||
|
> [!NOTE]
|
||||||
|
> If some dependencies are exclusive for some OS, you may need to run the last command for them adding `--profile:all <PROFILE>`.
|
||||||
|
|
||||||
## Building Clio
|
## Building Clio
|
||||||
|
|
||||||
@@ -175,7 +191,7 @@ Open the `index.html` file in your browser to see the documentation pages.
|
|||||||
It is also possible to build Clio using [Docker](https://www.docker.com/) if you don't want to install all the dependencies on your machine.
|
It is also possible to build Clio using [Docker](https://www.docker.com/) if you don't want to install all the dependencies on your machine.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
docker run -it ghcr.io/xrplf/clio-ci:14342e087ceb8b593027198bf9ef06a43833c696
|
docker run -it ghcr.io/xrplf/clio-ci:067449c3f8ae6755ea84752ea2962b589fe56c8f
|
||||||
git clone https://github.com/XRPLF/clio
|
git clone https://github.com/XRPLF/clio
|
||||||
cd clio
|
cd clio
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -457,14 +457,6 @@ This document provides a list of all available Clio configuration properties in
|
|||||||
- **Constraints**: None
|
- **Constraints**: None
|
||||||
- **Description**: Max allowed difference between the latest sequence in DB and in cache file. If the cache file is too old (contains too low latest sequence) Clio will reject using it.
|
- **Description**: Max allowed difference between the latest sequence in DB and in cache file. If the cache file is too old (contains too low latest sequence) Clio will reject using it.
|
||||||
|
|
||||||
### cache.file.async_save
|
|
||||||
|
|
||||||
- **Required**: True
|
|
||||||
- **Type**: boolean
|
|
||||||
- **Default value**: `False`
|
|
||||||
- **Constraints**: None
|
|
||||||
- **Description**: When false, Clio waits for cache saving to finish before shutting down. When true, cache saving runs in parallel with other shutdown operations.
|
|
||||||
|
|
||||||
### log.channels.[].channel
|
### log.channels.[].channel
|
||||||
|
|
||||||
- **Required**: False
|
- **Required**: False
|
||||||
|
|||||||
@@ -93,42 +93,3 @@ To completely disable Prometheus metrics add `"prometheus": { "enabled": false }
|
|||||||
It is important to know that Clio responds to Prometheus request only if they are admin requests. If you are using the admin password feature, the same password should be provided in the Authorization header of Prometheus requests.
|
It is important to know that Clio responds to Prometheus request only if they are admin requests. If you are using the admin password feature, the same password should be provided in the Authorization header of Prometheus requests.
|
||||||
|
|
||||||
You can find an example Docker Compose file, with Prometheus and Grafana configs, in [examples/infrastructure](../docs/examples/infrastructure/).
|
You can find an example Docker Compose file, with Prometheus and Grafana configs, in [examples/infrastructure](../docs/examples/infrastructure/).
|
||||||
|
|
||||||
## Ledger cache file
|
|
||||||
|
|
||||||
Since version 2.7.0, Clio supports saving the ledger cache to a local file on shutdown and loading it on startup. This feature is disabled by default but can significantly improve restart times.
|
|
||||||
|
|
||||||
### Benefits
|
|
||||||
|
|
||||||
- **Faster startup**: Loading cache from a file takes less than a minute, compared to 40-90 minutes on Mainnet when loading from the database.
|
|
||||||
- **Reduced database load**: Clio doesn't put extra load on the database when starting with a cache file.
|
|
||||||
- **Improved availability**: Faster restart times mean less downtime during maintenance or updates.
|
|
||||||
|
|
||||||
> [!NOTE]
|
|
||||||
> This feature only works when Clio is restarted. When starting Clio for the first time, the cache must be loaded from `rippled` or the database as usual.
|
|
||||||
|
|
||||||
### Configuration
|
|
||||||
|
|
||||||
To enable the ledger cache file feature, specify the [`cache.file.path`](./config-description.md#cachefilepath) option in your `config.json`:
|
|
||||||
|
|
||||||
```json
|
|
||||||
"cache": {
|
|
||||||
"file": {
|
|
||||||
"path": "/path/to/cache/file"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
You can optionally configure additional settings such as [`cache.file.max_sequence_age`](./config-description.md#cachefilemax_sequence_age) and [`cache.file.async_save`](./config-description.md#cachefileasync_save) to fine-tune the behavior. For a complete list of available options and their default values, see the [Configuration Description](./config-description.md#cachefilepath) documentation.
|
|
||||||
|
|
||||||
### How it works
|
|
||||||
|
|
||||||
1. **On shutdown**: Clio saves the current ledger cache to the specified file path. The file includes a hash for integrity verification.
|
|
||||||
2. **On startup**: Clio checks if a cache file exists at the configured path. If the file exists, Clio will:
|
|
||||||
- Verify the file's integrity to ensure it is complete and not corrupted.
|
|
||||||
- Compare the latest ledger sequence in the cache file with the latest sequence in the database.
|
|
||||||
- Use the cache file only if the difference is less than [`cache.file.max_sequence_age`](./config-description.md#cachefilemax_sequence_age).
|
|
||||||
- If validation fails or the cache is too old, Clio will fall back to loading from the database.
|
|
||||||
|
|
||||||
> [!IMPORTANT]
|
|
||||||
> The cache file path should point to a location with sufficient disk space. On typical deployments, the cache file size can be several gigabytes.
|
|
||||||
|
|||||||
@@ -2,11 +2,12 @@ add_library(clio_app)
|
|||||||
target_sources(clio_app PRIVATE CliArgs.cpp ClioApplication.cpp Stopper.cpp WebHandlers.cpp)
|
target_sources(clio_app PRIVATE CliArgs.cpp ClioApplication.cpp Stopper.cpp WebHandlers.cpp)
|
||||||
|
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
clio_app
|
clio_app
|
||||||
PUBLIC clio_cluster
|
PUBLIC clio_cluster
|
||||||
clio_etl
|
clio_etl
|
||||||
clio_feed
|
clio_feed
|
||||||
clio_migration
|
clio_migration
|
||||||
clio_rpc
|
clio_rpc
|
||||||
clio_web
|
clio_web
|
||||||
PRIVATE Boost::program_options)
|
PRIVATE Boost::program_options
|
||||||
|
)
|
||||||
|
|||||||
@@ -77,10 +77,7 @@ CliArgs::parse(int argc, char const* argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (parsed.contains("version")) {
|
if (parsed.contains("version")) {
|
||||||
std::cout << util::build::getClioFullVersionString() << '\n'
|
std::cout << util::build::getClioFullVersionString() << '\n';
|
||||||
<< "Git commit hash: " << util::build::getGitCommitHash() << '\n'
|
|
||||||
<< "Git build branch: " << util::build::getGitBuildBranch() << '\n'
|
|
||||||
<< "Build date: " << util::build::getBuildDate() << '\n';
|
|
||||||
return Action{Action::Exit{EXIT_SUCCESS}};
|
return Action{Action::Exit{EXIT_SUCCESS}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,8 +29,6 @@
|
|||||||
#include "etl/ETLService.hpp"
|
#include "etl/ETLService.hpp"
|
||||||
#include "etl/LoadBalancer.hpp"
|
#include "etl/LoadBalancer.hpp"
|
||||||
#include "etl/NetworkValidatedLedgers.hpp"
|
#include "etl/NetworkValidatedLedgers.hpp"
|
||||||
#include "etl/SystemState.hpp"
|
|
||||||
#include "etl/WriterState.hpp"
|
|
||||||
#include "feed/SubscriptionManager.hpp"
|
#include "feed/SubscriptionManager.hpp"
|
||||||
#include "migration/MigrationInspectorFactory.hpp"
|
#include "migration/MigrationInspectorFactory.hpp"
|
||||||
#include "rpc/Counters.hpp"
|
#include "rpc/Counters.hpp"
|
||||||
@@ -123,11 +121,7 @@ ClioApplication::run(bool const useNgWebServer)
|
|||||||
// Interface to the database
|
// Interface to the database
|
||||||
auto backend = data::makeBackend(config_, cache);
|
auto backend = data::makeBackend(config_, cache);
|
||||||
|
|
||||||
auto systemState = etl::SystemState::makeSystemState(config_);
|
cluster::ClusterCommunicationService clusterCommunicationService{backend};
|
||||||
|
|
||||||
cluster::ClusterCommunicationService clusterCommunicationService{
|
|
||||||
backend, std::make_unique<etl::WriterState>(systemState)
|
|
||||||
};
|
|
||||||
clusterCommunicationService.run();
|
clusterCommunicationService.run();
|
||||||
|
|
||||||
auto const amendmentCenter = std::make_shared<data::AmendmentCenter const>(backend);
|
auto const amendmentCenter = std::make_shared<data::AmendmentCenter const>(backend);
|
||||||
@@ -157,9 +151,7 @@ ClioApplication::run(bool const useNgWebServer)
|
|||||||
);
|
);
|
||||||
|
|
||||||
// ETL is responsible for writing and publishing to streams. In read-only mode, ETL only publishes
|
// ETL is responsible for writing and publishing to streams. In read-only mode, ETL only publishes
|
||||||
auto etl = etl::ETLService::makeETLService(
|
auto etl = etl::ETLService::makeETLService(config_, ctx, backend, subscriptions, balancer, ledgers);
|
||||||
config_, std::move(systemState), ctx, backend, subscriptions, balancer, ledgers
|
|
||||||
);
|
|
||||||
|
|
||||||
auto workQueue = rpc::WorkQueue::makeWorkQueue(config_);
|
auto workQueue = rpc::WorkQueue::makeWorkQueue(config_);
|
||||||
auto counters = rpc::Counters::makeCounters(workQueue);
|
auto counters = rpc::Counters::makeCounters(workQueue);
|
||||||
@@ -205,16 +197,7 @@ ClioApplication::run(bool const useNgWebServer)
|
|||||||
}
|
}
|
||||||
|
|
||||||
appStopper_.setOnStop(
|
appStopper_.setOnStop(
|
||||||
Stopper::makeOnStopCallback(
|
Stopper::makeOnStopCallback(httpServer.value(), *balancer, *etl, *subscriptions, *backend, cacheSaver, ioc)
|
||||||
httpServer.value(),
|
|
||||||
*balancer,
|
|
||||||
*etl,
|
|
||||||
*subscriptions,
|
|
||||||
*backend,
|
|
||||||
cacheSaver,
|
|
||||||
clusterCommunicationService,
|
|
||||||
ioc
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Blocks until stopped.
|
// Blocks until stopped.
|
||||||
@@ -230,9 +213,7 @@ ClioApplication::run(bool const useNgWebServer)
|
|||||||
|
|
||||||
auto const httpServer = web::makeHttpServer(config_, ioc, dosGuard, handler, cache);
|
auto const httpServer = web::makeHttpServer(config_, ioc, dosGuard, handler, cache);
|
||||||
appStopper_.setOnStop(
|
appStopper_.setOnStop(
|
||||||
Stopper::makeOnStopCallback(
|
Stopper::makeOnStopCallback(*httpServer, *balancer, *etl, *subscriptions, *backend, cacheSaver, ioc)
|
||||||
*httpServer, *balancer, *etl, *subscriptions, *backend, cacheSaver, clusterCommunicationService, ioc
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Blocks until stopped.
|
// Blocks until stopped.
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "cluster/Concepts.hpp"
|
|
||||||
#include "data/BackendInterface.hpp"
|
#include "data/BackendInterface.hpp"
|
||||||
#include "data/LedgerCacheSaver.hpp"
|
#include "data/LedgerCacheSaver.hpp"
|
||||||
#include "etl/ETLServiceInterface.hpp"
|
#include "etl/ETLServiceInterface.hpp"
|
||||||
@@ -83,14 +82,10 @@ public:
|
|||||||
* @param subscriptions The subscription manager to stop.
|
* @param subscriptions The subscription manager to stop.
|
||||||
* @param backend The backend to stop.
|
* @param backend The backend to stop.
|
||||||
* @param cacheSaver The ledger cache saver
|
* @param cacheSaver The ledger cache saver
|
||||||
* @param clusterCommunicationService The cluster communication service to stop.
|
|
||||||
* @param ioc The io_context to stop.
|
* @param ioc The io_context to stop.
|
||||||
* @return The callback to be called on application stop.
|
* @return The callback to be called on application stop.
|
||||||
*/
|
*/
|
||||||
template <
|
template <web::SomeServer ServerType, data::SomeLedgerCacheSaver LedgerCacheSaverType>
|
||||||
web::SomeServer ServerType,
|
|
||||||
data::SomeLedgerCacheSaver LedgerCacheSaverType,
|
|
||||||
cluster::SomeClusterCommunicationService ClusterCommunicationServiceType>
|
|
||||||
static std::function<void(boost::asio::yield_context)>
|
static std::function<void(boost::asio::yield_context)>
|
||||||
makeOnStopCallback(
|
makeOnStopCallback(
|
||||||
ServerType& server,
|
ServerType& server,
|
||||||
@@ -99,7 +94,6 @@ public:
|
|||||||
feed::SubscriptionManagerInterface& subscriptions,
|
feed::SubscriptionManagerInterface& subscriptions,
|
||||||
data::BackendInterface& backend,
|
data::BackendInterface& backend,
|
||||||
LedgerCacheSaverType& cacheSaver,
|
LedgerCacheSaverType& cacheSaver,
|
||||||
ClusterCommunicationServiceType& clusterCommunicationService,
|
|
||||||
boost::asio::io_context& ioc
|
boost::asio::io_context& ioc
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@@ -117,8 +111,6 @@ public:
|
|||||||
});
|
});
|
||||||
coroutineGroup.asyncWait(yield);
|
coroutineGroup.asyncWait(yield);
|
||||||
|
|
||||||
clusterCommunicationService.stop();
|
|
||||||
|
|
||||||
etl.stop();
|
etl.stop();
|
||||||
LOG(util::LogService::info()) << "ETL stopped";
|
LOG(util::LogService::info()) << "ETL stopped";
|
||||||
|
|
||||||
|
|||||||
@@ -1,134 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
/*
|
|
||||||
This file is part of clio: https://github.com/XRPLF/clio
|
|
||||||
Copyright (c) 2025, the clio developers.
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
//==============================================================================
|
|
||||||
|
|
||||||
#include "cluster/Backend.hpp"
|
|
||||||
|
|
||||||
#include "cluster/ClioNode.hpp"
|
|
||||||
#include "data/BackendInterface.hpp"
|
|
||||||
#include "etl/WriterState.hpp"
|
|
||||||
|
|
||||||
#include <boost/asio/spawn.hpp>
|
|
||||||
#include <boost/asio/thread_pool.hpp>
|
|
||||||
#include <boost/json/parse.hpp>
|
|
||||||
#include <boost/json/serialize.hpp>
|
|
||||||
#include <boost/json/value.hpp>
|
|
||||||
#include <boost/json/value_from.hpp>
|
|
||||||
#include <boost/json/value_to.hpp>
|
|
||||||
#include <boost/uuid/random_generator.hpp>
|
|
||||||
#include <boost/uuid/uuid.hpp>
|
|
||||||
#include <fmt/format.h>
|
|
||||||
|
|
||||||
#include <chrono>
|
|
||||||
#include <memory>
|
|
||||||
#include <utility>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace cluster {
|
|
||||||
|
|
||||||
Backend::Backend(
|
|
||||||
boost::asio::thread_pool& ctx,
|
|
||||||
std::shared_ptr<data::BackendInterface> backend,
|
|
||||||
std::unique_ptr<etl::WriterStateInterface const> writerState,
|
|
||||||
std::chrono::steady_clock::duration readInterval,
|
|
||||||
std::chrono::steady_clock::duration writeInterval
|
|
||||||
)
|
|
||||||
: backend_(std::move(backend))
|
|
||||||
, writerState_(std::move(writerState))
|
|
||||||
, readerTask_(readInterval, ctx)
|
|
||||||
, writerTask_(writeInterval, ctx)
|
|
||||||
, selfUuid_(std::make_shared<boost::uuids::uuid>(boost::uuids::random_generator{}()))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
Backend::run()
|
|
||||||
{
|
|
||||||
readerTask_.run([this](boost::asio::yield_context yield) {
|
|
||||||
auto clusterData = doRead(yield);
|
|
||||||
onNewState_(selfUuid_, std::make_shared<ClusterData>(std::move(clusterData)));
|
|
||||||
});
|
|
||||||
|
|
||||||
writerTask_.run([this]() { doWrite(); });
|
|
||||||
}
|
|
||||||
|
|
||||||
Backend::~Backend()
|
|
||||||
{
|
|
||||||
stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
Backend::stop()
|
|
||||||
{
|
|
||||||
readerTask_.stop();
|
|
||||||
writerTask_.stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
ClioNode::CUuid
|
|
||||||
Backend::selfId() const
|
|
||||||
{
|
|
||||||
return selfUuid_;
|
|
||||||
}
|
|
||||||
|
|
||||||
Backend::ClusterData
|
|
||||||
Backend::doRead(boost::asio::yield_context yield)
|
|
||||||
{
|
|
||||||
BackendInterface::ClioNodesDataFetchResult expectedResult;
|
|
||||||
try {
|
|
||||||
expectedResult = backend_->fetchClioNodesData(yield);
|
|
||||||
} catch (...) {
|
|
||||||
expectedResult = std::unexpected{"Failed to fetch Clio nodes data"};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!expectedResult.has_value()) {
|
|
||||||
return std::unexpected{std::move(expectedResult).error()};
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<ClioNode> otherNodesData;
|
|
||||||
for (auto const& [uuid, nodeDataStr] : expectedResult.value()) {
|
|
||||||
if (uuid == *selfUuid_) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
boost::system::error_code errorCode;
|
|
||||||
auto const json = boost::json::parse(nodeDataStr, errorCode);
|
|
||||||
if (errorCode.failed()) {
|
|
||||||
return std::unexpected{fmt::format("Error parsing json from DB: {}", nodeDataStr)};
|
|
||||||
}
|
|
||||||
|
|
||||||
auto expectedNodeData = boost::json::try_value_to<ClioNode>(json);
|
|
||||||
if (expectedNodeData.has_error()) {
|
|
||||||
return std::unexpected{fmt::format("Error converting json to ClioNode: {}", nodeDataStr)};
|
|
||||||
}
|
|
||||||
*expectedNodeData->uuid = uuid;
|
|
||||||
otherNodesData.push_back(std::move(expectedNodeData).value());
|
|
||||||
}
|
|
||||||
otherNodesData.push_back(ClioNode::from(selfUuid_, *writerState_));
|
|
||||||
return otherNodesData;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
Backend::doWrite()
|
|
||||||
{
|
|
||||||
auto const selfData = ClioNode::from(selfUuid_, *writerState_);
|
|
||||||
boost::json::value jsonValue{};
|
|
||||||
boost::json::value_from(selfData, jsonValue);
|
|
||||||
backend_->writeNodeMessage(*selfData.uuid, boost::json::serialize(jsonValue.as_object()));
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace cluster
|
|
||||||
@@ -1,147 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
/*
|
|
||||||
This file is part of clio: https://github.com/XRPLF/clio
|
|
||||||
Copyright (c) 2025, the clio developers.
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
//==============================================================================
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "cluster/ClioNode.hpp"
|
|
||||||
#include "cluster/impl/RepeatedTask.hpp"
|
|
||||||
#include "data/BackendInterface.hpp"
|
|
||||||
#include "etl/WriterState.hpp"
|
|
||||||
#include "util/log/Logger.hpp"
|
|
||||||
|
|
||||||
#include <boost/asio/any_io_executor.hpp>
|
|
||||||
#include <boost/asio/cancellation_signal.hpp>
|
|
||||||
#include <boost/asio/execution_context.hpp>
|
|
||||||
#include <boost/asio/executor.hpp>
|
|
||||||
#include <boost/asio/spawn.hpp>
|
|
||||||
#include <boost/asio/strand.hpp>
|
|
||||||
#include <boost/asio/thread_pool.hpp>
|
|
||||||
#include <boost/signals2/connection.hpp>
|
|
||||||
#include <boost/signals2/signal.hpp>
|
|
||||||
#include <boost/signals2/variadic_signal.hpp>
|
|
||||||
#include <boost/uuid/uuid.hpp>
|
|
||||||
|
|
||||||
#include <chrono>
|
|
||||||
#include <concepts>
|
|
||||||
#include <memory>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace cluster {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Backend communication handler for cluster state synchronization.
|
|
||||||
*
|
|
||||||
* This class manages reading and writing cluster state information to/from the backend database.
|
|
||||||
* It periodically reads the state of other nodes in the cluster and writes the current node's state,
|
|
||||||
* enabling cluster-wide coordination and awareness.
|
|
||||||
*/
|
|
||||||
class Backend {
|
|
||||||
public:
|
|
||||||
/** @brief Type representing cluster data result - either a vector of nodes or an error message */
|
|
||||||
using ClusterData = std::expected<std::vector<ClioNode>, std::string>;
|
|
||||||
|
|
||||||
private:
|
|
||||||
util::Logger log_{"ClusterCommunication"};
|
|
||||||
|
|
||||||
std::shared_ptr<data::BackendInterface> backend_;
|
|
||||||
std::unique_ptr<etl::WriterStateInterface const> writerState_;
|
|
||||||
|
|
||||||
impl::RepeatedTask<boost::asio::thread_pool> readerTask_;
|
|
||||||
impl::RepeatedTask<boost::asio::thread_pool> writerTask_;
|
|
||||||
|
|
||||||
ClioNode::Uuid selfUuid_;
|
|
||||||
|
|
||||||
boost::signals2::signal<void(ClioNode::CUuid, std::shared_ptr<ClusterData const>)> onNewState_;
|
|
||||||
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* @brief Construct a Backend communication handler.
|
|
||||||
*
|
|
||||||
* @param ctx The execution context for asynchronous operations
|
|
||||||
* @param backend Interface to the backend database
|
|
||||||
* @param writerState State indicating whether this node is writing to the database
|
|
||||||
* @param readInterval How often to read cluster state from the backend
|
|
||||||
* @param writeInterval How often to write this node's state to the backend
|
|
||||||
*/
|
|
||||||
Backend(
|
|
||||||
boost::asio::thread_pool& ctx,
|
|
||||||
std::shared_ptr<data::BackendInterface> backend,
|
|
||||||
std::unique_ptr<etl::WriterStateInterface const> writerState,
|
|
||||||
std::chrono::steady_clock::duration readInterval,
|
|
||||||
std::chrono::steady_clock::duration writeInterval
|
|
||||||
);
|
|
||||||
|
|
||||||
~Backend();
|
|
||||||
|
|
||||||
Backend(Backend&&) = delete;
|
|
||||||
Backend&
|
|
||||||
operator=(Backend&&) = delete;
|
|
||||||
Backend(Backend const&) = delete;
|
|
||||||
Backend&
|
|
||||||
operator=(Backend const&) = delete;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Start the backend read and write tasks.
|
|
||||||
*
|
|
||||||
* Begins periodic reading of cluster state from the backend and writing of this node's state.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
run();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Stop the backend read and write tasks.
|
|
||||||
*
|
|
||||||
* Stops all periodic tasks and waits for them to complete.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
stop();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Subscribe to new cluster state notifications.
|
|
||||||
*
|
|
||||||
* @tparam S Callable type accepting (ClioNode::cUUID, ClusterData)
|
|
||||||
* @param s Subscriber callback to be invoked when new cluster state is available
|
|
||||||
* @return A connection object that can be used to unsubscribe
|
|
||||||
*/
|
|
||||||
template <typename S>
|
|
||||||
requires std::invocable<S, ClioNode::CUuid, std::shared_ptr<ClusterData const>>
|
|
||||||
boost::signals2::connection
|
|
||||||
subscribeToNewState(S&& s)
|
|
||||||
{
|
|
||||||
return onNewState_.connect(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Get the UUID of this node in the cluster.
|
|
||||||
*
|
|
||||||
* @return The UUID of this node.
|
|
||||||
*/
|
|
||||||
ClioNode::CUuid
|
|
||||||
selfId() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
ClusterData
|
|
||||||
doRead(boost::asio::yield_context yield);
|
|
||||||
|
|
||||||
void
|
|
||||||
doWrite();
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace cluster
|
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
add_library(clio_cluster)
|
add_library(clio_cluster)
|
||||||
|
|
||||||
target_sources(clio_cluster PRIVATE Backend.cpp ClioNode.cpp ClusterCommunicationService.cpp Metrics.cpp
|
target_sources(clio_cluster PRIVATE ClioNode.cpp ClusterCommunicationService.cpp)
|
||||||
WriterDecider.cpp)
|
|
||||||
|
|
||||||
target_link_libraries(clio_cluster PRIVATE clio_util clio_data)
|
target_link_libraries(clio_cluster PRIVATE clio_util clio_data)
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
#include "cluster/ClioNode.hpp"
|
#include "cluster/ClioNode.hpp"
|
||||||
|
|
||||||
#include "etl/WriterState.hpp"
|
|
||||||
#include "util/TimeUtils.hpp"
|
#include "util/TimeUtils.hpp"
|
||||||
|
|
||||||
#include <boost/json/conversion.hpp>
|
#include <boost/json/conversion.hpp>
|
||||||
@@ -27,72 +26,39 @@
|
|||||||
#include <boost/json/value.hpp>
|
#include <boost/json/value.hpp>
|
||||||
#include <boost/uuid/uuid.hpp>
|
#include <boost/uuid/uuid.hpp>
|
||||||
|
|
||||||
#include <chrono>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
namespace cluster {
|
namespace cluster {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
struct JsonFields {
|
struct Fields {
|
||||||
static constexpr std::string_view const kUPDATE_TIME = "update_time";
|
static constexpr std::string_view const kUPDATE_TIME = "update_time";
|
||||||
static constexpr std::string_view const kDB_ROLE = "db_role";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
ClioNode
|
|
||||||
ClioNode::from(ClioNode::Uuid uuid, etl::WriterStateInterface const& writerState)
|
|
||||||
{
|
|
||||||
auto const dbRole = [&writerState]() {
|
|
||||||
if (writerState.isReadOnly()) {
|
|
||||||
return ClioNode::DbRole::ReadOnly;
|
|
||||||
}
|
|
||||||
if (writerState.isFallback()) {
|
|
||||||
return ClioNode::DbRole::Fallback;
|
|
||||||
}
|
|
||||||
if (writerState.isLoadingCache()) {
|
|
||||||
return ClioNode::DbRole::LoadingCache;
|
|
||||||
}
|
|
||||||
|
|
||||||
return writerState.isWriting() ? ClioNode::DbRole::Writer : ClioNode::DbRole::NotWriter;
|
|
||||||
}();
|
|
||||||
return ClioNode{.uuid = std::move(uuid), .updateTime = std::chrono::system_clock::now(), .dbRole = dbRole};
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
tag_invoke(boost::json::value_from_tag, boost::json::value& jv, ClioNode const& node)
|
tag_invoke(boost::json::value_from_tag, boost::json::value& jv, ClioNode const& node)
|
||||||
{
|
{
|
||||||
jv = {
|
jv = {
|
||||||
{JsonFields::kUPDATE_TIME, util::systemTpToUtcStr(node.updateTime, ClioNode::kTIME_FORMAT)},
|
{Fields::kUPDATE_TIME, util::systemTpToUtcStr(node.updateTime, ClioNode::kTIME_FORMAT)},
|
||||||
{JsonFields::kDB_ROLE, static_cast<int64_t>(node.dbRole)}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
ClioNode
|
ClioNode
|
||||||
tag_invoke(boost::json::value_to_tag<ClioNode>, boost::json::value const& jv)
|
tag_invoke(boost::json::value_to_tag<ClioNode>, boost::json::value const& jv)
|
||||||
{
|
{
|
||||||
auto const& updateTimeStr = jv.as_object().at(JsonFields::kUPDATE_TIME).as_string();
|
auto const& updateTimeStr = jv.as_object().at(Fields::kUPDATE_TIME).as_string();
|
||||||
auto const updateTime = util::systemTpFromUtcStr(std::string(updateTimeStr), ClioNode::kTIME_FORMAT);
|
auto const updateTime = util::systemTpFromUtcStr(std::string(updateTimeStr), ClioNode::kTIME_FORMAT);
|
||||||
if (!updateTime.has_value()) {
|
if (!updateTime.has_value()) {
|
||||||
throw std::runtime_error("Failed to parse update time");
|
throw std::runtime_error("Failed to parse update time");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto const dbRoleValue = jv.as_object().at(JsonFields::kDB_ROLE).as_int64();
|
return ClioNode{.uuid = std::make_shared<boost::uuids::uuid>(), .updateTime = updateTime.value()};
|
||||||
if (dbRoleValue > static_cast<int64_t>(ClioNode::DbRole::MAX))
|
|
||||||
throw std::runtime_error("Invalid db_role value");
|
|
||||||
|
|
||||||
return ClioNode{
|
|
||||||
// Json data doesn't contain uuid so leaving it empty here. It will be filled outside of this parsing
|
|
||||||
.uuid = std::make_shared<boost::uuids::uuid>(),
|
|
||||||
.updateTime = updateTime.value(),
|
|
||||||
.dbRole = static_cast<ClioNode::DbRole>(dbRoleValue)
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace cluster
|
} // namespace cluster
|
||||||
|
|||||||
@@ -19,8 +19,6 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "etl/WriterState.hpp"
|
|
||||||
|
|
||||||
#include <boost/json/conversion.hpp>
|
#include <boost/json/conversion.hpp>
|
||||||
#include <boost/json/value.hpp>
|
#include <boost/json/value.hpp>
|
||||||
#include <boost/uuid/uuid.hpp>
|
#include <boost/uuid/uuid.hpp>
|
||||||
@@ -39,37 +37,16 @@ struct ClioNode {
|
|||||||
*/
|
*/
|
||||||
static constexpr char const* kTIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ";
|
static constexpr char const* kTIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ";
|
||||||
|
|
||||||
/**
|
// enum class WriterRole {
|
||||||
* @brief Database role of a node in the cluster.
|
// ReadOnly,
|
||||||
*
|
// NotWriter,
|
||||||
* Roles are used to coordinate which node writes to the database:
|
// Writer
|
||||||
* - ReadOnly: Node is configured to never write (strict read-only mode)
|
// };
|
||||||
* - NotWriter: Node can write but is currently not the designated writer
|
|
||||||
* - Writer: Node is actively writing to the database
|
|
||||||
* - Fallback: Node is using the fallback writer decision mechanism
|
|
||||||
*
|
|
||||||
* When any node in the cluster is in Fallback mode, the entire cluster switches
|
|
||||||
* from the cluster communication mechanism to the slower but more reliable
|
|
||||||
* database-based conflict detection mechanism.
|
|
||||||
*/
|
|
||||||
enum class DbRole { ReadOnly = 0, LoadingCache = 1, NotWriter = 2, Writer = 3, Fallback = 4, MAX = 4 };
|
|
||||||
|
|
||||||
using Uuid = std::shared_ptr<boost::uuids::uuid>;
|
std::shared_ptr<boost::uuids::uuid> uuid; ///< The UUID of the node.
|
||||||
using CUuid = std::shared_ptr<boost::uuids::uuid const>;
|
|
||||||
|
|
||||||
Uuid uuid; ///< The UUID of the node.
|
|
||||||
std::chrono::system_clock::time_point updateTime; ///< The time the data about the node was last updated.
|
std::chrono::system_clock::time_point updateTime; ///< The time the data about the node was last updated.
|
||||||
DbRole dbRole; ///< The database role of the node
|
|
||||||
|
|
||||||
/**
|
// WriterRole writerRole;
|
||||||
* @brief Create a ClioNode from writer state.
|
|
||||||
*
|
|
||||||
* @param uuid The UUID of the node
|
|
||||||
* @param writerState The writer state to determine the node's database role
|
|
||||||
* @return A ClioNode with the current time and role derived from writerState
|
|
||||||
*/
|
|
||||||
static ClioNode
|
|
||||||
from(Uuid uuid, etl::WriterStateInterface const& writerState);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -19,37 +19,98 @@
|
|||||||
|
|
||||||
#include "cluster/ClusterCommunicationService.hpp"
|
#include "cluster/ClusterCommunicationService.hpp"
|
||||||
|
|
||||||
|
#include "cluster/ClioNode.hpp"
|
||||||
#include "data/BackendInterface.hpp"
|
#include "data/BackendInterface.hpp"
|
||||||
#include "etl/WriterState.hpp"
|
#include "util/Assert.hpp"
|
||||||
|
#include "util/Spawn.hpp"
|
||||||
|
#include "util/log/Logger.hpp"
|
||||||
|
|
||||||
|
#include <boost/asio/bind_cancellation_slot.hpp>
|
||||||
|
#include <boost/asio/cancellation_type.hpp>
|
||||||
|
#include <boost/asio/error.hpp>
|
||||||
|
#include <boost/asio/spawn.hpp>
|
||||||
|
#include <boost/asio/steady_timer.hpp>
|
||||||
|
#include <boost/asio/use_future.hpp>
|
||||||
|
#include <boost/json/parse.hpp>
|
||||||
|
#include <boost/json/serialize.hpp>
|
||||||
|
#include <boost/json/value.hpp>
|
||||||
|
#include <boost/json/value_from.hpp>
|
||||||
|
#include <boost/json/value_to.hpp>
|
||||||
|
#include <boost/uuid/random_generator.hpp>
|
||||||
|
#include <boost/uuid/uuid.hpp>
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
#include <latch>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
constexpr auto kTOTAL_WORKERS = 2uz; // 1 reading and 1 writing worker (coroutines)
|
||||||
|
} // namespace
|
||||||
|
|
||||||
namespace cluster {
|
namespace cluster {
|
||||||
|
|
||||||
ClusterCommunicationService::ClusterCommunicationService(
|
ClusterCommunicationService::ClusterCommunicationService(
|
||||||
std::shared_ptr<data::BackendInterface> backend,
|
std::shared_ptr<data::BackendInterface> backend,
|
||||||
std::unique_ptr<etl::WriterStateInterface> writerState,
|
|
||||||
std::chrono::steady_clock::duration readInterval,
|
std::chrono::steady_clock::duration readInterval,
|
||||||
std::chrono::steady_clock::duration writeInterval
|
std::chrono::steady_clock::duration writeInterval
|
||||||
)
|
)
|
||||||
: backend_(ctx_, std::move(backend), writerState->clone(), readInterval, writeInterval)
|
: backend_(std::move(backend))
|
||||||
, writerDecider_(ctx_, std::move(writerState))
|
, readInterval_(readInterval)
|
||||||
|
, writeInterval_(writeInterval)
|
||||||
|
, finishedCountdown_(kTOTAL_WORKERS)
|
||||||
|
, selfData_{ClioNode{
|
||||||
|
.uuid = std::make_shared<boost::uuids::uuid>(boost::uuids::random_generator{}()),
|
||||||
|
.updateTime = std::chrono::system_clock::time_point{}
|
||||||
|
}}
|
||||||
{
|
{
|
||||||
|
nodesInClusterMetric_.set(1); // The node always sees itself
|
||||||
|
isHealthy_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ClusterCommunicationService::run()
|
ClusterCommunicationService::run()
|
||||||
{
|
{
|
||||||
backend_.subscribeToNewState([this](auto&&... args) {
|
ASSERT(not running_ and not stopped_, "Can only be ran once");
|
||||||
metrics_.onNewState(std::forward<decltype(args)>(args)...);
|
running_ = true;
|
||||||
|
|
||||||
|
util::spawn(strand_, [this](boost::asio::yield_context yield) {
|
||||||
|
boost::asio::steady_timer timer(yield.get_executor());
|
||||||
|
boost::system::error_code ec;
|
||||||
|
|
||||||
|
while (running_) {
|
||||||
|
timer.expires_after(readInterval_);
|
||||||
|
auto token = cancelSignal_.slot();
|
||||||
|
timer.async_wait(boost::asio::bind_cancellation_slot(token, yield[ec]));
|
||||||
|
|
||||||
|
if (ec == boost::asio::error::operation_aborted or not running_)
|
||||||
|
break;
|
||||||
|
|
||||||
|
doRead(yield);
|
||||||
|
}
|
||||||
|
|
||||||
|
finishedCountdown_.count_down(1);
|
||||||
});
|
});
|
||||||
backend_.subscribeToNewState([this](auto&&... args) {
|
|
||||||
writerDecider_.onNewState(std::forward<decltype(args)>(args)...);
|
util::spawn(strand_, [this](boost::asio::yield_context yield) {
|
||||||
|
boost::asio::steady_timer timer(yield.get_executor());
|
||||||
|
boost::system::error_code ec;
|
||||||
|
|
||||||
|
while (running_) {
|
||||||
|
doWrite();
|
||||||
|
timer.expires_after(writeInterval_);
|
||||||
|
auto token = cancelSignal_.slot();
|
||||||
|
timer.async_wait(boost::asio::bind_cancellation_slot(token, yield[ec]));
|
||||||
|
|
||||||
|
if (ec == boost::asio::error::operation_aborted or not running_)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
finishedCountdown_.count_down(1);
|
||||||
});
|
});
|
||||||
backend_.run();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ClusterCommunicationService::~ClusterCommunicationService()
|
ClusterCommunicationService::~ClusterCommunicationService()
|
||||||
@@ -60,7 +121,107 @@ ClusterCommunicationService::~ClusterCommunicationService()
|
|||||||
void
|
void
|
||||||
ClusterCommunicationService::stop()
|
ClusterCommunicationService::stop()
|
||||||
{
|
{
|
||||||
backend_.stop();
|
if (stopped_)
|
||||||
|
return;
|
||||||
|
|
||||||
|
stopped_ = true;
|
||||||
|
|
||||||
|
// for ASAN to see through concurrency correctly we need to exit all coroutines before joining the ctx
|
||||||
|
running_ = false;
|
||||||
|
|
||||||
|
// cancelSignal_ is not thread safe so we execute emit on the same strand
|
||||||
|
boost::asio::spawn(
|
||||||
|
strand_, [this](auto&&) { cancelSignal_.emit(boost::asio::cancellation_type::all); }, boost::asio::use_future
|
||||||
|
)
|
||||||
|
.wait();
|
||||||
|
finishedCountdown_.wait();
|
||||||
|
|
||||||
|
ctx_.join();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<boost::uuids::uuid>
|
||||||
|
ClusterCommunicationService::selfUuid() const
|
||||||
|
{
|
||||||
|
// Uuid never changes so it is safe to copy it without using strand_
|
||||||
|
return selfData_.uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
ClioNode
|
||||||
|
ClusterCommunicationService::selfData() const
|
||||||
|
{
|
||||||
|
ClioNode result{};
|
||||||
|
util::spawn(strand_, [this, &result](boost::asio::yield_context) { result = selfData_; });
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::expected<std::vector<ClioNode>, std::string>
|
||||||
|
ClusterCommunicationService::clusterData() const
|
||||||
|
{
|
||||||
|
if (not isHealthy_) {
|
||||||
|
return std::unexpected{"Service is not healthy"};
|
||||||
|
}
|
||||||
|
std::vector<ClioNode> result;
|
||||||
|
util::spawn(strand_, [this, &result](boost::asio::yield_context) {
|
||||||
|
result = otherNodesData_;
|
||||||
|
result.push_back(selfData_);
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ClusterCommunicationService::doRead(boost::asio::yield_context yield)
|
||||||
|
{
|
||||||
|
otherNodesData_.clear();
|
||||||
|
|
||||||
|
BackendInterface::ClioNodesDataFetchResult expectedResult;
|
||||||
|
try {
|
||||||
|
expectedResult = backend_->fetchClioNodesData(yield);
|
||||||
|
} catch (...) {
|
||||||
|
expectedResult = std::unexpected{"Failed to fecth Clio nodes data"};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!expectedResult.has_value()) {
|
||||||
|
LOG(log_.error()) << "Failed to fetch nodes data";
|
||||||
|
isHealthy_ = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a new vector here to not have partially parsed data in otherNodesData_
|
||||||
|
std::vector<ClioNode> otherNodesData;
|
||||||
|
for (auto const& [uuid, nodeDataStr] : expectedResult.value()) {
|
||||||
|
if (uuid == *selfData_.uuid) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::system::error_code errorCode;
|
||||||
|
auto const json = boost::json::parse(nodeDataStr, errorCode);
|
||||||
|
if (errorCode.failed()) {
|
||||||
|
LOG(log_.error()) << "Error parsing json from DB: " << nodeDataStr;
|
||||||
|
isHealthy_ = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto expectedNodeData = boost::json::try_value_to<ClioNode>(json);
|
||||||
|
if (expectedNodeData.has_error()) {
|
||||||
|
LOG(log_.error()) << "Error converting json to ClioNode: " << json;
|
||||||
|
isHealthy_ = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
*expectedNodeData->uuid = uuid;
|
||||||
|
otherNodesData.push_back(std::move(expectedNodeData).value());
|
||||||
|
}
|
||||||
|
otherNodesData_ = std::move(otherNodesData);
|
||||||
|
nodesInClusterMetric_.set(otherNodesData_.size() + 1);
|
||||||
|
isHealthy_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ClusterCommunicationService::doWrite()
|
||||||
|
{
|
||||||
|
selfData_.updateTime = std::chrono::system_clock::now();
|
||||||
|
boost::json::value jsonValue{};
|
||||||
|
boost::json::value_from(selfData_, jsonValue);
|
||||||
|
backend_->writeNodeMessage(*selfData_.uuid, boost::json::serialize(jsonValue.as_object()));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace cluster
|
} // namespace cluster
|
||||||
|
|||||||
@@ -19,12 +19,13 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "cluster/Backend.hpp"
|
#include "cluster/ClioNode.hpp"
|
||||||
#include "cluster/Concepts.hpp"
|
#include "cluster/ClusterCommunicationServiceInterface.hpp"
|
||||||
#include "cluster/Metrics.hpp"
|
|
||||||
#include "cluster/WriterDecider.hpp"
|
|
||||||
#include "data/BackendInterface.hpp"
|
#include "data/BackendInterface.hpp"
|
||||||
#include "etl/WriterState.hpp"
|
#include "util/log/Logger.hpp"
|
||||||
|
#include "util/prometheus/Bool.hpp"
|
||||||
|
#include "util/prometheus/Gauge.hpp"
|
||||||
|
#include "util/prometheus/Prometheus.hpp"
|
||||||
|
|
||||||
#include <boost/asio/cancellation_signal.hpp>
|
#include <boost/asio/cancellation_signal.hpp>
|
||||||
#include <boost/asio/spawn.hpp>
|
#include <boost/asio/spawn.hpp>
|
||||||
@@ -32,49 +33,67 @@
|
|||||||
#include <boost/asio/thread_pool.hpp>
|
#include <boost/asio/thread_pool.hpp>
|
||||||
#include <boost/uuid/uuid.hpp>
|
#include <boost/uuid/uuid.hpp>
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <latch>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace cluster {
|
namespace cluster {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Service to post and read messages to/from the cluster. It uses a backend to communicate with the cluster.
|
* @brief Service to post and read messages to/from the cluster. It uses a backend to communicate with the cluster.
|
||||||
*/
|
*/
|
||||||
class ClusterCommunicationService : public ClusterCommunicationServiceTag {
|
class ClusterCommunicationService : public ClusterCommunicationServiceInterface {
|
||||||
|
util::prometheus::GaugeInt& nodesInClusterMetric_ = PrometheusService::gaugeInt(
|
||||||
|
"cluster_nodes_total_number",
|
||||||
|
{},
|
||||||
|
"Total number of nodes this node can detect in the cluster."
|
||||||
|
);
|
||||||
|
util::prometheus::Bool isHealthy_ = PrometheusService::boolMetric(
|
||||||
|
"cluster_communication_is_healthy",
|
||||||
|
{},
|
||||||
|
"Whether cluster communication service is operating healthy (1 - healthy, 0 - we have a problem)"
|
||||||
|
);
|
||||||
|
|
||||||
// TODO: Use util::async::CoroExecutionContext after https://github.com/XRPLF/clio/issues/1973 is implemented
|
// TODO: Use util::async::CoroExecutionContext after https://github.com/XRPLF/clio/issues/1973 is implemented
|
||||||
boost::asio::thread_pool ctx_{1};
|
boost::asio::thread_pool ctx_{1};
|
||||||
Backend backend_;
|
boost::asio::strand<boost::asio::thread_pool::executor_type> strand_ = boost::asio::make_strand(ctx_);
|
||||||
Metrics metrics_;
|
|
||||||
WriterDecider writerDecider_;
|
util::Logger log_{"ClusterCommunication"};
|
||||||
|
|
||||||
|
std::shared_ptr<data::BackendInterface> backend_;
|
||||||
|
|
||||||
|
std::chrono::steady_clock::duration readInterval_;
|
||||||
|
std::chrono::steady_clock::duration writeInterval_;
|
||||||
|
|
||||||
|
boost::asio::cancellation_signal cancelSignal_;
|
||||||
|
std::latch finishedCountdown_;
|
||||||
|
std::atomic_bool running_ = false;
|
||||||
|
bool stopped_ = false;
|
||||||
|
|
||||||
|
ClioNode selfData_;
|
||||||
|
std::vector<ClioNode> otherNodesData_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static constexpr std::chrono::milliseconds kDEFAULT_READ_INTERVAL{1000};
|
static constexpr std::chrono::milliseconds kDEFAULT_READ_INTERVAL{2100};
|
||||||
static constexpr std::chrono::milliseconds kDEFAULT_WRITE_INTERVAL{1000};
|
static constexpr std::chrono::milliseconds kDEFAULT_WRITE_INTERVAL{1200};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Construct a new Cluster Communication Service object.
|
* @brief Construct a new Cluster Communication Service object.
|
||||||
*
|
*
|
||||||
* @param backend The backend to use for communication.
|
* @param backend The backend to use for communication.
|
||||||
* @param writerState The state showing whether clio is writing to the database.
|
|
||||||
* @param readInterval The interval to read messages from the cluster.
|
* @param readInterval The interval to read messages from the cluster.
|
||||||
* @param writeInterval The interval to write messages to the cluster.
|
* @param writeInterval The interval to write messages to the cluster.
|
||||||
*/
|
*/
|
||||||
ClusterCommunicationService(
|
ClusterCommunicationService(
|
||||||
std::shared_ptr<data::BackendInterface> backend,
|
std::shared_ptr<data::BackendInterface> backend,
|
||||||
std::unique_ptr<etl::WriterStateInterface> writerState,
|
|
||||||
std::chrono::steady_clock::duration readInterval = kDEFAULT_READ_INTERVAL,
|
std::chrono::steady_clock::duration readInterval = kDEFAULT_READ_INTERVAL,
|
||||||
std::chrono::steady_clock::duration writeInterval = kDEFAULT_WRITE_INTERVAL
|
std::chrono::steady_clock::duration writeInterval = kDEFAULT_WRITE_INTERVAL
|
||||||
);
|
);
|
||||||
|
|
||||||
~ClusterCommunicationService() override;
|
~ClusterCommunicationService() override;
|
||||||
|
|
||||||
ClusterCommunicationService(ClusterCommunicationService&&) = delete;
|
|
||||||
ClusterCommunicationService(ClusterCommunicationService const&) = delete;
|
|
||||||
ClusterCommunicationService&
|
|
||||||
operator=(ClusterCommunicationService&&) = delete;
|
|
||||||
ClusterCommunicationService&
|
|
||||||
operator=(ClusterCommunicationService const&) = delete;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Start the service.
|
* @brief Start the service.
|
||||||
*/
|
*/
|
||||||
@@ -86,6 +105,44 @@ public:
|
|||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
|
ClusterCommunicationService(ClusterCommunicationService&&) = delete;
|
||||||
|
ClusterCommunicationService(ClusterCommunicationService const&) = delete;
|
||||||
|
ClusterCommunicationService&
|
||||||
|
operator=(ClusterCommunicationService&&) = delete;
|
||||||
|
ClusterCommunicationService&
|
||||||
|
operator=(ClusterCommunicationService const&) = delete;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the UUID of the current node.
|
||||||
|
*
|
||||||
|
* @return The UUID of the current node.
|
||||||
|
*/
|
||||||
|
std::shared_ptr<boost::uuids::uuid>
|
||||||
|
selfUuid() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the data of the current node.
|
||||||
|
*
|
||||||
|
* @return The data of the current node.
|
||||||
|
*/
|
||||||
|
ClioNode
|
||||||
|
selfData() const override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the data of all nodes in the cluster (including self).
|
||||||
|
*
|
||||||
|
* @return The data of all nodes in the cluster or error if the service is not healthy.
|
||||||
|
*/
|
||||||
|
std::expected<std::vector<ClioNode>, std::string>
|
||||||
|
clusterData() const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void
|
||||||
|
doRead(boost::asio::yield_context yield);
|
||||||
|
|
||||||
|
void
|
||||||
|
doWrite();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace cluster
|
} // namespace cluster
|
||||||
|
|||||||
@@ -17,31 +17,38 @@
|
|||||||
*/
|
*/
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|
||||||
#include "cluster/Metrics.hpp"
|
#pragma once
|
||||||
|
|
||||||
#include "cluster/Backend.hpp"
|
|
||||||
#include "cluster/ClioNode.hpp"
|
#include "cluster/ClioNode.hpp"
|
||||||
|
|
||||||
#include <memory>
|
#include <expected>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace cluster {
|
namespace cluster {
|
||||||
|
|
||||||
Metrics::Metrics()
|
/**
|
||||||
{
|
* @brief Interface for the cluster communication service.
|
||||||
nodesInClusterMetric_.set(1); // The node always sees itself
|
*/
|
||||||
isHealthy_ = true;
|
class ClusterCommunicationServiceInterface {
|
||||||
}
|
public:
|
||||||
|
virtual ~ClusterCommunicationServiceInterface() = default;
|
||||||
|
|
||||||
void
|
/**
|
||||||
Metrics::onNewState(ClioNode::CUuid, std::shared_ptr<Backend::ClusterData const> clusterData)
|
* @brief Get the data of the current node.
|
||||||
{
|
*
|
||||||
if (clusterData->has_value()) {
|
* @return The data of the current node.
|
||||||
isHealthy_ = true;
|
*/
|
||||||
nodesInClusterMetric_.set(clusterData->value().size());
|
[[nodiscard]] virtual ClioNode
|
||||||
} else {
|
selfData() const = 0;
|
||||||
isHealthy_ = false;
|
|
||||||
nodesInClusterMetric_.set(1);
|
/**
|
||||||
}
|
* @brief Get the data of all nodes in the cluster (including self).
|
||||||
}
|
*
|
||||||
|
* @return The data of all nodes in the cluster or error if the service is not healthy.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] virtual std::expected<std::vector<ClioNode>, std::string>
|
||||||
|
clusterData() const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace cluster
|
} // namespace cluster
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
/*
|
|
||||||
This file is part of clio: https://github.com/XRPLF/clio
|
|
||||||
Copyright (c) 2025, the clio developers.
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
//==============================================================================
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <concepts>
|
|
||||||
|
|
||||||
namespace cluster {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Tag type for cluster communication service implementations.
|
|
||||||
*
|
|
||||||
* This tag is used to identify types that implement cluster communication functionality.
|
|
||||||
* Types should inherit from this tag to be recognized as cluster communication services.
|
|
||||||
*/
|
|
||||||
struct ClusterCommunicationServiceTag {
|
|
||||||
virtual ~ClusterCommunicationServiceTag() = default;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
concept SomeClusterCommunicationService = std::derived_from<T, ClusterCommunicationServiceTag>;
|
|
||||||
|
|
||||||
} // namespace cluster
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
/*
|
|
||||||
This file is part of clio: https://github.com/XRPLF/clio
|
|
||||||
Copyright (c) 2025, the clio developers.
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
//==============================================================================
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "cluster/Backend.hpp"
|
|
||||||
#include "cluster/ClioNode.hpp"
|
|
||||||
#include "util/prometheus/Bool.hpp"
|
|
||||||
#include "util/prometheus/Gauge.hpp"
|
|
||||||
#include "util/prometheus/Prometheus.hpp"
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
namespace cluster {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Manages Prometheus metrics for cluster communication and node tracking.
|
|
||||||
*
|
|
||||||
* This class tracks cluster-related metrics including:
|
|
||||||
* - Total number of nodes detected in the cluster
|
|
||||||
* - Health status of cluster communication
|
|
||||||
*/
|
|
||||||
class Metrics {
|
|
||||||
/** @brief Gauge tracking the total number of nodes visible in the cluster */
|
|
||||||
util::prometheus::GaugeInt& nodesInClusterMetric_ = PrometheusService::gaugeInt(
|
|
||||||
"cluster_nodes_total_number",
|
|
||||||
{},
|
|
||||||
"Total number of nodes this node can detect in the cluster."
|
|
||||||
);
|
|
||||||
|
|
||||||
/** @brief Boolean metric indicating whether cluster communication is healthy */
|
|
||||||
util::prometheus::Bool isHealthy_ = PrometheusService::boolMetric(
|
|
||||||
"cluster_communication_is_healthy",
|
|
||||||
{},
|
|
||||||
"Whether cluster communication service is operating healthy (1 - healthy, 0 - we have a problem)"
|
|
||||||
);
|
|
||||||
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* @brief Constructs a Metrics instance and initializes metrics.
|
|
||||||
*
|
|
||||||
* Sets the initial node count to 1 (self) and marks communication as healthy.
|
|
||||||
*/
|
|
||||||
Metrics();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Updates metrics based on new cluster state.
|
|
||||||
*
|
|
||||||
* This callback is invoked when cluster state changes. It updates:
|
|
||||||
* - Health status based on whether cluster data is available
|
|
||||||
* - Node count to reflect the current cluster size
|
|
||||||
*
|
|
||||||
* @param uuid The UUID of the node (unused in current implementation)
|
|
||||||
* @param clusterData Shared pointer to the current cluster data; may be empty if communication failed
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
onNewState(ClioNode::CUuid uuid, std::shared_ptr<Backend::ClusterData const> clusterData);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace cluster
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
/*
|
|
||||||
This file is part of clio: https://github.com/XRPLF/clio
|
|
||||||
Copyright (c) 2025, the clio developers.
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
//==============================================================================
|
|
||||||
|
|
||||||
#include "cluster/WriterDecider.hpp"
|
|
||||||
|
|
||||||
#include "cluster/Backend.hpp"
|
|
||||||
#include "cluster/ClioNode.hpp"
|
|
||||||
#include "etl/WriterState.hpp"
|
|
||||||
#include "util/Assert.hpp"
|
|
||||||
#include "util/Spawn.hpp"
|
|
||||||
|
|
||||||
#include <boost/asio/thread_pool.hpp>
|
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <memory>
|
|
||||||
#include <utility>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace cluster {
|
|
||||||
|
|
||||||
WriterDecider::WriterDecider(boost::asio::thread_pool& ctx, std::unique_ptr<etl::WriterStateInterface> writerState)
|
|
||||||
: ctx_(ctx), writerState_(std::move(writerState))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
WriterDecider::onNewState(ClioNode::CUuid selfId, std::shared_ptr<Backend::ClusterData const> clusterData)
|
|
||||||
{
|
|
||||||
if (not clusterData->has_value())
|
|
||||||
return;
|
|
||||||
|
|
||||||
util::spawn(
|
|
||||||
ctx_,
|
|
||||||
[writerState = writerState_->clone(),
|
|
||||||
selfId = std::move(selfId),
|
|
||||||
clusterData = clusterData->value()](auto&&) mutable {
|
|
||||||
auto const selfData =
|
|
||||||
std::ranges::find_if(clusterData, [&selfId](ClioNode const& node) { return node.uuid == selfId; });
|
|
||||||
ASSERT(selfData != clusterData.end(), "Self data should always be in the cluster data");
|
|
||||||
|
|
||||||
if (selfData->dbRole == ClioNode::DbRole::Fallback) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selfData->dbRole == ClioNode::DbRole::ReadOnly) {
|
|
||||||
writerState->giveUpWriting();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If any node in the cluster is in Fallback mode, the entire cluster must switch
|
|
||||||
// to the fallback writer decision mechanism for consistency
|
|
||||||
if (std::ranges::any_of(clusterData, [](ClioNode const& node) {
|
|
||||||
return node.dbRole == ClioNode::DbRole::Fallback;
|
|
||||||
})) {
|
|
||||||
writerState->setWriterDecidingFallback();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We are not ReadOnly and there is no Fallback in the cluster
|
|
||||||
std::ranges::sort(clusterData, [](ClioNode const& lhs, ClioNode const& rhs) {
|
|
||||||
return *lhs.uuid < *rhs.uuid;
|
|
||||||
});
|
|
||||||
|
|
||||||
auto const it = std::ranges::find_if(clusterData, [](ClioNode const& node) {
|
|
||||||
return node.dbRole == ClioNode::DbRole::NotWriter or node.dbRole == ClioNode::DbRole::Writer;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (it == clusterData.end()) {
|
|
||||||
// No writer nodes in the cluster yet
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*it->uuid == *selfId) {
|
|
||||||
writerState->startWriting();
|
|
||||||
} else {
|
|
||||||
writerState->giveUpWriting();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace cluster
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
/*
|
|
||||||
This file is part of clio: https://github.com/XRPLF/clio
|
|
||||||
Copyright (c) 2025, the clio developers.
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
//==============================================================================
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "cluster/Backend.hpp"
|
|
||||||
#include "cluster/ClioNode.hpp"
|
|
||||||
#include "etl/WriterState.hpp"
|
|
||||||
|
|
||||||
#include <boost/asio/thread_pool.hpp>
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
namespace cluster {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Decides which node in the cluster should be the writer based on cluster state.
|
|
||||||
*
|
|
||||||
* This class monitors cluster state changes and determines whether the current node
|
|
||||||
* should act as the writer to the database. The decision is made by:
|
|
||||||
* 1. Sorting all nodes by UUID for deterministic ordering
|
|
||||||
* 2. Selecting the first node that is allowed to write (not ReadOnly)
|
|
||||||
* 3. Activating writing on this node if it's the current node, otherwise deactivating
|
|
||||||
*
|
|
||||||
* This ensures only one node in the cluster actively writes to the database at a time.
|
|
||||||
*/
|
|
||||||
class WriterDecider {
|
|
||||||
/** @brief Thread pool for spawning asynchronous tasks */
|
|
||||||
boost::asio::thread_pool& ctx_;
|
|
||||||
|
|
||||||
/** @brief Interface for controlling the writer state of this node */
|
|
||||||
std::unique_ptr<etl::WriterStateInterface> writerState_;
|
|
||||||
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* @brief Constructs a WriterDecider.
|
|
||||||
*
|
|
||||||
* @param ctx Thread pool for executing asynchronous operations
|
|
||||||
* @param writerState Writer state interface for controlling write operations
|
|
||||||
*/
|
|
||||||
WriterDecider(boost::asio::thread_pool& ctx, std::unique_ptr<etl::WriterStateInterface> writerState);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Handles cluster state changes and decides whether this node should be the writer.
|
|
||||||
*
|
|
||||||
* This method is called when cluster state changes. It asynchronously:
|
|
||||||
* - Sorts all nodes by UUID to establish a deterministic order
|
|
||||||
* - Identifies the first node allowed to write (not ReadOnly)
|
|
||||||
* - Activates writing if this node is selected, otherwise deactivates writing
|
|
||||||
* - Logs a warning if no nodes in the cluster are allowed to write
|
|
||||||
*
|
|
||||||
* @param selfId The UUID of the current node
|
|
||||||
* @param clusterData Shared pointer to current cluster data; may be empty if communication failed
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
onNewState(ClioNode::CUuid selfId, std::shared_ptr<Backend::ClusterData const> clusterData);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace cluster
|
|
||||||
@@ -1,108 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
/*
|
|
||||||
This file is part of clio: https://github.com/XRPLF/clio
|
|
||||||
Copyright (c) 2025, the clio developers.
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
//==============================================================================
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "util/Assert.hpp"
|
|
||||||
#include "util/Spawn.hpp"
|
|
||||||
|
|
||||||
#include <boost/asio/bind_cancellation_slot.hpp>
|
|
||||||
#include <boost/asio/cancellation_signal.hpp>
|
|
||||||
#include <boost/asio/cancellation_type.hpp>
|
|
||||||
#include <boost/asio/error.hpp>
|
|
||||||
#include <boost/asio/executor.hpp>
|
|
||||||
#include <boost/asio/spawn.hpp>
|
|
||||||
#include <boost/asio/steady_timer.hpp>
|
|
||||||
#include <boost/asio/strand.hpp>
|
|
||||||
|
|
||||||
#include <atomic>
|
|
||||||
#include <chrono>
|
|
||||||
#include <concepts>
|
|
||||||
#include <semaphore>
|
|
||||||
|
|
||||||
namespace cluster::impl {
|
|
||||||
|
|
||||||
// TODO: Try to replace util::Repeat by this. https://github.com/XRPLF/clio/issues/2926
|
|
||||||
template <typename Context>
|
|
||||||
class RepeatedTask {
|
|
||||||
std::chrono::steady_clock::duration interval_;
|
|
||||||
boost::asio::strand<typename Context::executor_type> strand_;
|
|
||||||
|
|
||||||
enum class State { Running, Stopped };
|
|
||||||
std::atomic<State> state_ = State::Stopped;
|
|
||||||
|
|
||||||
std::binary_semaphore semaphore_{0};
|
|
||||||
boost::asio::steady_timer timer_;
|
|
||||||
|
|
||||||
public:
|
|
||||||
RepeatedTask(std::chrono::steady_clock::duration interval, Context& ctx)
|
|
||||||
: interval_(interval), strand_(boost::asio::make_strand(ctx)), timer_(strand_)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
~RepeatedTask()
|
|
||||||
{
|
|
||||||
stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Fn>
|
|
||||||
requires std::invocable<Fn, boost::asio::yield_context> or std::invocable<Fn>
|
|
||||||
void
|
|
||||||
run(Fn&& f)
|
|
||||||
{
|
|
||||||
ASSERT(state_ == State::Stopped, "Can only be ran once");
|
|
||||||
state_ = State::Running;
|
|
||||||
util::spawn(strand_, [this, f = std::forward<Fn>(f)](boost::asio::yield_context yield) {
|
|
||||||
boost::system::error_code ec;
|
|
||||||
|
|
||||||
while (state_ == State::Running) {
|
|
||||||
timer_.expires_after(interval_);
|
|
||||||
timer_.async_wait(yield[ec]);
|
|
||||||
|
|
||||||
if (ec or state_ != State::Running)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if constexpr (std::invocable<decltype(f), boost::asio::yield_context>) {
|
|
||||||
f(yield);
|
|
||||||
} else {
|
|
||||||
f();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
semaphore_.release();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
stop()
|
|
||||||
{
|
|
||||||
if (auto expected = State::Running; not state_.compare_exchange_strong(expected, State::Stopped))
|
|
||||||
return; // Already stopped or not started
|
|
||||||
|
|
||||||
std::binary_semaphore cancelSemaphore{0};
|
|
||||||
boost::asio::post(strand_, [this, &cancelSemaphore]() {
|
|
||||||
timer_.cancel();
|
|
||||||
cancelSemaphore.release();
|
|
||||||
});
|
|
||||||
cancelSemaphore.acquire();
|
|
||||||
semaphore_.acquire();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace cluster::impl
|
|
||||||
@@ -146,12 +146,9 @@ AmendmentCenter::isEnabled(AmendmentKey const& key, uint32_t seq) const
|
|||||||
bool
|
bool
|
||||||
AmendmentCenter::isEnabled(boost::asio::yield_context yield, AmendmentKey const& key, uint32_t seq) const
|
AmendmentCenter::isEnabled(boost::asio::yield_context yield, AmendmentKey const& key, uint32_t seq) const
|
||||||
{
|
{
|
||||||
try {
|
if (auto const listAmendments = fetchAmendmentsList(yield, seq); listAmendments)
|
||||||
if (auto const listAmendments = fetchAmendmentsList(yield, seq); listAmendments)
|
return lookupAmendment(all_, *listAmendments, key);
|
||||||
return lookupAmendment(all_, *listAmendments, key);
|
|
||||||
} catch (std::runtime_error const&) {
|
|
||||||
return false; // Some old ledger does not contain Amendments ledger object so do best we can for now
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,19 +157,13 @@ AmendmentCenter::isEnabled(boost::asio::yield_context yield, std::vector<Amendme
|
|||||||
{
|
{
|
||||||
namespace rg = std::ranges;
|
namespace rg = std::ranges;
|
||||||
|
|
||||||
try {
|
if (auto const listAmendments = fetchAmendmentsList(yield, seq); listAmendments) {
|
||||||
if (auto const listAmendments = fetchAmendmentsList(yield, seq); listAmendments) {
|
std::vector<bool> out;
|
||||||
std::vector<bool> out;
|
rg::transform(keys, std::back_inserter(out), [this, &listAmendments](auto const& key) {
|
||||||
rg::transform(keys, std::back_inserter(out), [this, &listAmendments](auto const& key) {
|
return lookupAmendment(all_, *listAmendments, key);
|
||||||
return lookupAmendment(all_, *listAmendments, key);
|
});
|
||||||
});
|
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
|
||||||
} catch (std::runtime_error const&) {
|
|
||||||
return std::vector<bool>(
|
|
||||||
keys.size(), false
|
|
||||||
); // Some old ledger does not contain Amendments ledger object so do best we can for now
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::vector<bool>(keys.size(), false);
|
return std::vector<bool>(keys.size(), false);
|
||||||
|
|||||||
@@ -1,21 +1,23 @@
|
|||||||
add_library(clio_data)
|
add_library(clio_data)
|
||||||
target_sources(clio_data
|
target_sources(
|
||||||
PRIVATE AmendmentCenter.cpp
|
clio_data
|
||||||
BackendCounters.cpp
|
PRIVATE AmendmentCenter.cpp
|
||||||
BackendInterface.cpp
|
BackendCounters.cpp
|
||||||
LedgerCache.cpp
|
BackendInterface.cpp
|
||||||
LedgerCacheSaver.cpp
|
LedgerCache.cpp
|
||||||
LedgerHeaderCache.cpp
|
LedgerCacheSaver.cpp
|
||||||
cassandra/impl/Future.cpp
|
LedgerHeaderCache.cpp
|
||||||
cassandra/impl/Cluster.cpp
|
cassandra/impl/Future.cpp
|
||||||
cassandra/impl/Batch.cpp
|
cassandra/impl/Cluster.cpp
|
||||||
cassandra/impl/Result.cpp
|
cassandra/impl/Batch.cpp
|
||||||
cassandra/impl/Tuple.cpp
|
cassandra/impl/Result.cpp
|
||||||
cassandra/impl/SslContext.cpp
|
cassandra/impl/Tuple.cpp
|
||||||
cassandra/Handle.cpp
|
cassandra/impl/SslContext.cpp
|
||||||
cassandra/SettingsProvider.cpp
|
cassandra/Handle.cpp
|
||||||
impl/InputFile.cpp
|
cassandra/SettingsProvider.cpp
|
||||||
impl/LedgerCacheFile.cpp
|
impl/InputFile.cpp
|
||||||
impl/OutputFile.cpp)
|
impl/LedgerCacheFile.cpp
|
||||||
|
impl/OutputFile.cpp
|
||||||
|
)
|
||||||
|
|
||||||
target_link_libraries(clio_data PUBLIC cassandra-cpp-driver::cassandra-cpp-driver clio_util)
|
target_link_libraries(clio_data PUBLIC cassandra-cpp-driver::cassandra-cpp-driver clio_util)
|
||||||
|
|||||||
@@ -30,9 +30,7 @@
|
|||||||
namespace data {
|
namespace data {
|
||||||
|
|
||||||
LedgerCacheSaver::LedgerCacheSaver(util::config::ClioConfigDefinition const& config, LedgerCacheInterface const& cache)
|
LedgerCacheSaver::LedgerCacheSaver(util::config::ClioConfigDefinition const& config, LedgerCacheInterface const& cache)
|
||||||
: cacheFilePath_(config.maybeValue<std::string>("cache.file.path"))
|
: cacheFilePath_(config.maybeValue<std::string>("cache.file.path")), cache_(cache)
|
||||||
, cache_(cache)
|
|
||||||
, isAsync_(config.get<bool>("cache.file.async_save"))
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,9 +56,6 @@ LedgerCacheSaver::save()
|
|||||||
LOG(util::LogService::error()) << "Error saving LedgerCache to file: " << success.error();
|
LOG(util::LogService::error()) << "Error saving LedgerCache to file: " << success.error();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (not isAsync_) {
|
|
||||||
waitToFinish();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ class LedgerCacheSaver {
|
|||||||
std::optional<std::string> cacheFilePath_;
|
std::optional<std::string> cacheFilePath_;
|
||||||
std::reference_wrapper<LedgerCacheInterface const> cache_;
|
std::reference_wrapper<LedgerCacheInterface const> cache_;
|
||||||
std::optional<std::thread> savingThread_;
|
std::optional<std::thread> savingThread_;
|
||||||
bool isAsync_;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -115,11 +115,6 @@ LedgerCacheFile::write(DataView dataView)
|
|||||||
auto const hash = file.hash();
|
auto const hash = file.hash();
|
||||||
file.write(hash.data(), decltype(hash)::bytes);
|
file.write(hash.data(), decltype(hash)::bytes);
|
||||||
|
|
||||||
// flush internal buffer explicitly before renaming
|
|
||||||
if (auto const expectedSuccess = file.close(); not expectedSuccess.has_value()) {
|
|
||||||
return expectedSuccess;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
std::filesystem::rename(newFilePath, path_);
|
std::filesystem::rename(newFilePath, path_);
|
||||||
} catch (std::exception const& e) {
|
} catch (std::exception const& e) {
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <expected>
|
|
||||||
#include <ios>
|
#include <ios>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
@@ -60,14 +59,4 @@ OutputFile::hash() const
|
|||||||
return std::move(sum).finalize();
|
return std::move(sum).finalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::expected<void, std::string>
|
|
||||||
OutputFile::close()
|
|
||||||
{
|
|
||||||
file_.close();
|
|
||||||
if (not file_) {
|
|
||||||
return std::unexpected{"Error closing cache file"};
|
|
||||||
}
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace data::impl
|
} // namespace data::impl
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <expected>
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@@ -61,9 +60,6 @@ public:
|
|||||||
ripple::uint256
|
ripple::uint256
|
||||||
hash() const;
|
hash() const;
|
||||||
|
|
||||||
std::expected<void, std::string>
|
|
||||||
close();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void
|
void
|
||||||
writeToFile(char const* data, size_t size);
|
writeToFile(char const* data, size_t size);
|
||||||
|
|||||||
@@ -1,29 +1,30 @@
|
|||||||
add_library(clio_etl)
|
add_library(clio_etl)
|
||||||
|
|
||||||
target_sources(clio_etl
|
target_sources(
|
||||||
PRIVATE CacheLoaderSettings.cpp
|
clio_etl
|
||||||
ETLHelpers.cpp
|
PRIVATE CacheLoaderSettings.cpp
|
||||||
ETLService.cpp
|
ETLHelpers.cpp
|
||||||
ETLState.cpp
|
ETLService.cpp
|
||||||
LoadBalancer.cpp
|
ETLState.cpp
|
||||||
MPTHelpers.cpp
|
LoadBalancer.cpp
|
||||||
NetworkValidatedLedgers.cpp
|
MPTHelpers.cpp
|
||||||
NFTHelpers.cpp
|
NetworkValidatedLedgers.cpp
|
||||||
Source.cpp
|
NFTHelpers.cpp
|
||||||
WriterState.cpp
|
Source.cpp
|
||||||
impl/AmendmentBlockHandler.cpp
|
impl/AmendmentBlockHandler.cpp
|
||||||
impl/AsyncGrpcCall.cpp
|
impl/AsyncGrpcCall.cpp
|
||||||
impl/Extraction.cpp
|
impl/Extraction.cpp
|
||||||
impl/ForwardingSource.cpp
|
impl/ForwardingSource.cpp
|
||||||
impl/GrpcSource.cpp
|
impl/GrpcSource.cpp
|
||||||
impl/Loading.cpp
|
impl/Loading.cpp
|
||||||
impl/Monitor.cpp
|
impl/Monitor.cpp
|
||||||
impl/SubscriptionSource.cpp
|
impl/SubscriptionSource.cpp
|
||||||
impl/TaskManager.cpp
|
impl/TaskManager.cpp
|
||||||
impl/ext/Cache.cpp
|
impl/ext/Cache.cpp
|
||||||
impl/ext/Core.cpp
|
impl/ext/Core.cpp
|
||||||
impl/ext/MPT.cpp
|
impl/ext/MPT.cpp
|
||||||
impl/ext/NFT.cpp
|
impl/ext/NFT.cpp
|
||||||
impl/ext/Successor.cpp)
|
impl/ext/Successor.cpp
|
||||||
|
)
|
||||||
|
|
||||||
target_link_libraries(clio_etl PUBLIC clio_data)
|
target_link_libraries(clio_etl PUBLIC clio_data)
|
||||||
|
|||||||
@@ -78,7 +78,6 @@ namespace etl {
|
|||||||
std::shared_ptr<ETLServiceInterface>
|
std::shared_ptr<ETLServiceInterface>
|
||||||
ETLService::makeETLService(
|
ETLService::makeETLService(
|
||||||
util::config::ClioConfigDefinition const& config,
|
util::config::ClioConfigDefinition const& config,
|
||||||
std::shared_ptr<SystemState> state,
|
|
||||||
util::async::AnyExecutionContext ctx,
|
util::async::AnyExecutionContext ctx,
|
||||||
std::shared_ptr<BackendInterface> backend,
|
std::shared_ptr<BackendInterface> backend,
|
||||||
std::shared_ptr<feed::SubscriptionManagerInterface> subscriptions,
|
std::shared_ptr<feed::SubscriptionManagerInterface> subscriptions,
|
||||||
@@ -88,6 +87,9 @@ ETLService::makeETLService(
|
|||||||
{
|
{
|
||||||
std::shared_ptr<ETLServiceInterface> ret;
|
std::shared_ptr<ETLServiceInterface> ret;
|
||||||
|
|
||||||
|
auto state = std::make_shared<SystemState>();
|
||||||
|
state->isStrictReadonly = config.get<bool>("read_only");
|
||||||
|
|
||||||
auto fetcher = std::make_shared<impl::LedgerFetcher>(backend, balancer);
|
auto fetcher = std::make_shared<impl::LedgerFetcher>(backend, balancer);
|
||||||
auto extractor = std::make_shared<impl::Extractor>(fetcher);
|
auto extractor = std::make_shared<impl::Extractor>(fetcher);
|
||||||
auto publisher = std::make_shared<impl::LedgerPublisher>(ctx, backend, subscriptions, *state);
|
auto publisher = std::make_shared<impl::LedgerPublisher>(ctx, backend, subscriptions, *state);
|
||||||
@@ -171,7 +173,6 @@ ETLService::ETLService(
|
|||||||
, state_(std::move(state))
|
, state_(std::move(state))
|
||||||
, startSequence_(config.get().maybeValue<uint32_t>("start_sequence"))
|
, startSequence_(config.get().maybeValue<uint32_t>("start_sequence"))
|
||||||
, finishSequence_(config.get().maybeValue<uint32_t>("finish_sequence"))
|
, finishSequence_(config.get().maybeValue<uint32_t>("finish_sequence"))
|
||||||
, writeCommandStrand_(ctx_.makeStrand())
|
|
||||||
{
|
{
|
||||||
ASSERT(not state_->isWriting, "ETL should never start in writer mode");
|
ASSERT(not state_->isWriting, "ETL should never start in writer mode");
|
||||||
|
|
||||||
@@ -212,13 +213,14 @@ ETLService::run()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto const nextSequence = syncCacheWithDb();
|
auto nextSequence = rng->maxSequence + 1;
|
||||||
|
if (backend_->cache().latestLedgerSequence() != 0) {
|
||||||
|
nextSequence = backend_->cache().latestLedgerSequence();
|
||||||
|
}
|
||||||
|
|
||||||
LOG(log_.debug()) << "Database is populated. Starting monitor loop. sequence = " << nextSequence;
|
LOG(log_.debug()) << "Database is populated. Starting monitor loop. sequence = " << nextSequence;
|
||||||
|
|
||||||
startMonitor(nextSequence);
|
startMonitor(nextSequence);
|
||||||
|
|
||||||
state_->isLoadingCache = false;
|
|
||||||
|
|
||||||
// If we are a writer as the result of loading the initial ledger - start loading
|
// If we are a writer as the result of loading the initial ledger - start loading
|
||||||
if (state_->isWriting)
|
if (state_->isWriting)
|
||||||
startLoading(nextSequence);
|
startLoading(nextSequence);
|
||||||
@@ -230,13 +232,6 @@ ETLService::stop()
|
|||||||
{
|
{
|
||||||
LOG(log_.info()) << "Stop called";
|
LOG(log_.info()) << "Stop called";
|
||||||
|
|
||||||
systemStateWriteCommandSubscription_.disconnect();
|
|
||||||
auto count = runningWriteCommandHandlers_.load();
|
|
||||||
while (count != 0) {
|
|
||||||
runningWriteCommandHandlers_.wait(count); // Blocks until value changes
|
|
||||||
count = runningWriteCommandHandlers_.load();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mainLoop_)
|
if (mainLoop_)
|
||||||
mainLoop_->wait();
|
mainLoop_->wait();
|
||||||
if (taskMan_)
|
if (taskMan_)
|
||||||
@@ -348,77 +343,35 @@ ETLService::loadInitialLedgerIfNeeded()
|
|||||||
return rng;
|
return rng;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t
|
|
||||||
ETLService::syncCacheWithDb()
|
|
||||||
{
|
|
||||||
auto rng = backend_->hardFetchLedgerRangeNoThrow();
|
|
||||||
|
|
||||||
while (not backend_->cache().isDisabled() and rng->maxSequence > backend_->cache().latestLedgerSequence()) {
|
|
||||||
LOG(log_.info()) << "Syncing cache with DB. DB latest seq: " << rng->maxSequence
|
|
||||||
<< ". Cache latest seq: " << backend_->cache().latestLedgerSequence();
|
|
||||||
for (auto seq = backend_->cache().latestLedgerSequence(); seq <= rng->maxSequence; ++seq) {
|
|
||||||
LOG(log_.info()) << "ETLService (via syncCacheWithDb) got new seq from db: " << seq;
|
|
||||||
updateCache(seq);
|
|
||||||
}
|
|
||||||
rng = backend_->hardFetchLedgerRangeNoThrow();
|
|
||||||
}
|
|
||||||
return rng->maxSequence + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
ETLService::updateCache(uint32_t seq)
|
|
||||||
{
|
|
||||||
auto const cacheNeedsUpdate = backend_->cache().latestLedgerSequence() < seq;
|
|
||||||
auto const backendRange = backend_->fetchLedgerRange();
|
|
||||||
auto const backendNeedsUpdate = backendRange.has_value() and backendRange->maxSequence < seq;
|
|
||||||
|
|
||||||
if (cacheNeedsUpdate) {
|
|
||||||
auto const diff = data::synchronousAndRetryOnTimeout([this, seq](auto yield) {
|
|
||||||
return backend_->fetchLedgerDiff(seq, yield);
|
|
||||||
});
|
|
||||||
cacheUpdater_->update(seq, diff);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (backendNeedsUpdate)
|
|
||||||
backend_->updateRange(seq);
|
|
||||||
|
|
||||||
publisher_->publish(seq, {});
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ETLService::startMonitor(uint32_t seq)
|
ETLService::startMonitor(uint32_t seq)
|
||||||
{
|
{
|
||||||
monitor_ = monitorProvider_->make(ctx_, backend_, ledgers_, seq);
|
monitor_ = monitorProvider_->make(ctx_, backend_, ledgers_, seq);
|
||||||
|
|
||||||
systemStateWriteCommandSubscription_ =
|
|
||||||
state_->writeCommandSignal.connect([this](SystemState::WriteCommand command) {
|
|
||||||
++runningWriteCommandHandlers_;
|
|
||||||
writeCommandStrand_.submit([this, command]() {
|
|
||||||
switch (command) {
|
|
||||||
case etl::SystemState::WriteCommand::StartWriting:
|
|
||||||
attemptTakeoverWriter();
|
|
||||||
break;
|
|
||||||
case etl::SystemState::WriteCommand::StopWriting:
|
|
||||||
giveUpWriter();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
--runningWriteCommandHandlers_;
|
|
||||||
runningWriteCommandHandlers_.notify_one();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
monitorNewSeqSubscription_ = monitor_->subscribeToNewSequence([this](uint32_t seq) {
|
monitorNewSeqSubscription_ = monitor_->subscribeToNewSequence([this](uint32_t seq) {
|
||||||
LOG(log_.info()) << "ETLService (via Monitor) got new seq from db: " << seq;
|
LOG(log_.info()) << "ETLService (via Monitor) got new seq from db: " << seq;
|
||||||
updateCache(seq);
|
|
||||||
|
if (state_->writeConflict) {
|
||||||
|
LOG(log_.info()) << "Got a write conflict; Giving up writer seat immediately";
|
||||||
|
giveUpWriter();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (not state_->isWriting) {
|
||||||
|
auto const diff = data::synchronousAndRetryOnTimeout([this, seq](auto yield) {
|
||||||
|
return backend_->fetchLedgerDiff(seq, yield);
|
||||||
|
});
|
||||||
|
|
||||||
|
cacheUpdater_->update(seq, diff);
|
||||||
|
backend_->updateRange(seq);
|
||||||
|
}
|
||||||
|
|
||||||
|
publisher_->publish(seq, {});
|
||||||
});
|
});
|
||||||
|
|
||||||
monitorDbStalledSubscription_ = monitor_->subscribeToDbStalled([this]() {
|
monitorDbStalledSubscription_ = monitor_->subscribeToDbStalled([this]() {
|
||||||
LOG(log_.warn()) << "ETLService received DbStalled signal from Monitor";
|
LOG(log_.warn()) << "ETLService received DbStalled signal from Monitor";
|
||||||
// Database stall detected - no writer has been active for 10 seconds
|
|
||||||
// This triggers the fallback mechanism and attempts to become the writer
|
|
||||||
if (not state_->isStrictReadonly and not state_->isWriting)
|
if (not state_->isStrictReadonly and not state_->isWriting)
|
||||||
state_->writeCommandSignal(SystemState::WriteCommand::StartWriting);
|
attemptTakeoverWriter();
|
||||||
state_->isWriterDecidingFallback = true;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
monitor_->run();
|
monitor_->run();
|
||||||
@@ -441,13 +394,6 @@ ETLService::attemptTakeoverWriter()
|
|||||||
auto rng = backend_->hardFetchLedgerRangeNoThrow();
|
auto rng = backend_->hardFetchLedgerRangeNoThrow();
|
||||||
ASSERT(rng.has_value(), "Ledger range can't be null");
|
ASSERT(rng.has_value(), "Ledger range can't be null");
|
||||||
|
|
||||||
if (backend_->cache().latestLedgerSequence() != rng->maxSequence) {
|
|
||||||
LOG(log_.info()) << "Wanted to take over the ETL writer seat but LedgerCache is outdated";
|
|
||||||
// Give ETL time to update LedgerCache. This method will be called because ClusterCommunication will likely to
|
|
||||||
// continue sending StartWriting signal every 1 second
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
state_->isWriting = true; // switch to writer
|
state_->isWriting = true; // switch to writer
|
||||||
LOG(log_.info()) << "Taking over the ETL writer seat";
|
LOG(log_.info()) << "Taking over the ETL writer seat";
|
||||||
startLoading(rng->maxSequence + 1);
|
startLoading(rng->maxSequence + 1);
|
||||||
@@ -458,7 +404,7 @@ ETLService::giveUpWriter()
|
|||||||
{
|
{
|
||||||
ASSERT(not state_->isStrictReadonly, "This should only happen on writer nodes");
|
ASSERT(not state_->isStrictReadonly, "This should only happen on writer nodes");
|
||||||
state_->isWriting = false;
|
state_->isWriting = false;
|
||||||
LOG(log_.info()) << "Giving up writer seat";
|
state_->writeConflict = false;
|
||||||
taskMan_ = nullptr;
|
taskMan_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,6 @@
|
|||||||
#include "feed/SubscriptionManagerInterface.hpp"
|
#include "feed/SubscriptionManagerInterface.hpp"
|
||||||
#include "util/async/AnyExecutionContext.hpp"
|
#include "util/async/AnyExecutionContext.hpp"
|
||||||
#include "util/async/AnyOperation.hpp"
|
#include "util/async/AnyOperation.hpp"
|
||||||
#include "util/async/AnyStrand.hpp"
|
|
||||||
#include "util/config/ConfigDefinition.hpp"
|
#include "util/config/ConfigDefinition.hpp"
|
||||||
#include "util/log/Logger.hpp"
|
#include "util/log/Logger.hpp"
|
||||||
|
|
||||||
@@ -70,12 +69,12 @@
|
|||||||
#include <xrpl/protocol/TxFormats.h>
|
#include <xrpl/protocol/TxFormats.h>
|
||||||
#include <xrpl/protocol/TxMeta.h>
|
#include <xrpl/protocol/TxMeta.h>
|
||||||
|
|
||||||
#include <atomic>
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace etl {
|
namespace etl {
|
||||||
|
|
||||||
@@ -118,9 +117,6 @@ class ETLService : public ETLServiceInterface {
|
|||||||
|
|
||||||
boost::signals2::scoped_connection monitorNewSeqSubscription_;
|
boost::signals2::scoped_connection monitorNewSeqSubscription_;
|
||||||
boost::signals2::scoped_connection monitorDbStalledSubscription_;
|
boost::signals2::scoped_connection monitorDbStalledSubscription_;
|
||||||
boost::signals2::scoped_connection systemStateWriteCommandSubscription_;
|
|
||||||
util::async::AnyStrand writeCommandStrand_;
|
|
||||||
std::atomic<size_t> runningWriteCommandHandlers_{0};
|
|
||||||
|
|
||||||
std::optional<util::async::AnyOperation<void>> mainLoop_;
|
std::optional<util::async::AnyOperation<void>> mainLoop_;
|
||||||
|
|
||||||
@@ -131,7 +127,6 @@ public:
|
|||||||
* Creates and runs the ETL service.
|
* Creates and runs the ETL service.
|
||||||
*
|
*
|
||||||
* @param config The configuration to use
|
* @param config The configuration to use
|
||||||
* @param state The system state tracking object
|
|
||||||
* @param ctx Execution context for asynchronous operations
|
* @param ctx Execution context for asynchronous operations
|
||||||
* @param backend BackendInterface implementation
|
* @param backend BackendInterface implementation
|
||||||
* @param subscriptions Subscription manager
|
* @param subscriptions Subscription manager
|
||||||
@@ -142,7 +137,6 @@ public:
|
|||||||
static std::shared_ptr<ETLServiceInterface>
|
static std::shared_ptr<ETLServiceInterface>
|
||||||
makeETLService(
|
makeETLService(
|
||||||
util::config::ClioConfigDefinition const& config,
|
util::config::ClioConfigDefinition const& config,
|
||||||
std::shared_ptr<SystemState> state,
|
|
||||||
util::async::AnyExecutionContext ctx,
|
util::async::AnyExecutionContext ctx,
|
||||||
std::shared_ptr<BackendInterface> backend,
|
std::shared_ptr<BackendInterface> backend,
|
||||||
std::shared_ptr<feed::SubscriptionManagerInterface> subscriptions,
|
std::shared_ptr<feed::SubscriptionManagerInterface> subscriptions,
|
||||||
@@ -166,7 +160,7 @@ public:
|
|||||||
* @param initialLoadObserver The observer for initial data loading
|
* @param initialLoadObserver The observer for initial data loading
|
||||||
* @param taskManagerProvider The provider of the task manager instance
|
* @param taskManagerProvider The provider of the task manager instance
|
||||||
* @param monitorProvider The provider of the monitor instance
|
* @param monitorProvider The provider of the monitor instance
|
||||||
* @param state The system state tracking object
|
* @param state System state tracking object
|
||||||
*/
|
*/
|
||||||
ETLService(
|
ETLService(
|
||||||
util::async::AnyExecutionContext ctx,
|
util::async::AnyExecutionContext ctx,
|
||||||
@@ -212,12 +206,6 @@ private:
|
|||||||
std::optional<data::LedgerRange>
|
std::optional<data::LedgerRange>
|
||||||
loadInitialLedgerIfNeeded();
|
loadInitialLedgerIfNeeded();
|
||||||
|
|
||||||
[[nodiscard]] uint32_t
|
|
||||||
syncCacheWithDb();
|
|
||||||
|
|
||||||
void
|
|
||||||
updateCache(uint32_t seq);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
startMonitor(uint32_t seq);
|
startMonitor(uint32_t seq);
|
||||||
|
|
||||||
|
|||||||
@@ -19,16 +19,11 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "util/config/ConfigDefinition.hpp"
|
|
||||||
#include "util/log/Logger.hpp"
|
|
||||||
#include "util/prometheus/Bool.hpp"
|
#include "util/prometheus/Bool.hpp"
|
||||||
#include "util/prometheus/Label.hpp"
|
#include "util/prometheus/Label.hpp"
|
||||||
#include "util/prometheus/Prometheus.hpp"
|
#include "util/prometheus/Prometheus.hpp"
|
||||||
|
|
||||||
#include <boost/signals2/signal.hpp>
|
#include <atomic>
|
||||||
#include <boost/signals2/variadic_signal.hpp>
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
namespace etl {
|
namespace etl {
|
||||||
|
|
||||||
@@ -36,25 +31,6 @@ namespace etl {
|
|||||||
* @brief Represents the state of the ETL subsystem.
|
* @brief Represents the state of the ETL subsystem.
|
||||||
*/
|
*/
|
||||||
struct SystemState {
|
struct SystemState {
|
||||||
SystemState()
|
|
||||||
{
|
|
||||||
isLoadingCache = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Factory method to create a SystemState instance.
|
|
||||||
*
|
|
||||||
* @param config The configuration to use for initializing the system state
|
|
||||||
* @return A shared pointer to the newly created SystemState
|
|
||||||
*/
|
|
||||||
static std::shared_ptr<SystemState>
|
|
||||||
makeSystemState(util::config::ClioConfigDefinition const& config)
|
|
||||||
{
|
|
||||||
auto state = std::make_shared<SystemState>();
|
|
||||||
state->isStrictReadonly = config.get<bool>("read_only");
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Whether the process is in strict read-only mode.
|
* @brief Whether the process is in strict read-only mode.
|
||||||
*
|
*
|
||||||
@@ -74,31 +50,8 @@ struct SystemState {
|
|||||||
"Whether the process is writing to the database"
|
"Whether the process is writing to the database"
|
||||||
);
|
);
|
||||||
|
|
||||||
/** @brief Whether the process is still loading cache after startup. */
|
std::atomic_bool isStopping = false; /**< @brief Whether the software is stopping. */
|
||||||
util::prometheus::Bool isLoadingCache = PrometheusService::boolMetric(
|
std::atomic_bool writeConflict = false; /**< @brief Whether a write conflict was detected. */
|
||||||
"etl_loading_cache",
|
|
||||||
util::prometheus::Labels{},
|
|
||||||
"Whether etl is loading cache after clio startup"
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Commands for controlling the ETL writer state.
|
|
||||||
*
|
|
||||||
* These commands are emitted via writeCommandSignal to coordinate writer state transitions across components.
|
|
||||||
*/
|
|
||||||
enum class WriteCommand {
|
|
||||||
StartWriting, /**< Request to attempt taking over as the ETL writer */
|
|
||||||
StopWriting /**< Request to give up the ETL writer role (e.g., due to write conflict) */
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Signal for coordinating ETL writer state transitions.
|
|
||||||
*
|
|
||||||
* This signal allows components to request changes to the writer state without direct coupling.
|
|
||||||
* - Emitted with StartWriting when database stalls and node should attempt to become writer
|
|
||||||
* - Emitted with StopWriting when write conflicts are detected
|
|
||||||
*/
|
|
||||||
boost::signals2::signal<void(WriteCommand)> writeCommandSignal;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Whether clio detected an amendment block.
|
* @brief Whether clio detected an amendment block.
|
||||||
@@ -124,24 +77,6 @@ struct SystemState {
|
|||||||
util::prometheus::Labels{},
|
util::prometheus::Labels{},
|
||||||
"Whether clio detected a corruption that needs manual attention"
|
"Whether clio detected a corruption that needs manual attention"
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Whether the cluster is using the fallback writer decision mechanism.
|
|
||||||
*
|
|
||||||
* The fallback mechanism is triggered when:
|
|
||||||
* - The database stalls for 10 seconds (detected by Monitor), indicating no active writer
|
|
||||||
* - A write conflict is detected, indicating multiple nodes attempting to write simultaneously
|
|
||||||
*
|
|
||||||
* When fallback mode is active, the cluster stops using the cluster communication mechanism
|
|
||||||
* (TTL-based role announcements) and relies on the slower but more reliable database-based
|
|
||||||
* conflict detection. This flag propagates across the cluster - if any node enters fallback
|
|
||||||
* mode, all nodes in the cluster will switch to fallback mode.
|
|
||||||
*/
|
|
||||||
util::prometheus::Bool isWriterDecidingFallback = PrometheusService::boolMetric(
|
|
||||||
"etl_writing_deciding_fallback",
|
|
||||||
util::prometheus::Labels{},
|
|
||||||
"Whether the cluster is using the fallback writer decision mechanism"
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace etl
|
} // namespace etl
|
||||||
|
|||||||
@@ -1,88 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
/*
|
|
||||||
This file is part of clio: https://github.com/XRPLF/clio
|
|
||||||
Copyright (c) 2025, the clio developers.
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
//==============================================================================
|
|
||||||
|
|
||||||
#include "etl/WriterState.hpp"
|
|
||||||
|
|
||||||
#include "etl/SystemState.hpp"
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
namespace etl {
|
|
||||||
|
|
||||||
WriterState::WriterState(std::shared_ptr<SystemState> state) : systemState_(std::move(state))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
WriterState::isReadOnly() const
|
|
||||||
{
|
|
||||||
return systemState_->isStrictReadonly;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
WriterState::isWriting() const
|
|
||||||
{
|
|
||||||
return systemState_->isWriting;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
WriterState::startWriting()
|
|
||||||
{
|
|
||||||
if (isWriting())
|
|
||||||
return;
|
|
||||||
|
|
||||||
systemState_->writeCommandSignal(SystemState::WriteCommand::StartWriting);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
WriterState::giveUpWriting()
|
|
||||||
{
|
|
||||||
if (not isWriting())
|
|
||||||
return;
|
|
||||||
|
|
||||||
systemState_->writeCommandSignal(SystemState::WriteCommand::StopWriting);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
WriterState::setWriterDecidingFallback()
|
|
||||||
{
|
|
||||||
systemState_->isWriterDecidingFallback = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
WriterState::isFallback() const
|
|
||||||
{
|
|
||||||
return systemState_->isWriterDecidingFallback;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
WriterState::isLoadingCache() const
|
|
||||||
{
|
|
||||||
return systemState_->isLoadingCache;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<WriterStateInterface>
|
|
||||||
WriterState::clone() const
|
|
||||||
{
|
|
||||||
auto c = WriterState(*this);
|
|
||||||
return std::make_unique<WriterState>(std::move(c));
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace etl
|
|
||||||
@@ -1,193 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
/*
|
|
||||||
This file is part of clio: https://github.com/XRPLF/clio
|
|
||||||
Copyright (c) 2025, the clio developers.
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
//==============================================================================
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "etl/SystemState.hpp"
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
namespace etl {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Interface for managing writer state in the ETL subsystem.
|
|
||||||
*
|
|
||||||
* This interface provides methods to query and control whether the ETL process
|
|
||||||
* is actively writing to the database. Implementations should coordinate with
|
|
||||||
* the ETL system state to manage write responsibilities.
|
|
||||||
*/
|
|
||||||
class WriterStateInterface {
|
|
||||||
public:
|
|
||||||
virtual ~WriterStateInterface() = default;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Check if the ETL process is in strict read-only mode.
|
|
||||||
* @return true if the process is in strict read-only mode, false otherwise
|
|
||||||
*/
|
|
||||||
[[nodiscard]] virtual bool
|
|
||||||
isReadOnly() const = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Check if the ETL process is currently writing to the database.
|
|
||||||
* @return true if the process is writing, false otherwise
|
|
||||||
*/
|
|
||||||
[[nodiscard]] virtual bool
|
|
||||||
isWriting() const = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Request to start writing to the database.
|
|
||||||
*
|
|
||||||
* This method signals that the process should take over writing responsibilities.
|
|
||||||
* The actual transition to writing state may not be immediate.
|
|
||||||
*/
|
|
||||||
virtual void
|
|
||||||
startWriting() = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Request to stop writing to the database.
|
|
||||||
*
|
|
||||||
* This method signals that the process should give up writing responsibilities.
|
|
||||||
* The actual transition from writing state may not be immediate.
|
|
||||||
*/
|
|
||||||
virtual void
|
|
||||||
giveUpWriting() = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Check if the cluster is using the fallback writer decision mechanism.
|
|
||||||
*
|
|
||||||
* @return true if the cluster has switched to fallback mode, false otherwise
|
|
||||||
*/
|
|
||||||
[[nodiscard]] virtual bool
|
|
||||||
isFallback() const = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Switch the cluster to the fallback writer decision mechanism.
|
|
||||||
*
|
|
||||||
* This method is called when the cluster needs to transition from the cluster
|
|
||||||
* communication mechanism to the slower but more reliable fallback mechanism.
|
|
||||||
* Once set, this flag propagates to all nodes in the cluster through the
|
|
||||||
* ClioNode DbRole::Fallback state.
|
|
||||||
*/
|
|
||||||
virtual void
|
|
||||||
setWriterDecidingFallback() = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Whether clio is still loading cache after startup.
|
|
||||||
*
|
|
||||||
* @return true if clio is still loading cache, false otherwise.
|
|
||||||
*/
|
|
||||||
[[nodiscard]] virtual bool
|
|
||||||
isLoadingCache() const = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Create a clone of this writer state.
|
|
||||||
*
|
|
||||||
* Creates a new instance of the writer state with the same underlying system state.
|
|
||||||
* This is used when spawning operations that need their own writer state instance
|
|
||||||
* while sharing the same system state.
|
|
||||||
*
|
|
||||||
* @return A unique pointer to the cloned writer state.
|
|
||||||
*/
|
|
||||||
[[nodiscard]] virtual std::unique_ptr<WriterStateInterface>
|
|
||||||
clone() const = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Implementation of WriterStateInterface that manages ETL writer state.
|
|
||||||
*
|
|
||||||
* This class coordinates with SystemState to manage whether the ETL process
|
|
||||||
* is actively writing to the database. It provides methods to query the current
|
|
||||||
* writing state and request transitions between writing and non-writing states.
|
|
||||||
*/
|
|
||||||
class WriterState : public WriterStateInterface {
|
|
||||||
private:
|
|
||||||
std::shared_ptr<SystemState> systemState_; /**< @brief Shared system state for ETL coordination */
|
|
||||||
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* @brief Construct a WriterState with the given system state.
|
|
||||||
* @param state Shared pointer to the system state for coordination
|
|
||||||
*/
|
|
||||||
WriterState(std::shared_ptr<SystemState> state);
|
|
||||||
|
|
||||||
bool
|
|
||||||
isReadOnly() const override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Check if the ETL process is currently writing to the database.
|
|
||||||
* @return true if the process is writing, false otherwise
|
|
||||||
*/
|
|
||||||
bool
|
|
||||||
isWriting() const override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Request to start writing to the database.
|
|
||||||
*
|
|
||||||
* If already writing, this method does nothing. Otherwise, it sets the
|
|
||||||
* shouldTakeoverWriting flag in the system state to signal the request.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
startWriting() override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Request to stop writing to the database.
|
|
||||||
*
|
|
||||||
* If not currently writing, this method does nothing. Otherwise, it sets the
|
|
||||||
* shouldGiveUpWriter flag in the system state to signal the request.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
giveUpWriting() override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Switch the cluster to the fallback writer decision mechanism.
|
|
||||||
*
|
|
||||||
* Sets the isWriterDecidingFallback flag in the system state, which will be
|
|
||||||
* propagated to other nodes in the cluster through the ClioNode DbRole::Fallback state.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
setWriterDecidingFallback() override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Check if the cluster is using the fallback writer decision mechanism.
|
|
||||||
*
|
|
||||||
* @return true if the cluster has switched to fallback mode, false otherwise
|
|
||||||
*/
|
|
||||||
bool
|
|
||||||
isFallback() const override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Whether clio is still loading cache after startup.
|
|
||||||
*
|
|
||||||
* @return true if clio is still loading cache, false otherwise.
|
|
||||||
*/
|
|
||||||
bool
|
|
||||||
isLoadingCache() const override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Create a clone of this writer state.
|
|
||||||
*
|
|
||||||
* Creates a new WriterState instance sharing the same system state.
|
|
||||||
*
|
|
||||||
* @return A unique pointer to the cloned writer state.
|
|
||||||
*/
|
|
||||||
std::unique_ptr<WriterStateInterface>
|
|
||||||
clone() const override;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace etl
|
|
||||||
@@ -45,7 +45,6 @@
|
|||||||
#include <xrpl/protocol/Serializer.h>
|
#include <xrpl/protocol/Serializer.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <atomic>
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
@@ -77,8 +76,6 @@ class LedgerPublisher : public LedgerPublisherInterface {
|
|||||||
|
|
||||||
util::async::AnyStrand publishStrand_;
|
util::async::AnyStrand publishStrand_;
|
||||||
|
|
||||||
std::atomic_bool stop_{false};
|
|
||||||
|
|
||||||
std::shared_ptr<BackendInterface> backend_;
|
std::shared_ptr<BackendInterface> backend_;
|
||||||
std::shared_ptr<feed::SubscriptionManagerInterface> subscriptions_;
|
std::shared_ptr<feed::SubscriptionManagerInterface> subscriptions_;
|
||||||
std::reference_wrapper<SystemState const> state_; // shared state for ETL
|
std::reference_wrapper<SystemState const> state_; // shared state for ETL
|
||||||
@@ -128,7 +125,7 @@ public:
|
|||||||
{
|
{
|
||||||
LOG(log_.info()) << "Attempting to publish ledger = " << ledgerSequence;
|
LOG(log_.info()) << "Attempting to publish ledger = " << ledgerSequence;
|
||||||
size_t numAttempts = 0;
|
size_t numAttempts = 0;
|
||||||
while (not stop_) {
|
while (not state_.get().isStopping) {
|
||||||
auto range = backend_->hardFetchLedgerRangeNoThrow();
|
auto range = backend_->hardFetchLedgerRangeNoThrow();
|
||||||
|
|
||||||
if (!range || range->maxSequence < ledgerSequence) {
|
if (!range || range->maxSequence < ledgerSequence) {
|
||||||
@@ -261,18 +258,6 @@ public:
|
|||||||
return *lastPublishedSequence_.lock();
|
return *lastPublishedSequence_.lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Stops publishing
|
|
||||||
*
|
|
||||||
* @note This is a basic implementation to satisfy tests. This will be improved in
|
|
||||||
* https://github.com/XRPLF/clio/issues/2833
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
stop()
|
|
||||||
{
|
|
||||||
stop_ = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void
|
void
|
||||||
setLastClose(std::chrono::time_point<ripple::NetClock> lastCloseTime)
|
setLastClose(std::chrono::time_point<ripple::NetClock> lastCloseTime)
|
||||||
|
|||||||
@@ -75,10 +75,7 @@ Loader::load(model::LedgerData const& data)
|
|||||||
<< "; took " << duration << "ms";
|
<< "; took " << duration << "ms";
|
||||||
|
|
||||||
if (not success) {
|
if (not success) {
|
||||||
// Write conflict detected - another node wrote to the database
|
state_->writeConflict = true;
|
||||||
// This triggers the fallback mechanism and stops this node from writing
|
|
||||||
state_->writeCommandSignal(SystemState::WriteCommand::StopWriting);
|
|
||||||
state_->isWriterDecidingFallback = true;
|
|
||||||
LOG(log_.warn()) << "Another node wrote a ledger into the DB - we have a write conflict";
|
LOG(log_.warn()) << "Another node wrote a ledger into the DB - we have a write conflict";
|
||||||
return std::unexpected(LoaderError::WriteConflict);
|
return std::unexpected(LoaderError::WriteConflict);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
add_library(clio_feed)
|
add_library(clio_feed)
|
||||||
target_sources(clio_feed PRIVATE SubscriptionManager.cpp impl/TransactionFeed.cpp impl/LedgerFeed.cpp
|
target_sources(
|
||||||
impl/ProposedTransactionFeed.cpp impl/SingleFeedBase.cpp)
|
clio_feed PRIVATE SubscriptionManager.cpp impl/TransactionFeed.cpp impl/LedgerFeed.cpp
|
||||||
|
impl/ProposedTransactionFeed.cpp impl/SingleFeedBase.cpp
|
||||||
|
)
|
||||||
|
|
||||||
target_link_libraries(clio_feed PRIVATE clio_util)
|
target_link_libraries(clio_feed PRIVATE clio_util)
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ SingleFeedBase::unsub(SubscriberSharedPtr const& subscriber)
|
|||||||
void
|
void
|
||||||
SingleFeedBase::pub(std::string msg)
|
SingleFeedBase::pub(std::string msg)
|
||||||
{
|
{
|
||||||
strand_.submit([this, msg = std::move(msg)] {
|
[[maybe_unused]] auto task = strand_.execute([this, msg = std::move(msg)]() {
|
||||||
auto const msgPtr = std::make_shared<std::string>(msg);
|
auto const msgPtr = std::make_shared<std::string>(msg);
|
||||||
signal_.emit(msgPtr);
|
signal_.emit(msgPtr);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -73,15 +73,10 @@ public:
|
|||||||
|
|
||||||
// This class can't hold the trackable's shared_ptr, because disconnect should be able to be called in the
|
// This class can't hold the trackable's shared_ptr, because disconnect should be able to be called in the
|
||||||
// the trackable's destructor. However, the trackable can not be destroyed when the slot is being called
|
// the trackable's destructor. However, the trackable can not be destroyed when the slot is being called
|
||||||
// either. `track_foreign` is racey when one shared_ptr is tracked by multiple signals. Therefore we are storing
|
// either. track_foreign will hold a weak_ptr to the connection, which makes sure the connection is valid when
|
||||||
// a weak_ptr of the trackable and using weak_ptr::lock() to atomically check existence and acquire a shared_ptr
|
// the slot is called.
|
||||||
// during slot invocation. This guarantees to keep the trackable alive for the duration of the slot call and
|
|
||||||
// avoids potential race conditions.
|
|
||||||
connections->emplace(
|
connections->emplace(
|
||||||
trackable.get(), signal_.connect([slot, weakTrackable = std::weak_ptr(trackable)](Args&&... args) {
|
trackable.get(), signal_.connect(typename SignalType::slot_type(slot).track_foreign(trackable))
|
||||||
if (auto lifeExtender = weakTrackable.lock(); lifeExtender)
|
|
||||||
std::invoke(slot, std::forward<Args...>(args)...);
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,14 +4,16 @@ target_sources(clio_server PRIVATE Main.cpp)
|
|||||||
target_link_libraries(clio_server PRIVATE clio_app)
|
target_link_libraries(clio_server PRIVATE clio_app)
|
||||||
|
|
||||||
if (static)
|
if (static)
|
||||||
if (san)
|
if (san)
|
||||||
message(FATAL_ERROR "Static linkage not allowed when using sanitizers")
|
message(FATAL_ERROR "Static linkage not allowed when using sanitizers")
|
||||||
elseif (is_appleclang)
|
elseif (is_appleclang)
|
||||||
message(FATAL_ERROR "Static linkage not supported on AppleClang")
|
message(FATAL_ERROR "Static linkage not supported on AppleClang")
|
||||||
else ()
|
else ()
|
||||||
target_link_options(# Note: -static-libstdc++ can statically link both libstdc++ and libc++
|
target_link_options(
|
||||||
clio_server PRIVATE -static-libstdc++ -static-libgcc)
|
# Note: -static-libstdc++ can statically link both libstdc++ and libc++
|
||||||
endif ()
|
clio_server PRIVATE -static-libstdc++ -static-libgcc
|
||||||
|
)
|
||||||
|
endif ()
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
set_target_properties(clio_server PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
|
set_target_properties(clio_server PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
add_library(clio_migration)
|
add_library(clio_migration)
|
||||||
|
|
||||||
target_sources(clio_migration PRIVATE MigrationApplication.cpp impl/MigrationManagerFactory.cpp MigratorStatus.cpp
|
target_sources(
|
||||||
cassandra/impl/ObjectsAdapter.cpp cassandra/impl/TransactionsAdapter.cpp)
|
clio_migration PRIVATE MigrationApplication.cpp impl/MigrationManagerFactory.cpp MigratorStatus.cpp
|
||||||
|
cassandra/impl/ObjectsAdapter.cpp cassandra/impl/TransactionsAdapter.cpp
|
||||||
|
)
|
||||||
|
|
||||||
target_link_libraries(clio_migration PRIVATE clio_util clio_data)
|
target_link_libraries(clio_migration PRIVATE clio_util clio_data)
|
||||||
|
|||||||
@@ -6,53 +6,55 @@ target_link_libraries(clio_rpc_center PUBLIC clio_options)
|
|||||||
|
|
||||||
add_library(clio_rpc)
|
add_library(clio_rpc)
|
||||||
|
|
||||||
target_sources(clio_rpc
|
target_sources(
|
||||||
PRIVATE Errors.cpp
|
clio_rpc
|
||||||
Factories.cpp
|
PRIVATE Errors.cpp
|
||||||
AMMHelpers.cpp
|
Factories.cpp
|
||||||
RPCHelpers.cpp
|
AMMHelpers.cpp
|
||||||
CredentialHelpers.cpp
|
RPCHelpers.cpp
|
||||||
Counters.cpp
|
CredentialHelpers.cpp
|
||||||
WorkQueue.cpp
|
Counters.cpp
|
||||||
common/Specs.cpp
|
WorkQueue.cpp
|
||||||
common/Validators.cpp
|
common/Specs.cpp
|
||||||
common/MetaProcessors.cpp
|
common/Validators.cpp
|
||||||
common/impl/APIVersionParser.cpp
|
common/MetaProcessors.cpp
|
||||||
common/impl/HandlerProvider.cpp
|
common/impl/APIVersionParser.cpp
|
||||||
handlers/AccountChannels.cpp
|
common/impl/HandlerProvider.cpp
|
||||||
handlers/AccountCurrencies.cpp
|
handlers/AccountChannels.cpp
|
||||||
handlers/AccountInfo.cpp
|
handlers/AccountCurrencies.cpp
|
||||||
handlers/AccountLines.cpp
|
handlers/AccountInfo.cpp
|
||||||
handlers/AccountMPTokenIssuances.cpp
|
handlers/AccountLines.cpp
|
||||||
handlers/AccountMPTokens.cpp
|
handlers/AccountMPTokenIssuances.cpp
|
||||||
handlers/AccountNFTs.cpp
|
handlers/AccountMPTokens.cpp
|
||||||
handlers/AccountObjects.cpp
|
handlers/AccountNFTs.cpp
|
||||||
handlers/AccountOffers.cpp
|
handlers/AccountObjects.cpp
|
||||||
handlers/AccountTx.cpp
|
handlers/AccountOffers.cpp
|
||||||
handlers/AMMInfo.cpp
|
handlers/AccountTx.cpp
|
||||||
handlers/BookChanges.cpp
|
handlers/AMMInfo.cpp
|
||||||
handlers/BookOffers.cpp
|
handlers/BookChanges.cpp
|
||||||
handlers/DepositAuthorized.cpp
|
handlers/BookOffers.cpp
|
||||||
handlers/Feature.cpp
|
handlers/DepositAuthorized.cpp
|
||||||
handlers/GatewayBalances.cpp
|
handlers/Feature.cpp
|
||||||
handlers/GetAggregatePrice.cpp
|
handlers/GatewayBalances.cpp
|
||||||
handlers/Ledger.cpp
|
handlers/GetAggregatePrice.cpp
|
||||||
handlers/LedgerData.cpp
|
handlers/Ledger.cpp
|
||||||
handlers/LedgerEntry.cpp
|
handlers/LedgerData.cpp
|
||||||
handlers/LedgerIndex.cpp
|
handlers/LedgerEntry.cpp
|
||||||
handlers/LedgerRange.cpp
|
handlers/LedgerIndex.cpp
|
||||||
handlers/MPTHolders.cpp
|
handlers/LedgerRange.cpp
|
||||||
handlers/NFTsByIssuer.cpp
|
handlers/MPTHolders.cpp
|
||||||
handlers/NFTBuyOffers.cpp
|
handlers/NFTsByIssuer.cpp
|
||||||
handlers/NFTHistory.cpp
|
handlers/NFTBuyOffers.cpp
|
||||||
handlers/NFTInfo.cpp
|
handlers/NFTHistory.cpp
|
||||||
handlers/NFTOffersCommon.cpp
|
handlers/NFTInfo.cpp
|
||||||
handlers/NFTSellOffers.cpp
|
handlers/NFTOffersCommon.cpp
|
||||||
handlers/NoRippleCheck.cpp
|
handlers/NFTSellOffers.cpp
|
||||||
handlers/Random.cpp
|
handlers/NoRippleCheck.cpp
|
||||||
handlers/Subscribe.cpp
|
handlers/Random.cpp
|
||||||
handlers/TransactionEntry.cpp
|
handlers/Subscribe.cpp
|
||||||
handlers/Unsubscribe.cpp
|
handlers/TransactionEntry.cpp
|
||||||
handlers/VaultInfo.cpp)
|
handlers/Unsubscribe.cpp
|
||||||
|
handlers/VaultInfo.cpp
|
||||||
|
)
|
||||||
|
|
||||||
target_link_libraries(clio_rpc PRIVATE clio_util)
|
target_link_libraries(clio_rpc PRIVATE clio_util)
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ getErrorInfo(ClioError code)
|
|||||||
{.code = ClioError::RpcMalformedAuthorizedCredentials,
|
{.code = ClioError::RpcMalformedAuthorizedCredentials,
|
||||||
.error = "malformedAuthorizedCredentials",
|
.error = "malformedAuthorizedCredentials",
|
||||||
.message = "Malformed authorized credentials."},
|
.message = "Malformed authorized credentials."},
|
||||||
|
{.code = ClioError::RpcEntryNotFound, .error = "entryNotFound", .message = "Entry Not Found."},
|
||||||
// special system errors
|
// special system errors
|
||||||
{.code = ClioError::RpcInvalidApiVersion, .error = JS(invalid_API_version), .message = "Invalid API version."},
|
{.code = ClioError::RpcInvalidApiVersion, .error = JS(invalid_API_version), .message = "Invalid API version."},
|
||||||
{.code = ClioError::RpcCommandIsMissing,
|
{.code = ClioError::RpcCommandIsMissing,
|
||||||
|
|||||||
@@ -43,8 +43,7 @@ enum class ClioError {
|
|||||||
RpcFieldNotFoundTransaction = 5006,
|
RpcFieldNotFoundTransaction = 5006,
|
||||||
RpcMalformedOracleDocumentId = 5007,
|
RpcMalformedOracleDocumentId = 5007,
|
||||||
RpcMalformedAuthorizedCredentials = 5008,
|
RpcMalformedAuthorizedCredentials = 5008,
|
||||||
// NOTE: RpcEntryNotFound is replaced with RippledError::rpcENTRY_NOT_FOUND
|
RpcEntryNotFound = 5009,
|
||||||
// RpcEntryNotFound = 5009,
|
|
||||||
|
|
||||||
// special system errors start with 6000
|
// special system errors start with 6000
|
||||||
RpcInvalidApiVersion = 6000,
|
RpcInvalidApiVersion = 6000,
|
||||||
|
|||||||
@@ -25,39 +25,20 @@
|
|||||||
#include "util/prometheus/Label.hpp"
|
#include "util/prometheus/Label.hpp"
|
||||||
#include "util/prometheus/Prometheus.hpp"
|
#include "util/prometheus/Prometheus.hpp"
|
||||||
|
|
||||||
|
#include <boost/asio/post.hpp>
|
||||||
#include <boost/asio/spawn.hpp>
|
#include <boost/asio/spawn.hpp>
|
||||||
|
#include <boost/asio/strand.hpp>
|
||||||
#include <boost/json/object.hpp>
|
#include <boost/json/object.hpp>
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <optional>
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace rpc {
|
namespace rpc {
|
||||||
|
|
||||||
void
|
|
||||||
WorkQueue::OneTimeCallable::setCallable(std::function<void()> func)
|
|
||||||
{
|
|
||||||
func_ = std::move(func);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
WorkQueue::OneTimeCallable::operator()()
|
|
||||||
{
|
|
||||||
if (not called_) {
|
|
||||||
func_();
|
|
||||||
called_ = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
WorkQueue::OneTimeCallable::
|
|
||||||
operator bool() const
|
|
||||||
{
|
|
||||||
return func_.operator bool();
|
|
||||||
}
|
|
||||||
|
|
||||||
WorkQueue::WorkQueue(DontStartProcessingTag, std::uint32_t numWorkers, uint32_t maxSize)
|
WorkQueue::WorkQueue(DontStartProcessingTag, std::uint32_t numWorkers, uint32_t maxSize)
|
||||||
: queued_{PrometheusService::counterInt(
|
: queued_{PrometheusService::counterInt(
|
||||||
"work_queue_queued_total_number",
|
"work_queue_queued_total_number",
|
||||||
@@ -75,6 +56,8 @@ WorkQueue::WorkQueue(DontStartProcessingTag, std::uint32_t numWorkers, uint32_t
|
|||||||
"The current number of tasks in the queue"
|
"The current number of tasks in the queue"
|
||||||
)}
|
)}
|
||||||
, ioc_{numWorkers}
|
, ioc_{numWorkers}
|
||||||
|
, strand_{ioc_.get_executor()}
|
||||||
|
, waitTimer_(ioc_)
|
||||||
{
|
{
|
||||||
if (maxSize != 0)
|
if (maxSize != 0)
|
||||||
maxSize_ = maxSize;
|
maxSize_ = maxSize;
|
||||||
@@ -94,14 +77,12 @@ WorkQueue::~WorkQueue()
|
|||||||
void
|
void
|
||||||
WorkQueue::startProcessing()
|
WorkQueue::startProcessing()
|
||||||
{
|
{
|
||||||
ASSERT(not processingStarted_, "Attempt to start processing work queue more than once");
|
util::spawn(strand_, [this](auto yield) {
|
||||||
processingStarted_ = true;
|
ASSERT(not hasDispatcher_, "Dispatcher already running");
|
||||||
|
|
||||||
// Spawn workers for all tasks that were queued before processing started
|
hasDispatcher_ = true;
|
||||||
auto const numTasks = size();
|
dispatcherLoop(yield);
|
||||||
for (auto i = 0uz; i < numTasks; ++i) {
|
});
|
||||||
util::spawn(ioc_, [this](auto yield) { executeTask(yield); });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
@@ -117,28 +98,105 @@ WorkQueue::postCoro(TaskType func, bool isWhiteListed, Priority priority)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
++curSize_.get();
|
||||||
|
auto needsWakeup = false;
|
||||||
|
|
||||||
{
|
{
|
||||||
auto state = queueState_.lock();
|
auto state = dispatcherState_.lock();
|
||||||
|
|
||||||
|
needsWakeup = std::exchange(state->isIdle, false);
|
||||||
|
|
||||||
state->push(priority, std::move(func));
|
state->push(priority, std::move(func));
|
||||||
}
|
}
|
||||||
|
|
||||||
++curSize_.get();
|
if (needsWakeup)
|
||||||
|
boost::asio::post(strand_, [this] { waitTimer_.cancel(); });
|
||||||
if (not processingStarted_)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
util::spawn(ioc_, [this](auto yield) { executeTask(yield); });
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
WorkQueue::dispatcherLoop(boost::asio::yield_context yield)
|
||||||
|
{
|
||||||
|
LOG(log_.info()) << "WorkQueue dispatcher starting";
|
||||||
|
|
||||||
|
// all ongoing tasks must be completed before stopping fully
|
||||||
|
while (not stopping_ or size() > 0) {
|
||||||
|
std::vector<TaskType> batch;
|
||||||
|
|
||||||
|
{
|
||||||
|
auto state = dispatcherState_.lock();
|
||||||
|
|
||||||
|
if (state->empty()) {
|
||||||
|
state->isIdle = true;
|
||||||
|
} else {
|
||||||
|
for (auto count = 0uz; count < kTAKE_HIGH_PRIO and not state->high.empty(); ++count) {
|
||||||
|
batch.push_back(std::move(state->high.front()));
|
||||||
|
state->high.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (not state->normal.empty()) {
|
||||||
|
batch.push_back(std::move(state->normal.front()));
|
||||||
|
state->normal.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (not stopping_ and batch.empty()) {
|
||||||
|
waitTimer_.expires_at(std::chrono::steady_clock::time_point::max());
|
||||||
|
boost::system::error_code ec;
|
||||||
|
waitTimer_.async_wait(yield[ec]);
|
||||||
|
} else {
|
||||||
|
for (auto task : std::move(batch)) {
|
||||||
|
util::spawn(
|
||||||
|
ioc_,
|
||||||
|
[this, spawnedAt = std::chrono::system_clock::now(), task = std::move(task)](auto yield) mutable {
|
||||||
|
auto const takenAt = std::chrono::system_clock::now();
|
||||||
|
auto const waited =
|
||||||
|
std::chrono::duration_cast<std::chrono::microseconds>(takenAt - spawnedAt).count();
|
||||||
|
|
||||||
|
++queued_.get();
|
||||||
|
durationUs_.get() += waited;
|
||||||
|
LOG(log_.info()) << "WorkQueue wait time: " << waited << ", queue size: " << size();
|
||||||
|
|
||||||
|
task(yield);
|
||||||
|
|
||||||
|
--curSize_.get();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::asio::post(ioc_.get_executor(), yield); // yield back to avoid hijacking the thread
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG(log_.info()) << "WorkQueue dispatcher shutdown requested - time to execute onTasksComplete";
|
||||||
|
|
||||||
|
{
|
||||||
|
auto onTasksComplete = onQueueEmpty_.lock();
|
||||||
|
ASSERT(onTasksComplete->operator bool(), "onTasksComplete must be set when stopping is true.");
|
||||||
|
onTasksComplete->operator()();
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG(log_.info()) << "WorkQueue dispatcher finished";
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
WorkQueue::requestStop(std::function<void()> onQueueEmpty)
|
WorkQueue::requestStop(std::function<void()> onQueueEmpty)
|
||||||
{
|
{
|
||||||
auto handler = onQueueEmpty_.lock();
|
auto handler = onQueueEmpty_.lock();
|
||||||
handler->setCallable(std::move(onQueueEmpty));
|
*handler = std::move(onQueueEmpty);
|
||||||
|
|
||||||
stopping_ = true;
|
stopping_ = true;
|
||||||
|
auto needsWakeup = false;
|
||||||
|
|
||||||
|
{
|
||||||
|
auto state = dispatcherState_.lock();
|
||||||
|
needsWakeup = std::exchange(state->isIdle, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (needsWakeup)
|
||||||
|
boost::asio::post(strand_, [this] { waitTimer_.cancel(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -148,12 +206,6 @@ WorkQueue::stop()
|
|||||||
requestStop();
|
requestStop();
|
||||||
|
|
||||||
ioc_.join();
|
ioc_.join();
|
||||||
|
|
||||||
{
|
|
||||||
auto onTasksComplete = onQueueEmpty_.lock();
|
|
||||||
ASSERT(onTasksComplete->operator bool(), "onTasksComplete must be set when stopping is true.");
|
|
||||||
onTasksComplete->operator()();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WorkQueue
|
WorkQueue
|
||||||
@@ -187,29 +239,4 @@ WorkQueue::size() const
|
|||||||
return curSize_.get().value();
|
return curSize_.get().value();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
WorkQueue::executeTask(boost::asio::yield_context yield)
|
|
||||||
{
|
|
||||||
std::optional<TaskWithTimestamp> taskWithTimestamp;
|
|
||||||
{
|
|
||||||
auto state = queueState_.lock();
|
|
||||||
taskWithTimestamp = state->popNext();
|
|
||||||
}
|
|
||||||
|
|
||||||
ASSERT(
|
|
||||||
taskWithTimestamp.has_value(),
|
|
||||||
"Queue should not be empty as we spawn a coro with executeTask for each postCoro."
|
|
||||||
);
|
|
||||||
auto const takenAt = std::chrono::system_clock::now();
|
|
||||||
auto const waited =
|
|
||||||
std::chrono::duration_cast<std::chrono::microseconds>(takenAt - taskWithTimestamp->queuedAt).count();
|
|
||||||
|
|
||||||
++queued_.get();
|
|
||||||
durationUs_.get() += waited;
|
|
||||||
LOG(log_.info()) << "WorkQueue wait time: " << waited << ", queue size: " << size();
|
|
||||||
|
|
||||||
taskWithTimestamp->task(yield);
|
|
||||||
--curSize_.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace rpc
|
} // namespace rpc
|
||||||
|
|||||||
@@ -25,19 +25,20 @@
|
|||||||
#include "util/prometheus/Counter.hpp"
|
#include "util/prometheus/Counter.hpp"
|
||||||
#include "util/prometheus/Gauge.hpp"
|
#include "util/prometheus/Gauge.hpp"
|
||||||
|
|
||||||
|
#include <boost/asio.hpp>
|
||||||
#include <boost/asio/spawn.hpp>
|
#include <boost/asio/spawn.hpp>
|
||||||
|
#include <boost/asio/steady_timer.hpp>
|
||||||
|
#include <boost/asio/strand.hpp>
|
||||||
#include <boost/asio/thread_pool.hpp>
|
#include <boost/asio/thread_pool.hpp>
|
||||||
|
#include <boost/json.hpp>
|
||||||
#include <boost/json/object.hpp>
|
#include <boost/json/object.hpp>
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <chrono>
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <optional>
|
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
namespace rpc {
|
namespace rpc {
|
||||||
|
|
||||||
@@ -61,13 +62,7 @@ struct Reportable {
|
|||||||
*/
|
*/
|
||||||
class WorkQueue : public Reportable {
|
class WorkQueue : public Reportable {
|
||||||
using TaskType = std::function<void(boost::asio::yield_context)>;
|
using TaskType = std::function<void(boost::asio::yield_context)>;
|
||||||
|
using QueueType = std::queue<TaskType>;
|
||||||
struct TaskWithTimestamp {
|
|
||||||
TaskType task;
|
|
||||||
std::chrono::system_clock::time_point queuedAt;
|
|
||||||
};
|
|
||||||
|
|
||||||
using QueueType = std::queue<TaskWithTimestamp>;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@@ -79,21 +74,21 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct QueueState {
|
struct DispatcherState {
|
||||||
QueueType high;
|
QueueType high;
|
||||||
QueueType normal;
|
QueueType normal;
|
||||||
|
|
||||||
size_t highPriorityCounter = 0;
|
bool isIdle = false;
|
||||||
|
|
||||||
void
|
void
|
||||||
push(Priority priority, TaskType&& task)
|
push(Priority priority, auto&& task)
|
||||||
{
|
{
|
||||||
auto& queue = [this, priority] -> QueueType& {
|
auto& queue = [this, priority] -> QueueType& {
|
||||||
if (priority == Priority::High)
|
if (priority == Priority::High)
|
||||||
return high;
|
return high;
|
||||||
return normal;
|
return normal;
|
||||||
}();
|
}();
|
||||||
queue.push(TaskWithTimestamp{.task = std::move(task), .queuedAt = std::chrono::system_clock::now()});
|
queue.push(std::forward<decltype(task)>(task));
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] bool
|
[[nodiscard]] bool
|
||||||
@@ -101,26 +96,6 @@ private:
|
|||||||
{
|
{
|
||||||
return high.empty() and normal.empty();
|
return high.empty() and normal.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] std::optional<TaskWithTimestamp>
|
|
||||||
popNext()
|
|
||||||
{
|
|
||||||
if (not high.empty() and (highPriorityCounter < kTAKE_HIGH_PRIO or normal.empty())) {
|
|
||||||
auto taskWithTimestamp = std::move(high.front());
|
|
||||||
high.pop();
|
|
||||||
++highPriorityCounter;
|
|
||||||
return taskWithTimestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (not normal.empty()) {
|
|
||||||
auto taskWithTimestamp = std::move(normal.front());
|
|
||||||
normal.pop();
|
|
||||||
highPriorityCounter = 0;
|
|
||||||
return taskWithTimestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -135,26 +110,14 @@ private:
|
|||||||
|
|
||||||
util::Logger log_{"RPC"};
|
util::Logger log_{"RPC"};
|
||||||
boost::asio::thread_pool ioc_;
|
boost::asio::thread_pool ioc_;
|
||||||
|
boost::asio::strand<boost::asio::thread_pool::executor_type> strand_;
|
||||||
|
bool hasDispatcher_ = false;
|
||||||
|
|
||||||
std::atomic_bool stopping_;
|
std::atomic_bool stopping_;
|
||||||
std::atomic_bool processingStarted_{false};
|
|
||||||
|
|
||||||
class OneTimeCallable {
|
util::Mutex<std::function<void()>> onQueueEmpty_;
|
||||||
std::function<void()> func_;
|
util::Mutex<DispatcherState> dispatcherState_;
|
||||||
bool called_{false};
|
boost::asio::steady_timer waitTimer_;
|
||||||
|
|
||||||
public:
|
|
||||||
void
|
|
||||||
setCallable(std::function<void()> func);
|
|
||||||
|
|
||||||
void
|
|
||||||
operator()();
|
|
||||||
|
|
||||||
explicit
|
|
||||||
operator bool() const;
|
|
||||||
};
|
|
||||||
util::Mutex<OneTimeCallable> onQueueEmpty_;
|
|
||||||
util::Mutex<QueueState> queueState_;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct DontStartProcessingTag {};
|
struct DontStartProcessingTag {};
|
||||||
@@ -248,7 +211,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void
|
void
|
||||||
executeTask(boost::asio::yield_context yield);
|
dispatcherLoop(boost::asio::yield_context yield);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace rpc
|
} // namespace rpc
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ VaultInfoHandler::process(VaultInfoHandler::Input const& input, Context const& c
|
|||||||
sharedPtrBackend_->fetchLedgerObject(accountKeylet.key, lgrInfo.seq, ctx.yield);
|
sharedPtrBackend_->fetchLedgerObject(accountKeylet.key, lgrInfo.seq, ctx.yield);
|
||||||
|
|
||||||
if (!accountLedgerObject)
|
if (!accountLedgerObject)
|
||||||
return std::unexpected{Status{RippledError::rpcENTRY_NOT_FOUND}};
|
return std::unexpected{Status{ClioError::RpcEntryNotFound}};
|
||||||
}
|
}
|
||||||
|
|
||||||
return ripple::keylet::vault(*accountID, *input.tnxSequence);
|
return ripple::keylet::vault(*accountID, *input.tnxSequence);
|
||||||
@@ -116,7 +116,7 @@ VaultInfoHandler::process(VaultInfoHandler::Input const& input, Context const& c
|
|||||||
if (nodeIndex.parseHex(*input.vaultID))
|
if (nodeIndex.parseHex(*input.vaultID))
|
||||||
return ripple::keylet::vault(nodeIndex);
|
return ripple::keylet::vault(nodeIndex);
|
||||||
|
|
||||||
return std::unexpected{Status{RippledError::rpcENTRY_NOT_FOUND}};
|
return std::unexpected{Status{ClioError::RpcEntryNotFound}};
|
||||||
}();
|
}();
|
||||||
|
|
||||||
if (not vaultKeylet.has_value())
|
if (not vaultKeylet.has_value())
|
||||||
@@ -127,7 +127,7 @@ VaultInfoHandler::process(VaultInfoHandler::Input const& input, Context const& c
|
|||||||
sharedPtrBackend_->fetchLedgerObject(vaultKeylet.value().key, lgrInfo.seq, ctx.yield);
|
sharedPtrBackend_->fetchLedgerObject(vaultKeylet.value().key, lgrInfo.seq, ctx.yield);
|
||||||
|
|
||||||
if (not vaultLedgerObject)
|
if (not vaultLedgerObject)
|
||||||
return Error{Status{RippledError::rpcENTRY_NOT_FOUND, "vault object not found."}};
|
return Error{Status{ClioError::RpcEntryNotFound, "vault object not found."}};
|
||||||
|
|
||||||
ripple::STLedgerEntry const vaultSle{
|
ripple::STLedgerEntry const vaultSle{
|
||||||
ripple::SerialIter{vaultLedgerObject->data(), vaultLedgerObject->size()}, vaultKeylet.value().key
|
ripple::SerialIter{vaultLedgerObject->data(), vaultLedgerObject->size()}, vaultKeylet.value().key
|
||||||
@@ -137,7 +137,7 @@ VaultInfoHandler::process(VaultInfoHandler::Input const& input, Context const& c
|
|||||||
auto const issuanceObject = sharedPtrBackend_->fetchLedgerObject(issuanceKeylet, lgrInfo.seq, ctx.yield);
|
auto const issuanceObject = sharedPtrBackend_->fetchLedgerObject(issuanceKeylet, lgrInfo.seq, ctx.yield);
|
||||||
|
|
||||||
if (not issuanceObject)
|
if (not issuanceObject)
|
||||||
return Error{Status{RippledError::rpcENTRY_NOT_FOUND, "issuance object not found."}};
|
return Error{Status{ClioError::RpcEntryNotFound, "issuance object not found."}};
|
||||||
|
|
||||||
ripple::STLedgerEntry const issuanceSle{
|
ripple::STLedgerEntry const issuanceSle{
|
||||||
ripple::SerialIter{issuanceObject->data(), issuanceObject->size()}, issuanceKeylet
|
ripple::SerialIter{issuanceObject->data(), issuanceObject->size()}, issuanceKeylet
|
||||||
|
|||||||
@@ -54,10 +54,10 @@ OnAssert::resetAction()
|
|||||||
void
|
void
|
||||||
OnAssert::defaultAction(std::string_view message)
|
OnAssert::defaultAction(std::string_view message)
|
||||||
{
|
{
|
||||||
if (LogServiceState::initialized() and LogServiceState::hasSinks()) {
|
if (LogServiceState::initialized()) {
|
||||||
LOG(LogService::fatal()) << message;
|
LOG(LogService::fatal()) << message;
|
||||||
} else {
|
} else {
|
||||||
std::cerr << message << std::endl;
|
std::cerr << message;
|
||||||
}
|
}
|
||||||
std::exit(EXIT_FAILURE); // std::abort does not flush gcovr output and causes uncovered lines
|
std::exit(EXIT_FAILURE); // std::abort does not flush gcovr output and causes uncovered lines
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,64 +2,67 @@ add_subdirectory(build)
|
|||||||
|
|
||||||
add_library(clio_util)
|
add_library(clio_util)
|
||||||
|
|
||||||
target_sources(clio_util
|
target_sources(
|
||||||
PRIVATE Assert.cpp
|
clio_util
|
||||||
Coroutine.cpp
|
PRIVATE Assert.cpp
|
||||||
CoroutineGroup.cpp
|
Coroutine.cpp
|
||||||
log/Logger.cpp
|
CoroutineGroup.cpp
|
||||||
log/PrettyPath.cpp
|
log/Logger.cpp
|
||||||
prometheus/Http.cpp
|
log/PrettyPath.cpp
|
||||||
prometheus/Label.cpp
|
prometheus/Http.cpp
|
||||||
prometheus/MetricBase.cpp
|
prometheus/Label.cpp
|
||||||
prometheus/MetricBuilder.cpp
|
prometheus/MetricBase.cpp
|
||||||
prometheus/MetricsFamily.cpp
|
prometheus/MetricBuilder.cpp
|
||||||
prometheus/OStream.cpp
|
prometheus/MetricsFamily.cpp
|
||||||
prometheus/Prometheus.cpp
|
prometheus/OStream.cpp
|
||||||
Random.cpp
|
prometheus/Prometheus.cpp
|
||||||
Retry.cpp
|
Random.cpp
|
||||||
Repeat.cpp
|
Retry.cpp
|
||||||
requests/RequestBuilder.cpp
|
Repeat.cpp
|
||||||
requests/Types.cpp
|
requests/RequestBuilder.cpp
|
||||||
requests/WsConnection.cpp
|
requests/Types.cpp
|
||||||
requests/impl/SslContext.cpp
|
requests/WsConnection.cpp
|
||||||
ResponseExpirationCache.cpp
|
requests/impl/SslContext.cpp
|
||||||
Shasum.cpp
|
ResponseExpirationCache.cpp
|
||||||
SignalsHandler.cpp
|
Shasum.cpp
|
||||||
StopHelper.cpp
|
SignalsHandler.cpp
|
||||||
StringHash.cpp
|
StopHelper.cpp
|
||||||
Taggable.cpp
|
StringHash.cpp
|
||||||
TerminationHandler.cpp
|
Taggable.cpp
|
||||||
TimeUtils.cpp
|
TerminationHandler.cpp
|
||||||
TxUtils.cpp
|
TimeUtils.cpp
|
||||||
LedgerUtils.cpp
|
TxUtils.cpp
|
||||||
config/Array.cpp
|
LedgerUtils.cpp
|
||||||
config/ArrayView.cpp
|
config/Array.cpp
|
||||||
config/ConfigConstraints.cpp
|
config/ArrayView.cpp
|
||||||
config/ConfigDefinition.cpp
|
config/ConfigConstraints.cpp
|
||||||
config/ConfigFileJson.cpp
|
config/ConfigDefinition.cpp
|
||||||
config/ObjectView.cpp
|
config/ConfigFileJson.cpp
|
||||||
config/Types.cpp
|
config/ObjectView.cpp
|
||||||
config/ValueView.cpp)
|
config/Types.cpp
|
||||||
|
config/ValueView.cpp
|
||||||
|
)
|
||||||
|
|
||||||
# This must be above the target_link_libraries call otherwise backtrace doesn't work
|
# This must be above the target_link_libraries call otherwise backtrace doesn't work
|
||||||
if ("${san}" STREQUAL "")
|
if ("${san}" STREQUAL "")
|
||||||
target_link_libraries(clio_util PUBLIC Boost::stacktrace_backtrace)
|
target_link_libraries(clio_util PUBLIC Boost::stacktrace_backtrace)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
clio_util
|
clio_util
|
||||||
PUBLIC Boost::headers
|
PUBLIC Boost::headers
|
||||||
Boost::iostreams
|
Boost::iostreams
|
||||||
Boost::coroutine
|
Boost::coroutine
|
||||||
Boost::context
|
Boost::context
|
||||||
fmt::fmt
|
fmt::fmt
|
||||||
openssl::openssl
|
openssl::openssl
|
||||||
xrpl::libxrpl
|
xrpl::libxrpl
|
||||||
Threads::Threads
|
Threads::Threads
|
||||||
clio_options
|
clio_options
|
||||||
clio_rpc_center
|
clio_rpc_center
|
||||||
clio_build_version
|
clio_build_version
|
||||||
PRIVATE spdlog::spdlog)
|
PRIVATE spdlog::spdlog
|
||||||
|
)
|
||||||
|
|
||||||
# FIXME: needed on gcc-12, clang-16 and AppleClang for now (known boost 1.82 issue for some compilers)
|
# FIXME: needed on gcc-12, clang-16 and AppleClang for now (known boost 1.82 issue for some compilers)
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -1,460 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
/*
|
|
||||||
This file is part of clio: https://github.com/XRPLF/clio
|
|
||||||
Copyright (c) 2025, the clio developers.
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
//==============================================================================
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "util/async/Concepts.hpp"
|
|
||||||
|
|
||||||
#include <boost/asio/any_io_executor.hpp>
|
|
||||||
#include <boost/asio/experimental/channel.hpp>
|
|
||||||
#include <boost/asio/experimental/concurrent_channel.hpp>
|
|
||||||
#include <boost/asio/spawn.hpp>
|
|
||||||
#include <boost/system/detail/error_code.hpp>
|
|
||||||
|
|
||||||
#include <concepts>
|
|
||||||
#include <cstddef>
|
|
||||||
#include <memory>
|
|
||||||
#include <optional>
|
|
||||||
#include <type_traits>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
namespace util {
|
|
||||||
|
|
||||||
#ifdef __clang__
|
|
||||||
namespace detail {
|
|
||||||
// Forward declaration for compile-time check
|
|
||||||
template <typename T>
|
|
||||||
struct ChannelInstantiated;
|
|
||||||
} // namespace detail
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Specifies the producer concurrency model for a Channel.
|
|
||||||
*/
|
|
||||||
enum class ProducerType {
|
|
||||||
Single, /**< Only one Sender can exist (non-copyable). Uses direct Guard ownership for zero overhead. */
|
|
||||||
Multi /**< Multiple Senders can exist (copyable). Uses shared_ptr<Guard> for shared ownership. */
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Specifies the consumer concurrency model for a Channel.
|
|
||||||
*/
|
|
||||||
enum class ConsumerType {
|
|
||||||
Single, /**< Only one Receiver can exist (non-copyable). Uses direct Guard ownership for zero overhead. */
|
|
||||||
Multi /**< Multiple Receivers can exist (copyable). Uses shared_ptr<Guard> for shared ownership. */
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Represents a go-like channel, a multi-producer (Sender) multi-consumer (Receiver) thread-safe data pipe.
|
|
||||||
* @note Use INSTANTIATE_CHANNEL_FOR_CLANG macro when using this class. See docs at the bottom of the file for more
|
|
||||||
* details.
|
|
||||||
*
|
|
||||||
* @tparam T The type of data the channel transfers
|
|
||||||
* @tparam P ProducerType::Multi (default) for multi-producer or ProducerType::Single for single-producer
|
|
||||||
* @tparam C ConsumerType::Multi (default) for multi-consumer or ConsumerType::Single for single-consumer
|
|
||||||
*/
|
|
||||||
template <typename T, ProducerType P = ProducerType::Multi, ConsumerType C = ConsumerType::Multi>
|
|
||||||
class Channel {
|
|
||||||
static constexpr bool kIS_MULTI_PRODUCER = (P == ProducerType::Multi);
|
|
||||||
static constexpr bool kIS_MULTI_CONSUMER = (C == ConsumerType::Multi);
|
|
||||||
|
|
||||||
private:
|
|
||||||
class ControlBlock {
|
|
||||||
using InternalChannelType = boost::asio::experimental::concurrent_channel<void(boost::system::error_code, T)>;
|
|
||||||
boost::asio::any_io_executor executor_;
|
|
||||||
InternalChannelType ch_;
|
|
||||||
|
|
||||||
public:
|
|
||||||
template <typename ContextType>
|
|
||||||
requires(not async::SomeExecutionContext<ContextType>)
|
|
||||||
ControlBlock(ContextType&& context, std::size_t capacity)
|
|
||||||
: executor_(context.get_executor()), ch_(context, capacity)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
template <async::SomeExecutionContext ContextType>
|
|
||||||
ControlBlock(ContextType&& context, std::size_t capacity)
|
|
||||||
: executor_(context.getExecutor().get_executor()), ch_(context.getExecutor(), capacity)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] InternalChannelType&
|
|
||||||
channel()
|
|
||||||
{
|
|
||||||
return ch_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
close()
|
|
||||||
{
|
|
||||||
if (not isClosed()) {
|
|
||||||
ch_.close();
|
|
||||||
// Workaround for Boost bug: close() alone doesn't cancel pending async operations.
|
|
||||||
// We must call cancel() to unblock them. The bug also causes cancel() to return
|
|
||||||
// error_code 0 instead of channel_cancelled, so async operations must check
|
|
||||||
// isClosed() to detect this case.
|
|
||||||
// https://github.com/chriskohlhoff/asio/issues/1575
|
|
||||||
ch_.cancel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] bool
|
|
||||||
isClosed() const
|
|
||||||
{
|
|
||||||
return not ch_.is_open();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This is used to close the channel once either all Senders or all Receivers are destroyed
|
|
||||||
*/
|
|
||||||
struct Guard {
|
|
||||||
std::shared_ptr<ControlBlock> shared;
|
|
||||||
|
|
||||||
~Guard()
|
|
||||||
{
|
|
||||||
shared->close();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* @brief The sending end of a channel.
|
|
||||||
*
|
|
||||||
* Sender is movable. For multi-producer channels, Sender is also copyable.
|
|
||||||
* The channel remains open as long as at least one Sender exists.
|
|
||||||
* When all Sender instances are destroyed, the channel is closed and receivers will receive std::nullopt.
|
|
||||||
*/
|
|
||||||
class Sender {
|
|
||||||
std::shared_ptr<ControlBlock> shared_;
|
|
||||||
std::conditional_t<kIS_MULTI_PRODUCER, std::shared_ptr<Guard>, Guard> guard_;
|
|
||||||
|
|
||||||
friend class Channel<T, P, C>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Constructs a Sender from a shared control block.
|
|
||||||
* @param shared The shared control block managing the channel state
|
|
||||||
*/
|
|
||||||
Sender(std::shared_ptr<ControlBlock> shared)
|
|
||||||
: shared_(shared), guard_([shared = std::move(shared)]() {
|
|
||||||
if constexpr (kIS_MULTI_PRODUCER) {
|
|
||||||
return std::make_shared<Guard>(std::move(shared));
|
|
||||||
} else {
|
|
||||||
return Guard{std::move(shared)};
|
|
||||||
}
|
|
||||||
}())
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
Sender(Sender&&) = default;
|
|
||||||
Sender(Sender const&)
|
|
||||||
requires kIS_MULTI_PRODUCER
|
|
||||||
= default;
|
|
||||||
Sender(Sender const&)
|
|
||||||
requires(!kIS_MULTI_PRODUCER)
|
|
||||||
= delete;
|
|
||||||
|
|
||||||
Sender&
|
|
||||||
operator=(Sender&&) = default;
|
|
||||||
Sender&
|
|
||||||
operator=(Sender const&)
|
|
||||||
requires kIS_MULTI_PRODUCER
|
|
||||||
= default;
|
|
||||||
Sender&
|
|
||||||
operator=(Sender const&)
|
|
||||||
requires(!kIS_MULTI_PRODUCER)
|
|
||||||
= delete;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Asynchronously sends data through the channel using a coroutine.
|
|
||||||
*
|
|
||||||
* Blocks the coroutine until the data is sent or the channel is closed.
|
|
||||||
*
|
|
||||||
* @tparam D The type of data to send (must be convertible to T)
|
|
||||||
* @param data The data to send
|
|
||||||
* @param yield The Boost.Asio yield context for coroutine suspension
|
|
||||||
* @return true if the data was sent successfully, false if the channel is closed
|
|
||||||
*/
|
|
||||||
template <typename D>
|
|
||||||
bool
|
|
||||||
asyncSend(D&& data, boost::asio::yield_context yield)
|
|
||||||
requires(std::convertible_to<std::remove_cvref_t<D>, std::remove_cvref_t<T>>)
|
|
||||||
{
|
|
||||||
boost::system::error_code const ecIn;
|
|
||||||
boost::system::error_code ecOut;
|
|
||||||
shared_->channel().async_send(ecIn, std::forward<D>(data), yield[ecOut]);
|
|
||||||
|
|
||||||
// Workaround: asio channels bug returns ec=0 on cancel, check isClosed() instead
|
|
||||||
if (not ecOut and shared_->isClosed())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return not ecOut;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Asynchronously sends data through the channel using a callback.
|
|
||||||
*
|
|
||||||
* The callback is invoked when the send operation completes.
|
|
||||||
*
|
|
||||||
* @tparam D The type of data to send (must be convertible to T)
|
|
||||||
* @param data The data to send
|
|
||||||
* @param fn Callback function invoked with true if successful, false if the channel is closed
|
|
||||||
*/
|
|
||||||
template <typename D>
|
|
||||||
void
|
|
||||||
asyncSend(D&& data, std::invocable<bool> auto&& fn)
|
|
||||||
requires(std::convertible_to<std::remove_cvref_t<D>, std::remove_cvref_t<T>>)
|
|
||||||
{
|
|
||||||
boost::system::error_code const ecIn;
|
|
||||||
shared_->channel().async_send(
|
|
||||||
ecIn,
|
|
||||||
std::forward<D>(data),
|
|
||||||
[fn = std::forward<decltype(fn)>(fn), shared = shared_](boost::system::error_code ec) mutable {
|
|
||||||
// Workaround: asio channels bug returns ec=0 on cancel, check isClosed() instead
|
|
||||||
if (not ec and shared->isClosed()) {
|
|
||||||
fn(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn(not ec);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Attempts to send data through the channel without blocking.
|
|
||||||
*
|
|
||||||
* @tparam D The type of data to send (must be convertible to T)
|
|
||||||
* @param data The data to send
|
|
||||||
* @return true if the data was sent successfully, false if the channel is full or closed
|
|
||||||
*/
|
|
||||||
template <typename D>
|
|
||||||
bool
|
|
||||||
trySend(D&& data)
|
|
||||||
requires(std::convertible_to<std::remove_cvref_t<D>, std::remove_cvref_t<T>>)
|
|
||||||
{
|
|
||||||
boost::system::error_code ec;
|
|
||||||
return shared_->channel().try_send(ec, std::forward<D>(data));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The receiving end of a channel.
|
|
||||||
*
|
|
||||||
* Receiver is movable. For multi-consumer channels, Receiver is also copyable.
|
|
||||||
* Multiple receivers can consume from the same multi-consumer channel concurrently.
|
|
||||||
* When all Receiver instances are destroyed, the channel is closed and senders will fail to send.
|
|
||||||
*/
|
|
||||||
class Receiver {
|
|
||||||
std::shared_ptr<ControlBlock> shared_;
|
|
||||||
std::conditional_t<kIS_MULTI_CONSUMER, std::shared_ptr<Guard>, Guard> guard_;
|
|
||||||
|
|
||||||
friend class Channel<T, P, C>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Constructs a Receiver from a shared control block.
|
|
||||||
* @param shared The shared control block managing the channel state
|
|
||||||
*/
|
|
||||||
Receiver(std::shared_ptr<ControlBlock> shared)
|
|
||||||
: shared_(shared), guard_([shared = std::move(shared)]() {
|
|
||||||
if constexpr (kIS_MULTI_CONSUMER) {
|
|
||||||
return std::make_shared<Guard>(std::move(shared));
|
|
||||||
} else {
|
|
||||||
return Guard{std::move(shared)};
|
|
||||||
}
|
|
||||||
}())
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
Receiver(Receiver&&) = default;
|
|
||||||
Receiver(Receiver const&)
|
|
||||||
requires kIS_MULTI_CONSUMER
|
|
||||||
= default;
|
|
||||||
Receiver(Receiver const&)
|
|
||||||
requires(!kIS_MULTI_CONSUMER)
|
|
||||||
= delete;
|
|
||||||
|
|
||||||
Receiver&
|
|
||||||
operator=(Receiver&&) = default;
|
|
||||||
Receiver&
|
|
||||||
operator=(Receiver const&)
|
|
||||||
requires kIS_MULTI_CONSUMER
|
|
||||||
= default;
|
|
||||||
Receiver&
|
|
||||||
operator=(Receiver const&)
|
|
||||||
requires(!kIS_MULTI_CONSUMER)
|
|
||||||
= delete;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Attempts to receive data from the channel without blocking.
|
|
||||||
*
|
|
||||||
* @return std::optional containing the received value, or std::nullopt if the channel is empty or closed
|
|
||||||
*/
|
|
||||||
std::optional<T>
|
|
||||||
tryReceive()
|
|
||||||
{
|
|
||||||
std::optional<T> result;
|
|
||||||
shared_->channel().try_receive([&result](boost::system::error_code ec, auto&& value) {
|
|
||||||
if (not ec)
|
|
||||||
result = std::forward<decltype(value)>(value);
|
|
||||||
});
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Asynchronously receives data from the channel using a coroutine.
|
|
||||||
*
|
|
||||||
* Blocks the coroutine until data is available or the channel is closed.
|
|
||||||
*
|
|
||||||
* @param yield The Boost.Asio yield context for coroutine suspension
|
|
||||||
* @return std::optional containing the received value, or std::nullopt if the channel is closed
|
|
||||||
*/
|
|
||||||
[[nodiscard]] std::optional<T>
|
|
||||||
asyncReceive(boost::asio::yield_context yield)
|
|
||||||
{
|
|
||||||
boost::system::error_code ec;
|
|
||||||
auto value = shared_->channel().async_receive(yield[ec]);
|
|
||||||
|
|
||||||
if (ec)
|
|
||||||
return std::nullopt;
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Asynchronously receives data from the channel using a callback.
|
|
||||||
*
|
|
||||||
* The callback is invoked when data is available or the channel is closed.
|
|
||||||
*
|
|
||||||
* @param fn Callback function invoked with std::optional containing the value, or std::nullopt if closed
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
asyncReceive(std::invocable<std::optional<std::remove_cvref_t<T>>> auto&& fn)
|
|
||||||
{
|
|
||||||
shared_->channel().async_receive(
|
|
||||||
[fn = std::forward<decltype(fn)>(fn)](boost::system::error_code ec, T&& value) mutable {
|
|
||||||
if (ec) {
|
|
||||||
fn(std::optional<T>(std::nullopt));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn(std::make_optional<T>(std::move(value)));
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Checks if the channel is closed.
|
|
||||||
*
|
|
||||||
* A channel is closed when all Sender instances have been destroyed.
|
|
||||||
*
|
|
||||||
* @return true if the channel is closed, false otherwise
|
|
||||||
*/
|
|
||||||
[[nodiscard]] bool
|
|
||||||
isClosed() const
|
|
||||||
{
|
|
||||||
return shared_->isClosed();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Factory function to create channel components.
|
|
||||||
* @param context A supported context type (either io_context or thread_pool)
|
|
||||||
* @param capacity Size of the internal buffer on the channel
|
|
||||||
* @return A pair of Sender and Receiver
|
|
||||||
*/
|
|
||||||
static std::pair<Sender, Receiver>
|
|
||||||
create(auto&& context, std::size_t capacity)
|
|
||||||
{
|
|
||||||
#ifdef __clang__
|
|
||||||
static_assert(
|
|
||||||
util::detail::ChannelInstantiated<T>::value,
|
|
||||||
"When using Channel<T> with Clang, you must add INSTANTIATE_CHANNEL_FOR_CLANG(T) "
|
|
||||||
"to one .cpp file. See documentation at the bottom of Channel.hpp for details."
|
|
||||||
);
|
|
||||||
#endif
|
|
||||||
auto shared = std::make_shared<ControlBlock>(std::forward<decltype(context)>(context), capacity);
|
|
||||||
auto sender = Sender{shared};
|
|
||||||
auto receiver = Receiver{std::move(shared)};
|
|
||||||
|
|
||||||
return {std::move(sender), std::move(receiver)};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace util
|
|
||||||
|
|
||||||
// ================================================================================================
|
|
||||||
// Clang/Apple Clang Workaround for Boost.Asio Experimental Channels
|
|
||||||
// ================================================================================================
|
|
||||||
//
|
|
||||||
// IMPORTANT: When using Channel<T> with Clang or Apple Clang, you MUST add the following line
|
|
||||||
// to ONE .cpp file that uses Channel<T>:
|
|
||||||
//
|
|
||||||
// INSTANTIATE_CHANNEL_FOR_CLANG(YourType)
|
|
||||||
//
|
|
||||||
// Example:
|
|
||||||
// // In ChannelTests.cpp or any .cpp file that uses Channel<int>:
|
|
||||||
// #include "util/Channel.hpp"
|
|
||||||
// INSTANTIATE_CHANNEL_FOR_CLANG(int)
|
|
||||||
//
|
|
||||||
// Why this is needed:
|
|
||||||
// Boost.Asio's experimental concurrent_channel has a bug where close() doesn't properly cancel
|
|
||||||
// pending async operations. When using cancellation signals (which we do in our workaround),
|
|
||||||
// Clang generates vtable references for internal cancellation_handler types but Boost.Asio
|
|
||||||
// doesn't provide the definitions, causing linker errors:
|
|
||||||
//
|
|
||||||
// Undefined symbols for architecture arm64:
|
|
||||||
// "boost::asio::detail::cancellation_handler<...>::call(boost::asio::cancellation_type)"
|
|
||||||
// "boost::asio::detail::cancellation_handler<...>::destroy()"
|
|
||||||
//
|
|
||||||
// This macro explicitly instantiates the required template specializations.
|
|
||||||
//
|
|
||||||
// See: https://github.com/chriskohlhoff/asio/issues/1575
|
|
||||||
//
|
|
||||||
#ifdef __clang__
|
|
||||||
|
|
||||||
#include <boost/asio/cancellation_signal.hpp>
|
|
||||||
#include <boost/asio/experimental/channel_traits.hpp>
|
|
||||||
#include <boost/asio/experimental/detail/channel_service.hpp>
|
|
||||||
|
|
||||||
namespace util::detail {
|
|
||||||
// Tag type used to verify that INSTANTIATE_CHANNEL_FOR_CLANG was called for a given type
|
|
||||||
template <typename T>
|
|
||||||
struct ChannelInstantiated : std::false_type {};
|
|
||||||
} // namespace util::detail
|
|
||||||
|
|
||||||
#define INSTANTIATE_CHANNEL_FOR_CLANG(T) \
|
|
||||||
/* NOLINTNEXTLINE(cppcoreguidelines-virtual-class-destructor) */ \
|
|
||||||
template class boost::asio::detail::cancellation_handler< \
|
|
||||||
boost::asio::experimental::detail::channel_service<boost::asio::detail::posix_mutex>:: \
|
|
||||||
op_cancellation<boost::asio::experimental::channel_traits<>, void(boost::system::error_code, T)>>; \
|
|
||||||
namespace util::detail { \
|
|
||||||
template <> \
|
|
||||||
struct ChannelInstantiated<T> : std::true_type {}; \
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
// No workaround needed for non-Clang compilers
|
|
||||||
#define INSTANTIATE_CHANNEL_FOR_CLANG(T)
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -22,7 +22,6 @@
|
|||||||
#include <boost/asio/spawn.hpp>
|
#include <boost/asio/spawn.hpp>
|
||||||
#include <boost/asio/strand.hpp>
|
#include <boost/asio/strand.hpp>
|
||||||
|
|
||||||
#include <concepts>
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
|
|||||||
@@ -29,27 +29,6 @@
|
|||||||
|
|
||||||
namespace util::async {
|
namespace util::async {
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Tag type for identifying execution context types.
|
|
||||||
*
|
|
||||||
* Types that inherit from this tag can be detected using the SomeExecutionContext concept.
|
|
||||||
* This allows generic code to differentiate between raw Boost.Asio contexts and wrapped execution contexts.
|
|
||||||
*/
|
|
||||||
struct ExecutionContextTag {
|
|
||||||
virtual ~ExecutionContextTag() = default;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Concept that identifies types derived from ExecutionContextTag.
|
|
||||||
*
|
|
||||||
* This concept is used to detect custom execution context wrappers (like BasicExecutionContext)
|
|
||||||
* and distinguish them from raw Boost.Asio contexts (io_context, thread_pool, etc.).
|
|
||||||
*
|
|
||||||
* @tparam T The type to check
|
|
||||||
*/
|
|
||||||
template <typename T>
|
|
||||||
concept SomeExecutionContext = std::derived_from<std::remove_cvref_t<T>, ExecutionContextTag>;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Specifies the interface for an entity that can be stopped
|
* @brief Specifies the interface for an entity that can be stopped
|
||||||
*/
|
*/
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user