Compare commits
72 Commits
add-manual
...
v2.15.0-rc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
51aaccbab0 | ||
|
|
1dfeee14f7 | ||
|
|
f469428b8e | ||
|
|
ba34688153 | ||
|
|
6766b5bc96 | ||
|
|
7cf7bebaa6 | ||
|
|
f3d3275aaa | ||
|
|
312cdaf685 | ||
|
|
7f8a4f2a8b | ||
|
|
381feb7b35 | ||
|
|
710dba6a00 | ||
|
|
db79d7f55e | ||
|
|
d1cdf9a0ba | ||
|
|
be8b755673 | ||
|
|
48db39a16a | ||
|
|
0f7d774fc5 | ||
|
|
dfb3a62cc4 | ||
|
|
307c2e0881 | ||
|
|
b9b221cfe2 | ||
|
|
6698d48a82 | ||
|
|
fb281459b9 | ||
|
|
3a7e62f72c | ||
|
|
f48151576b | ||
|
|
4a7c7f0898 | ||
|
|
7688a1b068 | ||
|
|
4f4a569c72 | ||
|
|
a511e63c7a | ||
|
|
0133673f1d | ||
|
|
786cdea260 | ||
|
|
54f78f9217 | ||
|
|
dcdbd0a19a | ||
|
|
cf80687d1d | ||
|
|
2fa8e00124 | ||
|
|
c15b62a88d | ||
|
|
4ef6a1f9c3 | ||
|
|
7ead00f23e | ||
|
|
c46dad18fe | ||
|
|
cb7b88ad92 | ||
|
|
b443934b68 | ||
|
|
6ab4235cc9 | ||
|
|
a9ef28c68e | ||
|
|
79361e9205 | ||
|
|
97b1e67d80 | ||
|
|
78a88737f8 | ||
|
|
ff44d68843 | ||
|
|
f1484240a0 | ||
|
|
1c95c3dc59 | ||
|
|
9f7118d893 | ||
|
|
38ade99652 | ||
|
|
6706ebfa2b | ||
|
|
e7f6a5f4f4 | ||
|
|
071df2f439 | ||
|
|
7f10636470 | ||
|
|
76589903a4 | ||
|
|
a8b625d861 | ||
|
|
9c89fce249 | ||
|
|
5e5f215be4 | ||
|
|
23dff58d22 | ||
|
|
0a7a7bc0d1 | ||
|
|
c772cab766 | ||
|
|
2e4d27c59a | ||
|
|
31f15b3651 | ||
|
|
b3d0c2ccc2 | ||
|
|
d4bcdb77ad | ||
|
|
1ba2f4e619 | ||
|
|
4bb9238679 | ||
|
|
bd11266f82 | ||
|
|
57e40a2b18 | ||
|
|
0fb8e4116f | ||
|
|
7128e1cea8 | ||
|
|
4788a633a6 | ||
|
|
ce2705d012 |
@@ -6,6 +6,7 @@ Checks: '*,
|
|||||||
-altera-unroll-loops,
|
-altera-unroll-loops,
|
||||||
-android-*,
|
-android-*,
|
||||||
-cert-err58-cpp,
|
-cert-err58-cpp,
|
||||||
|
-cppcoreguidelines-avoid-do-while,
|
||||||
-cppcoreguidelines-avoid-c-arrays,
|
-cppcoreguidelines-avoid-c-arrays,
|
||||||
-cppcoreguidelines-avoid-goto,
|
-cppcoreguidelines-avoid-goto,
|
||||||
-cppcoreguidelines-avoid-magic-numbers,
|
-cppcoreguidelines-avoid-magic-numbers,
|
||||||
@@ -60,6 +61,7 @@ Checks: '*,
|
|||||||
-readability-implicit-bool-conversion,
|
-readability-implicit-bool-conversion,
|
||||||
-readability-magic-numbers,
|
-readability-magic-numbers,
|
||||||
-readability-named-parameter,
|
-readability-named-parameter,
|
||||||
|
-readability-identifier-length,
|
||||||
-misc-no-recursion,
|
-misc-no-recursion,
|
||||||
-concurrency-mt-unsafe,
|
-concurrency-mt-unsafe,
|
||||||
-bugprone-easily-swappable-parameters'
|
-bugprone-easily-swappable-parameters'
|
||||||
|
|||||||
2
.github/workflows/daily_benchmark.yaml
vendored
2
.github/workflows/daily_benchmark.yaml
vendored
@@ -16,7 +16,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Set up repository
|
- name: Set up repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
# Number of commits to fetch. `0` indicates all history for all
|
# Number of commits to fetch. `0` indicates all history for all
|
||||||
# branches and tags. (default: 1)
|
# branches and tags. (default: 1)
|
||||||
|
|||||||
55
.github/workflows/diff.yaml
vendored
55
.github/workflows/diff.yaml
vendored
@@ -27,7 +27,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Set up repository
|
- name: Set up repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
# Number of commits to fetch. `0` indicates all history for all
|
# Number of commits to fetch. `0` indicates all history for all
|
||||||
# branches and tags. (default: 1)
|
# branches and tags. (default: 1)
|
||||||
@@ -65,7 +65,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Set up repository
|
- name: Set up repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
# Number of commits to fetch. `0` indicates all history for all
|
# Number of commits to fetch. `0` indicates all history for all
|
||||||
# branches and tags. (default: 1)
|
# branches and tags. (default: 1)
|
||||||
@@ -96,7 +96,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Python code analysis
|
- name: Python code analysis
|
||||||
run: |
|
run: |
|
||||||
CHANGED_FILES=$(git diff -U0 ${{ env.BASE_BRANCH }}... --name-only)
|
CHANGED_FILES=$(git diff -U0 ${{ env.BASE_BRANCH }}... --name-only --diff-filter=d)
|
||||||
for file in ${CHANGED_FILES}; do
|
for file in ${CHANGED_FILES}; do
|
||||||
echo ${file}
|
echo ${file}
|
||||||
if [[ ${file} == *.py ]]; then
|
if [[ ${file} == *.py ]]; then
|
||||||
@@ -137,9 +137,9 @@ jobs:
|
|||||||
tar -czf code_coverage.tar.gz coverage.json html report.json summary.rmu
|
tar -czf code_coverage.tar.gz coverage.json html report.json summary.rmu
|
||||||
|
|
||||||
- name: Save code coverage
|
- name: Save code coverage
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: "Code coverage"
|
name: "Code coverage(Code analysis)"
|
||||||
path: tools/github/generated/code_coverage.tar.gz
|
path: tools/github/generated/code_coverage.tar.gz
|
||||||
|
|
||||||
- name: Run clang-tidy
|
- name: Run clang-tidy
|
||||||
@@ -162,7 +162,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Set up repository
|
- name: Set up repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
# Number of commits to fetch. `0` indicates all history for all
|
# Number of commits to fetch. `0` indicates all history for all
|
||||||
# branches and tags. (default: 1)
|
# branches and tags. (default: 1)
|
||||||
@@ -208,9 +208,9 @@ jobs:
|
|||||||
./cppcheck_and_clang_format diff
|
./cppcheck_and_clang_format diff
|
||||||
|
|
||||||
- name: Save cppcheck and clang-format errors
|
- name: Save cppcheck and clang-format errors
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: "Code coverage"
|
name: "Code coverage(Debug build)"
|
||||||
path: tools/github/cppcheck_and_clang_format.txt
|
path: tools/github/cppcheck_and_clang_format.txt
|
||||||
|
|
||||||
release_build:
|
release_build:
|
||||||
@@ -223,16 +223,12 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Set up repository
|
- name: Set up repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
# Number of commits to fetch. `0` indicates all history for all
|
# Number of commits to fetch. `0` indicates all history for all
|
||||||
# branches and tags. (default: 1)
|
# branches and tags. (default: 1)
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Check e2e service dependencies
|
|
||||||
run: |
|
|
||||||
cd tests/e2e
|
|
||||||
./dependency_check.sh
|
|
||||||
|
|
||||||
- name: Build release binaries
|
- name: Build release binaries
|
||||||
run: |
|
run: |
|
||||||
@@ -255,7 +251,7 @@ jobs:
|
|||||||
./continuous_integration
|
./continuous_integration
|
||||||
|
|
||||||
- name: Save quality assurance status
|
- name: Save quality assurance status
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: "GQL Behave Status"
|
name: "GQL Behave Status"
|
||||||
path: |
|
path: |
|
||||||
@@ -271,6 +267,13 @@ jobs:
|
|||||||
cd build
|
cd build
|
||||||
ctest -R memgraph__unit --output-on-failure -j$THREADS
|
ctest -R memgraph__unit --output-on-failure -j$THREADS
|
||||||
|
|
||||||
|
- name: Ensure Kafka and Pulsar are up
|
||||||
|
run: |
|
||||||
|
cd tests/e2e/streams/kafka
|
||||||
|
docker-compose up -d
|
||||||
|
cd ../pulsar
|
||||||
|
docker-compose up -d
|
||||||
|
|
||||||
- name: Run e2e tests
|
- name: Run e2e tests
|
||||||
run: |
|
run: |
|
||||||
cd tests
|
cd tests
|
||||||
@@ -279,6 +282,13 @@ jobs:
|
|||||||
cd e2e
|
cd e2e
|
||||||
./run.sh
|
./run.sh
|
||||||
|
|
||||||
|
- name: Ensure Kafka and Pulsar are down
|
||||||
|
run: |
|
||||||
|
cd tests/e2e/streams/kafka
|
||||||
|
docker-compose down
|
||||||
|
cd ../pulsar
|
||||||
|
docker-compose down
|
||||||
|
|
||||||
- name: Run stress test (plain)
|
- name: Run stress test (plain)
|
||||||
run: |
|
run: |
|
||||||
cd tests/stress
|
cd tests/stress
|
||||||
@@ -312,16 +322,16 @@ jobs:
|
|||||||
cpack -G DEB --config ../CPackConfig.cmake
|
cpack -G DEB --config ../CPackConfig.cmake
|
||||||
|
|
||||||
- name: Save enterprise DEB package
|
- name: Save enterprise DEB package
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: "Enterprise DEB package"
|
name: "Enterprise DEB package"
|
||||||
path: build/output/memgraph*.deb
|
path: build/output/memgraph*.deb
|
||||||
|
|
||||||
- name: Save test data
|
- name: Save test data
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
if: always()
|
if: always()
|
||||||
with:
|
with:
|
||||||
name: "Test data"
|
name: "Test data(Release build)"
|
||||||
path: |
|
path: |
|
||||||
# multiple paths could be defined
|
# multiple paths could be defined
|
||||||
build/logs
|
build/logs
|
||||||
@@ -337,7 +347,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Set up repository
|
- name: Set up repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
# Number of commits to fetch. `0` indicates all history for all
|
# Number of commits to fetch. `0` indicates all history for all
|
||||||
# branches and tags. (default: 1)
|
# branches and tags. (default: 1)
|
||||||
@@ -354,13 +364,18 @@ jobs:
|
|||||||
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
|
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
|
||||||
make -j$THREADS memgraph
|
make -j$THREADS memgraph
|
||||||
|
|
||||||
|
- name: Refresh Jepsen Cluster
|
||||||
|
run: |
|
||||||
|
cd tests/jepsen
|
||||||
|
./run.sh cluster-refresh
|
||||||
|
|
||||||
- name: Run Jepsen tests
|
- name: Run Jepsen tests
|
||||||
run: |
|
run: |
|
||||||
cd tests/jepsen
|
cd tests/jepsen
|
||||||
./run.sh test-all-individually --binary ../../build/memgraph --ignore-run-stdout-logs --ignore-run-stderr-logs
|
./run.sh test-all-individually --binary ../../build/memgraph --ignore-run-stdout-logs --ignore-run-stderr-logs
|
||||||
|
|
||||||
- name: Save Jepsen report
|
- name: Save Jepsen report
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
if: ${{ always() }}
|
if: ${{ always() }}
|
||||||
with:
|
with:
|
||||||
name: "Jepsen Report"
|
name: "Jepsen Report"
|
||||||
@@ -376,7 +391,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Set up repository
|
- name: Set up repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
# Number of commits to fetch. `0` indicates all history for all
|
# Number of commits to fetch. `0` indicates all history for all
|
||||||
# branches and tags. (default: 1)
|
# branches and tags. (default: 1)
|
||||||
|
|||||||
2
.github/workflows/full_clang_tidy.yaml
vendored
2
.github/workflows/full_clang_tidy.yaml
vendored
@@ -14,7 +14,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Set up repository
|
- name: Set up repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
# Number of commits to fetch. `0` indicates all history for all
|
# Number of commits to fetch. `0` indicates all history for all
|
||||||
# branches and tags. (default: 1)
|
# branches and tags. (default: 1)
|
||||||
|
|||||||
54
.github/workflows/package_memgraph.yaml
vendored
54
.github/workflows/package_memgraph.yaml
vendored
@@ -42,14 +42,14 @@ jobs:
|
|||||||
timeout-minutes: 60
|
timeout-minutes: 60
|
||||||
steps:
|
steps:
|
||||||
- name: "Set up repository"
|
- name: "Set up repository"
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0 # Required because of release/get_version.py
|
fetch-depth: 0 # Required because of release/get_version.py
|
||||||
- name: "Build package"
|
- name: "Build package"
|
||||||
run: |
|
run: |
|
||||||
./release/package/run.sh package amzn-2 ${{ github.event.inputs.build_type }}
|
./release/package/run.sh package amzn-2 ${{ github.event.inputs.build_type }}
|
||||||
- name: "Upload package"
|
- name: "Upload package"
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: amzn-2
|
name: amzn-2
|
||||||
path: build/output/amzn-2/memgraph*.rpm
|
path: build/output/amzn-2/memgraph*.rpm
|
||||||
@@ -60,14 +60,14 @@ jobs:
|
|||||||
timeout-minutes: 60
|
timeout-minutes: 60
|
||||||
steps:
|
steps:
|
||||||
- name: "Set up repository"
|
- name: "Set up repository"
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0 # Required because of release/get_version.py
|
fetch-depth: 0 # Required because of release/get_version.py
|
||||||
- name: "Build package"
|
- name: "Build package"
|
||||||
run: |
|
run: |
|
||||||
./release/package/run.sh package centos-7 ${{ github.event.inputs.build_type }}
|
./release/package/run.sh package centos-7 ${{ github.event.inputs.build_type }}
|
||||||
- name: "Upload package"
|
- name: "Upload package"
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: centos-7
|
name: centos-7
|
||||||
path: build/output/centos-7/memgraph*.rpm
|
path: build/output/centos-7/memgraph*.rpm
|
||||||
@@ -78,14 +78,14 @@ jobs:
|
|||||||
timeout-minutes: 60
|
timeout-minutes: 60
|
||||||
steps:
|
steps:
|
||||||
- name: "Set up repository"
|
- name: "Set up repository"
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0 # Required because of release/get_version.py
|
fetch-depth: 0 # Required because of release/get_version.py
|
||||||
- name: "Build package"
|
- name: "Build package"
|
||||||
run: |
|
run: |
|
||||||
./release/package/run.sh package centos-9 ${{ github.event.inputs.build_type }}
|
./release/package/run.sh package centos-9 ${{ github.event.inputs.build_type }}
|
||||||
- name: "Upload package"
|
- name: "Upload package"
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: centos-9
|
name: centos-9
|
||||||
path: build/output/centos-9/memgraph*.rpm
|
path: build/output/centos-9/memgraph*.rpm
|
||||||
@@ -96,14 +96,14 @@ jobs:
|
|||||||
timeout-minutes: 60
|
timeout-minutes: 60
|
||||||
steps:
|
steps:
|
||||||
- name: "Set up repository"
|
- name: "Set up repository"
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0 # Required because of release/get_version.py
|
fetch-depth: 0 # Required because of release/get_version.py
|
||||||
- name: "Build package"
|
- name: "Build package"
|
||||||
run: |
|
run: |
|
||||||
./release/package/run.sh package debian-10 ${{ github.event.inputs.build_type }}
|
./release/package/run.sh package debian-10 ${{ github.event.inputs.build_type }}
|
||||||
- name: "Upload package"
|
- name: "Upload package"
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: debian-10
|
name: debian-10
|
||||||
path: build/output/debian-10/memgraph*.deb
|
path: build/output/debian-10/memgraph*.deb
|
||||||
@@ -114,14 +114,14 @@ jobs:
|
|||||||
timeout-minutes: 60
|
timeout-minutes: 60
|
||||||
steps:
|
steps:
|
||||||
- name: "Set up repository"
|
- name: "Set up repository"
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0 # Required because of release/get_version.py
|
fetch-depth: 0 # Required because of release/get_version.py
|
||||||
- name: "Build package"
|
- name: "Build package"
|
||||||
run: |
|
run: |
|
||||||
./release/package/run.sh package debian-11 ${{ github.event.inputs.build_type }}
|
./release/package/run.sh package debian-11 ${{ github.event.inputs.build_type }}
|
||||||
- name: "Upload package"
|
- name: "Upload package"
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: debian-11
|
name: debian-11
|
||||||
path: build/output/debian-11/memgraph*.deb
|
path: build/output/debian-11/memgraph*.deb
|
||||||
@@ -132,14 +132,14 @@ jobs:
|
|||||||
timeout-minutes: 120
|
timeout-minutes: 120
|
||||||
steps:
|
steps:
|
||||||
- name: "Set up repository"
|
- name: "Set up repository"
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0 # Required because of release/get_version.py
|
fetch-depth: 0 # Required because of release/get_version.py
|
||||||
- name: "Build package"
|
- name: "Build package"
|
||||||
run: |
|
run: |
|
||||||
./release/package/run.sh package debian-11-arm ${{ github.event.inputs.build_type }}
|
./release/package/run.sh package debian-11-arm ${{ github.event.inputs.build_type }}
|
||||||
- name: "Upload package"
|
- name: "Upload package"
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: debian-11-aarch64
|
name: debian-11-aarch64
|
||||||
path: build/output/debian-11-arm/memgraph*.deb
|
path: build/output/debian-11-arm/memgraph*.deb
|
||||||
@@ -150,14 +150,14 @@ jobs:
|
|||||||
timeout-minutes: 60
|
timeout-minutes: 60
|
||||||
steps:
|
steps:
|
||||||
- name: "Set up repository"
|
- name: "Set up repository"
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0 # Required because of release/get_version.py
|
fetch-depth: 0 # Required because of release/get_version.py
|
||||||
- name: "Build package"
|
- name: "Build package"
|
||||||
run: |
|
run: |
|
||||||
./release/package/run.sh package debian-11 ${{ github.event.inputs.build_type }} --for-platform
|
./release/package/run.sh package debian-11 ${{ github.event.inputs.build_type }} --for-platform
|
||||||
- name: "Upload package"
|
- name: "Upload package"
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: debian-11-platform
|
name: debian-11-platform
|
||||||
path: build/output/debian-11/memgraph*.deb
|
path: build/output/debian-11/memgraph*.deb
|
||||||
@@ -168,7 +168,7 @@ jobs:
|
|||||||
timeout-minutes: 60
|
timeout-minutes: 60
|
||||||
steps:
|
steps:
|
||||||
- name: "Set up repository"
|
- name: "Set up repository"
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0 # Required because of release/get_version.py
|
fetch-depth: 0 # Required because of release/get_version.py
|
||||||
- name: "Build package"
|
- name: "Build package"
|
||||||
@@ -177,7 +177,7 @@ jobs:
|
|||||||
./run.sh package debian-11 ${{ github.event.inputs.build_type }} --for-docker
|
./run.sh package debian-11 ${{ github.event.inputs.build_type }} --for-docker
|
||||||
./run.sh docker
|
./run.sh docker
|
||||||
- name: "Upload package"
|
- name: "Upload package"
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: docker
|
name: docker
|
||||||
path: build/output/docker/memgraph*.tar.gz
|
path: build/output/docker/memgraph*.tar.gz
|
||||||
@@ -188,14 +188,14 @@ jobs:
|
|||||||
timeout-minutes: 60
|
timeout-minutes: 60
|
||||||
steps:
|
steps:
|
||||||
- name: "Set up repository"
|
- name: "Set up repository"
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0 # Required because of release/get_version.py
|
fetch-depth: 0 # Required because of release/get_version.py
|
||||||
- name: "Build package"
|
- name: "Build package"
|
||||||
run: |
|
run: |
|
||||||
./release/package/run.sh package fedora-36 ${{ github.event.inputs.build_type }}
|
./release/package/run.sh package fedora-36 ${{ github.event.inputs.build_type }}
|
||||||
- name: "Upload package"
|
- name: "Upload package"
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: fedora-36
|
name: fedora-36
|
||||||
path: build/output/fedora-36/memgraph*.rpm
|
path: build/output/fedora-36/memgraph*.rpm
|
||||||
@@ -206,14 +206,14 @@ jobs:
|
|||||||
timeout-minutes: 60
|
timeout-minutes: 60
|
||||||
steps:
|
steps:
|
||||||
- name: "Set up repository"
|
- name: "Set up repository"
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0 # Required because of release/get_version.py
|
fetch-depth: 0 # Required because of release/get_version.py
|
||||||
- name: "Build package"
|
- name: "Build package"
|
||||||
run: |
|
run: |
|
||||||
./release/package/run.sh package ubuntu-18.04 ${{ github.event.inputs.build_type }}
|
./release/package/run.sh package ubuntu-18.04 ${{ github.event.inputs.build_type }}
|
||||||
- name: "Upload package"
|
- name: "Upload package"
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: ubuntu-18.04
|
name: ubuntu-18.04
|
||||||
path: build/output/ubuntu-18.04/memgraph*.deb
|
path: build/output/ubuntu-18.04/memgraph*.deb
|
||||||
@@ -224,14 +224,14 @@ jobs:
|
|||||||
timeout-minutes: 60
|
timeout-minutes: 60
|
||||||
steps:
|
steps:
|
||||||
- name: "Set up repository"
|
- name: "Set up repository"
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0 # Required because of release/get_version.py
|
fetch-depth: 0 # Required because of release/get_version.py
|
||||||
- name: "Build package"
|
- name: "Build package"
|
||||||
run: |
|
run: |
|
||||||
./release/package/run.sh package ubuntu-20.04 ${{ github.event.inputs.build_type }}
|
./release/package/run.sh package ubuntu-20.04 ${{ github.event.inputs.build_type }}
|
||||||
- name: "Upload package"
|
- name: "Upload package"
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: ubuntu-20.04
|
name: ubuntu-20.04
|
||||||
path: build/output/ubuntu-20.04/memgraph*.deb
|
path: build/output/ubuntu-20.04/memgraph*.deb
|
||||||
@@ -242,14 +242,14 @@ jobs:
|
|||||||
timeout-minutes: 60
|
timeout-minutes: 60
|
||||||
steps:
|
steps:
|
||||||
- name: "Set up repository"
|
- name: "Set up repository"
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0 # Required because of release/get_version.py
|
fetch-depth: 0 # Required because of release/get_version.py
|
||||||
- name: "Build package"
|
- name: "Build package"
|
||||||
run: |
|
run: |
|
||||||
./release/package/run.sh package ubuntu-22.04 ${{ github.event.inputs.build_type }}
|
./release/package/run.sh package ubuntu-22.04 ${{ github.event.inputs.build_type }}
|
||||||
- name: "Upload package"
|
- name: "Upload package"
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: ubuntu-22.04
|
name: ubuntu-22.04
|
||||||
path: build/output/ubuntu-22.04/memgraph*.deb
|
path: build/output/ubuntu-22.04/memgraph*.deb
|
||||||
@@ -260,14 +260,14 @@ jobs:
|
|||||||
timeout-minutes: 120
|
timeout-minutes: 120
|
||||||
steps:
|
steps:
|
||||||
- name: "Set up repository"
|
- name: "Set up repository"
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0 # Required because of release/get_version.py
|
fetch-depth: 0 # Required because of release/get_version.py
|
||||||
- name: "Build package"
|
- name: "Build package"
|
||||||
run: |
|
run: |
|
||||||
./release/package/run.sh package ubuntu-22.04-arm ${{ github.event.inputs.build_type }}
|
./release/package/run.sh package ubuntu-22.04-arm ${{ github.event.inputs.build_type }}
|
||||||
- name: "Upload package"
|
- name: "Upload package"
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: ubuntu-22.04-aarch64
|
name: ubuntu-22.04-aarch64
|
||||||
path: build/output/ubuntu-22.04-arm/memgraph*.deb
|
path: build/output/ubuntu-22.04-arm/memgraph*.deb
|
||||||
@@ -279,7 +279,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Download artifacts
|
- name: Download artifacts
|
||||||
uses: actions/download-artifact@v3
|
uses: actions/download-artifact@v4
|
||||||
with:
|
with:
|
||||||
# name: # if name input parameter is not provided, all artifacts are downloaded
|
# name: # if name input parameter is not provided, all artifacts are downloaded
|
||||||
# and put in directories named after each one.
|
# and put in directories named after each one.
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Set up repository
|
- name: Set up repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
# Number of commits to fetch. `0` indicates all history for all
|
# Number of commits to fetch. `0` indicates all history for all
|
||||||
# branches and tags. (default: 1)
|
# branches and tags. (default: 1)
|
||||||
|
|||||||
162
.github/workflows/release_build_test.yaml
vendored
Normal file
162
.github/workflows/release_build_test.yaml
vendored
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
name: Release build test
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.ref_name }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
build_type:
|
||||||
|
type: choice
|
||||||
|
description: "Memgraph Build type. Default value is Release."
|
||||||
|
default: 'Release'
|
||||||
|
options:
|
||||||
|
- Release
|
||||||
|
- RelWithDebInfo
|
||||||
|
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- "release/**"
|
||||||
|
tags:
|
||||||
|
- "v*.*.*-rc*"
|
||||||
|
- "v*.*-rc*"
|
||||||
|
schedule:
|
||||||
|
# UTC
|
||||||
|
- cron: "0 22 * * *"
|
||||||
|
|
||||||
|
env:
|
||||||
|
THREADS: 24
|
||||||
|
MEMGRAPH_ENTERPRISE_LICENSE: ${{ secrets.MEMGRAPH_ENTERPRISE_LICENSE }}
|
||||||
|
MEMGRAPH_ORGANIZATION_NAME: ${{ secrets.MEMGRAPH_ORGANIZATION_NAME }}
|
||||||
|
BUILD_TYPE: ${{ github.event.inputs.build_type || 'Release' }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
Debian10:
|
||||||
|
uses: ./.github/workflows/release_debian10.yaml
|
||||||
|
with:
|
||||||
|
build_type: ${{ github.event.inputs.build_type || 'Release' }}
|
||||||
|
secrets: inherit
|
||||||
|
|
||||||
|
Ubuntu20_04:
|
||||||
|
uses: ./.github/workflows/release_ubuntu2004.yaml
|
||||||
|
with:
|
||||||
|
build_type: ${{ github.event.inputs.build_type || 'Release' }}
|
||||||
|
secrets: inherit
|
||||||
|
|
||||||
|
PackageDebian10:
|
||||||
|
if: github.ref_type == 'tag'
|
||||||
|
needs: [Debian10]
|
||||||
|
runs-on: [self-hosted, DockerMgBuild, X64]
|
||||||
|
timeout-minutes: 60
|
||||||
|
steps:
|
||||||
|
- name: "Set up repository"
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0 # Required because of release/get_version.py
|
||||||
|
- name: "Build package"
|
||||||
|
run: |
|
||||||
|
./release/package/run.sh package debian-10 $BUILD_TYPE
|
||||||
|
- name: "Upload package"
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: debian-10
|
||||||
|
path: build/output/debian-10/memgraph*.deb
|
||||||
|
|
||||||
|
PackageUbuntu20_04:
|
||||||
|
if: github.ref_type == 'tag'
|
||||||
|
needs: [Ubuntu20_04]
|
||||||
|
runs-on: [self-hosted, DockerMgBuild, X64]
|
||||||
|
timeout-minutes: 60
|
||||||
|
steps:
|
||||||
|
- name: "Set up repository"
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0 # Required because of release/get_version.py
|
||||||
|
- name: "Build package"
|
||||||
|
run: |
|
||||||
|
./release/package/run.sh package ubuntu-22.04 $BUILD_TYPE
|
||||||
|
- name: "Upload package"
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: ubuntu-22.04
|
||||||
|
path: build/output/ubuntu-22.04/memgraph*.deb
|
||||||
|
|
||||||
|
PackageUbuntu20_04_ARM:
|
||||||
|
if: github.ref_type == 'tag'
|
||||||
|
needs: [Ubuntu20_04]
|
||||||
|
runs-on: [self-hosted, DockerMgBuild, ARM64]
|
||||||
|
# M1 Mac mini is sometimes slower
|
||||||
|
timeout-minutes: 90
|
||||||
|
steps:
|
||||||
|
- name: "Set up repository"
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0 # Required because of release/get_version.py
|
||||||
|
- name: "Build package"
|
||||||
|
run: |
|
||||||
|
./release/package/run.sh package ubuntu-22.04-arm $BUILD_TYPE
|
||||||
|
- name: "Upload package"
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: ubuntu-22.04-aarch64
|
||||||
|
path: build/output/ubuntu-22.04-arm/memgraph*.deb
|
||||||
|
|
||||||
|
PackageDebian11:
|
||||||
|
if: github.ref_type == 'tag'
|
||||||
|
needs: [Debian10, Ubuntu20_04]
|
||||||
|
runs-on: [self-hosted, DockerMgBuild, X64]
|
||||||
|
timeout-minutes: 60
|
||||||
|
steps:
|
||||||
|
- name: "Set up repository"
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0 # Required because of release/get_version.py
|
||||||
|
- name: "Build package"
|
||||||
|
run: |
|
||||||
|
./release/package/run.sh package debian-11 $BUILD_TYPE
|
||||||
|
- name: "Upload package"
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: debian-11
|
||||||
|
path: build/output/debian-11/memgraph*.deb
|
||||||
|
|
||||||
|
PackageDebian11_ARM:
|
||||||
|
if: github.ref_type == 'tag'
|
||||||
|
needs: [Debian10, Ubuntu20_04]
|
||||||
|
runs-on: [self-hosted, DockerMgBuild, ARM64]
|
||||||
|
# M1 Mac mini is sometimes slower
|
||||||
|
timeout-minutes: 90
|
||||||
|
steps:
|
||||||
|
- name: "Set up repository"
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0 # Required because of release/get_version.py
|
||||||
|
- name: "Build package"
|
||||||
|
run: |
|
||||||
|
./release/package/run.sh package debian-11-arm $BUILD_TYPE
|
||||||
|
- name: "Upload package"
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: debian-11-aarch64
|
||||||
|
path: build/output/debian-11-arm/memgraph*.deb
|
||||||
|
|
||||||
|
PushToS3:
|
||||||
|
if: github.ref_type == 'tag'
|
||||||
|
needs: [PackageDebian10, PackageDebian11, PackageDebian11_ARM, PackageUbuntu20_04, PackageUbuntu20_04_ARM]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Download artifacts
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
# name: # if name input parameter is not provided, all artifacts are downloaded
|
||||||
|
# and put in directories named after each one.
|
||||||
|
path: build/output/release
|
||||||
|
- name: Upload to S3
|
||||||
|
uses: jakejarvis/s3-sync-action@v0.5.1
|
||||||
|
env:
|
||||||
|
AWS_S3_BUCKET: "deps.memgraph.io"
|
||||||
|
AWS_ACCESS_KEY_ID: ${{ secrets.S3_AWS_ACCESS_KEY_ID }}
|
||||||
|
AWS_SECRET_ACCESS_KEY: ${{ secrets.S3_AWS_SECRET_ACCESS_KEY }}
|
||||||
|
AWS_REGION: "eu-west-1"
|
||||||
|
SOURCE_DIR: "build/output/release"
|
||||||
|
DEST_DIR: "memgraph-unofficial/${{ github.ref_name }}/"
|
||||||
318
.github/workflows/release_centos8.yaml
vendored
318
.github/workflows/release_centos8.yaml
vendored
@@ -1,318 +0,0 @@
|
|||||||
name: Release CentOS 8
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_dispatch:
|
|
||||||
inputs:
|
|
||||||
build_type:
|
|
||||||
type: choice
|
|
||||||
description: "Memgraph Build type. Default value is Release."
|
|
||||||
default: 'Release'
|
|
||||||
options:
|
|
||||||
- Release
|
|
||||||
- RelWithDebInfo
|
|
||||||
|
|
||||||
schedule:
|
|
||||||
- cron: "0 22 * * *"
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
community_build:
|
|
||||||
name: "Community build"
|
|
||||||
runs-on: [self-hosted, Linux, X64, CentOS8]
|
|
||||||
env:
|
|
||||||
THREADS: 24
|
|
||||||
MEMGRAPH_ENTERPRISE_LICENSE: ${{ secrets.MEMGRAPH_ENTERPRISE_LICENSE }}
|
|
||||||
MEMGRAPH_ORGANIZATION_NAME: ${{ secrets.MEMGRAPH_ORGANIZATION_NAME }}
|
|
||||||
timeout-minutes: 960
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Set up repository
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
with:
|
|
||||||
# Number of commits to fetch. `0` indicates all history for all
|
|
||||||
# branches and tags. (default: 1)
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Build community binaries
|
|
||||||
run: |
|
|
||||||
# Activate toolchain.
|
|
||||||
source /opt/toolchain-v4/activate
|
|
||||||
|
|
||||||
# Initialize dependencies.
|
|
||||||
./init
|
|
||||||
|
|
||||||
# Set default build_type to Release
|
|
||||||
INPUT_BUILD_TYPE=${{ github.event.inputs.build_type }}
|
|
||||||
BUILD_TYPE=${INPUT_BUILD_TYPE:-"Release"}
|
|
||||||
|
|
||||||
# Build community binaries.
|
|
||||||
cd build
|
|
||||||
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DMG_ENTERPRISE=OFF ..
|
|
||||||
make -j$THREADS
|
|
||||||
|
|
||||||
- name: Run unit tests
|
|
||||||
run: |
|
|
||||||
# Activate toolchain.
|
|
||||||
source /opt/toolchain-v4/activate
|
|
||||||
|
|
||||||
# Run unit tests.
|
|
||||||
cd build
|
|
||||||
ctest -R memgraph__unit --output-on-failure
|
|
||||||
|
|
||||||
coverage_build:
|
|
||||||
name: "Coverage build"
|
|
||||||
runs-on: [self-hosted, Linux, X64, CentOS8]
|
|
||||||
env:
|
|
||||||
THREADS: 24
|
|
||||||
MEMGRAPH_ENTERPRISE_LICENSE: ${{ secrets.MEMGRAPH_ENTERPRISE_LICENSE }}
|
|
||||||
MEMGRAPH_ORGANIZATION_NAME: ${{ secrets.MEMGRAPH_ORGANIZATION_NAME }}
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Set up repository
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
with:
|
|
||||||
# Number of commits to fetch. `0` indicates all history for all
|
|
||||||
# branches and tags. (default: 1)
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Build coverage binaries
|
|
||||||
run: |
|
|
||||||
# Activate toolchain.
|
|
||||||
source /opt/toolchain-v4/activate
|
|
||||||
|
|
||||||
# Initialize dependencies.
|
|
||||||
./init
|
|
||||||
|
|
||||||
# Build coverage binaries.
|
|
||||||
cd build
|
|
||||||
cmake -DTEST_COVERAGE=ON ..
|
|
||||||
make -j$THREADS memgraph__unit
|
|
||||||
|
|
||||||
- name: Run unit tests
|
|
||||||
run: |
|
|
||||||
# Activate toolchain.
|
|
||||||
source /opt/toolchain-v4/activate
|
|
||||||
|
|
||||||
# Run unit tests.
|
|
||||||
cd build
|
|
||||||
ctest -R memgraph__unit --output-on-failure
|
|
||||||
|
|
||||||
- name: Compute code coverage
|
|
||||||
run: |
|
|
||||||
# Activate toolchain.
|
|
||||||
source /opt/toolchain-v4/activate
|
|
||||||
|
|
||||||
# Compute code coverage.
|
|
||||||
cd tools/github
|
|
||||||
./coverage_convert
|
|
||||||
|
|
||||||
# Package code coverage.
|
|
||||||
cd generated
|
|
||||||
tar -czf code_coverage.tar.gz coverage.json html report.json summary.rmu
|
|
||||||
|
|
||||||
- name: Save code coverage
|
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: "Code coverage"
|
|
||||||
path: tools/github/generated/code_coverage.tar.gz
|
|
||||||
|
|
||||||
debug_build:
|
|
||||||
name: "Debug build"
|
|
||||||
runs-on: [self-hosted, Linux, X64, CentOS8]
|
|
||||||
env:
|
|
||||||
THREADS: 24
|
|
||||||
MEMGRAPH_ENTERPRISE_LICENSE: ${{ secrets.MEMGRAPH_ENTERPRISE_LICENSE }}
|
|
||||||
MEMGRAPH_ORGANIZATION_NAME: ${{ secrets.MEMGRAPH_ORGANIZATION_NAME }}
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Set up repository
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
with:
|
|
||||||
# Number of commits to fetch. `0` indicates all history for all
|
|
||||||
# branches and tags. (default: 1)
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Build debug binaries
|
|
||||||
run: |
|
|
||||||
# Activate toolchain.
|
|
||||||
source /opt/toolchain-v4/activate
|
|
||||||
|
|
||||||
# Initialize dependencies.
|
|
||||||
./init
|
|
||||||
|
|
||||||
# Build debug binaries.
|
|
||||||
cd build
|
|
||||||
cmake ..
|
|
||||||
make -j$THREADS
|
|
||||||
|
|
||||||
- name: Run leftover CTest tests
|
|
||||||
run: |
|
|
||||||
# Activate toolchain.
|
|
||||||
source /opt/toolchain-v4/activate
|
|
||||||
|
|
||||||
# Run leftover CTest tests (all except unit and benchmark tests).
|
|
||||||
cd build
|
|
||||||
ctest -E "(memgraph__unit|memgraph__benchmark)" --output-on-failure
|
|
||||||
|
|
||||||
- name: Run drivers tests
|
|
||||||
run: |
|
|
||||||
./tests/drivers/run.sh
|
|
||||||
|
|
||||||
- name: Run integration tests
|
|
||||||
run: |
|
|
||||||
tests/integration/run.sh
|
|
||||||
|
|
||||||
- name: Run cppcheck and clang-format
|
|
||||||
run: |
|
|
||||||
# Activate toolchain.
|
|
||||||
source /opt/toolchain-v4/activate
|
|
||||||
|
|
||||||
# Run cppcheck and clang-format.
|
|
||||||
cd tools/github
|
|
||||||
./cppcheck_and_clang_format diff
|
|
||||||
|
|
||||||
- name: Save cppcheck and clang-format errors
|
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: "Code coverage"
|
|
||||||
path: tools/github/cppcheck_and_clang_format.txt
|
|
||||||
|
|
||||||
release_build:
|
|
||||||
name: "Release build"
|
|
||||||
runs-on: [self-hosted, Linux, X64, CentOS8]
|
|
||||||
env:
|
|
||||||
THREADS: 24
|
|
||||||
MEMGRAPH_ENTERPRISE_LICENSE: ${{ secrets.MEMGRAPH_ENTERPRISE_LICENSE }}
|
|
||||||
MEMGRAPH_ORGANIZATION_NAME: ${{ secrets.MEMGRAPH_ORGANIZATION_NAME }}
|
|
||||||
timeout-minutes: 960
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Set up repository
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
with:
|
|
||||||
# Number of commits to fetch. `0` indicates all history for all
|
|
||||||
# branches and tags. (default: 1)
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Build release binaries
|
|
||||||
run: |
|
|
||||||
# Activate toolchain.
|
|
||||||
source /opt/toolchain-v4/activate
|
|
||||||
|
|
||||||
# Initialize dependencies.
|
|
||||||
./init
|
|
||||||
|
|
||||||
# Set default build_type to Release
|
|
||||||
INPUT_BUILD_TYPE=${{ github.event.inputs.build_type }}
|
|
||||||
BUILD_TYPE=${INPUT_BUILD_TYPE:-"Release"}
|
|
||||||
|
|
||||||
# Build release binaries.
|
|
||||||
cd build
|
|
||||||
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE ..
|
|
||||||
make -j$THREADS
|
|
||||||
|
|
||||||
- name: Create enterprise RPM package
|
|
||||||
run: |
|
|
||||||
# Activate toolchain.
|
|
||||||
source /opt/toolchain-v4/activate
|
|
||||||
|
|
||||||
cd build
|
|
||||||
|
|
||||||
# create mgconsole
|
|
||||||
# we use the -B to force the build
|
|
||||||
make -j$THREADS -B mgconsole
|
|
||||||
|
|
||||||
# Create enterprise RPM package.
|
|
||||||
mkdir output && cd output
|
|
||||||
cpack -G RPM --config ../CPackConfig.cmake
|
|
||||||
rpmlint memgraph*.rpm
|
|
||||||
|
|
||||||
- name: Save enterprise RPM package
|
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: "Enterprise RPM package"
|
|
||||||
path: build/output/memgraph*.rpm
|
|
||||||
|
|
||||||
- name: Run micro benchmark tests
|
|
||||||
run: |
|
|
||||||
# Activate toolchain.
|
|
||||||
source /opt/toolchain-v4/activate
|
|
||||||
|
|
||||||
# Run micro benchmark tests.
|
|
||||||
cd build
|
|
||||||
# The `eval` benchmark needs a large stack limit.
|
|
||||||
ulimit -s 262144
|
|
||||||
ctest -R memgraph__benchmark -V
|
|
||||||
|
|
||||||
- name: Run macro benchmark tests
|
|
||||||
run: |
|
|
||||||
cd tests/macro_benchmark
|
|
||||||
./harness QuerySuite MemgraphRunner \
|
|
||||||
--groups aggregation 1000_create unwind_create dense_expand match \
|
|
||||||
--no-strict
|
|
||||||
|
|
||||||
- name: Run parallel macro benchmark tests
|
|
||||||
run: |
|
|
||||||
cd tests/macro_benchmark
|
|
||||||
./harness QueryParallelSuite MemgraphRunner \
|
|
||||||
--groups aggregation_parallel create_parallel bfs_parallel \
|
|
||||||
--num-database-workers 9 --num-clients-workers 30 \
|
|
||||||
--no-strict
|
|
||||||
|
|
||||||
- name: Run GQL Behave tests
|
|
||||||
run: |
|
|
||||||
cd tests
|
|
||||||
./setup.sh /opt/toolchain-v4/activate
|
|
||||||
cd gql_behave
|
|
||||||
./continuous_integration
|
|
||||||
|
|
||||||
- name: Save quality assurance status
|
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: "GQL Behave Status"
|
|
||||||
path: |
|
|
||||||
tests/gql_behave/gql_behave_status.csv
|
|
||||||
tests/gql_behave/gql_behave_status.html
|
|
||||||
|
|
||||||
- name: Run unit tests
|
|
||||||
run: |
|
|
||||||
# Activate toolchain.
|
|
||||||
source /opt/toolchain-v4/activate
|
|
||||||
|
|
||||||
# Run unit tests.
|
|
||||||
cd build
|
|
||||||
ctest -R memgraph__unit --output-on-failure
|
|
||||||
|
|
||||||
- name: Run e2e tests
|
|
||||||
run: |
|
|
||||||
cd tests
|
|
||||||
./setup.sh /opt/toolchain-v4/activate
|
|
||||||
source ve3/bin/activate_e2e
|
|
||||||
cd e2e
|
|
||||||
./run.sh
|
|
||||||
|
|
||||||
- name: Run stress test (plain)
|
|
||||||
run: |
|
|
||||||
cd tests/stress
|
|
||||||
./continuous_integration
|
|
||||||
|
|
||||||
- name: Run stress test (SSL)
|
|
||||||
run: |
|
|
||||||
cd tests/stress
|
|
||||||
./continuous_integration --use-ssl
|
|
||||||
|
|
||||||
- name: Run stress test (large)
|
|
||||||
run: |
|
|
||||||
cd tests/stress
|
|
||||||
./continuous_integration --large-dataset
|
|
||||||
|
|
||||||
- name: Run durability test (plain)
|
|
||||||
run: |
|
|
||||||
cd tests/stress
|
|
||||||
source ve3/bin/activate
|
|
||||||
python3 durability --num-steps 5
|
|
||||||
|
|
||||||
- name: Run durability test (large)
|
|
||||||
run: |
|
|
||||||
cd tests/stress
|
|
||||||
source ve3/bin/activate
|
|
||||||
python3 durability --num-steps 20
|
|
||||||
245
.github/workflows/release_debian10.yaml
vendored
245
.github/workflows/release_debian10.yaml
vendored
@@ -1,6 +1,12 @@
|
|||||||
name: Release Debian 10
|
name: Release Debian 10
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
workflow_call:
|
||||||
|
inputs:
|
||||||
|
build_type:
|
||||||
|
type: string
|
||||||
|
description: "Memgraph Build type. Default value is Release."
|
||||||
|
default: 'Release'
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
build_type:
|
build_type:
|
||||||
@@ -11,22 +17,22 @@ on:
|
|||||||
- Release
|
- Release
|
||||||
- RelWithDebInfo
|
- RelWithDebInfo
|
||||||
|
|
||||||
schedule:
|
env:
|
||||||
- cron: "0 22 * * *"
|
OS: "Debian10"
|
||||||
|
THREADS: 24
|
||||||
|
MEMGRAPH_ENTERPRISE_LICENSE: ${{ secrets.MEMGRAPH_ENTERPRISE_LICENSE }}
|
||||||
|
MEMGRAPH_ORGANIZATION_NAME: ${{ secrets.MEMGRAPH_ORGANIZATION_NAME }}
|
||||||
|
BUILD_TYPE: ${{ github.event.inputs.build_type || 'Release' }}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
community_build:
|
community_build:
|
||||||
name: "Community build"
|
name: "Community build"
|
||||||
runs-on: [self-hosted, Linux, X64, Debian10]
|
runs-on: [self-hosted, Linux, X64, Debian10]
|
||||||
env:
|
timeout-minutes: 60
|
||||||
THREADS: 24
|
|
||||||
MEMGRAPH_ENTERPRISE_LICENSE: ${{ secrets.MEMGRAPH_ENTERPRISE_LICENSE }}
|
|
||||||
MEMGRAPH_ORGANIZATION_NAME: ${{ secrets.MEMGRAPH_ORGANIZATION_NAME }}
|
|
||||||
timeout-minutes: 960
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Set up repository
|
- name: Set up repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
# Number of commits to fetch. `0` indicates all history for all
|
# Number of commits to fetch. `0` indicates all history for all
|
||||||
# branches and tags. (default: 1)
|
# branches and tags. (default: 1)
|
||||||
@@ -40,10 +46,6 @@ jobs:
|
|||||||
# Initialize dependencies.
|
# Initialize dependencies.
|
||||||
./init
|
./init
|
||||||
|
|
||||||
# Set default build_type to Release
|
|
||||||
INPUT_BUILD_TYPE=${{ github.event.inputs.build_type }}
|
|
||||||
BUILD_TYPE=${INPUT_BUILD_TYPE:-"Release"}
|
|
||||||
|
|
||||||
# Build community binaries.
|
# Build community binaries.
|
||||||
cd build
|
cd build
|
||||||
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DMG_ENTERPRISE=OFF ..
|
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DMG_ENTERPRISE=OFF ..
|
||||||
@@ -65,10 +67,11 @@ jobs:
|
|||||||
THREADS: 24
|
THREADS: 24
|
||||||
MEMGRAPH_ENTERPRISE_LICENSE: ${{ secrets.MEMGRAPH_ENTERPRISE_LICENSE }}
|
MEMGRAPH_ENTERPRISE_LICENSE: ${{ secrets.MEMGRAPH_ENTERPRISE_LICENSE }}
|
||||||
MEMGRAPH_ORGANIZATION_NAME: ${{ secrets.MEMGRAPH_ORGANIZATION_NAME }}
|
MEMGRAPH_ORGANIZATION_NAME: ${{ secrets.MEMGRAPH_ORGANIZATION_NAME }}
|
||||||
|
timeout-minutes: 60
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Set up repository
|
- name: Set up repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
# Number of commits to fetch. `0` indicates all history for all
|
# Number of commits to fetch. `0` indicates all history for all
|
||||||
# branches and tags. (default: 1)
|
# branches and tags. (default: 1)
|
||||||
@@ -110,22 +113,19 @@ jobs:
|
|||||||
tar -czf code_coverage.tar.gz coverage.json html report.json summary.rmu
|
tar -czf code_coverage.tar.gz coverage.json html report.json summary.rmu
|
||||||
|
|
||||||
- name: Save code coverage
|
- name: Save code coverage
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: "Code coverage"
|
name: "Code coverage(Coverage build)-${{ env.OS }}"
|
||||||
path: tools/github/generated/code_coverage.tar.gz
|
path: tools/github/generated/code_coverage.tar.gz
|
||||||
|
|
||||||
debug_build:
|
debug_build:
|
||||||
name: "Debug build"
|
name: "Debug build"
|
||||||
runs-on: [self-hosted, Linux, X64, Debian10]
|
runs-on: [self-hosted, Linux, X64, Debian10]
|
||||||
env:
|
timeout-minutes: 60
|
||||||
THREADS: 24
|
|
||||||
MEMGRAPH_ENTERPRISE_LICENSE: ${{ secrets.MEMGRAPH_ENTERPRISE_LICENSE }}
|
|
||||||
MEMGRAPH_ORGANIZATION_NAME: ${{ secrets.MEMGRAPH_ORGANIZATION_NAME }}
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Set up repository
|
- name: Set up repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
# Number of commits to fetch. `0` indicates all history for all
|
# Number of commits to fetch. `0` indicates all history for all
|
||||||
# branches and tags. (default: 1)
|
# branches and tags. (default: 1)
|
||||||
@@ -157,10 +157,6 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
./tests/drivers/run.sh
|
./tests/drivers/run.sh
|
||||||
|
|
||||||
- name: Run integration tests
|
|
||||||
run: |
|
|
||||||
tests/integration/run.sh
|
|
||||||
|
|
||||||
- name: Run cppcheck and clang-format
|
- name: Run cppcheck and clang-format
|
||||||
run: |
|
run: |
|
||||||
# Activate toolchain.
|
# Activate toolchain.
|
||||||
@@ -171,23 +167,49 @@ jobs:
|
|||||||
./cppcheck_and_clang_format diff
|
./cppcheck_and_clang_format diff
|
||||||
|
|
||||||
- name: Save cppcheck and clang-format errors
|
- name: Save cppcheck and clang-format errors
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: "Code coverage"
|
name: "Code coverage(Debug build)-${{ env.OS }}"
|
||||||
path: tools/github/cppcheck_and_clang_format.txt
|
path: tools/github/cppcheck_and_clang_format.txt
|
||||||
|
|
||||||
release_build:
|
debug_integration_test:
|
||||||
name: "Release build"
|
name: "Debug integration tests"
|
||||||
runs-on: [self-hosted, Linux, X64, Debian10, BigMemory]
|
runs-on: [self-hosted, Linux, X64, Debian10]
|
||||||
env:
|
timeout-minutes: 60
|
||||||
THREADS: 24
|
|
||||||
MEMGRAPH_ENTERPRISE_LICENSE: ${{ secrets.MEMGRAPH_ENTERPRISE_LICENSE }}
|
|
||||||
MEMGRAPH_ORGANIZATION_NAME: ${{ secrets.MEMGRAPH_ORGANIZATION_NAME }}
|
|
||||||
timeout-minutes: 960
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Set up repository
|
- name: Set up repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
# Number of commits to fetch. `0` indicates all history for all
|
||||||
|
# branches and tags. (default: 1)
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Build debug binaries
|
||||||
|
run: |
|
||||||
|
# Activate toolchain.
|
||||||
|
source /opt/toolchain-v4/activate
|
||||||
|
|
||||||
|
# Initialize dependencies.
|
||||||
|
./init
|
||||||
|
|
||||||
|
# Build debug binaries.
|
||||||
|
cd build
|
||||||
|
cmake ..
|
||||||
|
make -j$THREADS
|
||||||
|
|
||||||
|
- name: Run integration tests
|
||||||
|
run: |
|
||||||
|
tests/integration/run.sh
|
||||||
|
|
||||||
|
release_build:
|
||||||
|
name: "Release build"
|
||||||
|
runs-on: [self-hosted, Linux, X64, Debian10]
|
||||||
|
timeout-minutes: 60
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Set up repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
# Number of commits to fetch. `0` indicates all history for all
|
# Number of commits to fetch. `0` indicates all history for all
|
||||||
# branches and tags. (default: 1)
|
# branches and tags. (default: 1)
|
||||||
@@ -201,10 +223,6 @@ jobs:
|
|||||||
# Initialize dependencies.
|
# Initialize dependencies.
|
||||||
./init
|
./init
|
||||||
|
|
||||||
# Set default build_type to Release
|
|
||||||
INPUT_BUILD_TYPE=${{ github.event.inputs.build_type }}
|
|
||||||
BUILD_TYPE=${INPUT_BUILD_TYPE:-"Release"}
|
|
||||||
|
|
||||||
# Build release binaries.
|
# Build release binaries.
|
||||||
cd build
|
cd build
|
||||||
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE ..
|
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE ..
|
||||||
@@ -226,11 +244,60 @@ jobs:
|
|||||||
cpack -G DEB --config ../CPackConfig.cmake
|
cpack -G DEB --config ../CPackConfig.cmake
|
||||||
|
|
||||||
- name: Save enterprise DEB package
|
- name: Save enterprise DEB package
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: "Enterprise DEB package"
|
name: "Enterprise DEB package-${{ env.OS}}"
|
||||||
path: build/output/memgraph*.deb
|
path: build/output/memgraph*.deb
|
||||||
|
|
||||||
|
- name: Run GQL Behave tests
|
||||||
|
run: |
|
||||||
|
cd tests
|
||||||
|
./setup.sh /opt/toolchain-v4/activate
|
||||||
|
cd gql_behave
|
||||||
|
./continuous_integration
|
||||||
|
|
||||||
|
- name: Save quality assurance status
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: "GQL Behave Status-${{ env.OS }}"
|
||||||
|
path: |
|
||||||
|
tests/gql_behave/gql_behave_status.csv
|
||||||
|
tests/gql_behave/gql_behave_status.html
|
||||||
|
|
||||||
|
- name: Run unit tests
|
||||||
|
run: |
|
||||||
|
# Activate toolchain.
|
||||||
|
source /opt/toolchain-v4/activate
|
||||||
|
|
||||||
|
# Run unit tests.
|
||||||
|
cd build
|
||||||
|
ctest -R memgraph__unit --output-on-failure
|
||||||
|
|
||||||
|
release_benchmark_tests:
|
||||||
|
name: "Release Benchmark Tests"
|
||||||
|
runs-on: [self-hosted, Linux, X64, Debian10]
|
||||||
|
timeout-minutes: 60
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Set up repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
# Number of commits to fetch. `0` indicates all history for all
|
||||||
|
# branches and tags. (default: 1)
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Build release binaries
|
||||||
|
run: |
|
||||||
|
# Activate toolchain.
|
||||||
|
source /opt/toolchain-v4/activate
|
||||||
|
# Initialize dependencies.
|
||||||
|
./init
|
||||||
|
|
||||||
|
# Build release binaries
|
||||||
|
cd build
|
||||||
|
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE ..
|
||||||
|
make -j$THREADS
|
||||||
|
|
||||||
- name: Run micro benchmark tests
|
- name: Run micro benchmark tests
|
||||||
run: |
|
run: |
|
||||||
# Activate toolchain.
|
# Activate toolchain.
|
||||||
@@ -257,29 +324,37 @@ jobs:
|
|||||||
--num-database-workers 9 --num-clients-workers 30 \
|
--num-database-workers 9 --num-clients-workers 30 \
|
||||||
--no-strict
|
--no-strict
|
||||||
|
|
||||||
- name: Run GQL Behave tests
|
release_e2e_test:
|
||||||
run: |
|
name: "Release End-to-end Test"
|
||||||
cd tests
|
runs-on: [self-hosted, Linux, X64, Debian10]
|
||||||
./setup.sh /opt/toolchain-v4/activate
|
timeout-minutes: 60
|
||||||
cd gql_behave
|
|
||||||
./continuous_integration
|
|
||||||
|
|
||||||
- name: Save quality assurance status
|
steps:
|
||||||
uses: actions/upload-artifact@v3
|
- name: Set up repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
name: "GQL Behave Status"
|
# Number of commits to fetch. `0` indicates all history for all
|
||||||
path: |
|
# branches and tags. (default: 1)
|
||||||
tests/gql_behave/gql_behave_status.csv
|
fetch-depth: 0
|
||||||
tests/gql_behave/gql_behave_status.html
|
|
||||||
|
|
||||||
- name: Run unit tests
|
- name: Build release binaries
|
||||||
run: |
|
run: |
|
||||||
# Activate toolchain.
|
# Activate toolchain.
|
||||||
source /opt/toolchain-v4/activate
|
source /opt/toolchain-v4/activate
|
||||||
|
# Initialize dependencies.
|
||||||
|
./init
|
||||||
|
|
||||||
# Run unit tests.
|
# Build release binaries
|
||||||
cd build
|
cd build
|
||||||
ctest -R memgraph__unit --output-on-failure
|
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE ..
|
||||||
|
make -j$THREADS
|
||||||
|
|
||||||
|
- name: Ensure Kafka and Pulsar are up
|
||||||
|
run: |
|
||||||
|
cd tests/e2e/streams/kafka
|
||||||
|
docker-compose up -d
|
||||||
|
cd ../pulsar
|
||||||
|
docker-compose up -d
|
||||||
|
|
||||||
- name: Run e2e tests
|
- name: Run e2e tests
|
||||||
run: |
|
run: |
|
||||||
@@ -289,6 +364,40 @@ jobs:
|
|||||||
cd e2e
|
cd e2e
|
||||||
./run.sh
|
./run.sh
|
||||||
|
|
||||||
|
- name: Ensure Kafka and Pulsar are down
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
cd tests/e2e/streams/kafka
|
||||||
|
docker-compose down
|
||||||
|
cd ../pulsar
|
||||||
|
docker-compose down
|
||||||
|
|
||||||
|
release_durability_stress_tests:
|
||||||
|
name: "Release durability and stress tests"
|
||||||
|
runs-on: [self-hosted, Linux, X64, Debian10]
|
||||||
|
timeout-minutes: 60
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Set up repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
# Number of commits to fetch. `0` indicates all history for all
|
||||||
|
# branches and tags. (default: 1)
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Build release binaries
|
||||||
|
run: |
|
||||||
|
# Activate toolchain.
|
||||||
|
source /opt/toolchain-v4/activate
|
||||||
|
|
||||||
|
# Initialize dependencies.
|
||||||
|
./init
|
||||||
|
|
||||||
|
# Build release binaries.
|
||||||
|
cd build
|
||||||
|
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE ..
|
||||||
|
make -j$THREADS
|
||||||
|
|
||||||
- name: Run stress test (plain)
|
- name: Run stress test (plain)
|
||||||
run: |
|
run: |
|
||||||
cd tests/stress
|
cd tests/stress
|
||||||
@@ -299,11 +408,6 @@ jobs:
|
|||||||
cd tests/stress
|
cd tests/stress
|
||||||
./continuous_integration --use-ssl
|
./continuous_integration --use-ssl
|
||||||
|
|
||||||
- name: Run stress test (large)
|
|
||||||
run: |
|
|
||||||
cd tests/stress
|
|
||||||
./continuous_integration --large-dataset
|
|
||||||
|
|
||||||
- name: Run durability test (plain)
|
- name: Run durability test (plain)
|
||||||
run: |
|
run: |
|
||||||
cd tests/stress
|
cd tests/stress
|
||||||
@@ -319,15 +423,11 @@ jobs:
|
|||||||
release_jepsen_test:
|
release_jepsen_test:
|
||||||
name: "Release Jepsen Test"
|
name: "Release Jepsen Test"
|
||||||
runs-on: [self-hosted, Linux, X64, Debian10, JepsenControl]
|
runs-on: [self-hosted, Linux, X64, Debian10, JepsenControl]
|
||||||
env:
|
|
||||||
THREADS: 24
|
|
||||||
MEMGRAPH_ENTERPRISE_LICENSE: ${{ secrets.MEMGRAPH_ENTERPRISE_LICENSE }}
|
|
||||||
MEMGRAPH_ORGANIZATION_NAME: ${{ secrets.MEMGRAPH_ORGANIZATION_NAME }}
|
|
||||||
timeout-minutes: 60
|
timeout-minutes: 60
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Set up repository
|
- name: Set up repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
# Number of commits to fetch. `0` indicates all history for all
|
# Number of commits to fetch. `0` indicates all history for all
|
||||||
# branches and tags. (default: 1)
|
# branches and tags. (default: 1)
|
||||||
@@ -340,23 +440,24 @@ jobs:
|
|||||||
# Initialize dependencies.
|
# Initialize dependencies.
|
||||||
./init
|
./init
|
||||||
|
|
||||||
# Set default build_type to Release
|
|
||||||
INPUT_BUILD_TYPE=${{ github.event.inputs.build_type }}
|
|
||||||
BUILD_TYPE=${INPUT_BUILD_TYPE:-"Release"}
|
|
||||||
|
|
||||||
# Build only memgraph release binary.
|
# Build only memgraph release binary.
|
||||||
cd build
|
cd build
|
||||||
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE ..
|
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE ..
|
||||||
make -j$THREADS memgraph
|
make -j$THREADS memgraph
|
||||||
|
|
||||||
|
- name: Refresh Jepsen Cluster
|
||||||
|
run: |
|
||||||
|
cd tests/jepsen
|
||||||
|
./run.sh cluster-refresh
|
||||||
|
|
||||||
- name: Run Jepsen tests
|
- name: Run Jepsen tests
|
||||||
run: |
|
run: |
|
||||||
cd tests/jepsen
|
cd tests/jepsen
|
||||||
./run.sh test-all-individually --binary ../../build/memgraph --ignore-run-stdout-logs --ignore-run-stderr-logs
|
./run.sh test-all-individually --binary ../../build/memgraph --ignore-run-stdout-logs --ignore-run-stderr-logs
|
||||||
|
|
||||||
- name: Save Jepsen report
|
- name: Save Jepsen report
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
if: ${{ always() }}
|
if: ${{ always() }}
|
||||||
with:
|
with:
|
||||||
name: "Jepsen Report"
|
name: "Jepsen Report-${{ env.OS }}"
|
||||||
path: tests/jepsen/Jepsen.tar.gz
|
path: tests/jepsen/Jepsen.tar.gz
|
||||||
|
|||||||
2
.github/workflows/release_docker.yaml
vendored
2
.github/workflows/release_docker.yaml
vendored
@@ -19,7 +19,7 @@ jobs:
|
|||||||
DOCKER_REPOSITORY_NAME: memgraph
|
DOCKER_REPOSITORY_NAME: memgraph
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v2
|
uses: docker/setup-qemu-action@v2
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v2
|
uses: docker/setup-qemu-action@v2
|
||||||
|
|||||||
224
.github/workflows/release_ubuntu2004.yaml
vendored
224
.github/workflows/release_ubuntu2004.yaml
vendored
@@ -1,6 +1,12 @@
|
|||||||
name: Release Ubuntu 20.04
|
name: Release Ubuntu 20.04
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
workflow_call:
|
||||||
|
inputs:
|
||||||
|
build_type:
|
||||||
|
type: string
|
||||||
|
description: "Memgraph Build type. Default value is Release."
|
||||||
|
default: 'Release'
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
build_type:
|
build_type:
|
||||||
@@ -11,22 +17,22 @@ on:
|
|||||||
- Release
|
- Release
|
||||||
- RelWithDebInfo
|
- RelWithDebInfo
|
||||||
|
|
||||||
schedule:
|
env:
|
||||||
- cron: "0 22 * * *"
|
OS: "Ubuntu 20.04"
|
||||||
|
THREADS: 24
|
||||||
|
MEMGRAPH_ENTERPRISE_LICENSE: ${{ secrets.MEMGRAPH_ENTERPRISE_LICENSE }}
|
||||||
|
MEMGRAPH_ORGANIZATION_NAME: ${{ secrets.MEMGRAPH_ORGANIZATION_NAME }}
|
||||||
|
BUILD_TYPE: ${{ github.event.inputs.build_type || 'Release' }}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
community_build:
|
community_build:
|
||||||
name: "Community build"
|
name: "Community build"
|
||||||
runs-on: [self-hosted, Linux, X64, Ubuntu20.04]
|
runs-on: [self-hosted, Linux, X64, Ubuntu20.04]
|
||||||
env:
|
timeout-minutes: 60
|
||||||
THREADS: 24
|
|
||||||
MEMGRAPH_ENTERPRISE_LICENSE: ${{ secrets.MEMGRAPH_ENTERPRISE_LICENSE }}
|
|
||||||
MEMGRAPH_ORGANIZATION_NAME: ${{ secrets.MEMGRAPH_ORGANIZATION_NAME }}
|
|
||||||
timeout-minutes: 960
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Set up repository
|
- name: Set up repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
# Number of commits to fetch. `0` indicates all history for all
|
# Number of commits to fetch. `0` indicates all history for all
|
||||||
# branches and tags. (default: 1)
|
# branches and tags. (default: 1)
|
||||||
@@ -40,10 +46,6 @@ jobs:
|
|||||||
# Initialize dependencies.
|
# Initialize dependencies.
|
||||||
./init
|
./init
|
||||||
|
|
||||||
# Set default build_type to Release
|
|
||||||
INPUT_BUILD_TYPE=${{ github.event.inputs.build_type }}
|
|
||||||
BUILD_TYPE=${INPUT_BUILD_TYPE:-"Release"}
|
|
||||||
|
|
||||||
# Build community binaries.
|
# Build community binaries.
|
||||||
cd build
|
cd build
|
||||||
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DMG_ENTERPRISE=OFF ..
|
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DMG_ENTERPRISE=OFF ..
|
||||||
@@ -61,14 +63,11 @@ jobs:
|
|||||||
coverage_build:
|
coverage_build:
|
||||||
name: "Coverage build"
|
name: "Coverage build"
|
||||||
runs-on: [self-hosted, Linux, X64, Ubuntu20.04]
|
runs-on: [self-hosted, Linux, X64, Ubuntu20.04]
|
||||||
env:
|
timeout-minutes: 60
|
||||||
THREADS: 24
|
|
||||||
MEMGRAPH_ENTERPRISE_LICENSE: ${{ secrets.MEMGRAPH_ENTERPRISE_LICENSE }}
|
|
||||||
MEMGRAPH_ORGANIZATION_NAME: ${{ secrets.MEMGRAPH_ORGANIZATION_NAME }}
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Set up repository
|
- name: Set up repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
# Number of commits to fetch. `0` indicates all history for all
|
# Number of commits to fetch. `0` indicates all history for all
|
||||||
# branches and tags. (default: 1)
|
# branches and tags. (default: 1)
|
||||||
@@ -110,22 +109,19 @@ jobs:
|
|||||||
tar -czf code_coverage.tar.gz coverage.json html report.json summary.rmu
|
tar -czf code_coverage.tar.gz coverage.json html report.json summary.rmu
|
||||||
|
|
||||||
- name: Save code coverage
|
- name: Save code coverage
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: "Code coverage"
|
name: "Code coverage(Coverage build)-${{ env.OS }}"
|
||||||
path: tools/github/generated/code_coverage.tar.gz
|
path: tools/github/generated/code_coverage.tar.gz
|
||||||
|
|
||||||
debug_build:
|
debug_build:
|
||||||
name: "Debug build"
|
name: "Debug build"
|
||||||
runs-on: [self-hosted, Linux, X64, Ubuntu20.04]
|
runs-on: [self-hosted, Linux, X64, Ubuntu20.04]
|
||||||
env:
|
timeout-minutes: 60
|
||||||
THREADS: 24
|
|
||||||
MEMGRAPH_ENTERPRISE_LICENSE: ${{ secrets.MEMGRAPH_ENTERPRISE_LICENSE }}
|
|
||||||
MEMGRAPH_ORGANIZATION_NAME: ${{ secrets.MEMGRAPH_ORGANIZATION_NAME }}
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Set up repository
|
- name: Set up repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
# Number of commits to fetch. `0` indicates all history for all
|
# Number of commits to fetch. `0` indicates all history for all
|
||||||
# branches and tags. (default: 1)
|
# branches and tags. (default: 1)
|
||||||
@@ -157,10 +153,6 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
./tests/drivers/run.sh
|
./tests/drivers/run.sh
|
||||||
|
|
||||||
- name: Run integration tests
|
|
||||||
run: |
|
|
||||||
tests/integration/run.sh
|
|
||||||
|
|
||||||
- name: Run cppcheck and clang-format
|
- name: Run cppcheck and clang-format
|
||||||
run: |
|
run: |
|
||||||
# Activate toolchain.
|
# Activate toolchain.
|
||||||
@@ -171,23 +163,49 @@ jobs:
|
|||||||
./cppcheck_and_clang_format diff
|
./cppcheck_and_clang_format diff
|
||||||
|
|
||||||
- name: Save cppcheck and clang-format errors
|
- name: Save cppcheck and clang-format errors
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: "Code coverage"
|
name: "Code coverage(Debug build)-${{ env.OS }}"
|
||||||
path: tools/github/cppcheck_and_clang_format.txt
|
path: tools/github/cppcheck_and_clang_format.txt
|
||||||
|
|
||||||
|
debug_integration_test:
|
||||||
|
name: "Debug integration tests"
|
||||||
|
runs-on: [self-hosted, Linux, X64, Ubuntu20.04]
|
||||||
|
timeout-minutes: 60
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Set up repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
# Number of commits to fetch. `0` indicates all history for all
|
||||||
|
# branches and tags. (default: 1)
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Build debug binaries
|
||||||
|
run: |
|
||||||
|
# Activate toolchain.
|
||||||
|
source /opt/toolchain-v4/activate
|
||||||
|
|
||||||
|
# Initialize dependencies.
|
||||||
|
./init
|
||||||
|
|
||||||
|
# Build debug binaries.
|
||||||
|
cd build
|
||||||
|
cmake ..
|
||||||
|
make -j$THREADS
|
||||||
|
|
||||||
|
- name: Run integration tests
|
||||||
|
run: |
|
||||||
|
tests/integration/run.sh
|
||||||
|
|
||||||
release_build:
|
release_build:
|
||||||
name: "Release build"
|
name: "Release build"
|
||||||
runs-on: [self-hosted, Linux, X64, Ubuntu20.04]
|
runs-on: [self-hosted, Linux, X64, Ubuntu20.04]
|
||||||
env:
|
timeout-minutes: 60
|
||||||
THREADS: 24
|
|
||||||
MEMGRAPH_ENTERPRISE_LICENSE: ${{ secrets.MEMGRAPH_ENTERPRISE_LICENSE }}
|
|
||||||
MEMGRAPH_ORGANIZATION_NAME: ${{ secrets.MEMGRAPH_ORGANIZATION_NAME }}
|
|
||||||
timeout-minutes: 960
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Set up repository
|
- name: Set up repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
# Number of commits to fetch. `0` indicates all history for all
|
# Number of commits to fetch. `0` indicates all history for all
|
||||||
# branches and tags. (default: 1)
|
# branches and tags. (default: 1)
|
||||||
@@ -201,10 +219,6 @@ jobs:
|
|||||||
# Initialize dependencies.
|
# Initialize dependencies.
|
||||||
./init
|
./init
|
||||||
|
|
||||||
# Set default build_type to Release
|
|
||||||
INPUT_BUILD_TYPE=${{ github.event.inputs.build_type }}
|
|
||||||
BUILD_TYPE=${INPUT_BUILD_TYPE:-"Release"}
|
|
||||||
|
|
||||||
# Build release binaries.
|
# Build release binaries.
|
||||||
cd build
|
cd build
|
||||||
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE ..
|
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE ..
|
||||||
@@ -226,11 +240,60 @@ jobs:
|
|||||||
cpack -G DEB --config ../CPackConfig.cmake
|
cpack -G DEB --config ../CPackConfig.cmake
|
||||||
|
|
||||||
- name: Save enterprise DEB package
|
- name: Save enterprise DEB package
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: "Enterprise DEB package"
|
name: "Enterprise DEB package-${{ env.OS }}"
|
||||||
path: build/output/memgraph*.deb
|
path: build/output/memgraph*.deb
|
||||||
|
|
||||||
|
- name: Run GQL Behave tests
|
||||||
|
run: |
|
||||||
|
cd tests
|
||||||
|
./setup.sh /opt/toolchain-v4/activate
|
||||||
|
cd gql_behave
|
||||||
|
./continuous_integration
|
||||||
|
|
||||||
|
- name: Save quality assurance status
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: "GQL Behave Status-${{ env.OS }}"
|
||||||
|
path: |
|
||||||
|
tests/gql_behave/gql_behave_status.csv
|
||||||
|
tests/gql_behave/gql_behave_status.html
|
||||||
|
|
||||||
|
- name: Run unit tests
|
||||||
|
run: |
|
||||||
|
# Activate toolchain.
|
||||||
|
source /opt/toolchain-v4/activate
|
||||||
|
|
||||||
|
# Run unit tests.
|
||||||
|
cd build
|
||||||
|
ctest -R memgraph__unit --output-on-failure
|
||||||
|
|
||||||
|
release_benchmark_tests:
|
||||||
|
name: "Release Benchmark Tests"
|
||||||
|
runs-on: [self-hosted, Linux, X64, Ubuntu20.04]
|
||||||
|
timeout-minutes: 60
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Set up repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
# Number of commits to fetch. `0` indicates all history for all
|
||||||
|
# branches and tags. (default: 1)
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Build release binaries
|
||||||
|
run: |
|
||||||
|
# Activate toolchain.
|
||||||
|
source /opt/toolchain-v4/activate
|
||||||
|
# Initialize dependencies.
|
||||||
|
./init
|
||||||
|
|
||||||
|
# Build release binaries
|
||||||
|
cd build
|
||||||
|
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE ..
|
||||||
|
make -j$THREADS
|
||||||
|
|
||||||
- name: Run micro benchmark tests
|
- name: Run micro benchmark tests
|
||||||
run: |
|
run: |
|
||||||
# Activate toolchain.
|
# Activate toolchain.
|
||||||
@@ -257,29 +320,37 @@ jobs:
|
|||||||
--num-database-workers 9 --num-clients-workers 30 \
|
--num-database-workers 9 --num-clients-workers 30 \
|
||||||
--no-strict
|
--no-strict
|
||||||
|
|
||||||
- name: Run GQL Behave tests
|
release_e2e_test:
|
||||||
run: |
|
name: "Release End-to-end Test"
|
||||||
cd tests
|
runs-on: [self-hosted, Linux, X64, Ubuntu20.04]
|
||||||
./setup.sh /opt/toolchain-v4/activate
|
timeout-minutes: 60
|
||||||
cd gql_behave
|
|
||||||
./continuous_integration
|
|
||||||
|
|
||||||
- name: Save quality assurance status
|
steps:
|
||||||
uses: actions/upload-artifact@v3
|
- name: Set up repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
name: "GQL Behave Status"
|
# Number of commits to fetch. `0` indicates all history for all
|
||||||
path: |
|
# branches and tags. (default: 1)
|
||||||
tests/gql_behave/gql_behave_status.csv
|
fetch-depth: 0
|
||||||
tests/gql_behave/gql_behave_status.html
|
|
||||||
|
|
||||||
- name: Run unit tests
|
- name: Build release binaries
|
||||||
run: |
|
run: |
|
||||||
# Activate toolchain.
|
# Activate toolchain.
|
||||||
source /opt/toolchain-v4/activate
|
source /opt/toolchain-v4/activate
|
||||||
|
# Initialize dependencies.
|
||||||
|
./init
|
||||||
|
|
||||||
# Run unit tests.
|
# Build release binaries
|
||||||
cd build
|
cd build
|
||||||
ctest -R memgraph__unit --output-on-failure
|
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE ..
|
||||||
|
make -j$THREADS
|
||||||
|
|
||||||
|
- name: Ensure Kafka and Pulsar are up
|
||||||
|
run: |
|
||||||
|
cd tests/e2e/streams/kafka
|
||||||
|
docker-compose up -d
|
||||||
|
cd ../pulsar
|
||||||
|
docker-compose up -d
|
||||||
|
|
||||||
- name: Run e2e tests
|
- name: Run e2e tests
|
||||||
run: |
|
run: |
|
||||||
@@ -289,6 +360,40 @@ jobs:
|
|||||||
cd e2e
|
cd e2e
|
||||||
./run.sh
|
./run.sh
|
||||||
|
|
||||||
|
- name: Ensure Kafka and Pulsar are down
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
cd tests/e2e/streams/kafka
|
||||||
|
docker-compose down
|
||||||
|
cd ../pulsar
|
||||||
|
docker-compose down
|
||||||
|
|
||||||
|
release_durability_stress_tests:
|
||||||
|
name: "Release durability and stress tests"
|
||||||
|
runs-on: [self-hosted, Linux, X64, Ubuntu20.04]
|
||||||
|
timeout-minutes: 60
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Set up repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
# Number of commits to fetch. `0` indicates all history for all
|
||||||
|
# branches and tags. (default: 1)
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Build release binaries
|
||||||
|
run: |
|
||||||
|
# Activate toolchain.
|
||||||
|
source /opt/toolchain-v4/activate
|
||||||
|
|
||||||
|
# Initialize dependencies.
|
||||||
|
./init
|
||||||
|
|
||||||
|
# Build release binaries.
|
||||||
|
cd build
|
||||||
|
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE ..
|
||||||
|
make -j$THREADS
|
||||||
|
|
||||||
- name: Run stress test (plain)
|
- name: Run stress test (plain)
|
||||||
run: |
|
run: |
|
||||||
cd tests/stress
|
cd tests/stress
|
||||||
@@ -299,11 +404,6 @@ jobs:
|
|||||||
cd tests/stress
|
cd tests/stress
|
||||||
./continuous_integration --use-ssl
|
./continuous_integration --use-ssl
|
||||||
|
|
||||||
- name: Run stress test (large)
|
|
||||||
run: |
|
|
||||||
cd tests/stress
|
|
||||||
./continuous_integration --large-dataset
|
|
||||||
|
|
||||||
- name: Run durability test (plain)
|
- name: Run durability test (plain)
|
||||||
run: |
|
run: |
|
||||||
cd tests/stress
|
cd tests/stress
|
||||||
|
|||||||
68
.github/workflows/stress_test_large.yaml
vendored
Normal file
68
.github/workflows/stress_test_large.yaml
vendored
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
name: Stress test large
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.ref_name }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
build_type:
|
||||||
|
type: choice
|
||||||
|
description: "Memgraph Build type. Default value is Release."
|
||||||
|
default: 'Release'
|
||||||
|
options:
|
||||||
|
- Release
|
||||||
|
- RelWithDebInfo
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- "v*.*.*-rc*"
|
||||||
|
- "v*.*-rc*"
|
||||||
|
schedule:
|
||||||
|
- cron: "0 22 * * *"
|
||||||
|
|
||||||
|
env:
|
||||||
|
THREADS: 24
|
||||||
|
MEMGRAPH_ENTERPRISE_LICENSE: ${{ secrets.MEMGRAPH_ENTERPRISE_LICENSE }}
|
||||||
|
MEMGRAPH_ORGANIZATION_NAME: ${{ secrets.MEMGRAPH_ORGANIZATION_NAME }}
|
||||||
|
BUILD_TYPE: ${{ github.event.inputs.build_type || 'Release' }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
stress_test_large:
|
||||||
|
name: "Stress test large"
|
||||||
|
timeout-minutes: 720
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [Debian10, Ubuntu20.04]
|
||||||
|
extra: [BigMemory, Gen8]
|
||||||
|
exclude:
|
||||||
|
- os: Debian10
|
||||||
|
extra: Gen8
|
||||||
|
- os: Ubuntu20.04
|
||||||
|
extra: BigMemory
|
||||||
|
runs-on: [self-hosted, Linux, X64, "${{ matrix.os }}", "${{ matrix.extra }}"]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Set up repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
# Number of commits to fetch. `0` indicates all history for all
|
||||||
|
# branches and tags. (default: 1)
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Build release binaries
|
||||||
|
run: |
|
||||||
|
# Activate toolchain.
|
||||||
|
source /opt/toolchain-v4/activate
|
||||||
|
|
||||||
|
# Initialize dependencies.
|
||||||
|
./init
|
||||||
|
|
||||||
|
# Build release binaries.
|
||||||
|
cd build
|
||||||
|
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE ..
|
||||||
|
make -j$THREADS
|
||||||
|
|
||||||
|
- name: Run stress test (large)
|
||||||
|
run: |
|
||||||
|
cd tests/stress
|
||||||
|
./continuous_integration --large-dataset
|
||||||
2
.github/workflows/upload_to_s3.yaml
vendored
2
.github/workflows/upload_to_s3.yaml
vendored
@@ -15,7 +15,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Download artifacts
|
- name: Download artifacts
|
||||||
uses: dawidd6/action-download-artifact@v2
|
uses: dawidd6/action-download-artifact@v4
|
||||||
with:
|
with:
|
||||||
workflow: package_all.yaml
|
workflow: package_all.yaml
|
||||||
workflow_conclusion: success
|
workflow_conclusion: success
|
||||||
|
|||||||
32
ADRs/001_tantivy.md
Normal file
32
ADRs/001_tantivy.md
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
# Tantivy ADR
|
||||||
|
|
||||||
|
**Author**
|
||||||
|
Marko Budiselic (github.com/gitbuda)
|
||||||
|
|
||||||
|
**Status**
|
||||||
|
APPROVED
|
||||||
|
|
||||||
|
**Date**
|
||||||
|
January 5, 2024
|
||||||
|
|
||||||
|
**Problem**
|
||||||
|
|
||||||
|
For some of Memgraph workloads, text search is a required feature. We don't
|
||||||
|
want to build a new text search engine because that's not Memgraph's core
|
||||||
|
value.
|
||||||
|
|
||||||
|
**Criteria**
|
||||||
|
|
||||||
|
- easy integration with our C++ codebase
|
||||||
|
- ability to operate in-memory and on-disk
|
||||||
|
- sufficient features (regex, full-text search, fuzzy search, aggregations over
|
||||||
|
text data)
|
||||||
|
- production-ready
|
||||||
|
|
||||||
|
**Decision**
|
||||||
|
|
||||||
|
All known C++ libraries are not production-ready. Recent Rust libraries, in
|
||||||
|
particular [Tantivy](https://github.com/quickwit-oss/tantivy), seem to provide
|
||||||
|
much more features, it is production ready. The way how we'll integrate Tantivy
|
||||||
|
into the current Memgraph codebase is via
|
||||||
|
[cxx](https://github.com/dtolnay/cxx). **We select Tantivy.**
|
||||||
34
ADRs/002_nuraft.md
Normal file
34
ADRs/002_nuraft.md
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
# NuRaft ADR
|
||||||
|
|
||||||
|
**Author**
|
||||||
|
Marko Budiselic (github.com/gitbuda)
|
||||||
|
|
||||||
|
**Status**
|
||||||
|
PROPOSED
|
||||||
|
|
||||||
|
**Date**
|
||||||
|
January 10, 2024
|
||||||
|
|
||||||
|
**Problem**
|
||||||
|
|
||||||
|
In order to enhance Memgraph to have High Availability features as requested by
|
||||||
|
customers, we want to have reliable coordinators backed by RAFT consensus algorithm. Implementing
|
||||||
|
RAFT to be correct and performant is a very challenging task. Skillful Memgraph
|
||||||
|
engineers already tried 3 times and failed to deliver in a reasonable timeframe
|
||||||
|
all three times (approximately 4 person-weeks of engineering work each time).
|
||||||
|
|
||||||
|
**Criteria**
|
||||||
|
|
||||||
|
- easy integration with our C++ codebase
|
||||||
|
- heavily tested in production environments
|
||||||
|
- implementation of performance optimizations on top of the canonical Raft
|
||||||
|
implementation
|
||||||
|
|
||||||
|
**Decision**
|
||||||
|
|
||||||
|
There are a few, robust C++ implementations of Raft but as a part of other
|
||||||
|
projects or bigger libraries. **We select
|
||||||
|
[NuRaft](https://github.com/eBay/NuRaft)** because it focuses on delivering
|
||||||
|
Raft without bloatware, and it's used by
|
||||||
|
[Clickhouse](https://github.com/ClickHouse/ClickHouse) (an comparable peer to
|
||||||
|
Memgraph, a very well-established product).
|
||||||
38
ADRs/003_rocksdb.md
Normal file
38
ADRs/003_rocksdb.md
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
# RocksDB ADR
|
||||||
|
|
||||||
|
**Author**
|
||||||
|
Marko Budiselic (github.com/gitbuda)
|
||||||
|
|
||||||
|
**Status**
|
||||||
|
ACCEPTED
|
||||||
|
|
||||||
|
**Date**
|
||||||
|
January 23, 2024
|
||||||
|
|
||||||
|
**Problem**
|
||||||
|
|
||||||
|
Interacting with data (reads and writes) on disk in a concurrent, safe, and
|
||||||
|
fast way is a challenging task. Implementing all low-level primitives to
|
||||||
|
interact with various disk hardware efficiently consumes significant
|
||||||
|
engineering people. Whenever Memgraph has to store data on disk (or any
|
||||||
|
other colder than RAM storage system), the problem is how to do that in the
|
||||||
|
least amount of development time while satisfying all functional requirements
|
||||||
|
(often performance).
|
||||||
|
|
||||||
|
**Criteria**
|
||||||
|
|
||||||
|
- working efficiently in a highly concurrent environment
|
||||||
|
- easy integration with Memgraph's C++ codebase
|
||||||
|
- providing low-level key-value API
|
||||||
|
- heavily tested in production environments
|
||||||
|
- providing abstractions for the storage hardware (even for cloud-based
|
||||||
|
storages like S3)
|
||||||
|
|
||||||
|
**Decision**
|
||||||
|
|
||||||
|
There are a few robust key-value stores, but finding one that is
|
||||||
|
production-ready and compatible with Memgraph's C++ codebase is challenging.
|
||||||
|
**We select [RocksDB](https://github.com/facebook/rocksdb)** because it
|
||||||
|
delivers robust API to manage data on disk; it's battle-tested in many
|
||||||
|
production environments (many databases systems are embedding RocksDB), and
|
||||||
|
it's the most compatible one.
|
||||||
67
ADRs/README.md
Normal file
67
ADRs/README.md
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
# Architecture Decision Records
|
||||||
|
|
||||||
|
Also known as ADRs. This practice has become widespread in many
|
||||||
|
high performing engineering teams. It is a technique for communicating
|
||||||
|
between software engineers. ADRs provide a clear and documented
|
||||||
|
history of architectural choices, ensuring that everyone on the
|
||||||
|
team is on the same page. This improves communication and reduces
|
||||||
|
misunderstandings. The act of recording decisions encourages
|
||||||
|
thoughtful consideration before making choices. This can lead to
|
||||||
|
more robust and better-informed architectural decisions.
|
||||||
|
|
||||||
|
Links must be created, pointing both to and from the Github Issues
|
||||||
|
and/or the Notion Program Management "Initiative" database.
|
||||||
|
|
||||||
|
ADRs are complimentary to any tech specs that get written while
|
||||||
|
designing a solution. ADRs are very short and to the point, while
|
||||||
|
tech specs will include diagrams and can be quite verbose.
|
||||||
|
|
||||||
|
## HOWTO
|
||||||
|
|
||||||
|
Each ADR will be assigned a monotonically increasing unique numeric
|
||||||
|
identifier, which will be zero-padded to 3 digits. Each ADR will
|
||||||
|
be in a single markdown file containing no more than one page of
|
||||||
|
text, and the filename will start with that unique identifier,
|
||||||
|
followed by a camel case phrase summarizing the problem. For
|
||||||
|
example: `001_architecture_decision_records.md` or
|
||||||
|
`002_big_integration_cap_theorem.md`.
|
||||||
|
|
||||||
|
We want to use an ADR when:
|
||||||
|
1. Significant Impact: This includes choices that affect scalability, performance, or fundamental design principles.
|
||||||
|
1. Long-Term Ramifications: When a decision is expected to have long-term ramifications or is difficult to reverse.
|
||||||
|
1. Architectural Principles: ADRs are suitable for documenting decisions related to architectural principles, frameworks, or patterns that shape the system's structure.
|
||||||
|
1. Controversial Choices: When a decision is likely to be controversial or may require justification in the future.
|
||||||
|
|
||||||
|
The most senior engineer on a project will evaluate and decide
|
||||||
|
whether or not an ADR is needed.
|
||||||
|
|
||||||
|
## Do
|
||||||
|
|
||||||
|
1. Keep them brief and concise.
|
||||||
|
1. Explain the trade-offs.
|
||||||
|
1. Each ADR should be about one AD, not multiple ADs
|
||||||
|
1. Don't alter existing information in an ADR. Instead, amend the ADR by adding new information, or supersede the ADR by creating a new ADR.
|
||||||
|
1. Explain your organization's situation and business priorities.
|
||||||
|
1. Include rationale and considerations based on social and skills makeups of your teams.
|
||||||
|
1. Include pros and cons that are relevant, and describe them in terms that align with your needs and goals.
|
||||||
|
1. Explain what follows from making the decision. This can include the effects, outcomes, outputs, follow ups, and more.
|
||||||
|
|
||||||
|
## Don't
|
||||||
|
|
||||||
|
1. Try to guess what the executive leader wants, and then attempt to please them. Be objective.
|
||||||
|
1. Try to solve everything all at once. A pretty good solution now is MUCH BETTER than a perfect solution later. Carpe diem!
|
||||||
|
1. Hide any doubts or unanswered questions.
|
||||||
|
1. Make it a sales pitch. Everything has upsides and downsides - be authentic and honest about them.
|
||||||
|
1. Perform merely a superficial investigation. If an ADR doesn't call for some deep thinking, then it probably shouldn't exist.
|
||||||
|
1. Ignore the long-term costs such as performance, tech debt or hardware and maintenance.
|
||||||
|
1. Get tunnel vision where creative or surprising approaches are not explored.
|
||||||
|
|
||||||
|
# Template - use the format below for each new ADR
|
||||||
|
|
||||||
|
1. **Author** - who has written the ADR
|
||||||
|
1. **Status** - one of: PROPOSED, ACCEPTED, REJECTED, SUPERSEDED-BY or DEPRECATED
|
||||||
|
1. **Date** - when the status was most recently updated
|
||||||
|
1. **Problem** - a concise paragraph explaining the context
|
||||||
|
1. **Criteria** - a list of the two or three metrics by which the solution was evaluated, and their relative weights (importance)
|
||||||
|
1. **Decision** - what was chosen as the way forward, and what the consequences are of the decision
|
||||||
|
|
||||||
@@ -64,11 +64,11 @@ option(MG_ENTERPRISE "Build Memgraph Enterprise Edition" ON)
|
|||||||
# Set the current version here to override the automatic version detection. The
|
# Set the current version here to override the automatic version detection. The
|
||||||
# version must be specified as `X.Y.Z`. Primarily used when building new patch
|
# version must be specified as `X.Y.Z`. Primarily used when building new patch
|
||||||
# versions.
|
# versions.
|
||||||
set(MEMGRAPH_OVERRIDE_VERSION "")
|
set(MEMGRAPH_OVERRIDE_VERSION "2.15.0")
|
||||||
|
|
||||||
# Custom suffix that this version should have. The suffix can be any arbitrary
|
# Custom suffix that this version should have. The suffix can be any arbitrary
|
||||||
# string. Primarily used when building a version for a specific customer.
|
# string. Primarily used when building a version for a specific customer.
|
||||||
set(MEMGRAPH_OVERRIDE_VERSION_SUFFIX "")
|
set(MEMGRAPH_OVERRIDE_VERSION_SUFFIX "rc4")
|
||||||
|
|
||||||
# Variables used to generate the versions.
|
# Variables used to generate the versions.
|
||||||
if (MG_ENTERPRISE)
|
if (MG_ENTERPRISE)
|
||||||
@@ -211,8 +211,13 @@ set(CMAKE_CXX_FLAGS_RELWITHDEBINFO
|
|||||||
# ** Static linking is allowed only for executables! **
|
# ** Static linking is allowed only for executables! **
|
||||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++")
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++")
|
||||||
|
|
||||||
# Use lld linker to speedup build
|
# Use lld linker to speedup build and use less memory.
|
||||||
add_link_options(-fuse-ld=lld) # TODO: use mold linker
|
add_link_options(-fuse-ld=lld)
|
||||||
|
# NOTE: Moving to latest Clang (probably starting from 15), lld stopped to work
|
||||||
|
# without explicit link_directories call.
|
||||||
|
string(REPLACE ":" " " LD_LIBS $ENV{LD_LIBRARY_PATH})
|
||||||
|
separate_arguments(LD_LIBS)
|
||||||
|
link_directories(${LD_LIBS})
|
||||||
|
|
||||||
# release flags
|
# release flags
|
||||||
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
|
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
|
||||||
@@ -271,7 +276,6 @@ endif()
|
|||||||
set(libs_dir ${CMAKE_SOURCE_DIR}/libs)
|
set(libs_dir ${CMAKE_SOURCE_DIR}/libs)
|
||||||
add_subdirectory(libs EXCLUDE_FROM_ALL)
|
add_subdirectory(libs EXCLUDE_FROM_ALL)
|
||||||
|
|
||||||
# Optional subproject configuration -------------------------------------------
|
|
||||||
option(TEST_COVERAGE "Generate coverage reports from running memgraph" OFF)
|
option(TEST_COVERAGE "Generate coverage reports from running memgraph" OFF)
|
||||||
option(TOOLS "Build tools binaries" ON)
|
option(TOOLS "Build tools binaries" ON)
|
||||||
option(QUERY_MODULES "Build query modules containing custom procedures" ON)
|
option(QUERY_MODULES "Build query modules containing custom procedures" ON)
|
||||||
@@ -279,6 +283,8 @@ option(ASAN "Build with Address Sanitizer. To get a reasonable performance optio
|
|||||||
option(TSAN "Build with Thread Sanitizer. To get a reasonable performance option should be used only in Release or RelWithDebInfo build " OFF)
|
option(TSAN "Build with Thread Sanitizer. To get a reasonable performance option should be used only in Release or RelWithDebInfo build " OFF)
|
||||||
option(UBSAN "Build with Undefined Behaviour Sanitizer" OFF)
|
option(UBSAN "Build with Undefined Behaviour Sanitizer" OFF)
|
||||||
|
|
||||||
|
# Build feature flags
|
||||||
|
|
||||||
if (TEST_COVERAGE)
|
if (TEST_COVERAGE)
|
||||||
string(TOLOWER ${CMAKE_BUILD_TYPE} lower_build_type)
|
string(TOLOWER ${CMAKE_BUILD_TYPE} lower_build_type)
|
||||||
if (NOT lower_build_type STREQUAL "debug")
|
if (NOT lower_build_type STREQUAL "debug")
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -Eeuo pipefail
|
set -Eeuo pipefail
|
||||||
|
|
||||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||||
source "$DIR/../util.sh"
|
source "$DIR/../util.sh"
|
||||||
|
|
||||||
@@ -9,7 +7,7 @@ check_operating_system "amzn-2"
|
|||||||
check_architecture "x86_64"
|
check_architecture "x86_64"
|
||||||
|
|
||||||
TOOLCHAIN_BUILD_DEPS=(
|
TOOLCHAIN_BUILD_DEPS=(
|
||||||
gcc gcc-c++ make # generic build tools
|
git gcc gcc-c++ make # generic build tools
|
||||||
wget # used for archive download
|
wget # used for archive download
|
||||||
gnupg2 # used for archive signature verification
|
gnupg2 # used for archive signature verification
|
||||||
tar gzip bzip2 xz unzip # used for archive unpacking
|
tar gzip bzip2 xz unzip # used for archive unpacking
|
||||||
@@ -63,6 +61,8 @@ MEMGRAPH_BUILD_DEPS=(
|
|||||||
cyrus-sasl-devel
|
cyrus-sasl-devel
|
||||||
)
|
)
|
||||||
|
|
||||||
|
MEMGRAPH_TEST_DEPS="${MEMGRAPH_BUILD_DEPS[*]}"
|
||||||
|
|
||||||
MEMGRAPH_RUN_DEPS=(
|
MEMGRAPH_RUN_DEPS=(
|
||||||
logrotate openssl python3 libseccomp
|
logrotate openssl python3 libseccomp
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -Eeuo pipefail
|
set -Eeuo pipefail
|
||||||
|
|
||||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||||
source "$DIR/../util.sh"
|
source "$DIR/../util.sh"
|
||||||
|
|
||||||
@@ -63,6 +61,8 @@ MEMGRAPH_BUILD_DEPS=(
|
|||||||
cyrus-sasl-devel
|
cyrus-sasl-devel
|
||||||
)
|
)
|
||||||
|
|
||||||
|
MEMGRAPH_TEST_DEPS="${MEMGRAPH_BUILD_DEPS[*]}"
|
||||||
|
|
||||||
MEMGRAPH_RUN_DEPS=(
|
MEMGRAPH_RUN_DEPS=(
|
||||||
logrotate openssl python3 libseccomp
|
logrotate openssl python3 libseccomp
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -Eeuo pipefail
|
set -Eeuo pipefail
|
||||||
|
|
||||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||||
source "$DIR/../util.sh"
|
source "$DIR/../util.sh"
|
||||||
|
|
||||||
@@ -9,8 +7,10 @@ check_operating_system "centos-9"
|
|||||||
check_architecture "x86_64"
|
check_architecture "x86_64"
|
||||||
|
|
||||||
TOOLCHAIN_BUILD_DEPS=(
|
TOOLCHAIN_BUILD_DEPS=(
|
||||||
coreutils-common gcc gcc-c++ make # generic build tools
|
|
||||||
wget # used for archive download
|
wget # used for archive download
|
||||||
|
coreutils-common gcc gcc-c++ make # generic build tools
|
||||||
|
# NOTE: Pure libcurl conflicts with libcurl-minimal
|
||||||
|
libcurl-devel # cmake build requires it
|
||||||
gnupg2 # used for archive signature verification
|
gnupg2 # used for archive signature verification
|
||||||
tar gzip bzip2 xz unzip # used for archive unpacking
|
tar gzip bzip2 xz unzip # used for archive unpacking
|
||||||
zlib-devel # zlib library used for all builds
|
zlib-devel # zlib library used for all builds
|
||||||
@@ -64,6 +64,8 @@ MEMGRAPH_BUILD_DEPS=(
|
|||||||
cyrus-sasl-devel
|
cyrus-sasl-devel
|
||||||
)
|
)
|
||||||
|
|
||||||
|
MEMGRAPH_TEST_DEPS="${MEMGRAPH_BUILD_DEPS[*]}"
|
||||||
|
|
||||||
MEMGRAPH_RUN_DEPS=(
|
MEMGRAPH_RUN_DEPS=(
|
||||||
logrotate openssl python3 libseccomp
|
logrotate openssl python3 libseccomp
|
||||||
)
|
)
|
||||||
@@ -123,7 +125,9 @@ install() {
|
|||||||
else
|
else
|
||||||
echo "NOTE: export LANG=en_US.utf8"
|
echo "NOTE: export LANG=en_US.utf8"
|
||||||
fi
|
fi
|
||||||
yum update -y
|
# --nobest is used because of libipt because we install custom versions
|
||||||
|
# because libipt-devel is not available on CentOS 9 Stream
|
||||||
|
yum update -y --nobest
|
||||||
yum install -y wget git python3 python3-pip
|
yum install -y wget git python3 python3-pip
|
||||||
|
|
||||||
for pkg in $1; do
|
for pkg in $1; do
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -Eeuo pipefail
|
set -Eeuo pipefail
|
||||||
|
|
||||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||||
source "$DIR/../util.sh"
|
source "$DIR/../util.sh"
|
||||||
|
|
||||||
|
# IMPORTANT: Deprecated since memgraph v2.12.0.
|
||||||
|
|
||||||
check_operating_system "debian-10"
|
check_operating_system "debian-10"
|
||||||
check_architecture "x86_64"
|
check_architecture "x86_64"
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -Eeuo pipefail
|
set -Eeuo pipefail
|
||||||
|
|
||||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||||
source "$DIR/../util.sh"
|
source "$DIR/../util.sh"
|
||||||
|
|
||||||
|
# IMPORTANT: Deprecated since memgraph v2.12.0.
|
||||||
|
|
||||||
check_operating_system "debian-11"
|
check_operating_system "debian-11"
|
||||||
check_architecture "arm64" "aarch64"
|
check_architecture "arm64" "aarch64"
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -Eeuo pipefail
|
set -Eeuo pipefail
|
||||||
|
|
||||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||||
source "$DIR/../util.sh"
|
source "$DIR/../util.sh"
|
||||||
|
|
||||||
@@ -61,6 +59,8 @@ MEMGRAPH_BUILD_DEPS=(
|
|||||||
libsasl2-dev
|
libsasl2-dev
|
||||||
)
|
)
|
||||||
|
|
||||||
|
MEMGRAPH_TEST_DEPS="${MEMGRAPH_BUILD_DEPS[*]}"
|
||||||
|
|
||||||
MEMGRAPH_RUN_DEPS=(
|
MEMGRAPH_RUN_DEPS=(
|
||||||
logrotate openssl python3 libseccomp
|
logrotate openssl python3 libseccomp
|
||||||
)
|
)
|
||||||
|
|||||||
134
environment/os/debian-12-arm.sh
Executable file
134
environment/os/debian-12-arm.sh
Executable file
@@ -0,0 +1,134 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -Eeuo pipefail
|
||||||
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||||
|
source "$DIR/../util.sh"
|
||||||
|
|
||||||
|
check_operating_system "debian-12"
|
||||||
|
check_architecture "arm64" "aarch64"
|
||||||
|
|
||||||
|
TOOLCHAIN_BUILD_DEPS=(
|
||||||
|
coreutils gcc g++ build-essential make # generic build tools
|
||||||
|
wget # used for archive download
|
||||||
|
gnupg # used for archive signature verification
|
||||||
|
tar gzip bzip2 xz-utils unzip # used for archive unpacking
|
||||||
|
zlib1g-dev # zlib library used for all builds
|
||||||
|
libexpat1-dev liblzma-dev python3-dev texinfo # for gdb
|
||||||
|
libcurl4-openssl-dev # for cmake
|
||||||
|
libreadline-dev # for cmake and llvm
|
||||||
|
libffi-dev libxml2-dev # for llvm
|
||||||
|
libedit-dev libpcre2-dev libpcre3-dev automake bison # for swig
|
||||||
|
curl # snappy
|
||||||
|
file # for libunwind
|
||||||
|
libssl-dev # for libevent
|
||||||
|
libgmp-dev
|
||||||
|
gperf # for proxygen
|
||||||
|
git # for fbthrift
|
||||||
|
)
|
||||||
|
|
||||||
|
TOOLCHAIN_RUN_DEPS=(
|
||||||
|
make # generic build tools
|
||||||
|
tar gzip bzip2 xz-utils # used for archive unpacking
|
||||||
|
zlib1g # zlib library used for all builds
|
||||||
|
libexpat1 liblzma5 python3 # for gdb
|
||||||
|
libcurl4 # for cmake
|
||||||
|
file # for CPack
|
||||||
|
libreadline8 # for cmake and llvm
|
||||||
|
libffi8 libxml2 # for llvm
|
||||||
|
libssl-dev # for libevent
|
||||||
|
)
|
||||||
|
|
||||||
|
MEMGRAPH_BUILD_DEPS=(
|
||||||
|
git # source code control
|
||||||
|
make pkg-config # build system
|
||||||
|
curl wget # for downloading libs
|
||||||
|
uuid-dev default-jre-headless # required by antlr
|
||||||
|
libreadline-dev # for memgraph console
|
||||||
|
libpython3-dev python3-dev # for query modules
|
||||||
|
libssl-dev
|
||||||
|
libseccomp-dev
|
||||||
|
netcat # tests are using nc to wait for memgraph
|
||||||
|
python3 virtualenv python3-virtualenv python3-pip # for qa, macro_benchmark and stress tests
|
||||||
|
python3-yaml # for the configuration generator
|
||||||
|
libcurl4-openssl-dev # mg-requests
|
||||||
|
sbcl # for custom Lisp C++ preprocessing
|
||||||
|
doxygen graphviz # source documentation generators
|
||||||
|
mono-runtime mono-mcs zip unzip default-jdk-headless custom-maven3.9.3 # for driver tests
|
||||||
|
dotnet-sdk-7.0 golang custom-golang1.18.9 nodejs npm
|
||||||
|
autoconf # for jemalloc code generation
|
||||||
|
libtool # for protobuf code generation
|
||||||
|
libsasl2-dev
|
||||||
|
)
|
||||||
|
|
||||||
|
MEMGRAPH_RUN_DEPS=(
|
||||||
|
logrotate openssl python3 libseccomp
|
||||||
|
)
|
||||||
|
|
||||||
|
NEW_DEPS=(
|
||||||
|
wget curl tar gzip
|
||||||
|
)
|
||||||
|
|
||||||
|
list() {
|
||||||
|
echo "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
check() {
|
||||||
|
local missing=""
|
||||||
|
for pkg in $1; do
|
||||||
|
if [ "$pkg" == custom-maven3.9.3 ]; then
|
||||||
|
if [ ! -f "/opt/apache-maven-3.9.3/bin/mvn" ]; then
|
||||||
|
missing="$pkg $missing"
|
||||||
|
fi
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if [ "$pkg" == custom-golang1.18.9 ]; then
|
||||||
|
if [ ! -f "/opt/go1.18.9/go/bin/go" ]; then
|
||||||
|
missing="$pkg $missing"
|
||||||
|
fi
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if ! dpkg -s "$pkg" >/dev/null 2>/dev/null; then
|
||||||
|
missing="$pkg $missing"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [ "$missing" != "" ]; then
|
||||||
|
echo "MISSING PACKAGES: $missing"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
install() {
|
||||||
|
cd "$DIR"
|
||||||
|
apt update
|
||||||
|
# If GitHub Actions runner is installed, append LANG to the environment.
|
||||||
|
# Python related tests doesn't work the LANG export.
|
||||||
|
if [ -d "/home/gh/actions-runner" ]; then
|
||||||
|
echo "LANG=en_US.utf8" >> /home/gh/actions-runner/.env
|
||||||
|
else
|
||||||
|
echo "NOTE: export LANG=en_US.utf8"
|
||||||
|
fi
|
||||||
|
apt install -y wget
|
||||||
|
|
||||||
|
for pkg in $1; do
|
||||||
|
if [ "$pkg" == custom-maven3.9.3 ]; then
|
||||||
|
install_custom_maven "3.9.3"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if [ "$pkg" == custom-golang1.18.9 ]; then
|
||||||
|
install_custom_golang "1.18.9"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if [ "$pkg" == dotnet-sdk-7.0 ]; then
|
||||||
|
if ! dpkg -s "$pkg" 2>/dev/null >/dev/null; then
|
||||||
|
wget -nv https://packages.microsoft.com/config/debian/12/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
|
||||||
|
dpkg -i packages-microsoft-prod.deb
|
||||||
|
apt-get update
|
||||||
|
apt-get install -y apt-transport-https dotnet-sdk-7.0
|
||||||
|
fi
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
apt install -y "$pkg"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
deps=$2"[*]"
|
||||||
|
"$1" "${!deps}"
|
||||||
136
environment/os/debian-12.sh
Executable file
136
environment/os/debian-12.sh
Executable file
@@ -0,0 +1,136 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -Eeuo pipefail
|
||||||
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||||
|
source "$DIR/../util.sh"
|
||||||
|
|
||||||
|
check_operating_system "debian-12"
|
||||||
|
check_architecture "x86_64"
|
||||||
|
|
||||||
|
TOOLCHAIN_BUILD_DEPS=(
|
||||||
|
coreutils gcc g++ build-essential make # generic build tools
|
||||||
|
wget # used for archive download
|
||||||
|
gnupg # used for archive signature verification
|
||||||
|
tar gzip bzip2 xz-utils unzip # used for archive unpacking
|
||||||
|
zlib1g-dev # zlib library used for all builds
|
||||||
|
libexpat1-dev libipt-dev libbabeltrace-dev liblzma-dev python3-dev texinfo # for gdb
|
||||||
|
libcurl4-openssl-dev # for cmake
|
||||||
|
libreadline-dev # for cmake and llvm
|
||||||
|
libffi-dev libxml2-dev # for llvm
|
||||||
|
libedit-dev libpcre2-dev libpcre3-dev automake bison # for swig
|
||||||
|
curl # snappy
|
||||||
|
file # for libunwind
|
||||||
|
libssl-dev # for libevent
|
||||||
|
libgmp-dev
|
||||||
|
gperf # for proxygen
|
||||||
|
git # for fbthrift
|
||||||
|
)
|
||||||
|
|
||||||
|
TOOLCHAIN_RUN_DEPS=(
|
||||||
|
make # generic build tools
|
||||||
|
tar gzip bzip2 xz-utils # used for archive unpacking
|
||||||
|
zlib1g # zlib library used for all builds
|
||||||
|
libexpat1 libipt2 libbabeltrace1 liblzma5 python3 # for gdb
|
||||||
|
libcurl4 # for cmake
|
||||||
|
file # for CPack
|
||||||
|
libreadline8 # for cmake and llvm
|
||||||
|
libffi8 libxml2 # for llvm
|
||||||
|
libssl-dev # for libevent
|
||||||
|
)
|
||||||
|
|
||||||
|
MEMGRAPH_BUILD_DEPS=(
|
||||||
|
git # source code control
|
||||||
|
make cmake pkg-config # build system
|
||||||
|
curl wget # for downloading libs
|
||||||
|
uuid-dev default-jre-headless # required by antlr
|
||||||
|
libreadline-dev # for memgraph console
|
||||||
|
libpython3-dev python3-dev # for query modules
|
||||||
|
libssl-dev
|
||||||
|
libseccomp-dev
|
||||||
|
netcat-traditional # tests are using nc to wait for memgraph
|
||||||
|
python3 virtualenv python3-virtualenv python3-pip # for qa, macro_benchmark and stress tests
|
||||||
|
python3-yaml # for the configuration generator
|
||||||
|
libcurl4-openssl-dev # mg-requests
|
||||||
|
sbcl # for custom Lisp C++ preprocessing
|
||||||
|
doxygen graphviz # source documentation generators
|
||||||
|
mono-runtime mono-mcs zip unzip default-jdk-headless custom-maven3.9.3 # for driver tests
|
||||||
|
dotnet-sdk-7.0 golang custom-golang1.18.9 nodejs npm
|
||||||
|
autoconf # for jemalloc code generation
|
||||||
|
libtool # for protobuf code generation
|
||||||
|
libsasl2-dev
|
||||||
|
)
|
||||||
|
|
||||||
|
MEMGRAPH_TEST_DEPS="${MEMGRAPH_BUILD_DEPS[*]}"
|
||||||
|
|
||||||
|
MEMGRAPH_RUN_DEPS=(
|
||||||
|
logrotate openssl python3 libseccomp
|
||||||
|
)
|
||||||
|
|
||||||
|
NEW_DEPS=(
|
||||||
|
wget curl tar gzip
|
||||||
|
)
|
||||||
|
|
||||||
|
list() {
|
||||||
|
echo "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
check() {
|
||||||
|
local missing=""
|
||||||
|
for pkg in $1; do
|
||||||
|
if [ "$pkg" == custom-maven3.9.3 ]; then
|
||||||
|
if [ ! -f "/opt/apache-maven-3.9.3/bin/mvn" ]; then
|
||||||
|
missing="$pkg $missing"
|
||||||
|
fi
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if [ "$pkg" == custom-golang1.18.9 ]; then
|
||||||
|
if [ ! -f "/opt/go1.18.9/go/bin/go" ]; then
|
||||||
|
missing="$pkg $missing"
|
||||||
|
fi
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if ! dpkg -s "$pkg" >/dev/null 2>/dev/null; then
|
||||||
|
missing="$pkg $missing"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [ "$missing" != "" ]; then
|
||||||
|
echo "MISSING PACKAGES: $missing"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
install() {
|
||||||
|
cd "$DIR"
|
||||||
|
apt update
|
||||||
|
# If GitHub Actions runner is installed, append LANG to the environment.
|
||||||
|
# Python related tests doesn't work the LANG export.
|
||||||
|
if [ -d "/home/gh/actions-runner" ]; then
|
||||||
|
echo "LANG=en_US.utf8" >> /home/gh/actions-runner/.env
|
||||||
|
else
|
||||||
|
echo "NOTE: export LANG=en_US.utf8"
|
||||||
|
fi
|
||||||
|
apt install -y wget
|
||||||
|
|
||||||
|
for pkg in $1; do
|
||||||
|
if [ "$pkg" == custom-maven3.9.3 ]; then
|
||||||
|
install_custom_maven "3.9.3"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if [ "$pkg" == custom-golang1.18.9 ]; then
|
||||||
|
install_custom_golang "1.18.9"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if [ "$pkg" == dotnet-sdk-7.0 ]; then
|
||||||
|
if ! dpkg -s "$pkg" 2>/dev/null >/dev/null; then
|
||||||
|
wget -nv https://packages.microsoft.com/config/debian/12/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
|
||||||
|
dpkg -i packages-microsoft-prod.deb
|
||||||
|
apt-get update
|
||||||
|
apt-get install -y apt-transport-https dotnet-sdk-7.0
|
||||||
|
fi
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
apt install -y "$pkg"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
deps=$2"[*]"
|
||||||
|
"$1" "${!deps}"
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -Eeuo pipefail
|
set -Eeuo pipefail
|
||||||
|
|
||||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||||
source "$DIR/../util.sh"
|
source "$DIR/../util.sh"
|
||||||
|
|
||||||
|
# IMPORTANT: Deprecated since memgraph v2.12.0.
|
||||||
|
|
||||||
check_operating_system "fedora-36"
|
check_operating_system "fedora-36"
|
||||||
check_architecture "x86_64"
|
check_architecture "x86_64"
|
||||||
|
|
||||||
@@ -27,6 +27,7 @@ TOOLCHAIN_BUILD_DEPS=(
|
|||||||
libipt libipt-devel # intel
|
libipt libipt-devel # intel
|
||||||
patch
|
patch
|
||||||
perl # for openssl
|
perl # for openssl
|
||||||
|
git
|
||||||
)
|
)
|
||||||
|
|
||||||
TOOLCHAIN_RUN_DEPS=(
|
TOOLCHAIN_RUN_DEPS=(
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -Eeuo pipefail
|
set -Eeuo pipefail
|
||||||
|
|
||||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||||
source "$DIR/../util.sh"
|
source "$DIR/../util.sh"
|
||||||
|
|
||||||
@@ -27,6 +25,7 @@ TOOLCHAIN_BUILD_DEPS=(
|
|||||||
libipt libipt-devel # intel
|
libipt libipt-devel # intel
|
||||||
patch
|
patch
|
||||||
perl # for openssl
|
perl # for openssl
|
||||||
|
git
|
||||||
)
|
)
|
||||||
|
|
||||||
TOOLCHAIN_RUN_DEPS=(
|
TOOLCHAIN_RUN_DEPS=(
|
||||||
@@ -58,6 +57,16 @@ MEMGRAPH_BUILD_DEPS=(
|
|||||||
libtool # for protobuf code generation
|
libtool # for protobuf code generation
|
||||||
)
|
)
|
||||||
|
|
||||||
|
MEMGRAPH_TEST_DEPS="${MEMGRAPH_BUILD_DEPS[*]}"
|
||||||
|
|
||||||
|
MEMGRAPH_RUN_DEPS=(
|
||||||
|
logrotate openssl python3 libseccomp
|
||||||
|
)
|
||||||
|
|
||||||
|
NEW_DEPS=(
|
||||||
|
wget curl tar gzip
|
||||||
|
)
|
||||||
|
|
||||||
list() {
|
list() {
|
||||||
echo "$1"
|
echo "$1"
|
||||||
}
|
}
|
||||||
|
|||||||
117
environment/os/fedora-39.sh
Executable file
117
environment/os/fedora-39.sh
Executable file
@@ -0,0 +1,117 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -Eeuo pipefail
|
||||||
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||||
|
source "$DIR/../util.sh"
|
||||||
|
|
||||||
|
check_operating_system "fedora-39"
|
||||||
|
check_architecture "x86_64"
|
||||||
|
|
||||||
|
TOOLCHAIN_BUILD_DEPS=(
|
||||||
|
coreutils-common gcc gcc-c++ make # generic build tools
|
||||||
|
wget # used for archive download
|
||||||
|
gnupg2 # used for archive signature verification
|
||||||
|
tar gzip bzip2 xz unzip # used for archive unpacking
|
||||||
|
zlib-devel # zlib library used for all builds
|
||||||
|
expat-devel xz-devel python3-devel texinfo libbabeltrace-devel # for gdb
|
||||||
|
curl libcurl-devel # for cmake
|
||||||
|
readline-devel # for cmake and llvm
|
||||||
|
libffi-devel libxml2-devel # for llvm
|
||||||
|
libedit-devel pcre-devel pcre2-devel automake bison # for swig
|
||||||
|
file
|
||||||
|
openssl-devel
|
||||||
|
gmp-devel
|
||||||
|
gperf
|
||||||
|
diffutils
|
||||||
|
libipt libipt-devel # intel
|
||||||
|
patch
|
||||||
|
perl # for openssl
|
||||||
|
git
|
||||||
|
)
|
||||||
|
|
||||||
|
TOOLCHAIN_RUN_DEPS=(
|
||||||
|
make # generic build tools
|
||||||
|
tar gzip bzip2 xz # used for archive unpacking
|
||||||
|
zlib # zlib library used for all builds
|
||||||
|
expat xz-libs python3 # for gdb
|
||||||
|
readline # for cmake and llvm
|
||||||
|
libffi libxml2 # for llvm
|
||||||
|
openssl-devel
|
||||||
|
)
|
||||||
|
|
||||||
|
MEMGRAPH_BUILD_DEPS=(
|
||||||
|
git # source code control
|
||||||
|
make pkgconf-pkg-config # build system
|
||||||
|
wget # for downloading libs
|
||||||
|
libuuid-devel java-11-openjdk # required by antlr
|
||||||
|
readline-devel # for memgraph console
|
||||||
|
python3-devel # for query modules
|
||||||
|
openssl-devel
|
||||||
|
libseccomp-devel
|
||||||
|
python3 python3-pip python3-virtualenv python3-virtualenvwrapper python3-pyyaml nmap-ncat # for tests
|
||||||
|
libcurl-devel # mg-requests
|
||||||
|
rpm-build rpmlint # for RPM package building
|
||||||
|
doxygen graphviz # source documentation generators
|
||||||
|
which nodejs golang zip unzip java-11-openjdk-devel # for driver tests
|
||||||
|
sbcl # for custom Lisp C++ preprocessing
|
||||||
|
autoconf # for jemalloc code generation
|
||||||
|
libtool # for protobuf code generation
|
||||||
|
)
|
||||||
|
|
||||||
|
MEMGRAPH_TEST_DEPS="${MEMGRAPH_BUILD_DEPS[*]}"
|
||||||
|
|
||||||
|
MEMGRAPH_RUN_DEPS=(
|
||||||
|
logrotate openssl python3 libseccomp
|
||||||
|
)
|
||||||
|
|
||||||
|
NEW_DEPS=(
|
||||||
|
wget curl tar gzip
|
||||||
|
)
|
||||||
|
|
||||||
|
list() {
|
||||||
|
echo "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
check() {
|
||||||
|
if [ -v LD_LIBRARY_PATH ]; then
|
||||||
|
# On Fedora 38 yum/dnf and python11 use newer glibc which is not compatible
|
||||||
|
# with ours, so we need to momentarely disable env
|
||||||
|
local OLD_LD_LIBRARY_PATH=${LD_LIBRARY_PATH}
|
||||||
|
LD_LIBRARY_PATH=""
|
||||||
|
fi
|
||||||
|
local missing=""
|
||||||
|
for pkg in $1; do
|
||||||
|
if ! dnf list installed "$pkg" >/dev/null 2>/dev/null; then
|
||||||
|
missing="$pkg $missing"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [ "$missing" != "" ]; then
|
||||||
|
echo "MISSING PACKAGES: $missing"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [ -v OLD_LD_LIBRARY_PATH ]; then
|
||||||
|
echo "Restoring LD_LIBRARY_PATH..."
|
||||||
|
LD_LIBRARY_PATH=${OLD_LD_LIBRARY_PATH}
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
install() {
|
||||||
|
cd "$DIR"
|
||||||
|
if [ "$EUID" -ne 0 ]; then
|
||||||
|
echo "Please run as root."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
# If GitHub Actions runner is installed, append LANG to the environment.
|
||||||
|
# Python related tests don't work without the LANG export.
|
||||||
|
if [ -d "/home/gh/actions-runner" ]; then
|
||||||
|
echo "LANG=en_US.utf8" >> /home/gh/actions-runner/.env
|
||||||
|
else
|
||||||
|
echo "NOTE: export LANG=en_US.utf8"
|
||||||
|
fi
|
||||||
|
dnf update -y
|
||||||
|
for pkg in $1; do
|
||||||
|
dnf install -y "$pkg"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
deps=$2"[*]"
|
||||||
|
"$1" "${!deps}"
|
||||||
188
environment/os/rocky-9.3.sh
Executable file
188
environment/os/rocky-9.3.sh
Executable file
@@ -0,0 +1,188 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -Eeuo pipefail
|
||||||
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||||
|
source "$DIR/../util.sh"
|
||||||
|
|
||||||
|
# TODO(gitbuda): Rocky gets automatically updates -> figure out how to handle it.
|
||||||
|
check_operating_system "rocky-9.3"
|
||||||
|
check_architecture "x86_64"
|
||||||
|
|
||||||
|
TOOLCHAIN_BUILD_DEPS=(
|
||||||
|
wget # used for archive download
|
||||||
|
coreutils-common gcc gcc-c++ make # generic build tools
|
||||||
|
# NOTE: Pure libcurl conflicts with libcurl-minimal
|
||||||
|
libcurl-devel # cmake build requires it
|
||||||
|
gnupg2 # used for archive signature verification
|
||||||
|
tar gzip bzip2 xz unzip # used for archive unpacking
|
||||||
|
zlib-devel # zlib library used for all builds
|
||||||
|
expat-devel xz-devel python3-devel perl-Unicode-EastAsianWidth texinfo libbabeltrace-devel # for gdb
|
||||||
|
readline-devel # for cmake and llvm
|
||||||
|
libffi-devel libxml2-devel # for llvm
|
||||||
|
libedit-devel pcre-devel pcre2-devel automake bison # for swig
|
||||||
|
file
|
||||||
|
openssl-devel
|
||||||
|
gmp-devel
|
||||||
|
gperf
|
||||||
|
diffutils
|
||||||
|
libipt libipt-devel # intel
|
||||||
|
patch
|
||||||
|
)
|
||||||
|
|
||||||
|
TOOLCHAIN_RUN_DEPS=(
|
||||||
|
make # generic build tools
|
||||||
|
tar gzip bzip2 xz # used for archive unpacking
|
||||||
|
zlib # zlib library used for all builds
|
||||||
|
expat xz-libs python3 # for gdb
|
||||||
|
readline # for cmake and llvm
|
||||||
|
libffi libxml2 # for llvm
|
||||||
|
openssl-devel
|
||||||
|
perl # for openssl
|
||||||
|
)
|
||||||
|
|
||||||
|
MEMGRAPH_BUILD_DEPS=(
|
||||||
|
git # source code control
|
||||||
|
make cmake pkgconf-pkg-config # build system
|
||||||
|
wget # for downloading libs
|
||||||
|
libuuid-devel java-11-openjdk # required by antlr
|
||||||
|
readline-devel # for memgraph console
|
||||||
|
python3-devel # for query modules
|
||||||
|
openssl-devel
|
||||||
|
libseccomp-devel
|
||||||
|
python3 python3-pip python3-virtualenv nmap-ncat # for qa, macro_benchmark and stress tests
|
||||||
|
#
|
||||||
|
# IMPORTANT: python3-yaml does NOT exist on CentOS
|
||||||
|
# Install it manually using `pip3 install PyYAML`
|
||||||
|
#
|
||||||
|
PyYAML # Package name here does not correspond to the yum package!
|
||||||
|
libcurl-devel # mg-requests
|
||||||
|
rpm-build rpmlint # for RPM package building
|
||||||
|
doxygen graphviz # source documentation generators
|
||||||
|
which nodejs golang custom-golang1.18.9 # for driver tests
|
||||||
|
zip unzip java-11-openjdk-devel java-17-openjdk java-17-openjdk-devel custom-maven3.9.3 # for driver tests
|
||||||
|
sbcl # for custom Lisp C++ preprocessing
|
||||||
|
autoconf # for jemalloc code generation
|
||||||
|
libtool # for protobuf code generation
|
||||||
|
cyrus-sasl-devel
|
||||||
|
)
|
||||||
|
|
||||||
|
MEMGRAPH_TEST_DEPS="${MEMGRAPH_BUILD_DEPS[*]}"
|
||||||
|
|
||||||
|
MEMGRAPH_RUN_DEPS=(
|
||||||
|
logrotate openssl python3 libseccomp
|
||||||
|
)
|
||||||
|
|
||||||
|
NEW_DEPS=(
|
||||||
|
wget curl tar gzip
|
||||||
|
)
|
||||||
|
|
||||||
|
list() {
|
||||||
|
echo "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
check() {
|
||||||
|
local missing=""
|
||||||
|
for pkg in $1; do
|
||||||
|
if [ "$pkg" == custom-maven3.9.3 ]; then
|
||||||
|
if [ ! -f "/opt/apache-maven-3.9.3/bin/mvn" ]; then
|
||||||
|
missing="$pkg $missing"
|
||||||
|
fi
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if [ "$pkg" == custom-golang1.18.9 ]; then
|
||||||
|
if [ ! -f "/opt/go1.18.9/go/bin/go" ]; then
|
||||||
|
missing="$pkg $missing"
|
||||||
|
fi
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if [ "$pkg" == "PyYAML" ]; then
|
||||||
|
if ! python3 -c "import yaml" >/dev/null 2>/dev/null; then
|
||||||
|
missing="$pkg $missing"
|
||||||
|
fi
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if [ "$pkg" == "python3-virtualenv" ]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if ! yum list installed "$pkg" >/dev/null 2>/dev/null; then
|
||||||
|
missing="$pkg $missing"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [ "$missing" != "" ]; then
|
||||||
|
echo "MISSING PACKAGES: $missing"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
install() {
|
||||||
|
cd "$DIR"
|
||||||
|
if [ "$EUID" -ne 0 ]; then
|
||||||
|
echo "Please run as root."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
# If GitHub Actions runner is installed, append LANG to the environment.
|
||||||
|
# Python related tests doesn't work the LANG export.
|
||||||
|
if [ -d "/home/gh/actions-runner" ]; then
|
||||||
|
echo "LANG=en_US.utf8" >> /home/gh/actions-runner/.env
|
||||||
|
else
|
||||||
|
echo "NOTE: export LANG=en_US.utf8"
|
||||||
|
fi
|
||||||
|
yum update -y
|
||||||
|
yum install -y wget git python3 python3-pip
|
||||||
|
|
||||||
|
for pkg in $1; do
|
||||||
|
if [ "$pkg" == custom-maven3.9.3 ]; then
|
||||||
|
install_custom_maven "3.9.3"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if [ "$pkg" == custom-golang1.18.9 ]; then
|
||||||
|
install_custom_golang "1.18.9"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if [ "$pkg" == perl-Unicode-EastAsianWidth ]; then
|
||||||
|
if ! dnf list installed perl-Unicode-EastAsianWidth >/dev/null 2>/dev/null; then
|
||||||
|
dnf install -y https://dl.rockylinux.org/pub/rocky/9/CRB/x86_64/os/Packages/p/perl-Unicode-EastAsianWidth-12.0-7.el9.noarch.rpm
|
||||||
|
fi
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if [ "$pkg" == texinfo ]; then
|
||||||
|
if ! dnf list installed texinfo >/dev/null 2>/dev/null; then
|
||||||
|
dnf install -y https://dl.rockylinux.org/pub/rocky/9/CRB/x86_64/os/Packages/t/texinfo-6.7-15.el9.x86_64.rpm
|
||||||
|
fi
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if [ "$pkg" == libbabeltrace-devel ]; then
|
||||||
|
if ! dnf list installed libbabeltrace-devel >/dev/null 2>/dev/null; then
|
||||||
|
dnf install -y https://dl.rockylinux.org/pub/rocky/9/devel/x86_64/os/Packages/l/libbabeltrace-devel-1.5.8-10.el9.x86_64.rpm
|
||||||
|
fi
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if [ "$pkg" == libipt-devel ]; then
|
||||||
|
if ! dnf list installed libipt-devel >/dev/null 2>/dev/null; then
|
||||||
|
dnf install -y https://dl.rockylinux.org/pub/rocky/9/devel/x86_64/os/Packages/l/libipt-devel-2.0.4-5.el9.x86_64.rpm
|
||||||
|
fi
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if [ "$pkg" == PyYAML ]; then
|
||||||
|
if [ -z ${SUDO_USER+x} ]; then # Running as root (e.g. Docker).
|
||||||
|
pip3 install --user PyYAML
|
||||||
|
else # Running using sudo.
|
||||||
|
sudo -H -u "$SUDO_USER" bash -c "pip3 install --user PyYAML"
|
||||||
|
fi
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if [ "$pkg" == python3-virtualenv ]; then
|
||||||
|
if [ -z ${SUDO_USER+x} ]; then # Running as root (e.g. Docker).
|
||||||
|
pip3 install virtualenv
|
||||||
|
pip3 install virtualenvwrapper
|
||||||
|
else # Running using sudo.
|
||||||
|
sudo -H -u "$SUDO_USER" bash -c "pip3 install virtualenv"
|
||||||
|
sudo -H -u "$SUDO_USER" bash -c "pip3 install virtualenvwrapper"
|
||||||
|
fi
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
yum install -y "$pkg"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
deps=$2"[*]"
|
||||||
|
"$1" "${!deps}"
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -Eeuo pipefail
|
set -Eeuo pipefail
|
||||||
|
|
||||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||||
source "$DIR/../util.sh"
|
source "$DIR/../util.sh"
|
||||||
|
|
||||||
@@ -20,6 +18,10 @@ MEMGRAPH_BUILD_DEPS=(
|
|||||||
pkg
|
pkg
|
||||||
)
|
)
|
||||||
|
|
||||||
|
MEMGRAPH_TEST_DEPS=(
|
||||||
|
pkg
|
||||||
|
)
|
||||||
|
|
||||||
MEMGRAPH_RUN_DEPS=(
|
MEMGRAPH_RUN_DEPS=(
|
||||||
pkg
|
pkg
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -Eeuo pipefail
|
set -Eeuo pipefail
|
||||||
|
|
||||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||||
source "$DIR/../util.sh"
|
source "$DIR/../util.sh"
|
||||||
|
|
||||||
|
# IMPORTANT: Deprecated since memgraph v2.12.0.
|
||||||
|
|
||||||
check_operating_system "ubuntu-18.04"
|
check_operating_system "ubuntu-18.04"
|
||||||
check_architecture "x86_64"
|
check_architecture "x86_64"
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -Eeuo pipefail
|
set -Eeuo pipefail
|
||||||
|
|
||||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||||
source "$DIR/../util.sh"
|
source "$DIR/../util.sh"
|
||||||
|
|
||||||
@@ -60,6 +58,8 @@ MEMGRAPH_BUILD_DEPS=(
|
|||||||
libsasl2-dev
|
libsasl2-dev
|
||||||
)
|
)
|
||||||
|
|
||||||
|
MEMGRAPH_TEST_DEPS="${MEMGRAPH_BUILD_DEPS[*]}"
|
||||||
|
|
||||||
MEMGRAPH_RUN_DEPS=(
|
MEMGRAPH_RUN_DEPS=(
|
||||||
logrotate openssl python3 libseccomp2
|
logrotate openssl python3 libseccomp2
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -Eeuo pipefail
|
set -Eeuo pipefail
|
||||||
|
|
||||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||||
source "$DIR/../util.sh"
|
source "$DIR/../util.sh"
|
||||||
|
|
||||||
@@ -60,6 +58,8 @@ MEMGRAPH_BUILD_DEPS=(
|
|||||||
libsasl2-dev
|
libsasl2-dev
|
||||||
)
|
)
|
||||||
|
|
||||||
|
MEMGRAPH_TEST_DEPS="${MEMGRAPH_BUILD_DEPS[*]}"
|
||||||
|
|
||||||
MEMGRAPH_RUN_DEPS=(
|
MEMGRAPH_RUN_DEPS=(
|
||||||
logrotate openssl python3 libseccomp2
|
logrotate openssl python3 libseccomp2
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -Eeuo pipefail
|
set -Eeuo pipefail
|
||||||
|
|
||||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||||
source "$DIR/../util.sh"
|
source "$DIR/../util.sh"
|
||||||
|
|
||||||
@@ -60,6 +58,8 @@ MEMGRAPH_BUILD_DEPS=(
|
|||||||
libsasl2-dev
|
libsasl2-dev
|
||||||
)
|
)
|
||||||
|
|
||||||
|
MEMGRAPH_TEST_DEPS="${MEMGRAPH_BUILD_DEPS[*]}"
|
||||||
|
|
||||||
MEMGRAPH_RUN_DEPS=(
|
MEMGRAPH_RUN_DEPS=(
|
||||||
logrotate openssl python3 libseccomp2
|
logrotate openssl python3 libseccomp2
|
||||||
)
|
)
|
||||||
|
|||||||
1
environment/toolchain/.gitignore
vendored
1
environment/toolchain/.gitignore
vendored
@@ -2,3 +2,4 @@ archives
|
|||||||
build
|
build
|
||||||
output
|
output
|
||||||
*.tar.gz
|
*.tar.gz
|
||||||
|
tmp_build.sh
|
||||||
|
|||||||
48
environment/toolchain/template_build.sh
Normal file
48
environment/toolchain/template_build.sh
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
#!/bin/bash -e
|
||||||
|
|
||||||
|
# NOTE: Copy this under memgraph/environment/toolchain/vN/tmp_build.sh, edit and test.
|
||||||
|
|
||||||
|
pushd () { command pushd "$@" > /dev/null; }
|
||||||
|
popd () { command popd "$@" > /dev/null; }
|
||||||
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||||
|
CPUS=$( grep -c processor < /proc/cpuinfo )
|
||||||
|
cd "$DIR"
|
||||||
|
source "$DIR/../../util.sh"
|
||||||
|
DISTRO="$(operating_system)"
|
||||||
|
TOOLCHAIN_VERSION=5
|
||||||
|
NAME=toolchain-v$TOOLCHAIN_VERSION
|
||||||
|
PREFIX=/opt/$NAME
|
||||||
|
function log_tool_name () {
|
||||||
|
echo ""
|
||||||
|
echo ""
|
||||||
|
echo "#### $1 ####"
|
||||||
|
echo ""
|
||||||
|
echo ""
|
||||||
|
}
|
||||||
|
|
||||||
|
# HERE: Remove/clear dependencies from a given toolchain.
|
||||||
|
|
||||||
|
mkdir -p archives && pushd archives
|
||||||
|
# HERE: Download dependencies here.
|
||||||
|
popd
|
||||||
|
|
||||||
|
mkdir -p build
|
||||||
|
pushd build
|
||||||
|
source $PREFIX/activate
|
||||||
|
export CC=$PREFIX/bin/clang
|
||||||
|
export CXX=$PREFIX/bin/clang++
|
||||||
|
export CFLAGS="$CFLAGS -fPIC"
|
||||||
|
export PATH=$PREFIX/bin:$PATH
|
||||||
|
export LD_LIBRARY_PATH=$PREFIX/lib64
|
||||||
|
COMMON_CMAKE_FLAGS="-DCMAKE_INSTALL_PREFIX=$PREFIX
|
||||||
|
-DCMAKE_PREFIX_PATH=$PREFIX
|
||||||
|
-DCMAKE_BUILD_TYPE=Release
|
||||||
|
-DCMAKE_C_COMPILER=$CC
|
||||||
|
-DCMAKE_CXX_COMPILER=$CXX
|
||||||
|
-DBUILD_SHARED_LIBS=OFF
|
||||||
|
-DCMAKE_CXX_STANDARD=20
|
||||||
|
-DBUILD_TESTING=OFF
|
||||||
|
-DCMAKE_REQUIRED_INCLUDES=$PREFIX/include
|
||||||
|
-DCMAKE_POSITION_INDEPENDENT_CODE=ON"
|
||||||
|
|
||||||
|
# HERE: Add dependencies to test below.
|
||||||
@@ -307,7 +307,7 @@ if [ ! -f $PREFIX/bin/ld.gold ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
log_tool_name "GDB $GDB_VERSION"
|
log_tool_name "GDB $GDB_VERSION"
|
||||||
if [ ! -f $PREFIX/bin/gdb ]; then
|
if [[ ! -f "$PREFIX/bin/gdb" && "$DISTRO" -ne "amzn-2" ]]; then
|
||||||
if [ -d gdb-$GDB_VERSION ]; then
|
if [ -d gdb-$GDB_VERSION ]; then
|
||||||
rm -rf gdb-$GDB_VERSION
|
rm -rf gdb-$GDB_VERSION
|
||||||
fi
|
fi
|
||||||
@@ -671,7 +671,6 @@ PROXYGEN_SHA256=5360a8ccdfb2f5a6c7b3eed331ec7ab0e2c792d579c6fff499c85c516c11fe14
|
|||||||
WANGLE_SHA256=1002e9c32b6f4837f6a760016e3b3e22f3509880ef3eaad191c80dc92655f23f
|
WANGLE_SHA256=1002e9c32b6f4837f6a760016e3b3e22f3509880ef3eaad191c80dc92655f23f
|
||||||
# WANGLE_SHA256=0e493c03572bb27fe9ca03a9da5023e52fde99c95abdcaa919bb6190e7e69532
|
# WANGLE_SHA256=0e493c03572bb27fe9ca03a9da5023e52fde99c95abdcaa919bb6190e7e69532
|
||||||
|
|
||||||
FLEX_VERSION=2.6.4
|
|
||||||
FMT_SHA256=78b8c0a72b1c35e4443a7e308df52498252d1cefc2b08c9a97bc9ee6cfe61f8b
|
FMT_SHA256=78b8c0a72b1c35e4443a7e308df52498252d1cefc2b08c9a97bc9ee6cfe61f8b
|
||||||
FMT_VERSION=10.1.1
|
FMT_VERSION=10.1.1
|
||||||
# NOTE: spdlog depends on exact fmt versions -> UPGRADE fmt and spdlog TOGETHER.
|
# NOTE: spdlog depends on exact fmt versions -> UPGRADE fmt and spdlog TOGETHER.
|
||||||
@@ -690,8 +689,8 @@ LZ4_VERSION=1.9.4
|
|||||||
SNAPPY_SHA256=75c1fbb3d618dd3a0483bff0e26d0a92b495bbe5059c8b4f1c962b478b6e06e7
|
SNAPPY_SHA256=75c1fbb3d618dd3a0483bff0e26d0a92b495bbe5059c8b4f1c962b478b6e06e7
|
||||||
SNAPPY_VERSION=1.1.9
|
SNAPPY_VERSION=1.1.9
|
||||||
XZ_VERSION=5.2.5 # for LZMA
|
XZ_VERSION=5.2.5 # for LZMA
|
||||||
ZLIB_VERSION=1.3
|
ZLIB_VERSION=1.3.1
|
||||||
ZSTD_VERSION=1.5.0
|
ZSTD_VERSION=1.5.5
|
||||||
|
|
||||||
pushd archives
|
pushd archives
|
||||||
if [ ! -f boost_$BOOST_VERSION_UNDERSCORES.tar.gz ]; then
|
if [ ! -f boost_$BOOST_VERSION_UNDERSCORES.tar.gz ]; then
|
||||||
@@ -700,7 +699,7 @@ if [ ! -f boost_$BOOST_VERSION_UNDERSCORES.tar.gz ]; then
|
|||||||
wget https://boostorg.jfrog.io/artifactory/main/release/$BOOST_VERSION/source/boost_$BOOST_VERSION_UNDERSCORES.tar.gz -O boost_$BOOST_VERSION_UNDERSCORES.tar.gz
|
wget https://boostorg.jfrog.io/artifactory/main/release/$BOOST_VERSION/source/boost_$BOOST_VERSION_UNDERSCORES.tar.gz -O boost_$BOOST_VERSION_UNDERSCORES.tar.gz
|
||||||
fi
|
fi
|
||||||
if [ ! -f bzip2-$BZIP2_VERSION.tar.gz ]; then
|
if [ ! -f bzip2-$BZIP2_VERSION.tar.gz ]; then
|
||||||
wget https://sourceforge.net/projects/bzip2/files/bzip2-$BZIP2_VERSION.tar.gz -O bzip2-$BZIP2_VERSION.tar.gz
|
wget https://sourceware.org/pub/bzip2/bzip2-$BZIP2_VERSION.tar.gz -O bzip2-$BZIP2_VERSION.tar.gz
|
||||||
fi
|
fi
|
||||||
if [ ! -f double-conversion-$DOUBLE_CONVERSION_VERSION.tar.gz ]; then
|
if [ ! -f double-conversion-$DOUBLE_CONVERSION_VERSION.tar.gz ]; then
|
||||||
wget https://github.com/google/double-conversion/archive/refs/tags/v$DOUBLE_CONVERSION_VERSION.tar.gz -O double-conversion-$DOUBLE_CONVERSION_VERSION.tar.gz
|
wget https://github.com/google/double-conversion/archive/refs/tags/v$DOUBLE_CONVERSION_VERSION.tar.gz -O double-conversion-$DOUBLE_CONVERSION_VERSION.tar.gz
|
||||||
@@ -708,9 +707,7 @@ fi
|
|||||||
if [ ! -f fizz-$FBLIBS_VERSION.tar.gz ]; then
|
if [ ! -f fizz-$FBLIBS_VERSION.tar.gz ]; then
|
||||||
wget https://github.com/facebookincubator/fizz/releases/download/v$FBLIBS_VERSION/fizz-v$FBLIBS_VERSION.tar.gz -O fizz-$FBLIBS_VERSION.tar.gz
|
wget https://github.com/facebookincubator/fizz/releases/download/v$FBLIBS_VERSION/fizz-v$FBLIBS_VERSION.tar.gz -O fizz-$FBLIBS_VERSION.tar.gz
|
||||||
fi
|
fi
|
||||||
if [ ! -f flex-$FLEX_VERSION.tar.gz ]; then
|
|
||||||
wget https://github.com/westes/flex/releases/download/v$FLEX_VERSION/flex-$FLEX_VERSION.tar.gz -O flex-$FLEX_VERSION.tar.gz
|
|
||||||
fi
|
|
||||||
if [ ! -f fmt-$FMT_VERSION.tar.gz ]; then
|
if [ ! -f fmt-$FMT_VERSION.tar.gz ]; then
|
||||||
wget https://github.com/fmtlib/fmt/archive/refs/tags/$FMT_VERSION.tar.gz -O fmt-$FMT_VERSION.tar.gz
|
wget https://github.com/fmtlib/fmt/archive/refs/tags/$FMT_VERSION.tar.gz -O fmt-$FMT_VERSION.tar.gz
|
||||||
fi
|
fi
|
||||||
@@ -765,14 +762,6 @@ echo "$BZIP2_SHA256 bzip2-$BZIP2_VERSION.tar.gz" | sha256sum -c
|
|||||||
echo "$DOUBLE_CONVERSION_SHA256 double-conversion-$DOUBLE_CONVERSION_VERSION.tar.gz" | sha256sum -c
|
echo "$DOUBLE_CONVERSION_SHA256 double-conversion-$DOUBLE_CONVERSION_VERSION.tar.gz" | sha256sum -c
|
||||||
# verify fizz
|
# verify fizz
|
||||||
echo "$FIZZ_SHA256 fizz-$FBLIBS_VERSION.tar.gz" | sha256sum -c
|
echo "$FIZZ_SHA256 fizz-$FBLIBS_VERSION.tar.gz" | sha256sum -c
|
||||||
# verify flex
|
|
||||||
if [ ! -f flex-$FLEX_VERSION.tar.gz.sig ]; then
|
|
||||||
wget https://github.com/westes/flex/releases/download/v$FLEX_VERSION/flex-$FLEX_VERSION.tar.gz.sig
|
|
||||||
fi
|
|
||||||
if false; then
|
|
||||||
$GPG --keyserver $KEYSERVER --recv-keys 0xE4B29C8D64885307
|
|
||||||
$GPG --verify flex-$FLEX_VERSION.tar.gz.sig flex-$FLEX_VERSION.tar.gz
|
|
||||||
fi
|
|
||||||
# verify fmt
|
# verify fmt
|
||||||
echo "$FMT_SHA256 fmt-$FMT_VERSION.tar.gz" | sha256sum -c
|
echo "$FMT_SHA256 fmt-$FMT_VERSION.tar.gz" | sha256sum -c
|
||||||
# verify spdlog
|
# verify spdlog
|
||||||
@@ -1025,7 +1014,6 @@ if [ ! -d $PREFIX/include/gflags ]; then
|
|||||||
if [ -d gflags ]; then
|
if [ -d gflags ]; then
|
||||||
rm -rf gflags
|
rm -rf gflags
|
||||||
fi
|
fi
|
||||||
|
|
||||||
git clone https://github.com/memgraph/gflags.git gflags
|
git clone https://github.com/memgraph/gflags.git gflags
|
||||||
pushd gflags
|
pushd gflags
|
||||||
git checkout $GFLAGS_COMMIT_HASH
|
git checkout $GFLAGS_COMMIT_HASH
|
||||||
@@ -1034,7 +1022,7 @@ if [ ! -d $PREFIX/include/gflags ]; then
|
|||||||
cmake .. $COMMON_CMAKE_FLAGS \
|
cmake .. $COMMON_CMAKE_FLAGS \
|
||||||
-DREGISTER_INSTALL_PREFIX=OFF \
|
-DREGISTER_INSTALL_PREFIX=OFF \
|
||||||
-DBUILD_gflags_nothreads_LIB=OFF \
|
-DBUILD_gflags_nothreads_LIB=OFF \
|
||||||
-DGFLAGS_NO_FILENAMES=0
|
-DGFLAGS_NO_FILENAMES=1
|
||||||
make -j$CPUS install
|
make -j$CPUS install
|
||||||
popd && popd
|
popd && popd
|
||||||
fi
|
fi
|
||||||
@@ -1232,18 +1220,6 @@ if false; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log_tool_name "flex $FLEX_VERSION"
|
|
||||||
if [ ! -f $PREFIX/include/FlexLexer.h ]; then
|
|
||||||
if [ -d flex-$FLEX_VERSION ]; then
|
|
||||||
rm -rf flex-$FLEX_VERSION
|
|
||||||
fi
|
|
||||||
tar -xzf ../archives/flex-$FLEX_VERSION.tar.gz
|
|
||||||
pushd flex-$FLEX_VERSION
|
|
||||||
./configure $COMMON_CONFIGURE_FLAGS
|
|
||||||
make -j$CPUS install
|
|
||||||
popd
|
|
||||||
fi
|
|
||||||
|
|
||||||
popd
|
popd
|
||||||
# NOTE: It's important/clean (e.g., easier upload to S3) to have a separated
|
# NOTE: It's important/clean (e.g., easier upload to S3) to have a separated
|
||||||
# folder to the output archive.
|
# folder to the output archive.
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2023 Memgraph Ltd.
|
// Copyright 2024 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@@ -283,7 +283,7 @@ inline mgp_list *list_all_unique_constraints(mgp_graph *graph, mgp_memory *memor
|
|||||||
}
|
}
|
||||||
|
|
||||||
// mgp_graph
|
// mgp_graph
|
||||||
|
|
||||||
inline bool graph_is_transactional(mgp_graph *graph) { return MgInvoke<int>(mgp_graph_is_transactional, graph); }
|
inline bool graph_is_transactional(mgp_graph *graph) { return MgInvoke<int>(mgp_graph_is_transactional, graph); }
|
||||||
|
|
||||||
inline bool graph_is_mutable(mgp_graph *graph) { return MgInvoke<int>(mgp_graph_is_mutable, graph); }
|
inline bool graph_is_mutable(mgp_graph *graph) { return MgInvoke<int>(mgp_graph_is_mutable, graph); }
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2023 Memgraph Ltd.
|
// Copyright 2024 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@@ -25,7 +25,7 @@ namespace mg_exception {
|
|||||||
template <typename FirstArg, typename... Args>
|
template <typename FirstArg, typename... Args>
|
||||||
std::string StringSerialize(FirstArg &&firstArg, Args &&...args) {
|
std::string StringSerialize(FirstArg &&firstArg, Args &&...args) {
|
||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
stream << firstArg;
|
stream << std::forward<FirstArg>(firstArg);
|
||||||
((stream << " " << args), ...);
|
((stream << " " << args), ...);
|
||||||
return stream.str();
|
return stream.str();
|
||||||
}
|
}
|
||||||
|
|||||||
1
libs/.gitignore
vendored
1
libs/.gitignore
vendored
@@ -7,3 +7,4 @@
|
|||||||
!pulsar.patch
|
!pulsar.patch
|
||||||
!antlr4.10.1.patch
|
!antlr4.10.1.patch
|
||||||
!rocksdb8.1.1.patch
|
!rocksdb8.1.1.patch
|
||||||
|
!nuraft2.1.0.patch
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ set(GFLAGS_NOTHREADS OFF)
|
|||||||
|
|
||||||
# NOTE: config/generate.py depends on the gflags help XML format.
|
# NOTE: config/generate.py depends on the gflags help XML format.
|
||||||
find_package(gflags REQUIRED)
|
find_package(gflags REQUIRED)
|
||||||
find_package(fmt 8.0.1)
|
find_package(fmt 8.0.1 REQUIRED)
|
||||||
find_package(ZLIB 1.2.11 REQUIRED)
|
find_package(ZLIB 1.2.11 REQUIRED)
|
||||||
|
|
||||||
set(LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
set(LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
@@ -294,3 +294,10 @@ set_path_external_library(jemalloc STATIC
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/jemalloc/include/)
|
${CMAKE_CURRENT_SOURCE_DIR}/jemalloc/include/)
|
||||||
|
|
||||||
import_header_library(rangev3 ${CMAKE_CURRENT_SOURCE_DIR}/rangev3/include)
|
import_header_library(rangev3 ${CMAKE_CURRENT_SOURCE_DIR}/rangev3/include)
|
||||||
|
|
||||||
|
# Setup NuRaft
|
||||||
|
import_external_library(nuraft STATIC
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/nuraft/lib/libnuraft.a
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/nuraft/include/)
|
||||||
|
find_package(OpenSSL REQUIRED)
|
||||||
|
target_link_libraries(nuraft INTERFACE ${OPENSSL_LIBRARIES})
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ index ee9b58c..31359a9 100644
|
|||||||
@@ -48,7 +48,7 @@ option(LIBRDTSC_USE_PMU "Enables PMU usage on ARM platforms" OFF)
|
@@ -48,7 +48,7 @@ option(LIBRDTSC_USE_PMU "Enables PMU usage on ARM platforms" OFF)
|
||||||
# | Library Build and Install Properties |
|
# | Library Build and Install Properties |
|
||||||
# +--------------------------------------------------------+
|
# +--------------------------------------------------------+
|
||||||
|
|
||||||
-add_library(rdtsc SHARED
|
-add_library(rdtsc SHARED
|
||||||
+add_library(rdtsc
|
+add_library(rdtsc
|
||||||
src/cycles.c
|
src/cycles.c
|
||||||
@@ -14,7 +14,7 @@ index ee9b58c..31359a9 100644
|
|||||||
@@ -72,15 +72,6 @@ target_include_directories(rdtsc
|
@@ -72,15 +72,6 @@ target_include_directories(rdtsc
|
||||||
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include
|
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||||
)
|
)
|
||||||
|
|
||||||
-# Install directory changes depending on build mode
|
-# Install directory changes depending on build mode
|
||||||
-if (CMAKE_BUILD_TYPE MATCHES "^[Dd]ebug")
|
-if (CMAKE_BUILD_TYPE MATCHES "^[Dd]ebug")
|
||||||
- # During debug, the library will be installed into a local directory
|
- # During debug, the library will be installed into a local directory
|
||||||
@@ -27,3 +27,15 @@ index ee9b58c..31359a9 100644
|
|||||||
# Specifying what to export when installing (GNUInstallDirs required)
|
# Specifying what to export when installing (GNUInstallDirs required)
|
||||||
install(TARGETS rdtsc
|
install(TARGETS rdtsc
|
||||||
EXPORT librstsc-config
|
EXPORT librstsc-config
|
||||||
|
diff --git a/include/librdtsc/common_timer.h b/include/librdtsc/common_timer.h
|
||||||
|
index a6922d8..080dc77 100644
|
||||||
|
--- a/include/librdtsc/common_timer.h
|
||||||
|
+++ b/include/librdtsc/common_timer.h
|
||||||
|
@@ -2,6 +2,7 @@
|
||||||
|
#define LIBRDTSC_COMMON_TIMER_H
|
||||||
|
|
||||||
|
#include <librdtsc/common.h>
|
||||||
|
+#include <librdtsc/cycles.h>
|
||||||
|
|
||||||
|
extern uint64_t rdtsc_get_tsc_freq_arch();
|
||||||
|
extern uint64_t rdtsc_get_tsc_freq();
|
||||||
|
|||||||
24
libs/nuraft2.1.0.patch
Normal file
24
libs/nuraft2.1.0.patch
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
diff --git a/include/libnuraft/asio_service_options.hxx b/include/libnuraft/asio_service_options.hxx
|
||||||
|
index 8fe1ec9..9497355 100644
|
||||||
|
--- a/include/libnuraft/asio_service_options.hxx
|
||||||
|
+++ b/include/libnuraft/asio_service_options.hxx
|
||||||
|
@@ -17,6 +17,7 @@ limitations under the License.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
+#include <cstdint>
|
||||||
|
#include <functional>
|
||||||
|
#include <string>
|
||||||
|
#include <system_error>
|
||||||
|
diff --git a/include/libnuraft/callback.hxx b/include/libnuraft/callback.hxx
|
||||||
|
index 7b71624..d48c1e2 100644
|
||||||
|
--- a/include/libnuraft/callback.hxx
|
||||||
|
+++ b/include/libnuraft/callback.hxx
|
||||||
|
@@ -18,6 +18,7 @@ limitations under the License.
|
||||||
|
#ifndef _CALLBACK_H_
|
||||||
|
#define _CALLBACK_H_
|
||||||
|
|
||||||
|
+#include <cstdint>
|
||||||
|
#include <functional>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
|
||||||
index 6761929..6a369af 100644
|
|
||||||
--- a/CMakeLists.txt
|
|
||||||
+++ b/CMakeLists.txt
|
|
||||||
@@ -220,6 +220,7 @@ else()
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -momit-leaf-frame-pointer")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-copy -Wno-unused-but-set-variable")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
include(CheckCCompilerFlag)
|
|
||||||
@@ -997,7 +998,7 @@ if(NOT WIN32 OR ROCKSDB_INSTALL_ON_WINDOWS)
|
|
||||||
|
|
||||||
if(ROCKSDB_BUILD_SHARED)
|
|
||||||
install(
|
|
||||||
- TARGETS ${ROCKSDB_SHARED_LIB}
|
|
||||||
+ TARGETS ${ROCKSDB_SHARED_LIB} OPTIONAL
|
|
||||||
EXPORT RocksDBTargets
|
|
||||||
COMPONENT runtime
|
|
||||||
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
|
||||||
@@ -123,9 +123,10 @@ declare -A primary_urls=(
|
|||||||
["pulsar"]="http://$local_cache_host/git/pulsar.git"
|
["pulsar"]="http://$local_cache_host/git/pulsar.git"
|
||||||
["librdtsc"]="http://$local_cache_host/git/librdtsc.git"
|
["librdtsc"]="http://$local_cache_host/git/librdtsc.git"
|
||||||
["ctre"]="http://$local_cache_host/file/hanickadot/compile-time-regular-expressions/v3.7.2/single-header/ctre.hpp"
|
["ctre"]="http://$local_cache_host/file/hanickadot/compile-time-regular-expressions/v3.7.2/single-header/ctre.hpp"
|
||||||
["absl"]="https://$local_cache_host/git/abseil-cpp.git"
|
["absl"]="http://$local_cache_host/git/abseil-cpp.git"
|
||||||
["jemalloc"]="https://$local_cache_host/git/jemalloc.git"
|
["jemalloc"]="http://$local_cache_host/git/jemalloc.git"
|
||||||
["range-v3"]="https://$local_cache_host/git/ericniebler/range-v3.git"
|
["range-v3"]="http://$local_cache_host/git/range-v3.git"
|
||||||
|
["nuraft"]="http://$local_cache_host/git/NuRaft.git"
|
||||||
)
|
)
|
||||||
|
|
||||||
# The goal of secondary urls is to have links to the "source of truth" of
|
# The goal of secondary urls is to have links to the "source of truth" of
|
||||||
@@ -155,6 +156,7 @@ declare -A secondary_urls=(
|
|||||||
["absl"]="https://github.com/abseil/abseil-cpp.git"
|
["absl"]="https://github.com/abseil/abseil-cpp.git"
|
||||||
["jemalloc"]="https://github.com/jemalloc/jemalloc.git"
|
["jemalloc"]="https://github.com/jemalloc/jemalloc.git"
|
||||||
["range-v3"]="https://github.com/ericniebler/range-v3.git"
|
["range-v3"]="https://github.com/ericniebler/range-v3.git"
|
||||||
|
["nuraft"]="https://github.com/eBay/NuRaft.git"
|
||||||
)
|
)
|
||||||
|
|
||||||
# antlr
|
# antlr
|
||||||
@@ -166,12 +168,11 @@ pushd antlr4
|
|||||||
git apply ../antlr4.10.1.patch
|
git apply ../antlr4.10.1.patch
|
||||||
popd
|
popd
|
||||||
|
|
||||||
# cppitertools v2.0 2019-12-23
|
cppitertools_ref="v2.1" # 2021-01-15
|
||||||
cppitertools_ref="cb3635456bdb531121b82b4d2e3afc7ae1f56d47"
|
|
||||||
repo_clone_try_double "${primary_urls[cppitertools]}" "${secondary_urls[cppitertools]}" "cppitertools" "$cppitertools_ref"
|
repo_clone_try_double "${primary_urls[cppitertools]}" "${secondary_urls[cppitertools]}" "cppitertools" "$cppitertools_ref"
|
||||||
|
|
||||||
# rapidcheck
|
# rapidcheck
|
||||||
rapidcheck_tag="7bc7d302191a4f3d0bf005692677126136e02f60" # (2020-05-04)
|
rapidcheck_tag="1c91f40e64d87869250cfb610376c629307bf77d" # (2023-08-15)
|
||||||
repo_clone_try_double "${primary_urls[rapidcheck]}" "${secondary_urls[rapidcheck]}" "rapidcheck" "$rapidcheck_tag"
|
repo_clone_try_double "${primary_urls[rapidcheck]}" "${secondary_urls[rapidcheck]}" "rapidcheck" "$rapidcheck_tag"
|
||||||
|
|
||||||
# google benchmark
|
# google benchmark
|
||||||
@@ -219,7 +220,7 @@ repo_clone_try_double "${primary_urls[pymgclient]}" "${secondary_urls[pymgclient
|
|||||||
mgconsole_tag="v1.4.0" # (2023-05-21)
|
mgconsole_tag="v1.4.0" # (2023-05-21)
|
||||||
repo_clone_try_double "${primary_urls[mgconsole]}" "${secondary_urls[mgconsole]}" "mgconsole" "$mgconsole_tag" true
|
repo_clone_try_double "${primary_urls[mgconsole]}" "${secondary_urls[mgconsole]}" "mgconsole" "$mgconsole_tag" true
|
||||||
|
|
||||||
spdlog_tag="v1.9.2" # (2021-08-12)
|
spdlog_tag="v1.12.0" # (2022-11-02)
|
||||||
repo_clone_try_double "${primary_urls[spdlog]}" "${secondary_urls[spdlog]}" "spdlog" "$spdlog_tag" true
|
repo_clone_try_double "${primary_urls[spdlog]}" "${secondary_urls[spdlog]}" "spdlog" "$spdlog_tag" true
|
||||||
|
|
||||||
# librdkafka
|
# librdkafka
|
||||||
@@ -268,6 +269,8 @@ pushd jemalloc
|
|||||||
MALLOC_CONF="retain:false,percpu_arena:percpu,oversize_threshold:0,muzzy_decay_ms:5000,dirty_decay_ms:5000" \
|
MALLOC_CONF="retain:false,percpu_arena:percpu,oversize_threshold:0,muzzy_decay_ms:5000,dirty_decay_ms:5000" \
|
||||||
./configure \
|
./configure \
|
||||||
--disable-cxx \
|
--disable-cxx \
|
||||||
|
--with-lg-page=12 \
|
||||||
|
--with-lg-hugepage=21 \
|
||||||
--enable-shared=no --prefix=$working_dir \
|
--enable-shared=no --prefix=$working_dir \
|
||||||
--with-malloc-conf="retain:false,percpu_arena:percpu,oversize_threshold:0,muzzy_decay_ms:5000,dirty_decay_ms:5000"
|
--with-malloc-conf="retain:false,percpu_arena:percpu,oversize_threshold:0,muzzy_decay_ms:5000,dirty_decay_ms:5000"
|
||||||
|
|
||||||
@@ -277,3 +280,11 @@ popd
|
|||||||
#range-v3 release-0.12.0
|
#range-v3 release-0.12.0
|
||||||
range_v3_ref="release-0.12.0"
|
range_v3_ref="release-0.12.0"
|
||||||
repo_clone_try_double "${primary_urls[range-v3]}" "${secondary_urls[range-v3]}" "rangev3" "$range_v3_ref"
|
repo_clone_try_double "${primary_urls[range-v3]}" "${secondary_urls[range-v3]}" "rangev3" "$range_v3_ref"
|
||||||
|
|
||||||
|
# NuRaft
|
||||||
|
nuraft_tag="v2.1.0"
|
||||||
|
repo_clone_try_double "${primary_urls[nuraft]}" "${secondary_urls[nuraft]}" "nuraft" "$nuraft_tag" true
|
||||||
|
pushd nuraft
|
||||||
|
git apply ../nuraft2.1.0.patch
|
||||||
|
./prepare.sh
|
||||||
|
popd
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ ADDITIONAL USE GRANT: You may use the Licensed Work in accordance with the
|
|||||||
3. using the Licensed Work to create a work or solution
|
3. using the Licensed Work to create a work or solution
|
||||||
which competes (or might reasonably be expected to
|
which competes (or might reasonably be expected to
|
||||||
compete) with the Licensed Work.
|
compete) with the Licensed Work.
|
||||||
CHANGE DATE: 2027-08-12
|
CHANGE DATE: 2028-28-02
|
||||||
CHANGE LICENSE: Apache License, Version 2.0
|
CHANGE LICENSE: Apache License, Version 2.0
|
||||||
|
|
||||||
For information about alternative licensing arrangements, please visit: https://memgraph.com/legal.
|
For information about alternative licensing arrangements, please visit: https://memgraph.com/legal.
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ add_subdirectory(dbms)
|
|||||||
add_subdirectory(flags)
|
add_subdirectory(flags)
|
||||||
add_subdirectory(distributed)
|
add_subdirectory(distributed)
|
||||||
add_subdirectory(replication)
|
add_subdirectory(replication)
|
||||||
|
add_subdirectory(replication_handler)
|
||||||
|
add_subdirectory(coordination)
|
||||||
|
add_subdirectory(replication_coordination_glue)
|
||||||
|
add_subdirectory(system)
|
||||||
|
|
||||||
string(TOLOWER ${CMAKE_BUILD_TYPE} lower_build_type)
|
string(TOLOWER ${CMAKE_BUILD_TYPE} lower_build_type)
|
||||||
|
|
||||||
@@ -41,10 +45,10 @@ set(mg_single_node_v2_sources
|
|||||||
add_executable(memgraph ${mg_single_node_v2_sources})
|
add_executable(memgraph ${mg_single_node_v2_sources})
|
||||||
target_include_directories(memgraph PUBLIC ${CMAKE_SOURCE_DIR}/include)
|
target_include_directories(memgraph PUBLIC ${CMAKE_SOURCE_DIR}/include)
|
||||||
target_link_libraries(memgraph stdc++fs Threads::Threads
|
target_link_libraries(memgraph stdc++fs Threads::Threads
|
||||||
mg-telemetry mg-communication mg-communication-metrics mg-memory mg-utils mg-license mg-settings mg-glue mg-flags)
|
mg-telemetry mg-communication mg-communication-metrics mg-memory mg-utils mg-license mg-settings mg-glue mg-flags mg::system mg::replication_handler)
|
||||||
|
|
||||||
# NOTE: `include/mg_procedure.syms` describes a pattern match for symbols which
|
# NOTE: `include/mg_procedure.syms` describes a pattern match for symbols which
|
||||||
# should be dynamically exported, so that `dlopen` can correctly link the
|
# should be dynamically exported, so that `dlopen` can correctly link th
|
||||||
# symbols in custom procedure module libraries.
|
# symbols in custom procedure module libraries.
|
||||||
target_link_libraries(memgraph "-Wl,--dynamic-list=${CMAKE_SOURCE_DIR}/include/mg_procedure.syms")
|
target_link_libraries(memgraph "-Wl,--dynamic-list=${CMAKE_SOURCE_DIR}/include/mg_procedure.syms")
|
||||||
set_target_properties(memgraph PROPERTIES
|
set_target_properties(memgraph PROPERTIES
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ set(auth_src_files
|
|||||||
auth.cpp
|
auth.cpp
|
||||||
crypto.cpp
|
crypto.cpp
|
||||||
models.cpp
|
models.cpp
|
||||||
module.cpp)
|
module.cpp
|
||||||
|
rpc.cpp
|
||||||
|
replication_handlers.cpp)
|
||||||
|
|
||||||
find_package(Seccomp REQUIRED)
|
find_package(Seccomp REQUIRED)
|
||||||
find_package(fmt REQUIRED)
|
find_package(fmt REQUIRED)
|
||||||
@@ -11,7 +13,7 @@ find_package(gflags REQUIRED)
|
|||||||
|
|
||||||
add_library(mg-auth STATIC ${auth_src_files})
|
add_library(mg-auth STATIC ${auth_src_files})
|
||||||
target_link_libraries(mg-auth json libbcrypt gflags fmt::fmt)
|
target_link_libraries(mg-auth json libbcrypt gflags fmt::fmt)
|
||||||
target_link_libraries(mg-auth mg-utils mg-kvstore mg-license )
|
target_link_libraries(mg-auth mg-utils mg-kvstore mg-license mg::system mg-replication)
|
||||||
|
|
||||||
target_link_libraries(mg-auth ${Seccomp_LIBRARIES})
|
target_link_libraries(mg-auth ${Seccomp_LIBRARIES})
|
||||||
target_include_directories(mg-auth SYSTEM PRIVATE ${Seccomp_INCLUDE_DIRS})
|
target_include_directories(mg-auth SYSTEM PRIVATE ${Seccomp_INCLUDE_DIRS})
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2023 Memgraph Ltd.
|
// Copyright 2024 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Licensed as a Memgraph Enterprise file under the Memgraph Enterprise
|
// Licensed as a Memgraph Enterprise file under the Memgraph Enterprise
|
||||||
// License (the "License"); by using this file, you agree to be bound by the terms of the License, and you may not use
|
// License (the "License"); by using this file, you agree to be bound by the terms of the License, and you may not use
|
||||||
@@ -8,17 +8,18 @@
|
|||||||
|
|
||||||
#include "auth/auth.hpp"
|
#include "auth/auth.hpp"
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <limits>
|
#include <optional>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
|
|
||||||
|
#include "auth/crypto.hpp"
|
||||||
#include "auth/exceptions.hpp"
|
#include "auth/exceptions.hpp"
|
||||||
|
#include "auth/rpc.hpp"
|
||||||
#include "license/license.hpp"
|
#include "license/license.hpp"
|
||||||
|
#include "system/transaction.hpp"
|
||||||
#include "utils/flag_validation.hpp"
|
#include "utils/flag_validation.hpp"
|
||||||
#include "utils/logging.hpp"
|
|
||||||
#include "utils/message.hpp"
|
#include "utils/message.hpp"
|
||||||
#include "utils/settings.hpp"
|
#include "utils/settings.hpp"
|
||||||
#include "utils/string.hpp"
|
#include "utils/string.hpp"
|
||||||
@@ -34,18 +35,124 @@ DEFINE_VALIDATED_string(auth_module_executable, "", "Absolute path to the auth m
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
DEFINE_bool(auth_module_create_missing_user, true, "Set to false to disable creation of missing users.");
|
|
||||||
DEFINE_bool(auth_module_create_missing_role, true, "Set to false to disable creation of missing roles.");
|
|
||||||
DEFINE_bool(auth_module_manage_roles, true, "Set to false to disable management of roles through the auth module.");
|
|
||||||
DEFINE_VALIDATED_int32(auth_module_timeout_ms, 10000,
|
DEFINE_VALIDATED_int32(auth_module_timeout_ms, 10000,
|
||||||
"Timeout (in milliseconds) used when waiting for a "
|
"Timeout (in milliseconds) used when waiting for a "
|
||||||
"response from the auth module.",
|
"response from the auth module.",
|
||||||
FLAG_IN_RANGE(100, 1800000));
|
FLAG_IN_RANGE(100, 1800000));
|
||||||
|
|
||||||
|
// DEPRECATED FLAGS
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables, misc-unused-parameters)
|
||||||
|
DEFINE_VALIDATED_HIDDEN_bool(auth_module_create_missing_user, true,
|
||||||
|
"Set to false to disable creation of missing users.", {
|
||||||
|
spdlog::warn(
|
||||||
|
"auth_module_create_missing_user flag is deprecated. It not possible to create "
|
||||||
|
"users through the module anymore.");
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables, misc-unused-parameters)
|
||||||
|
DEFINE_VALIDATED_HIDDEN_bool(auth_module_create_missing_role, true,
|
||||||
|
"Set to false to disable creation of missing roles.", {
|
||||||
|
spdlog::warn(
|
||||||
|
"auth_module_create_missing_role flag is deprecated. It not possible to create "
|
||||||
|
"roles through the module anymore.");
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables, misc-unused-parameters)
|
||||||
|
DEFINE_VALIDATED_HIDDEN_bool(
|
||||||
|
auth_module_manage_roles, true, "Set to false to disable management of roles through the auth module.", {
|
||||||
|
spdlog::warn(
|
||||||
|
"auth_module_manage_roles flag is deprecated. It not possible to create roles through the module anymore.");
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
namespace memgraph::auth {
|
namespace memgraph::auth {
|
||||||
|
|
||||||
|
const Auth::Epoch Auth::kStartEpoch = 1;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
#ifdef MG_ENTERPRISE
|
||||||
|
/**
|
||||||
|
* REPLICATION SYSTEM ACTION IMPLEMENTATIONS
|
||||||
|
*/
|
||||||
|
struct UpdateAuthData : memgraph::system::ISystemAction {
|
||||||
|
explicit UpdateAuthData(User user) : user_{std::move(user)}, role_{std::nullopt} {}
|
||||||
|
explicit UpdateAuthData(Role role) : user_{std::nullopt}, role_{std::move(role)} {}
|
||||||
|
|
||||||
|
void DoDurability() override { /* Done during Auth execution */
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DoReplication(replication::ReplicationClient &client, const utils::UUID &main_uuid,
|
||||||
|
replication::ReplicationEpoch const &epoch,
|
||||||
|
memgraph::system::Transaction const &txn) const override {
|
||||||
|
auto check_response = [](const replication::UpdateAuthDataRes &response) { return response.success; };
|
||||||
|
if (user_) {
|
||||||
|
return client.SteamAndFinalizeDelta<replication::UpdateAuthDataRpc>(
|
||||||
|
check_response, main_uuid, std::string{epoch.id()}, txn.last_committed_system_timestamp(), txn.timestamp(),
|
||||||
|
*user_);
|
||||||
|
}
|
||||||
|
if (role_) {
|
||||||
|
return client.SteamAndFinalizeDelta<replication::UpdateAuthDataRpc>(
|
||||||
|
check_response, main_uuid, std::string{epoch.id()}, txn.last_committed_system_timestamp(), txn.timestamp(),
|
||||||
|
*role_);
|
||||||
|
}
|
||||||
|
// Should never get here
|
||||||
|
MG_ASSERT(false, "Trying to update auth data that is not a user nor a role");
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
void PostReplication(replication::RoleMainData &mainData) const override {}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::optional<User> user_;
|
||||||
|
std::optional<Role> role_;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct DropAuthData : memgraph::system::ISystemAction {
|
||||||
|
enum class AuthDataType { USER, ROLE };
|
||||||
|
|
||||||
|
explicit DropAuthData(AuthDataType type, std::string_view name) : type_{type}, name_{name} {}
|
||||||
|
|
||||||
|
void DoDurability() override { /* Done during Auth execution */
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DoReplication(replication::ReplicationClient &client, const utils::UUID &main_uuid,
|
||||||
|
replication::ReplicationEpoch const &epoch,
|
||||||
|
memgraph::system::Transaction const &txn) const override {
|
||||||
|
auto check_response = [](const replication::DropAuthDataRes &response) { return response.success; };
|
||||||
|
|
||||||
|
memgraph::replication::DropAuthDataReq::DataType type{};
|
||||||
|
switch (type_) {
|
||||||
|
case AuthDataType::USER:
|
||||||
|
type = memgraph::replication::DropAuthDataReq::DataType::USER;
|
||||||
|
break;
|
||||||
|
case AuthDataType::ROLE:
|
||||||
|
type = memgraph::replication::DropAuthDataReq::DataType::ROLE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return client.SteamAndFinalizeDelta<replication::DropAuthDataRpc>(
|
||||||
|
check_response, main_uuid, std::string{epoch.id()}, txn.last_committed_system_timestamp(), txn.timestamp(),
|
||||||
|
type, name_);
|
||||||
|
}
|
||||||
|
void PostReplication(replication::RoleMainData &mainData) const override {}
|
||||||
|
|
||||||
|
private:
|
||||||
|
AuthDataType type_;
|
||||||
|
std::string name_;
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CONSTANTS
|
||||||
|
*/
|
||||||
const std::string kUserPrefix = "user:";
|
const std::string kUserPrefix = "user:";
|
||||||
const std::string kRolePrefix = "role:";
|
const std::string kRolePrefix = "role:";
|
||||||
const std::string kLinkPrefix = "link:";
|
const std::string kLinkPrefix = "link:";
|
||||||
|
const std::string kVersion = "version";
|
||||||
|
|
||||||
|
static constexpr auto kVersionV1 = "V1";
|
||||||
|
} // namespace
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All data stored in the `Auth` storage is stored in an underlying
|
* All data stored in the `Auth` storage is stored in an underlying
|
||||||
@@ -64,10 +171,76 @@ const std::string kLinkPrefix = "link:";
|
|||||||
* key="link:<username>", value="<rolename>"
|
* key="link:<username>", value="<rolename>"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Auth::Auth(const std::string &storage_directory) : storage_(storage_directory), module_(FLAGS_auth_module_executable) {}
|
namespace {
|
||||||
|
void MigrateVersions(kvstore::KVStore &store) {
|
||||||
|
static constexpr auto kPasswordHashV0V1 = "password_hash";
|
||||||
|
auto version_str = store.Get(kVersion);
|
||||||
|
|
||||||
std::optional<User> Auth::Authenticate(const std::string &username, const std::string &password) {
|
if (!version_str) {
|
||||||
|
using namespace std::string_literals;
|
||||||
|
|
||||||
|
// pre versioning, add version to the store
|
||||||
|
auto puts = std::map<std::string, std::string>{{kVersion, kVersionV1}};
|
||||||
|
|
||||||
|
// also add hash kind into durability
|
||||||
|
|
||||||
|
auto it = store.begin(kUserPrefix);
|
||||||
|
auto const e = store.end(kUserPrefix);
|
||||||
|
|
||||||
|
if (it != e) {
|
||||||
|
const auto hash_algo = CurrentHashAlgorithm();
|
||||||
|
spdlog::info("Updating auth durability, assuming previously stored as {}", AsString(hash_algo));
|
||||||
|
|
||||||
|
for (; it != e; ++it) {
|
||||||
|
auto const &[key, value] = *it;
|
||||||
|
try {
|
||||||
|
auto user_data = nlohmann::json::parse(value);
|
||||||
|
|
||||||
|
auto password_hash = user_data[kPasswordHashV0V1];
|
||||||
|
if (!password_hash.is_string()) {
|
||||||
|
throw AuthException("Couldn't load user data!");
|
||||||
|
}
|
||||||
|
// upgrade the password_hash to include the hash algortihm
|
||||||
|
if (password_hash.empty()) {
|
||||||
|
user_data[kPasswordHashV0V1] = nullptr;
|
||||||
|
} else {
|
||||||
|
user_data[kPasswordHashV0V1] = HashedPassword{hash_algo, password_hash};
|
||||||
|
}
|
||||||
|
puts.emplace(key, user_data.dump());
|
||||||
|
} catch (const nlohmann::json::parse_error &e) {
|
||||||
|
throw AuthException("Couldn't load user data!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Perform migration to V1
|
||||||
|
store.PutMultiple(puts);
|
||||||
|
version_str = kVersionV1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto ParseJson(std::string_view str) {
|
||||||
|
nlohmann::json data;
|
||||||
|
try {
|
||||||
|
data = nlohmann::json::parse(str);
|
||||||
|
} catch (const nlohmann::json::parse_error &e) {
|
||||||
|
throw AuthException("Couldn't load auth data!");
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
}; // namespace
|
||||||
|
|
||||||
|
Auth::Auth(std::string storage_directory, Config config)
|
||||||
|
: storage_(std::move(storage_directory)), module_(FLAGS_auth_module_executable), config_{std::move(config)} {
|
||||||
|
MigrateVersions(storage_);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<UserOrRole> Auth::Authenticate(const std::string &username, const std::string &password) {
|
||||||
if (module_.IsUsed()) {
|
if (module_.IsUsed()) {
|
||||||
|
/*
|
||||||
|
* MODULE AUTH STORAGE
|
||||||
|
*/
|
||||||
const auto license_check_result = license::global_license_checker.IsEnterpriseValid(utils::global_settings);
|
const auto license_check_result = license::global_license_checker.IsEnterpriseValid(utils::global_settings);
|
||||||
if (license_check_result.HasError()) {
|
if (license_check_result.HasError()) {
|
||||||
spdlog::warn(license::LicenseCheckErrorToString(license_check_result.GetError(), "authentication modules"));
|
spdlog::warn(license::LicenseCheckErrorToString(license_check_result.GetError(), "authentication modules"));
|
||||||
@@ -92,98 +265,64 @@ std::optional<User> Auth::Authenticate(const std::string &username, const std::s
|
|||||||
auto is_authenticated = ret_authenticated.get<bool>();
|
auto is_authenticated = ret_authenticated.get<bool>();
|
||||||
const auto &rolename = ret_role.get<std::string>();
|
const auto &rolename = ret_role.get<std::string>();
|
||||||
|
|
||||||
|
// Check if role is present
|
||||||
|
auto role = GetRole(rolename);
|
||||||
|
if (!role) {
|
||||||
|
spdlog::warn(utils::MessageWithLink("Couldn't authenticate user '{}' because the role '{}' doesn't exist.",
|
||||||
|
username, rolename, "https://memgr.ph/auth"));
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
// Authenticate the user.
|
// Authenticate the user.
|
||||||
if (!is_authenticated) return std::nullopt;
|
if (!is_authenticated) return std::nullopt;
|
||||||
|
|
||||||
// Find or create the user and return it.
|
return RoleWUsername{username, std::move(*role)};
|
||||||
auto user = GetUser(username);
|
|
||||||
if (!user) {
|
|
||||||
if (FLAGS_auth_module_create_missing_user) {
|
|
||||||
user = AddUser(username, password);
|
|
||||||
if (!user) {
|
|
||||||
spdlog::warn(utils::MessageWithLink(
|
|
||||||
"Couldn't create the missing user '{}' using the auth module because the user already exists as a role.",
|
|
||||||
username, "https://memgr.ph/auth"));
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
spdlog::warn(utils::MessageWithLink(
|
|
||||||
"Couldn't authenticate user '{}' using the auth module because the user doesn't exist.", username,
|
|
||||||
"https://memgr.ph/auth"));
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
user->UpdatePassword(password);
|
|
||||||
}
|
|
||||||
if (FLAGS_auth_module_manage_roles) {
|
|
||||||
if (!rolename.empty()) {
|
|
||||||
auto role = GetRole(rolename);
|
|
||||||
if (!role) {
|
|
||||||
if (FLAGS_auth_module_create_missing_role) {
|
|
||||||
role = AddRole(rolename);
|
|
||||||
if (!role) {
|
|
||||||
spdlog::warn(
|
|
||||||
utils::MessageWithLink("Couldn't authenticate user '{}' using the auth module because the user's "
|
|
||||||
"role '{}' already exists as a user.",
|
|
||||||
username, rolename, "https://memgr.ph/auth"));
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
SaveRole(*role);
|
|
||||||
} else {
|
|
||||||
spdlog::warn(utils::MessageWithLink(
|
|
||||||
"Couldn't authenticate user '{}' using the auth module because the user's role '{}' doesn't exist.",
|
|
||||||
username, rolename, "https://memgr.ph/auth"));
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
user->SetRole(*role);
|
|
||||||
} else {
|
|
||||||
user->ClearRole();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SaveUser(*user);
|
|
||||||
return user;
|
|
||||||
} else {
|
|
||||||
auto user = GetUser(username);
|
|
||||||
if (!user) {
|
|
||||||
spdlog::warn(utils::MessageWithLink("Couldn't authenticate user '{}' because the user doesn't exist.", username,
|
|
||||||
"https://memgr.ph/auth"));
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
if (!user->CheckPassword(password)) {
|
|
||||||
spdlog::warn(utils::MessageWithLink("Couldn't authenticate user '{}' because the password is not correct.",
|
|
||||||
username, "https://memgr.ph/auth"));
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
return user;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* LOCAL AUTH STORAGE
|
||||||
|
*/
|
||||||
|
auto user = GetUser(username);
|
||||||
|
if (!user) {
|
||||||
|
spdlog::warn(utils::MessageWithLink("Couldn't authenticate user '{}' because the user doesn't exist.", username,
|
||||||
|
"https://memgr.ph/auth"));
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
if (!user->CheckPassword(password)) {
|
||||||
|
spdlog::warn(utils::MessageWithLink("Couldn't authenticate user '{}' because the password is not correct.",
|
||||||
|
username, "https://memgr.ph/auth"));
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
if (user->UpgradeHash(password)) {
|
||||||
|
SaveUser(*user);
|
||||||
|
}
|
||||||
|
|
||||||
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<User> Auth::GetUser(const std::string &username_orig) const {
|
void Auth::LinkUser(User &user) const {
|
||||||
auto username = utils::ToLowerCase(username_orig);
|
auto link = storage_.Get(kLinkPrefix + user.username());
|
||||||
auto existing_user = storage_.Get(kUserPrefix + username);
|
|
||||||
if (!existing_user) return std::nullopt;
|
|
||||||
|
|
||||||
nlohmann::json data;
|
|
||||||
try {
|
|
||||||
data = nlohmann::json::parse(*existing_user);
|
|
||||||
} catch (const nlohmann::json::parse_error &e) {
|
|
||||||
throw AuthException("Couldn't load user data!");
|
|
||||||
}
|
|
||||||
|
|
||||||
auto user = User::Deserialize(data);
|
|
||||||
auto link = storage_.Get(kLinkPrefix + username);
|
|
||||||
|
|
||||||
if (link) {
|
if (link) {
|
||||||
auto role = GetRole(*link);
|
auto role = GetRole(*link);
|
||||||
if (role) {
|
if (role) {
|
||||||
user.SetRole(*role);
|
user.SetRole(*role);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<User> Auth::GetUser(const std::string &username_orig) const {
|
||||||
|
if (module_.IsUsed()) return std::nullopt; // User's are not supported when using module
|
||||||
|
auto username = utils::ToLowerCase(username_orig);
|
||||||
|
auto existing_user = storage_.Get(kUserPrefix + username);
|
||||||
|
if (!existing_user) return std::nullopt;
|
||||||
|
|
||||||
|
auto user = User::Deserialize(ParseJson(*existing_user));
|
||||||
|
LinkUser(user);
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Auth::SaveUser(const User &user) {
|
void Auth::SaveUser(const User &user, system::Transaction *system_tx) {
|
||||||
|
DisableIfModuleUsed();
|
||||||
bool success = false;
|
bool success = false;
|
||||||
if (const auto *role = user.role(); role != nullptr) {
|
if (const auto *role = user.role(); role != nullptr) {
|
||||||
success = storage_.PutMultiple(
|
success = storage_.PutMultiple(
|
||||||
@@ -195,26 +334,83 @@ void Auth::SaveUser(const User &user) {
|
|||||||
if (!success) {
|
if (!success) {
|
||||||
throw AuthException("Couldn't save user '{}'!", user.username());
|
throw AuthException("Couldn't save user '{}'!", user.username());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Durability updated -> new epoch
|
||||||
|
UpdateEpoch();
|
||||||
|
|
||||||
|
// All changes to the user end up calling this function, so no need to add a delta anywhere else
|
||||||
|
if (system_tx) {
|
||||||
|
#ifdef MG_ENTERPRISE
|
||||||
|
system_tx->AddAction<UpdateAuthData>(user);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<User> Auth::AddUser(const std::string &username, const std::optional<std::string> &password) {
|
void Auth::UpdatePassword(auth::User &user, const std::optional<std::string> &password) {
|
||||||
|
DisableIfModuleUsed();
|
||||||
|
// Check if null
|
||||||
|
if (!password) {
|
||||||
|
if (!config_.password_permit_null) {
|
||||||
|
throw AuthException("Null passwords aren't permitted!");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Check if compliant with our filter
|
||||||
|
if (config_.custom_password_regex) {
|
||||||
|
if (const auto license_check_result = license::global_license_checker.IsEnterpriseValid(utils::global_settings);
|
||||||
|
license_check_result.HasError()) {
|
||||||
|
throw AuthException(
|
||||||
|
"Custom password regex is a Memgraph Enterprise feature. Please set the config "
|
||||||
|
"(\"--auth-password-strength-regex\") to its default value (\"{}\") or remove the flag.\n{}",
|
||||||
|
glue::kDefaultPasswordRegex,
|
||||||
|
license::LicenseCheckErrorToString(license_check_result.GetError(), "password regex"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!std::regex_match(*password, config_.password_regex)) {
|
||||||
|
throw AuthException(
|
||||||
|
"The user password doesn't conform to the required strength! Regex: "
|
||||||
|
"\"{}\"",
|
||||||
|
config_.password_regex_str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// All checks passed; update
|
||||||
|
user.UpdatePassword(password);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<User> Auth::AddUser(const std::string &username, const std::optional<std::string> &password,
|
||||||
|
system::Transaction *system_tx) {
|
||||||
|
DisableIfModuleUsed();
|
||||||
|
if (!NameRegexMatch(username)) {
|
||||||
|
throw AuthException("Invalid user name.");
|
||||||
|
}
|
||||||
auto existing_user = GetUser(username);
|
auto existing_user = GetUser(username);
|
||||||
if (existing_user) return std::nullopt;
|
if (existing_user) return std::nullopt;
|
||||||
auto existing_role = GetRole(username);
|
auto existing_role = GetRole(username);
|
||||||
if (existing_role) return std::nullopt;
|
if (existing_role) return std::nullopt;
|
||||||
auto new_user = User(username);
|
auto new_user = User(username);
|
||||||
new_user.UpdatePassword(password);
|
UpdatePassword(new_user, password);
|
||||||
SaveUser(new_user);
|
SaveUser(new_user, system_tx);
|
||||||
return new_user;
|
return new_user;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Auth::RemoveUser(const std::string &username_orig) {
|
bool Auth::RemoveUser(const std::string &username_orig, system::Transaction *system_tx) {
|
||||||
|
DisableIfModuleUsed();
|
||||||
auto username = utils::ToLowerCase(username_orig);
|
auto username = utils::ToLowerCase(username_orig);
|
||||||
if (!storage_.Get(kUserPrefix + username)) return false;
|
if (!storage_.Get(kUserPrefix + username)) return false;
|
||||||
std::vector<std::string> keys({kLinkPrefix + username, kUserPrefix + username});
|
std::vector<std::string> keys({kLinkPrefix + username, kUserPrefix + username});
|
||||||
if (!storage_.DeleteMultiple(keys)) {
|
if (!storage_.DeleteMultiple(keys)) {
|
||||||
throw AuthException("Couldn't remove user '{}'!", username);
|
throw AuthException("Couldn't remove user '{}'!", username);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Durability updated -> new epoch
|
||||||
|
UpdateEpoch();
|
||||||
|
|
||||||
|
// Handling drop user delta
|
||||||
|
if (system_tx) {
|
||||||
|
#ifdef MG_ENTERPRISE
|
||||||
|
system_tx->AddAction<DropAuthData>(DropAuthData::AuthDataType::USER, username);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,9 +419,28 @@ std::vector<auth::User> Auth::AllUsers() const {
|
|||||||
for (auto it = storage_.begin(kUserPrefix); it != storage_.end(kUserPrefix); ++it) {
|
for (auto it = storage_.begin(kUserPrefix); it != storage_.end(kUserPrefix); ++it) {
|
||||||
auto username = it->first.substr(kUserPrefix.size());
|
auto username = it->first.substr(kUserPrefix.size());
|
||||||
if (username != utils::ToLowerCase(username)) continue;
|
if (username != utils::ToLowerCase(username)) continue;
|
||||||
auto user = GetUser(username);
|
try {
|
||||||
if (user) {
|
User user = auth::User::Deserialize(ParseJson(it->second)); // Will throw on failure
|
||||||
ret.push_back(std::move(*user));
|
LinkUser(user);
|
||||||
|
ret.emplace_back(std::move(user));
|
||||||
|
} catch (AuthException &) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> Auth::AllUsernames() const {
|
||||||
|
std::vector<std::string> ret;
|
||||||
|
for (auto it = storage_.begin(kUserPrefix); it != storage_.end(kUserPrefix); ++it) {
|
||||||
|
auto username = it->first.substr(kUserPrefix.size());
|
||||||
|
if (username != utils::ToLowerCase(username)) continue;
|
||||||
|
try {
|
||||||
|
// Check if serialized correctly
|
||||||
|
memgraph::auth::User::Deserialize(ParseJson(it->second)); // Will throw on failure
|
||||||
|
ret.emplace_back(std::move(username));
|
||||||
|
} catch (AuthException &) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
@@ -233,38 +448,44 @@ std::vector<auth::User> Auth::AllUsers() const {
|
|||||||
|
|
||||||
bool Auth::HasUsers() const { return storage_.begin(kUserPrefix) != storage_.end(kUserPrefix); }
|
bool Auth::HasUsers() const { return storage_.begin(kUserPrefix) != storage_.end(kUserPrefix); }
|
||||||
|
|
||||||
|
bool Auth::AccessControlled() const { return HasUsers() || module_.IsUsed(); }
|
||||||
|
|
||||||
std::optional<Role> Auth::GetRole(const std::string &rolename_orig) const {
|
std::optional<Role> Auth::GetRole(const std::string &rolename_orig) const {
|
||||||
auto rolename = utils::ToLowerCase(rolename_orig);
|
auto rolename = utils::ToLowerCase(rolename_orig);
|
||||||
auto existing_role = storage_.Get(kRolePrefix + rolename);
|
auto existing_role = storage_.Get(kRolePrefix + rolename);
|
||||||
if (!existing_role) return std::nullopt;
|
if (!existing_role) return std::nullopt;
|
||||||
|
|
||||||
nlohmann::json data;
|
return Role::Deserialize(ParseJson(*existing_role));
|
||||||
try {
|
|
||||||
data = nlohmann::json::parse(*existing_role);
|
|
||||||
} catch (const nlohmann::json::parse_error &e) {
|
|
||||||
throw AuthException("Couldn't load role data!");
|
|
||||||
}
|
|
||||||
|
|
||||||
return Role::Deserialize(data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Auth::SaveRole(const Role &role) {
|
void Auth::SaveRole(const Role &role, system::Transaction *system_tx) {
|
||||||
if (!storage_.Put(kRolePrefix + role.rolename(), role.Serialize().dump())) {
|
if (!storage_.Put(kRolePrefix + role.rolename(), role.Serialize().dump())) {
|
||||||
throw AuthException("Couldn't save role '{}'!", role.rolename());
|
throw AuthException("Couldn't save role '{}'!", role.rolename());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Durability updated -> new epoch
|
||||||
|
UpdateEpoch();
|
||||||
|
|
||||||
|
// All changes to the role end up calling this function, so no need to add a delta anywhere else
|
||||||
|
if (system_tx) {
|
||||||
|
#ifdef MG_ENTERPRISE
|
||||||
|
system_tx->AddAction<UpdateAuthData>(role);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<Role> Auth::AddRole(const std::string &rolename) {
|
std::optional<Role> Auth::AddRole(const std::string &rolename, system::Transaction *system_tx) {
|
||||||
auto existing_role = GetRole(rolename);
|
if (!NameRegexMatch(rolename)) {
|
||||||
if (existing_role) return std::nullopt;
|
throw AuthException("Invalid role name.");
|
||||||
auto existing_user = GetUser(rolename);
|
}
|
||||||
if (existing_user) return std::nullopt;
|
if (auto existing_role = GetRole(rolename)) return std::nullopt;
|
||||||
|
if (auto existing_user = GetUser(rolename)) return std::nullopt;
|
||||||
auto new_role = Role(rolename);
|
auto new_role = Role(rolename);
|
||||||
SaveRole(new_role);
|
SaveRole(new_role, system_tx);
|
||||||
return new_role;
|
return new_role;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Auth::RemoveRole(const std::string &rolename_orig) {
|
bool Auth::RemoveRole(const std::string &rolename_orig, system::Transaction *system_tx) {
|
||||||
auto rolename = utils::ToLowerCase(rolename_orig);
|
auto rolename = utils::ToLowerCase(rolename_orig);
|
||||||
if (!storage_.Get(kRolePrefix + rolename)) return false;
|
if (!storage_.Get(kRolePrefix + rolename)) return false;
|
||||||
std::vector<std::string> keys;
|
std::vector<std::string> keys;
|
||||||
@@ -277,6 +498,16 @@ bool Auth::RemoveRole(const std::string &rolename_orig) {
|
|||||||
if (!storage_.DeleteMultiple(keys)) {
|
if (!storage_.DeleteMultiple(keys)) {
|
||||||
throw AuthException("Couldn't remove role '{}'!", rolename);
|
throw AuthException("Couldn't remove role '{}'!", rolename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Durability updated -> new epoch
|
||||||
|
UpdateEpoch();
|
||||||
|
|
||||||
|
// Handling drop role delta
|
||||||
|
if (system_tx) {
|
||||||
|
#ifdef MG_ENTERPRISE
|
||||||
|
system_tx->AddAction<DropAuthData>(DropAuthData::AuthDataType::ROLE, rolename);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,26 +516,38 @@ std::vector<auth::Role> Auth::AllRoles() const {
|
|||||||
for (auto it = storage_.begin(kRolePrefix); it != storage_.end(kRolePrefix); ++it) {
|
for (auto it = storage_.begin(kRolePrefix); it != storage_.end(kRolePrefix); ++it) {
|
||||||
auto rolename = it->first.substr(kRolePrefix.size());
|
auto rolename = it->first.substr(kRolePrefix.size());
|
||||||
if (rolename != utils::ToLowerCase(rolename)) continue;
|
if (rolename != utils::ToLowerCase(rolename)) continue;
|
||||||
auto role = GetRole(rolename);
|
Role role = memgraph::auth::Role::Deserialize(ParseJson(it->second)); // Will throw on failure
|
||||||
if (role) {
|
ret.emplace_back(std::move(role));
|
||||||
ret.push_back(*role);
|
}
|
||||||
} else {
|
return ret;
|
||||||
throw AuthException("Couldn't load role '{}'!", rolename);
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> Auth::AllRolenames() const {
|
||||||
|
std::vector<std::string> ret;
|
||||||
|
for (auto it = storage_.begin(kRolePrefix); it != storage_.end(kRolePrefix); ++it) {
|
||||||
|
auto rolename = it->first.substr(kRolePrefix.size());
|
||||||
|
if (rolename != utils::ToLowerCase(rolename)) continue;
|
||||||
|
try {
|
||||||
|
// Check that the data is serialized correctly
|
||||||
|
memgraph::auth::Role::Deserialize(ParseJson(it->second));
|
||||||
|
ret.emplace_back(std::move(rolename));
|
||||||
|
} catch (AuthException &) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<auth::User> Auth::AllUsersForRole(const std::string &rolename_orig) const {
|
std::vector<auth::User> Auth::AllUsersForRole(const std::string &rolename_orig) const {
|
||||||
auto rolename = utils::ToLowerCase(rolename_orig);
|
DisableIfModuleUsed();
|
||||||
|
const auto rolename = utils::ToLowerCase(rolename_orig);
|
||||||
std::vector<auth::User> ret;
|
std::vector<auth::User> ret;
|
||||||
for (auto it = storage_.begin(kLinkPrefix); it != storage_.end(kLinkPrefix); ++it) {
|
for (auto it = storage_.begin(kLinkPrefix); it != storage_.end(kLinkPrefix); ++it) {
|
||||||
auto username = it->first.substr(kLinkPrefix.size());
|
auto username = it->first.substr(kLinkPrefix.size());
|
||||||
if (username != utils::ToLowerCase(username)) continue;
|
if (username != utils::ToLowerCase(username)) continue;
|
||||||
if (it->second != utils::ToLowerCase(it->second)) continue;
|
if (it->second != utils::ToLowerCase(it->second)) continue;
|
||||||
if (it->second == rolename) {
|
if (it->second == rolename) {
|
||||||
auto user = GetUser(username);
|
if (auto user = GetUser(username)) {
|
||||||
if (user) {
|
|
||||||
ret.push_back(std::move(*user));
|
ret.push_back(std::move(*user));
|
||||||
} else {
|
} else {
|
||||||
throw AuthException("Couldn't load user '{}'!", username);
|
throw AuthException("Couldn't load user '{}'!", username);
|
||||||
@@ -315,56 +558,192 @@ std::vector<auth::User> Auth::AllUsersForRole(const std::string &rolename_orig)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MG_ENTERPRISE
|
#ifdef MG_ENTERPRISE
|
||||||
bool Auth::GrantDatabaseToUser(const std::string &db, const std::string &name) {
|
Auth::Result Auth::GrantDatabase(const std::string &db, const std::string &name, system::Transaction *system_tx) {
|
||||||
auto user = GetUser(name);
|
using enum Auth::Result;
|
||||||
if (user) {
|
if (module_.IsUsed()) {
|
||||||
if (db == kAllDatabases) {
|
if (auto role = GetRole(name)) {
|
||||||
user->db_access().GrantAll();
|
GrantDatabase(db, *role, system_tx);
|
||||||
} else {
|
return SUCCESS;
|
||||||
user->db_access().Add(db);
|
|
||||||
}
|
}
|
||||||
SaveUser(*user);
|
return NO_ROLE;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
if (auto user = GetUser(name)) {
|
||||||
|
GrantDatabase(db, *user, system_tx);
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
if (auto role = GetRole(name)) {
|
||||||
|
GrantDatabase(db, *role, system_tx);
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
return NO_USER_ROLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Auth::RevokeDatabaseFromUser(const std::string &db, const std::string &name) {
|
void Auth::GrantDatabase(const std::string &db, User &user, system::Transaction *system_tx) {
|
||||||
auto user = GetUser(name);
|
if (db == kAllDatabases) {
|
||||||
if (user) {
|
user.db_access().GrantAll();
|
||||||
if (db == kAllDatabases) {
|
} else {
|
||||||
user->db_access().DenyAll();
|
user.db_access().Grant(db);
|
||||||
} else {
|
|
||||||
user->db_access().Remove(db);
|
|
||||||
}
|
|
||||||
SaveUser(*user);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
SaveUser(user, system_tx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Auth::DeleteDatabase(const std::string &db) {
|
void Auth::GrantDatabase(const std::string &db, Role &role, system::Transaction *system_tx) {
|
||||||
|
if (db == kAllDatabases) {
|
||||||
|
role.db_access().GrantAll();
|
||||||
|
} else {
|
||||||
|
role.db_access().Grant(db);
|
||||||
|
}
|
||||||
|
SaveRole(role, system_tx);
|
||||||
|
}
|
||||||
|
|
||||||
|
Auth::Result Auth::DenyDatabase(const std::string &db, const std::string &name, system::Transaction *system_tx) {
|
||||||
|
using enum Auth::Result;
|
||||||
|
if (module_.IsUsed()) {
|
||||||
|
if (auto role = GetRole(name)) {
|
||||||
|
DenyDatabase(db, *role, system_tx);
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
return NO_ROLE;
|
||||||
|
}
|
||||||
|
if (auto user = GetUser(name)) {
|
||||||
|
DenyDatabase(db, *user, system_tx);
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
if (auto role = GetRole(name)) {
|
||||||
|
DenyDatabase(db, *role, system_tx);
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
return NO_USER_ROLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Auth::DenyDatabase(const std::string &db, User &user, system::Transaction *system_tx) {
|
||||||
|
if (db == kAllDatabases) {
|
||||||
|
user.db_access().DenyAll();
|
||||||
|
} else {
|
||||||
|
user.db_access().Deny(db);
|
||||||
|
}
|
||||||
|
SaveUser(user, system_tx);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Auth::DenyDatabase(const std::string &db, Role &role, system::Transaction *system_tx) {
|
||||||
|
if (db == kAllDatabases) {
|
||||||
|
role.db_access().DenyAll();
|
||||||
|
} else {
|
||||||
|
role.db_access().Deny(db);
|
||||||
|
}
|
||||||
|
SaveRole(role, system_tx);
|
||||||
|
}
|
||||||
|
|
||||||
|
Auth::Result Auth::RevokeDatabase(const std::string &db, const std::string &name, system::Transaction *system_tx) {
|
||||||
|
using enum Auth::Result;
|
||||||
|
if (module_.IsUsed()) {
|
||||||
|
if (auto role = GetRole(name)) {
|
||||||
|
RevokeDatabase(db, *role, system_tx);
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
return NO_ROLE;
|
||||||
|
}
|
||||||
|
if (auto user = GetUser(name)) {
|
||||||
|
RevokeDatabase(db, *user, system_tx);
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
if (auto role = GetRole(name)) {
|
||||||
|
RevokeDatabase(db, *role, system_tx);
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
return NO_USER_ROLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Auth::RevokeDatabase(const std::string &db, User &user, system::Transaction *system_tx) {
|
||||||
|
if (db == kAllDatabases) {
|
||||||
|
user.db_access().RevokeAll();
|
||||||
|
} else {
|
||||||
|
user.db_access().Revoke(db);
|
||||||
|
}
|
||||||
|
SaveUser(user, system_tx);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Auth::RevokeDatabase(const std::string &db, Role &role, system::Transaction *system_tx) {
|
||||||
|
if (db == kAllDatabases) {
|
||||||
|
role.db_access().RevokeAll();
|
||||||
|
} else {
|
||||||
|
role.db_access().Revoke(db);
|
||||||
|
}
|
||||||
|
SaveRole(role, system_tx);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Auth::DeleteDatabase(const std::string &db, system::Transaction *system_tx) {
|
||||||
for (auto it = storage_.begin(kUserPrefix); it != storage_.end(kUserPrefix); ++it) {
|
for (auto it = storage_.begin(kUserPrefix); it != storage_.end(kUserPrefix); ++it) {
|
||||||
auto username = it->first.substr(kUserPrefix.size());
|
auto username = it->first.substr(kUserPrefix.size());
|
||||||
auto user = GetUser(username);
|
try {
|
||||||
if (user) {
|
User user = auth::User::Deserialize(ParseJson(it->second));
|
||||||
user->db_access().Delete(db);
|
LinkUser(user);
|
||||||
SaveUser(*user);
|
user.db_access().Revoke(db);
|
||||||
|
SaveUser(user, system_tx);
|
||||||
|
} catch (AuthException &) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (auto it = storage_.begin(kRolePrefix); it != storage_.end(kRolePrefix); ++it) {
|
||||||
|
auto rolename = it->first.substr(kRolePrefix.size());
|
||||||
|
try {
|
||||||
|
auto role = memgraph::auth::Role::Deserialize(ParseJson(it->second));
|
||||||
|
role.db_access().Revoke(db);
|
||||||
|
SaveRole(role, system_tx);
|
||||||
|
} catch (AuthException &) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Auth::SetMainDatabase(const std::string &db, const std::string &name) {
|
Auth::Result Auth::SetMainDatabase(std::string_view db, const std::string &name, system::Transaction *system_tx) {
|
||||||
auto user = GetUser(name);
|
using enum Auth::Result;
|
||||||
if (user) {
|
if (module_.IsUsed()) {
|
||||||
if (!user->db_access().SetDefault(db)) {
|
if (auto role = GetRole(name)) {
|
||||||
throw AuthException("Couldn't set default database '{}' for user '{}'!", db, name);
|
SetMainDatabase(db, *role, system_tx);
|
||||||
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
SaveUser(*user);
|
return NO_ROLE;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
if (auto user = GetUser(name)) {
|
||||||
|
SetMainDatabase(db, *user, system_tx);
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
if (auto role = GetRole(name)) {
|
||||||
|
SetMainDatabase(db, *role, system_tx);
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
return NO_USER_ROLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Auth::SetMainDatabase(std::string_view db, User &user, system::Transaction *system_tx) {
|
||||||
|
if (!user.db_access().SetMain(db)) {
|
||||||
|
throw AuthException("Couldn't set default database '{}' for '{}'!", db, user.username());
|
||||||
|
}
|
||||||
|
SaveUser(user, system_tx);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Auth::SetMainDatabase(std::string_view db, Role &role, system::Transaction *system_tx) {
|
||||||
|
if (!role.db_access().SetMain(db)) {
|
||||||
|
throw AuthException("Couldn't set default database '{}' for '{}'!", db, role.rolename());
|
||||||
|
}
|
||||||
|
SaveRole(role, system_tx);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
bool Auth::NameRegexMatch(const std::string &user_or_role) const {
|
||||||
|
if (config_.custom_name_regex) {
|
||||||
|
if (const auto license_check_result =
|
||||||
|
memgraph::license::global_license_checker.IsEnterpriseValid(memgraph::utils::global_settings);
|
||||||
|
license_check_result.HasError()) {
|
||||||
|
throw memgraph::auth::AuthException(
|
||||||
|
"Custom user/role regex is a Memgraph Enterprise feature. Please set the config "
|
||||||
|
"(\"--auth-user-or-role-name-regex\") to its default value (\"{}\") or remove the flag.\n{}",
|
||||||
|
glue::kDefaultUserRoleRegex,
|
||||||
|
memgraph::license::LicenseCheckErrorToString(license_check_result.GetError(), "user/role regex"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return std::regex_match(user_or_role, config_.name_regex);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace memgraph::auth
|
} // namespace memgraph::auth
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2023 Memgraph Ltd.
|
// Copyright 2024 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Licensed as a Memgraph Enterprise file under the Memgraph Enterprise
|
// Licensed as a Memgraph Enterprise file under the Memgraph Enterprise
|
||||||
// License (the "License"); by using this file, you agree to be bound by the terms of the License, and you may not use
|
// License (the "License"); by using this file, you agree to be bound by the terms of the License, and you may not use
|
||||||
@@ -10,18 +10,37 @@
|
|||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include <regex>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "auth/exceptions.hpp"
|
#include "auth/exceptions.hpp"
|
||||||
#include "auth/models.hpp"
|
#include "auth/models.hpp"
|
||||||
#include "auth/module.hpp"
|
#include "auth/module.hpp"
|
||||||
|
#include "glue/auth_global.hpp"
|
||||||
#include "kvstore/kvstore.hpp"
|
#include "kvstore/kvstore.hpp"
|
||||||
|
#include "system/action.hpp"
|
||||||
#include "utils/settings.hpp"
|
#include "utils/settings.hpp"
|
||||||
|
#include "utils/synchronized.hpp"
|
||||||
|
|
||||||
namespace memgraph::auth {
|
namespace memgraph::auth {
|
||||||
|
|
||||||
|
class Auth;
|
||||||
|
using SynchedAuth = memgraph::utils::Synchronized<memgraph::auth::Auth, memgraph::utils::WritePrioritizedRWLock>;
|
||||||
|
|
||||||
static const constexpr char *const kAllDatabases = "*";
|
static const constexpr char *const kAllDatabases = "*";
|
||||||
|
|
||||||
|
struct RoleWUsername : Role {
|
||||||
|
template <typename... Args>
|
||||||
|
RoleWUsername(std::string_view username, Args &&...args) : Role{std::forward<Args>(args)...}, username_{username} {}
|
||||||
|
|
||||||
|
std::string username() { return username_; }
|
||||||
|
const std::string &username() const { return username_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string username_;
|
||||||
|
};
|
||||||
|
using UserOrRole = std::variant<User, RoleWUsername>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class serves as the main Authentication/Authorization storage.
|
* This class serves as the main Authentication/Authorization storage.
|
||||||
* It provides functions for managing Users, Roles, Permissions and FineGrainedAccessPermissions.
|
* It provides functions for managing Users, Roles, Permissions and FineGrainedAccessPermissions.
|
||||||
@@ -31,7 +50,66 @@ static const constexpr char *const kAllDatabases = "*";
|
|||||||
*/
|
*/
|
||||||
class Auth final {
|
class Auth final {
|
||||||
public:
|
public:
|
||||||
explicit Auth(const std::string &storage_directory);
|
struct Config {
|
||||||
|
Config() {}
|
||||||
|
Config(std::string name_regex, std::string password_regex, bool password_permit_null)
|
||||||
|
: name_regex_str{std::move(name_regex)},
|
||||||
|
password_regex_str{std::move(password_regex)},
|
||||||
|
password_permit_null{password_permit_null},
|
||||||
|
custom_name_regex{name_regex_str != glue::kDefaultUserRoleRegex},
|
||||||
|
name_regex{name_regex_str},
|
||||||
|
custom_password_regex{password_regex_str != glue::kDefaultPasswordRegex},
|
||||||
|
password_regex{password_regex_str} {}
|
||||||
|
|
||||||
|
std::string name_regex_str{glue::kDefaultUserRoleRegex};
|
||||||
|
std::string password_regex_str{glue::kDefaultPasswordRegex};
|
||||||
|
bool password_permit_null{true};
|
||||||
|
|
||||||
|
private:
|
||||||
|
friend class Auth;
|
||||||
|
bool custom_name_regex{false};
|
||||||
|
std::regex name_regex{name_regex_str};
|
||||||
|
bool custom_password_regex{false};
|
||||||
|
std::regex password_regex{password_regex_str};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Epoch {
|
||||||
|
Epoch() : epoch_{0} {}
|
||||||
|
Epoch(unsigned e) : epoch_{e} {}
|
||||||
|
|
||||||
|
Epoch operator++() { return ++epoch_; }
|
||||||
|
bool operator==(const Epoch &rhs) const = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
unsigned epoch_;
|
||||||
|
};
|
||||||
|
|
||||||
|
static const Epoch kStartEpoch;
|
||||||
|
|
||||||
|
enum class Result {
|
||||||
|
SUCCESS,
|
||||||
|
NO_USER_ROLE,
|
||||||
|
NO_ROLE,
|
||||||
|
};
|
||||||
|
|
||||||
|
explicit Auth(std::string storage_directory, Config config);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the Config object
|
||||||
|
*
|
||||||
|
* @param config
|
||||||
|
*/
|
||||||
|
void SetConfig(Config config) {
|
||||||
|
// NOTE: The Auth class itself is not thread-safe, higher-level code needs to synchronize it when using it.
|
||||||
|
config_ = std::move(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @return Config
|
||||||
|
*/
|
||||||
|
Config GetConfig() const { return config_; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Authenticates a user using his username and password.
|
* Authenticates a user using his username and password.
|
||||||
@@ -42,7 +120,7 @@ class Auth final {
|
|||||||
* @return a user when the username and password match, nullopt otherwise
|
* @return a user when the username and password match, nullopt otherwise
|
||||||
* @throw AuthException if unable to authenticate for whatever reason.
|
* @throw AuthException if unable to authenticate for whatever reason.
|
||||||
*/
|
*/
|
||||||
std::optional<User> Authenticate(const std::string &username, const std::string &password);
|
std::optional<UserOrRole> Authenticate(const std::string &username, const std::string &password);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a user from the storage.
|
* Gets a user from the storage.
|
||||||
@@ -54,6 +132,8 @@ class Auth final {
|
|||||||
*/
|
*/
|
||||||
std::optional<User> GetUser(const std::string &username) const;
|
std::optional<User> GetUser(const std::string &username) const;
|
||||||
|
|
||||||
|
void LinkUser(User &user) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves a user object to the storage.
|
* Saves a user object to the storage.
|
||||||
*
|
*
|
||||||
@@ -61,7 +141,7 @@ class Auth final {
|
|||||||
*
|
*
|
||||||
* @throw AuthException if unable to save the user.
|
* @throw AuthException if unable to save the user.
|
||||||
*/
|
*/
|
||||||
void SaveUser(const User &user);
|
void SaveUser(const User &user, system::Transaction *system_tx = nullptr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a user if the user doesn't exist.
|
* Creates a user if the user doesn't exist.
|
||||||
@@ -72,7 +152,8 @@ class Auth final {
|
|||||||
* @return a user when the user is created, nullopt if the user exists
|
* @return a user when the user is created, nullopt if the user exists
|
||||||
* @throw AuthException if unable to save the user.
|
* @throw AuthException if unable to save the user.
|
||||||
*/
|
*/
|
||||||
std::optional<User> AddUser(const std::string &username, const std::optional<std::string> &password = std::nullopt);
|
std::optional<User> AddUser(const std::string &username, const std::optional<std::string> &password = std::nullopt,
|
||||||
|
system::Transaction *system_tx = nullptr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a user from the storage.
|
* Removes a user from the storage.
|
||||||
@@ -83,7 +164,15 @@ class Auth final {
|
|||||||
* doesn't exist
|
* doesn't exist
|
||||||
* @throw AuthException if unable to remove the user.
|
* @throw AuthException if unable to remove the user.
|
||||||
*/
|
*/
|
||||||
bool RemoveUser(const std::string &username);
|
bool RemoveUser(const std::string &username, system::Transaction *system_tx = nullptr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param user
|
||||||
|
* @param password
|
||||||
|
*/
|
||||||
|
void UpdatePassword(auth::User &user, const std::optional<std::string> &password);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all users from the storage.
|
* Gets all users from the storage.
|
||||||
@@ -93,6 +182,13 @@ class Auth final {
|
|||||||
*/
|
*/
|
||||||
std::vector<User> AllUsers() const;
|
std::vector<User> AllUsers() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @return std::vector<std::string>
|
||||||
|
*/
|
||||||
|
std::vector<std::string> AllUsernames() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether there are users in the storage.
|
* Returns whether there are users in the storage.
|
||||||
*
|
*
|
||||||
@@ -100,6 +196,13 @@ class Auth final {
|
|||||||
*/
|
*/
|
||||||
bool HasUsers() const;
|
bool HasUsers() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the access is controlled by authentication/authorization.
|
||||||
|
*
|
||||||
|
* @return `true` if auth needs to run
|
||||||
|
*/
|
||||||
|
bool AccessControlled() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a role from the storage.
|
* Gets a role from the storage.
|
||||||
*
|
*
|
||||||
@@ -110,6 +213,37 @@ class Auth final {
|
|||||||
*/
|
*/
|
||||||
std::optional<Role> GetRole(const std::string &rolename) const;
|
std::optional<Role> GetRole(const std::string &rolename) const;
|
||||||
|
|
||||||
|
std::optional<UserOrRole> GetUserOrRole(const std::optional<std::string> &username,
|
||||||
|
const std::optional<std::string> &rolename) const {
|
||||||
|
auto expect = [](bool condition, std::string &&msg) {
|
||||||
|
if (!condition) throw AuthException(std::move(msg));
|
||||||
|
};
|
||||||
|
// Special case if we are using a module; we must find the specified role
|
||||||
|
if (module_.IsUsed()) {
|
||||||
|
expect(username && rolename, "When using a module, a role needs to be connected to a username.");
|
||||||
|
const auto role = GetRole(*rolename);
|
||||||
|
expect(role != std::nullopt, "No role named " + *rolename);
|
||||||
|
return UserOrRole(auth::RoleWUsername{*username, *role});
|
||||||
|
}
|
||||||
|
|
||||||
|
// First check if we need to find a role
|
||||||
|
if (username && rolename) {
|
||||||
|
const auto role = GetRole(*rolename);
|
||||||
|
expect(role != std::nullopt, "No role named " + *rolename);
|
||||||
|
return UserOrRole(auth::RoleWUsername{*username, *role});
|
||||||
|
}
|
||||||
|
|
||||||
|
// We are only looking for a user
|
||||||
|
if (username) {
|
||||||
|
const auto user = GetUser(*username);
|
||||||
|
expect(user != std::nullopt, "No user named " + *username);
|
||||||
|
return *user;
|
||||||
|
}
|
||||||
|
|
||||||
|
// No user or role
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves a role object to the storage.
|
* Saves a role object to the storage.
|
||||||
*
|
*
|
||||||
@@ -117,7 +251,7 @@ class Auth final {
|
|||||||
*
|
*
|
||||||
* @throw AuthException if unable to save the role.
|
* @throw AuthException if unable to save the role.
|
||||||
*/
|
*/
|
||||||
void SaveRole(const Role &role);
|
void SaveRole(const Role &role, system::Transaction *system_tx = nullptr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a role if the role doesn't exist.
|
* Creates a role if the role doesn't exist.
|
||||||
@@ -127,7 +261,7 @@ class Auth final {
|
|||||||
* @return a role when the role is created, nullopt if the role exists
|
* @return a role when the role is created, nullopt if the role exists
|
||||||
* @throw AuthException if unable to save the role.
|
* @throw AuthException if unable to save the role.
|
||||||
*/
|
*/
|
||||||
std::optional<Role> AddRole(const std::string &rolename);
|
std::optional<Role> AddRole(const std::string &rolename, system::Transaction *system_tx = nullptr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a role from the storage.
|
* Removes a role from the storage.
|
||||||
@@ -138,7 +272,7 @@ class Auth final {
|
|||||||
* doesn't exist
|
* doesn't exist
|
||||||
* @throw AuthException if unable to remove the role.
|
* @throw AuthException if unable to remove the role.
|
||||||
*/
|
*/
|
||||||
bool RemoveRole(const std::string &rolename);
|
bool RemoveRole(const std::string &rolename, system::Transaction *system_tx = nullptr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all roles from the storage.
|
* Gets all roles from the storage.
|
||||||
@@ -148,6 +282,13 @@ class Auth final {
|
|||||||
*/
|
*/
|
||||||
std::vector<Role> AllRoles() const;
|
std::vector<Role> AllRoles() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @return std::vector<std::string>
|
||||||
|
*/
|
||||||
|
std::vector<std::string> AllRolenames() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all users for a role from the storage.
|
* Gets all users for a role from the storage.
|
||||||
*
|
*
|
||||||
@@ -159,16 +300,6 @@ class Auth final {
|
|||||||
std::vector<User> AllUsersForRole(const std::string &rolename) const;
|
std::vector<User> AllUsersForRole(const std::string &rolename) const;
|
||||||
|
|
||||||
#ifdef MG_ENTERPRISE
|
#ifdef MG_ENTERPRISE
|
||||||
/**
|
|
||||||
* @brief Revoke access to individual database for a user.
|
|
||||||
*
|
|
||||||
* @param db name of the database to revoke
|
|
||||||
* @param name user's username
|
|
||||||
* @return true on success
|
|
||||||
* @throw AuthException if unable to find or update the user
|
|
||||||
*/
|
|
||||||
bool RevokeDatabaseFromUser(const std::string &db, const std::string &name);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Grant access to individual database for a user.
|
* @brief Grant access to individual database for a user.
|
||||||
*
|
*
|
||||||
@@ -177,7 +308,33 @@ class Auth final {
|
|||||||
* @return true on success
|
* @return true on success
|
||||||
* @throw AuthException if unable to find or update the user
|
* @throw AuthException if unable to find or update the user
|
||||||
*/
|
*/
|
||||||
bool GrantDatabaseToUser(const std::string &db, const std::string &name);
|
Result GrantDatabase(const std::string &db, const std::string &name, system::Transaction *system_tx = nullptr);
|
||||||
|
void GrantDatabase(const std::string &db, User &user, system::Transaction *system_tx = nullptr);
|
||||||
|
void GrantDatabase(const std::string &db, Role &role, system::Transaction *system_tx = nullptr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Revoke access to individual database for a user.
|
||||||
|
*
|
||||||
|
* @param db name of the database to revoke
|
||||||
|
* @param name user's username
|
||||||
|
* @return true on success
|
||||||
|
* @throw AuthException if unable to find or update the user
|
||||||
|
*/
|
||||||
|
Result DenyDatabase(const std::string &db, const std::string &name, system::Transaction *system_tx = nullptr);
|
||||||
|
void DenyDatabase(const std::string &db, User &user, system::Transaction *system_tx = nullptr);
|
||||||
|
void DenyDatabase(const std::string &db, Role &role, system::Transaction *system_tx = nullptr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Revoke access to individual database for a user.
|
||||||
|
*
|
||||||
|
* @param db name of the database to revoke
|
||||||
|
* @param name user's username
|
||||||
|
* @return true on success
|
||||||
|
* @throw AuthException if unable to find or update the user
|
||||||
|
*/
|
||||||
|
Result RevokeDatabase(const std::string &db, const std::string &name, system::Transaction *system_tx = nullptr);
|
||||||
|
void RevokeDatabase(const std::string &db, User &user, system::Transaction *system_tx = nullptr);
|
||||||
|
void RevokeDatabase(const std::string &db, Role &role, system::Transaction *system_tx = nullptr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Delete a database from all users.
|
* @brief Delete a database from all users.
|
||||||
@@ -185,7 +342,7 @@ class Auth final {
|
|||||||
* @param db name of the database to delete
|
* @param db name of the database to delete
|
||||||
* @throw AuthException if unable to read data
|
* @throw AuthException if unable to read data
|
||||||
*/
|
*/
|
||||||
void DeleteDatabase(const std::string &db);
|
void DeleteDatabase(const std::string &db, system::Transaction *system_tx = nullptr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set main database for an individual user.
|
* @brief Set main database for an individual user.
|
||||||
@@ -195,14 +352,39 @@ class Auth final {
|
|||||||
* @return true on success
|
* @return true on success
|
||||||
* @throw AuthException if unable to find or update the user
|
* @throw AuthException if unable to find or update the user
|
||||||
*/
|
*/
|
||||||
bool SetMainDatabase(const std::string &db, const std::string &name);
|
Result SetMainDatabase(std::string_view db, const std::string &name, system::Transaction *system_tx = nullptr);
|
||||||
|
void SetMainDatabase(std::string_view db, User &user, system::Transaction *system_tx = nullptr);
|
||||||
|
void SetMainDatabase(std::string_view db, Role &role, system::Transaction *system_tx = nullptr);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
bool UpToDate(Epoch &e) const {
|
||||||
|
bool res = e == epoch_;
|
||||||
|
e = epoch_;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param user_or_role
|
||||||
|
* @return true
|
||||||
|
* @return false
|
||||||
|
*/
|
||||||
|
bool NameRegexMatch(const std::string &user_or_role) const;
|
||||||
|
|
||||||
|
void UpdateEpoch() { ++epoch_; }
|
||||||
|
|
||||||
|
void DisableIfModuleUsed() const {
|
||||||
|
if (module_.IsUsed()) throw AuthException("Operation not permited when using an authentication module.");
|
||||||
|
}
|
||||||
|
|
||||||
// Even though the `kvstore::KVStore` class is guaranteed to be thread-safe,
|
// Even though the `kvstore::KVStore` class is guaranteed to be thread-safe,
|
||||||
// Auth is not thread-safe because modifying users and roles might require
|
// Auth is not thread-safe because modifying users and roles might require
|
||||||
// more than one operation on the storage.
|
// more than one operation on the storage.
|
||||||
kvstore::KVStore storage_;
|
kvstore::KVStore storage_;
|
||||||
auth::Module module_;
|
auth::Module module_;
|
||||||
|
Config config_;
|
||||||
|
Epoch epoch_{kStartEpoch};
|
||||||
};
|
};
|
||||||
} // namespace memgraph::auth
|
} // namespace memgraph::auth
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2023 Memgraph Ltd.
|
// Copyright 2024 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Licensed as a Memgraph Enterprise file under the Memgraph Enterprise
|
// Licensed as a Memgraph Enterprise file under the Memgraph Enterprise
|
||||||
// License (the "License"); by using this file, you agree to be bound by the terms of the License, and you may not use
|
// License (the "License"); by using this file, you agree to be bound by the terms of the License, and you may not use
|
||||||
@@ -22,10 +22,14 @@
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
using namespace std::literals;
|
using namespace std::literals;
|
||||||
inline constexpr std::array password_encryption_mappings{
|
|
||||||
std::pair{"bcrypt"sv, memgraph::auth::PasswordEncryptionAlgorithm::BCRYPT},
|
constexpr auto kHashAlgo = "hash_algo";
|
||||||
std::pair{"sha256"sv, memgraph::auth::PasswordEncryptionAlgorithm::SHA256},
|
constexpr auto kPasswordHash = "password_hash";
|
||||||
std::pair{"sha256-multiple"sv, memgraph::auth::PasswordEncryptionAlgorithm::SHA256_MULTIPLE}};
|
|
||||||
|
inline constexpr std::array password_hash_mappings{
|
||||||
|
std::pair{"bcrypt"sv, memgraph::auth::PasswordHashAlgorithm::BCRYPT},
|
||||||
|
std::pair{"sha256"sv, memgraph::auth::PasswordHashAlgorithm::SHA256},
|
||||||
|
std::pair{"sha256-multiple"sv, memgraph::auth::PasswordHashAlgorithm::SHA256_MULTIPLE}};
|
||||||
|
|
||||||
inline constexpr uint64_t ONE_SHA_ITERATION = 1;
|
inline constexpr uint64_t ONE_SHA_ITERATION = 1;
|
||||||
inline constexpr uint64_t MULTIPLE_SHA_ITERATIONS = 1024;
|
inline constexpr uint64_t MULTIPLE_SHA_ITERATIONS = 1024;
|
||||||
@@ -35,7 +39,7 @@ inline constexpr uint64_t MULTIPLE_SHA_ITERATIONS = 1024;
|
|||||||
DEFINE_VALIDATED_string(password_encryption_algorithm, "bcrypt",
|
DEFINE_VALIDATED_string(password_encryption_algorithm, "bcrypt",
|
||||||
"The password encryption algorithm used for authentication.", {
|
"The password encryption algorithm used for authentication.", {
|
||||||
if (const auto result =
|
if (const auto result =
|
||||||
memgraph::utils::IsValidEnumValueString(value, password_encryption_mappings);
|
memgraph::utils::IsValidEnumValueString(value, password_hash_mappings);
|
||||||
result.HasError()) {
|
result.HasError()) {
|
||||||
const auto error = result.GetError();
|
const auto error = result.GetError();
|
||||||
switch (error) {
|
switch (error) {
|
||||||
@@ -45,7 +49,7 @@ DEFINE_VALIDATED_string(password_encryption_algorithm, "bcrypt",
|
|||||||
}
|
}
|
||||||
case memgraph::utils::ValidationError::InvalidValue: {
|
case memgraph::utils::ValidationError::InvalidValue: {
|
||||||
std::cout << "Invalid value for password encryption algorithm. Allowed values: "
|
std::cout << "Invalid value for password encryption algorithm. Allowed values: "
|
||||||
<< memgraph::utils::GetAllowedEnumValuesString(password_encryption_mappings)
|
<< memgraph::utils::GetAllowedEnumValuesString(password_hash_mappings)
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -58,7 +62,7 @@ DEFINE_VALIDATED_string(password_encryption_algorithm, "bcrypt",
|
|||||||
|
|
||||||
namespace memgraph::auth {
|
namespace memgraph::auth {
|
||||||
namespace BCrypt {
|
namespace BCrypt {
|
||||||
std::string EncryptPassword(const std::string &password) {
|
std::string HashPassword(const std::string &password) {
|
||||||
char salt[BCRYPT_HASHSIZE];
|
char salt[BCRYPT_HASHSIZE];
|
||||||
char hash[BCRYPT_HASHSIZE];
|
char hash[BCRYPT_HASHSIZE];
|
||||||
|
|
||||||
@@ -86,16 +90,30 @@ bool VerifyPassword(const std::string &password, const std::string &hash) {
|
|||||||
} // namespace BCrypt
|
} // namespace BCrypt
|
||||||
|
|
||||||
namespace SHA {
|
namespace SHA {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
constexpr auto SHA_LENGTH = 64U;
|
||||||
|
constexpr auto SALT_SIZE = 16U;
|
||||||
|
constexpr auto SALT_SIZE_DURABLE = SALT_SIZE * 2;
|
||||||
|
|
||||||
#if OPENSSL_VERSION_MAJOR >= 3
|
#if OPENSSL_VERSION_MAJOR >= 3
|
||||||
std::string EncryptPasswordOpenSSL3(const std::string &password, const uint64_t number_of_iterations) {
|
std::string HashPasswordOpenSSL3(std::string_view password, const uint64_t number_of_iterations,
|
||||||
|
std::string_view salt) {
|
||||||
unsigned char hash[SHA256_DIGEST_LENGTH];
|
unsigned char hash[SHA256_DIGEST_LENGTH];
|
||||||
|
|
||||||
EVP_MD_CTX *ctx = EVP_MD_CTX_new();
|
EVP_MD_CTX *ctx = EVP_MD_CTX_new();
|
||||||
EVP_MD *md = EVP_MD_fetch(nullptr, "SHA2-256", nullptr);
|
EVP_MD *md = EVP_MD_fetch(nullptr, "SHA2-256", nullptr);
|
||||||
|
|
||||||
EVP_DigestInit_ex(ctx, md, nullptr);
|
EVP_DigestInit_ex(ctx, md, nullptr);
|
||||||
|
|
||||||
|
if (!salt.empty()) {
|
||||||
|
DMG_ASSERT(salt.size() == SALT_SIZE);
|
||||||
|
EVP_DigestUpdate(ctx, salt.data(), salt.size());
|
||||||
|
}
|
||||||
|
|
||||||
for (auto i = 0; i < number_of_iterations; i++) {
|
for (auto i = 0; i < number_of_iterations; i++) {
|
||||||
EVP_DigestUpdate(ctx, password.c_str(), password.size());
|
EVP_DigestUpdate(ctx, password.data(), password.size());
|
||||||
}
|
}
|
||||||
EVP_DigestFinal_ex(ctx, hash, nullptr);
|
EVP_DigestFinal_ex(ctx, hash, nullptr);
|
||||||
|
|
||||||
@@ -103,6 +121,11 @@ std::string EncryptPasswordOpenSSL3(const std::string &password, const uint64_t
|
|||||||
EVP_MD_CTX_free(ctx);
|
EVP_MD_CTX_free(ctx);
|
||||||
|
|
||||||
std::stringstream result_stream;
|
std::stringstream result_stream;
|
||||||
|
|
||||||
|
for (unsigned char salt_char : salt) {
|
||||||
|
result_stream << std::hex << std::setw(2) << std::setfill('0') << (((unsigned int)salt_char) & 0xFFU);
|
||||||
|
}
|
||||||
|
|
||||||
for (auto hash_char : hash) {
|
for (auto hash_char : hash) {
|
||||||
result_stream << std::hex << std::setw(2) << std::setfill('0') << (int)hash_char;
|
result_stream << std::hex << std::setw(2) << std::setfill('0') << (int)hash_char;
|
||||||
}
|
}
|
||||||
@@ -110,17 +133,27 @@ std::string EncryptPasswordOpenSSL3(const std::string &password, const uint64_t
|
|||||||
return result_stream.str();
|
return result_stream.str();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
std::string EncryptPasswordOpenSSL1_1(const std::string &password, const uint64_t number_of_iterations) {
|
std::string HashPasswordOpenSSL1_1(std::string_view password, const uint64_t number_of_iterations,
|
||||||
|
std::string_view salt) {
|
||||||
unsigned char hash[SHA256_DIGEST_LENGTH];
|
unsigned char hash[SHA256_DIGEST_LENGTH];
|
||||||
|
|
||||||
SHA256_CTX sha256;
|
SHA256_CTX sha256;
|
||||||
SHA256_Init(&sha256);
|
SHA256_Init(&sha256);
|
||||||
|
|
||||||
|
if (!salt.empty()) {
|
||||||
|
DMG_ASSERT(salt.size() == SALT_SIZE);
|
||||||
|
SHA256_Update(&sha256, salt.data(), salt.size());
|
||||||
|
}
|
||||||
|
|
||||||
for (auto i = 0; i < number_of_iterations; i++) {
|
for (auto i = 0; i < number_of_iterations; i++) {
|
||||||
SHA256_Update(&sha256, password.c_str(), password.size());
|
SHA256_Update(&sha256, password.data(), password.size());
|
||||||
}
|
}
|
||||||
SHA256_Final(hash, &sha256);
|
SHA256_Final(hash, &sha256);
|
||||||
|
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
|
for (unsigned char salt_char : salt) {
|
||||||
|
ss << std::hex << std::setw(2) << std::setfill('0') << (((unsigned int)salt_char) & 0xFFU);
|
||||||
|
}
|
||||||
for (auto hash_char : hash) {
|
for (auto hash_char : hash) {
|
||||||
ss << std::hex << std::setw(2) << std::setfill('0') << (int)hash_char;
|
ss << std::hex << std::setw(2) << std::setfill('0') << (int)hash_char;
|
||||||
}
|
}
|
||||||
@@ -129,55 +162,144 @@ std::string EncryptPasswordOpenSSL1_1(const std::string &password, const uint64_
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::string EncryptPassword(const std::string &password, const uint64_t number_of_iterations) {
|
std::string HashPassword(std::string_view password, const uint64_t number_of_iterations, std::string_view salt) {
|
||||||
#if OPENSSL_VERSION_MAJOR >= 3
|
#if OPENSSL_VERSION_MAJOR >= 3
|
||||||
return EncryptPasswordOpenSSL3(password, number_of_iterations);
|
return HashPasswordOpenSSL3(password, number_of_iterations, salt);
|
||||||
#else
|
#else
|
||||||
return EncryptPasswordOpenSSL1_1(password, number_of_iterations);
|
return HashPasswordOpenSSL1_1(password, number_of_iterations, salt);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VerifyPassword(const std::string &password, const std::string &hash, const uint64_t number_of_iterations) {
|
auto ExtractSalt(std::string_view salt_durable) -> std::array<char, SALT_SIZE> {
|
||||||
auto password_hash = EncryptPassword(password, number_of_iterations);
|
static_assert(SALT_SIZE_DURABLE % 2 == 0);
|
||||||
|
static_assert(SALT_SIZE_DURABLE / 2 == SALT_SIZE);
|
||||||
|
|
||||||
|
MG_ASSERT(salt_durable.size() == SALT_SIZE_DURABLE);
|
||||||
|
auto const *b = salt_durable.cbegin();
|
||||||
|
auto const *const e = salt_durable.cend();
|
||||||
|
|
||||||
|
auto salt = std::array<char, SALT_SIZE>{};
|
||||||
|
auto *inserter = salt.begin();
|
||||||
|
|
||||||
|
auto const toval = [](char a) -> uint8_t {
|
||||||
|
if ('0' <= a && a <= '9') {
|
||||||
|
return a - '0';
|
||||||
|
}
|
||||||
|
if ('a' <= a && a <= 'f') {
|
||||||
|
return 10 + (a - 'a');
|
||||||
|
}
|
||||||
|
MG_ASSERT(false, "Currupt hash, can't extract salt");
|
||||||
|
__builtin_unreachable();
|
||||||
|
};
|
||||||
|
|
||||||
|
for (; b != e; b += 2, ++inserter) {
|
||||||
|
*inserter = static_cast<char>(static_cast<uint8_t>(toval(b[0]) << 4U) | toval(b[1]));
|
||||||
|
}
|
||||||
|
return salt;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsSalted(std::string_view hash) { return hash.size() == SHA_LENGTH + SALT_SIZE_DURABLE; }
|
||||||
|
|
||||||
|
bool VerifyPassword(std::string_view password, std::string_view hash, const uint64_t number_of_iterations) {
|
||||||
|
auto password_hash = std::invoke([&] {
|
||||||
|
if (hash.size() == SHA_LENGTH) [[unlikely]] {
|
||||||
|
// Just SHA256
|
||||||
|
return HashPassword(password, number_of_iterations, {});
|
||||||
|
} else {
|
||||||
|
// SHA256 + SALT
|
||||||
|
MG_ASSERT(IsSalted(hash));
|
||||||
|
auto const salt_durable = std::string_view{hash.data(), SALT_SIZE_DURABLE};
|
||||||
|
std::array<char, SALT_SIZE> salt = ExtractSalt(salt_durable);
|
||||||
|
return HashPassword(password, number_of_iterations, {salt.data(), salt.size()});
|
||||||
|
}
|
||||||
|
});
|
||||||
return password_hash == hash;
|
return password_hash == hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
} // namespace SHA
|
} // namespace SHA
|
||||||
|
|
||||||
bool VerifyPassword(const std::string &password, const std::string &hash) {
|
HashedPassword HashPassword(const std::string &password, std::optional<PasswordHashAlgorithm> override_algo) {
|
||||||
const auto password_encryption_algorithm = utils::StringToEnum<PasswordEncryptionAlgorithm>(
|
auto const hash_algo = override_algo.value_or(CurrentHashAlgorithm());
|
||||||
FLAGS_password_encryption_algorithm, password_encryption_mappings);
|
auto password_hash = std::invoke([&] {
|
||||||
|
switch (hash_algo) {
|
||||||
|
case PasswordHashAlgorithm::BCRYPT: {
|
||||||
|
return BCrypt::HashPassword(password);
|
||||||
|
}
|
||||||
|
case PasswordHashAlgorithm::SHA256:
|
||||||
|
case PasswordHashAlgorithm::SHA256_MULTIPLE: {
|
||||||
|
auto gen = std::mt19937(std::random_device{}());
|
||||||
|
auto salt = std::array<char, SHA::SALT_SIZE>{};
|
||||||
|
auto dis = std::uniform_int_distribution<unsigned char>(0, 255);
|
||||||
|
std::generate(salt.begin(), salt.end(), [&]() { return dis(gen); });
|
||||||
|
auto iterations = (hash_algo == PasswordHashAlgorithm::SHA256) ? ONE_SHA_ITERATION : MULTIPLE_SHA_ITERATIONS;
|
||||||
|
return SHA::HashPassword(password, iterations, {salt.data(), salt.size()});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return HashedPassword{hash_algo, std::move(password_hash)};
|
||||||
|
};
|
||||||
|
|
||||||
if (!password_encryption_algorithm.has_value()) {
|
namespace {
|
||||||
throw AuthException("Invalid password encryption flag '{}'!", FLAGS_password_encryption_algorithm);
|
|
||||||
|
auto InternalParseHashAlgorithm(std::string_view algo) -> PasswordHashAlgorithm {
|
||||||
|
auto maybe_parsed = utils::StringToEnum<PasswordHashAlgorithm>(algo, password_hash_mappings);
|
||||||
|
if (!maybe_parsed) {
|
||||||
|
throw AuthException("Invalid password encryption '{}'!", algo);
|
||||||
}
|
}
|
||||||
|
return *maybe_parsed;
|
||||||
switch (password_encryption_algorithm.value()) {
|
|
||||||
case PasswordEncryptionAlgorithm::BCRYPT:
|
|
||||||
return BCrypt::VerifyPassword(password, hash);
|
|
||||||
case PasswordEncryptionAlgorithm::SHA256:
|
|
||||||
return SHA::VerifyPassword(password, hash, ONE_SHA_ITERATION);
|
|
||||||
case PasswordEncryptionAlgorithm::SHA256_MULTIPLE:
|
|
||||||
return SHA::VerifyPassword(password, hash, MULTIPLE_SHA_ITERATIONS);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw AuthException("Invalid password encryption flag '{}'!", FLAGS_password_encryption_algorithm);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string EncryptPassword(const std::string &password) {
|
PasswordHashAlgorithm &InternalCurrentHashAlgorithm() {
|
||||||
const auto password_encryption_algorithm = utils::StringToEnum<PasswordEncryptionAlgorithm>(
|
static auto current = PasswordHashAlgorithm::BCRYPT;
|
||||||
FLAGS_password_encryption_algorithm, password_encryption_mappings);
|
static std::once_flag flag;
|
||||||
|
std::call_once(flag, [] { current = InternalParseHashAlgorithm(FLAGS_password_encryption_algorithm); });
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
if (!password_encryption_algorithm.has_value()) {
|
auto CurrentHashAlgorithm() -> PasswordHashAlgorithm { return InternalCurrentHashAlgorithm(); }
|
||||||
throw AuthException("Invalid password encryption flag '{}'!", FLAGS_password_encryption_algorithm);
|
|
||||||
|
void SetHashAlgorithm(std::string_view algo) {
|
||||||
|
auto ¤t = InternalCurrentHashAlgorithm();
|
||||||
|
current = InternalParseHashAlgorithm(algo);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto AsString(PasswordHashAlgorithm hash_algo) -> std::string_view {
|
||||||
|
return *utils::EnumToString<PasswordHashAlgorithm>(hash_algo, password_hash_mappings);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HashedPassword::VerifyPassword(const std::string &password) {
|
||||||
|
switch (hash_algo) {
|
||||||
|
case PasswordHashAlgorithm::BCRYPT:
|
||||||
|
return BCrypt::VerifyPassword(password, password_hash);
|
||||||
|
case PasswordHashAlgorithm::SHA256:
|
||||||
|
return SHA::VerifyPassword(password, password_hash, ONE_SHA_ITERATION);
|
||||||
|
case PasswordHashAlgorithm::SHA256_MULTIPLE:
|
||||||
|
return SHA::VerifyPassword(password, password_hash, MULTIPLE_SHA_ITERATIONS);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (password_encryption_algorithm.value()) {
|
void to_json(nlohmann::json &j, const HashedPassword &p) {
|
||||||
case PasswordEncryptionAlgorithm::BCRYPT:
|
j = nlohmann::json{{kHashAlgo, p.hash_algo}, {kPasswordHash, p.password_hash}};
|
||||||
return BCrypt::EncryptPassword(password);
|
}
|
||||||
case PasswordEncryptionAlgorithm::SHA256:
|
|
||||||
return SHA::EncryptPassword(password, ONE_SHA_ITERATION);
|
void from_json(const nlohmann::json &j, HashedPassword &p) {
|
||||||
case PasswordEncryptionAlgorithm::SHA256_MULTIPLE:
|
// NOLINTNEXTLINE(cppcoreguidelines-init-variables)
|
||||||
return SHA::EncryptPassword(password, MULTIPLE_SHA_ITERATIONS);
|
PasswordHashAlgorithm hash_algo;
|
||||||
|
j.at(kHashAlgo).get_to(hash_algo);
|
||||||
|
auto password_hash = j.value(kPasswordHash, std::string());
|
||||||
|
p = HashedPassword{hash_algo, std::move(password_hash)};
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HashedPassword::IsSalted() const {
|
||||||
|
switch (hash_algo) {
|
||||||
|
case PasswordHashAlgorithm::BCRYPT:
|
||||||
|
return true;
|
||||||
|
case PasswordHashAlgorithm::SHA256:
|
||||||
|
case PasswordHashAlgorithm::SHA256_MULTIPLE:
|
||||||
|
return SHA::IsSalted(password_hash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2023 Memgraph Ltd.
|
// Copyright 2024 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Licensed as a Memgraph Enterprise file under the Memgraph Enterprise
|
// Licensed as a Memgraph Enterprise file under the Memgraph Enterprise
|
||||||
// License (the "License"); by using this file, you agree to be bound by the terms of the License, and you may not use
|
// License (the "License"); by using this file, you agree to be bound by the terms of the License, and you may not use
|
||||||
@@ -8,14 +8,47 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include <json/json.hpp>
|
||||||
|
|
||||||
namespace memgraph::auth {
|
namespace memgraph::auth {
|
||||||
enum class PasswordEncryptionAlgorithm : uint8_t { BCRYPT, SHA256, SHA256_MULTIPLE };
|
/// Need to be stable, auth durability depends on this
|
||||||
|
enum class PasswordHashAlgorithm : uint8_t { BCRYPT = 0, SHA256 = 1, SHA256_MULTIPLE = 2 };
|
||||||
|
|
||||||
/// @throw AuthException if unable to encrypt the password.
|
void SetHashAlgorithm(std::string_view algo);
|
||||||
std::string EncryptPassword(const std::string &password);
|
|
||||||
|
|
||||||
/// @throw AuthException if unable to verify the password.
|
auto CurrentHashAlgorithm() -> PasswordHashAlgorithm;
|
||||||
bool VerifyPassword(const std::string &password, const std::string &hash);
|
|
||||||
|
auto AsString(PasswordHashAlgorithm hash_algo) -> std::string_view;
|
||||||
|
|
||||||
|
struct HashedPassword {
|
||||||
|
HashedPassword() = default;
|
||||||
|
HashedPassword(PasswordHashAlgorithm hash_algo, std::string password_hash)
|
||||||
|
: hash_algo{hash_algo}, password_hash{std::move(password_hash)} {}
|
||||||
|
HashedPassword(HashedPassword const &) = default;
|
||||||
|
HashedPassword(HashedPassword &&) = default;
|
||||||
|
HashedPassword &operator=(HashedPassword const &) = default;
|
||||||
|
HashedPassword &operator=(HashedPassword &&) = default;
|
||||||
|
|
||||||
|
friend bool operator==(HashedPassword const &, HashedPassword const &) = default;
|
||||||
|
|
||||||
|
bool VerifyPassword(const std::string &password);
|
||||||
|
|
||||||
|
bool IsSalted() const;
|
||||||
|
|
||||||
|
auto HashAlgo() const -> PasswordHashAlgorithm { return hash_algo; }
|
||||||
|
|
||||||
|
friend void to_json(nlohmann::json &j, const HashedPassword &p);
|
||||||
|
friend void from_json(const nlohmann::json &j, HashedPassword &p);
|
||||||
|
|
||||||
|
private:
|
||||||
|
PasswordHashAlgorithm hash_algo{PasswordHashAlgorithm::BCRYPT};
|
||||||
|
std::string password_hash{};
|
||||||
|
};
|
||||||
|
|
||||||
|
/// @throw AuthException if unable to hash the password.
|
||||||
|
HashedPassword HashPassword(const std::string &password, std::optional<PasswordHashAlgorithm> override_algo = {});
|
||||||
} // namespace memgraph::auth
|
} // namespace memgraph::auth
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2023 Memgraph Ltd.
|
// Copyright 2024 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Licensed as a Memgraph Enterprise file under the Memgraph Enterprise
|
// Licensed as a Memgraph Enterprise file under the Memgraph Enterprise
|
||||||
// License (the "License"); by using this file, you agree to be bound by the terms of the License, and you may not use
|
// License (the "License"); by using this file, you agree to be bound by the terms of the License, and you may not use
|
||||||
@@ -9,7 +9,6 @@
|
|||||||
#include "auth/models.hpp"
|
#include "auth/models.hpp"
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <regex>
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include <gflags/gflags.h>
|
#include <gflags/gflags.h>
|
||||||
@@ -21,22 +20,26 @@
|
|||||||
#include "query/constants.hpp"
|
#include "query/constants.hpp"
|
||||||
#include "spdlog/spdlog.h"
|
#include "spdlog/spdlog.h"
|
||||||
#include "utils/cast.hpp"
|
#include "utils/cast.hpp"
|
||||||
#include "utils/logging.hpp"
|
|
||||||
#include "utils/settings.hpp"
|
|
||||||
#include "utils/string.hpp"
|
#include "utils/string.hpp"
|
||||||
|
|
||||||
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
|
|
||||||
DEFINE_bool(auth_password_permit_null, true, "Set to false to disable null passwords.");
|
|
||||||
|
|
||||||
inline constexpr std::string_view default_password_regex = ".+";
|
|
||||||
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
|
|
||||||
DEFINE_string(auth_password_strength_regex, default_password_regex.data(),
|
|
||||||
"The regular expression that should be used to match the entire "
|
|
||||||
"entered password to ensure its strength.");
|
|
||||||
|
|
||||||
namespace memgraph::auth {
|
namespace memgraph::auth {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
constexpr auto kRoleName = "rolename";
|
||||||
|
constexpr auto kPermissions = "permissions";
|
||||||
|
constexpr auto kGrants = "grants";
|
||||||
|
constexpr auto kDenies = "denies";
|
||||||
|
constexpr auto kUsername = "username";
|
||||||
|
constexpr auto kPasswordHash = "password_hash";
|
||||||
|
|
||||||
|
#ifdef MG_ENTERPRISE
|
||||||
|
constexpr auto kGlobalPermission = "global_permission";
|
||||||
|
constexpr auto kFineGrainedAccessHandler = "fine_grained_access_handler";
|
||||||
|
constexpr auto kAllowAll = "allow_all";
|
||||||
|
constexpr auto kDefault = "default";
|
||||||
|
constexpr auto kDatabases = "databases";
|
||||||
|
#endif
|
||||||
|
|
||||||
// Constant list of all available permissions.
|
// Constant list of all available permissions.
|
||||||
const std::vector<Permission> kPermissionsAll = {Permission::MATCH,
|
const std::vector<Permission> kPermissionsAll = {Permission::MATCH,
|
||||||
Permission::CREATE,
|
Permission::CREATE,
|
||||||
@@ -62,7 +65,8 @@ const std::vector<Permission> kPermissionsAll = {Permission::MATCH,
|
|||||||
Permission::TRANSACTION_MANAGEMENT,
|
Permission::TRANSACTION_MANAGEMENT,
|
||||||
Permission::STORAGE_MODE,
|
Permission::STORAGE_MODE,
|
||||||
Permission::MULTI_DATABASE_EDIT,
|
Permission::MULTI_DATABASE_EDIT,
|
||||||
Permission::MULTI_DATABASE_USE};
|
Permission::MULTI_DATABASE_USE,
|
||||||
|
Permission::COORDINATOR};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
@@ -118,6 +122,8 @@ std::string PermissionToString(Permission permission) {
|
|||||||
return "MULTI_DATABASE_EDIT";
|
return "MULTI_DATABASE_EDIT";
|
||||||
case Permission::MULTI_DATABASE_USE:
|
case Permission::MULTI_DATABASE_USE:
|
||||||
return "MULTI_DATABASE_USE";
|
return "MULTI_DATABASE_USE";
|
||||||
|
case Permission::COORDINATOR:
|
||||||
|
return "COORDINATOR";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,8 +248,9 @@ std::vector<Permission> Permissions::GetDenies() const {
|
|||||||
|
|
||||||
nlohmann::json Permissions::Serialize() const {
|
nlohmann::json Permissions::Serialize() const {
|
||||||
nlohmann::json data = nlohmann::json::object();
|
nlohmann::json data = nlohmann::json::object();
|
||||||
data["grants"] = grants_;
|
|
||||||
data["denies"] = denies_;
|
data[kGrants] = grants_;
|
||||||
|
data[kDenies] = denies_;
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,10 +258,10 @@ Permissions Permissions::Deserialize(const nlohmann::json &data) {
|
|||||||
if (!data.is_object()) {
|
if (!data.is_object()) {
|
||||||
throw AuthException("Couldn't load permissions data!");
|
throw AuthException("Couldn't load permissions data!");
|
||||||
}
|
}
|
||||||
if (!data["grants"].is_number_unsigned() || !data["denies"].is_number_unsigned()) {
|
if (!data[kGrants].is_number_unsigned() || !data[kDenies].is_number_unsigned()) {
|
||||||
throw AuthException("Couldn't load permissions data!");
|
throw AuthException("Couldn't load permissions data!");
|
||||||
}
|
}
|
||||||
return Permissions{data["grants"], data["denies"]};
|
return Permissions{data[kGrants], data[kDenies]};
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t Permissions::grants() const { return grants_; }
|
uint64_t Permissions::grants() const { return grants_; }
|
||||||
@@ -316,8 +323,8 @@ nlohmann::json FineGrainedAccessPermissions::Serialize() const {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
nlohmann::json data = nlohmann::json::object();
|
nlohmann::json data = nlohmann::json::object();
|
||||||
data["permissions"] = permissions_;
|
data[kPermissions] = permissions_;
|
||||||
data["global_permission"] = global_permission_.has_value() ? global_permission_.value() : -1;
|
data[kGlobalPermission] = global_permission_.has_value() ? global_permission_.value() : -1;
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -330,13 +337,13 @@ FineGrainedAccessPermissions FineGrainedAccessPermissions::Deserialize(const nlo
|
|||||||
}
|
}
|
||||||
std::optional<uint64_t> global_permission;
|
std::optional<uint64_t> global_permission;
|
||||||
|
|
||||||
if (data["global_permission"].empty() || data["global_permission"] == -1) {
|
if (data[kGlobalPermission].empty() || data[kGlobalPermission] == -1) {
|
||||||
global_permission = std::nullopt;
|
global_permission = std::nullopt;
|
||||||
} else {
|
} else {
|
||||||
global_permission = data["global_permission"];
|
global_permission = data[kGlobalPermission];
|
||||||
}
|
}
|
||||||
|
|
||||||
return FineGrainedAccessPermissions(data["permissions"], global_permission);
|
return FineGrainedAccessPermissions(data[kPermissions], global_permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::unordered_map<std::string, uint64_t> &FineGrainedAccessPermissions::GetPermissions() const {
|
const std::unordered_map<std::string, uint64_t> &FineGrainedAccessPermissions::GetPermissions() const {
|
||||||
@@ -418,10 +425,11 @@ Role::Role(const std::string &rolename, const Permissions &permissions)
|
|||||||
: rolename_(utils::ToLowerCase(rolename)), permissions_(permissions) {}
|
: rolename_(utils::ToLowerCase(rolename)), permissions_(permissions) {}
|
||||||
#ifdef MG_ENTERPRISE
|
#ifdef MG_ENTERPRISE
|
||||||
Role::Role(const std::string &rolename, const Permissions &permissions,
|
Role::Role(const std::string &rolename, const Permissions &permissions,
|
||||||
FineGrainedAccessHandler fine_grained_access_handler)
|
FineGrainedAccessHandler fine_grained_access_handler, Databases db_access)
|
||||||
: rolename_(utils::ToLowerCase(rolename)),
|
: rolename_(utils::ToLowerCase(rolename)),
|
||||||
permissions_(permissions),
|
permissions_(permissions),
|
||||||
fine_grained_access_handler_(std::move(fine_grained_access_handler)) {}
|
fine_grained_access_handler_(std::move(fine_grained_access_handler)),
|
||||||
|
db_access_(std::move(db_access)) {}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const std::string &Role::rolename() const { return rolename_; }
|
const std::string &Role::rolename() const { return rolename_; }
|
||||||
@@ -442,13 +450,15 @@ const FineGrainedAccessPermissions &Role::GetFineGrainedAccessEdgeTypePermission
|
|||||||
|
|
||||||
nlohmann::json Role::Serialize() const {
|
nlohmann::json Role::Serialize() const {
|
||||||
nlohmann::json data = nlohmann::json::object();
|
nlohmann::json data = nlohmann::json::object();
|
||||||
data["rolename"] = rolename_;
|
data[kRoleName] = rolename_;
|
||||||
data["permissions"] = permissions_.Serialize();
|
data[kPermissions] = permissions_.Serialize();
|
||||||
#ifdef MG_ENTERPRISE
|
#ifdef MG_ENTERPRISE
|
||||||
if (memgraph::license::global_license_checker.IsEnterpriseValidFast()) {
|
if (memgraph::license::global_license_checker.IsEnterpriseValidFast()) {
|
||||||
data["fine_grained_access_handler"] = fine_grained_access_handler_.Serialize();
|
data[kFineGrainedAccessHandler] = fine_grained_access_handler_.Serialize();
|
||||||
|
data[kDatabases] = db_access_.Serialize();
|
||||||
} else {
|
} else {
|
||||||
data["fine_grained_access_handler"] = {};
|
data[kFineGrainedAccessHandler] = {};
|
||||||
|
data[kDatabases] = {};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return data;
|
return data;
|
||||||
@@ -458,21 +468,30 @@ Role Role::Deserialize(const nlohmann::json &data) {
|
|||||||
if (!data.is_object()) {
|
if (!data.is_object()) {
|
||||||
throw AuthException("Couldn't load role data!");
|
throw AuthException("Couldn't load role data!");
|
||||||
}
|
}
|
||||||
if (!data["rolename"].is_string() || !data["permissions"].is_object()) {
|
if (!data[kRoleName].is_string() || !data[kPermissions].is_object()) {
|
||||||
throw AuthException("Couldn't load role data!");
|
throw AuthException("Couldn't load role data!");
|
||||||
}
|
}
|
||||||
auto permissions = Permissions::Deserialize(data["permissions"]);
|
auto permissions = Permissions::Deserialize(data[kPermissions]);
|
||||||
#ifdef MG_ENTERPRISE
|
#ifdef MG_ENTERPRISE
|
||||||
if (memgraph::license::global_license_checker.IsEnterpriseValidFast()) {
|
if (memgraph::license::global_license_checker.IsEnterpriseValidFast()) {
|
||||||
|
Databases db_access;
|
||||||
|
if (data[kDatabases].is_structured()) {
|
||||||
|
db_access = Databases::Deserialize(data[kDatabases]);
|
||||||
|
} else {
|
||||||
|
// Back-compatibility
|
||||||
|
spdlog::warn("Role without specified database access. Given access to the default database.");
|
||||||
|
db_access.Grant(dbms::kDefaultDB);
|
||||||
|
db_access.SetMain(dbms::kDefaultDB);
|
||||||
|
}
|
||||||
FineGrainedAccessHandler fine_grained_access_handler;
|
FineGrainedAccessHandler fine_grained_access_handler;
|
||||||
// We can have an empty fine_grained if the user was created without a valid license
|
// We can have an empty fine_grained if the user was created without a valid license
|
||||||
if (data["fine_grained_access_handler"].is_object()) {
|
if (data[kFineGrainedAccessHandler].is_object()) {
|
||||||
fine_grained_access_handler = FineGrainedAccessHandler::Deserialize(data["fine_grained_access_handler"]);
|
fine_grained_access_handler = FineGrainedAccessHandler::Deserialize(data[kFineGrainedAccessHandler]);
|
||||||
}
|
}
|
||||||
return {data["rolename"], permissions, std::move(fine_grained_access_handler)};
|
return {data[kRoleName], permissions, std::move(fine_grained_access_handler), std::move(db_access)};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return {data["rolename"], permissions};
|
return {data[kRoleName], permissions};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const Role &first, const Role &second) {
|
bool operator==(const Role &first, const Role &second) {
|
||||||
@@ -486,28 +505,28 @@ bool operator==(const Role &first, const Role &second) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MG_ENTERPRISE
|
#ifdef MG_ENTERPRISE
|
||||||
void Databases::Add(const std::string &db) {
|
void Databases::Grant(std::string_view db) {
|
||||||
if (allow_all_) {
|
if (allow_all_) {
|
||||||
grants_dbs_.clear();
|
grants_dbs_.clear();
|
||||||
allow_all_ = false;
|
allow_all_ = false;
|
||||||
}
|
}
|
||||||
grants_dbs_.emplace(db);
|
grants_dbs_.emplace(db);
|
||||||
denies_dbs_.erase(db);
|
denies_dbs_.erase(std::string{db}); // TODO: C++23 use transparent key compare
|
||||||
}
|
}
|
||||||
|
|
||||||
void Databases::Remove(const std::string &db) {
|
void Databases::Deny(const std::string &db) {
|
||||||
denies_dbs_.emplace(db);
|
denies_dbs_.emplace(db);
|
||||||
grants_dbs_.erase(db);
|
grants_dbs_.erase(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Databases::Delete(const std::string &db) {
|
void Databases::Revoke(const std::string &db) {
|
||||||
denies_dbs_.erase(db);
|
denies_dbs_.erase(db);
|
||||||
if (!allow_all_) {
|
if (!allow_all_) {
|
||||||
grants_dbs_.erase(db);
|
grants_dbs_.erase(db);
|
||||||
}
|
}
|
||||||
// Reset if default deleted
|
// Reset if default deleted
|
||||||
if (default_db_ == db) {
|
if (main_db_ == db) {
|
||||||
default_db_ = "";
|
main_db_ = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -523,29 +542,36 @@ void Databases::DenyAll() {
|
|||||||
denies_dbs_.clear();
|
denies_dbs_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Databases::SetDefault(const std::string &db) {
|
void Databases::RevokeAll() {
|
||||||
|
allow_all_ = false;
|
||||||
|
grants_dbs_.clear();
|
||||||
|
denies_dbs_.clear();
|
||||||
|
main_db_ = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Databases::SetMain(std::string_view db) {
|
||||||
if (!Contains(db)) return false;
|
if (!Contains(db)) return false;
|
||||||
default_db_ = db;
|
main_db_ = db;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] bool Databases::Contains(const std::string &db) const {
|
[[nodiscard]] bool Databases::Contains(std::string_view db) const {
|
||||||
return !denies_dbs_.contains(db) && (allow_all_ || grants_dbs_.contains(db));
|
return !denies_dbs_.contains(db) && (allow_all_ || grants_dbs_.contains(db));
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string &Databases::GetDefault() const {
|
const std::string &Databases::GetMain() const {
|
||||||
if (!Contains(default_db_)) {
|
if (!Contains(main_db_)) {
|
||||||
throw AuthException("No access to the set default database \"{}\".", default_db_);
|
throw AuthException("No access to the set default database \"{}\".", main_db_);
|
||||||
}
|
}
|
||||||
return default_db_;
|
return main_db_;
|
||||||
}
|
}
|
||||||
|
|
||||||
nlohmann::json Databases::Serialize() const {
|
nlohmann::json Databases::Serialize() const {
|
||||||
nlohmann::json data = nlohmann::json::object();
|
nlohmann::json data = nlohmann::json::object();
|
||||||
data["grants"] = grants_dbs_;
|
data[kGrants] = grants_dbs_;
|
||||||
data["denies"] = denies_dbs_;
|
data[kDenies] = denies_dbs_;
|
||||||
data["allow_all"] = allow_all_;
|
data[kAllowAll] = allow_all_;
|
||||||
data["default"] = default_db_;
|
data[kDefault] = main_db_;
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -553,22 +579,22 @@ Databases Databases::Deserialize(const nlohmann::json &data) {
|
|||||||
if (!data.is_object()) {
|
if (!data.is_object()) {
|
||||||
throw AuthException("Couldn't load database data!");
|
throw AuthException("Couldn't load database data!");
|
||||||
}
|
}
|
||||||
if (!data["grants"].is_structured() || !data["denies"].is_structured() || !data["allow_all"].is_boolean() ||
|
if (!data[kGrants].is_structured() || !data[kDenies].is_structured() || !data[kAllowAll].is_boolean() ||
|
||||||
!data["default"].is_string()) {
|
!data[kDefault].is_string()) {
|
||||||
throw AuthException("Couldn't load database data!");
|
throw AuthException("Couldn't load database data!");
|
||||||
}
|
}
|
||||||
return {data["allow_all"], data["grants"], data["denies"], data["default"]};
|
return {data[kAllowAll], data[kGrants], data[kDenies], data[kDefault]};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
User::User() = default;
|
User::User() = default;
|
||||||
|
|
||||||
User::User(const std::string &username) : username_(utils::ToLowerCase(username)) {}
|
User::User(const std::string &username) : username_(utils::ToLowerCase(username)) {}
|
||||||
User::User(const std::string &username, std::string password_hash, const Permissions &permissions)
|
User::User(const std::string &username, std::optional<HashedPassword> password_hash, const Permissions &permissions)
|
||||||
: username_(utils::ToLowerCase(username)), password_hash_(std::move(password_hash)), permissions_(permissions) {}
|
: username_(utils::ToLowerCase(username)), password_hash_(std::move(password_hash)), permissions_(permissions) {}
|
||||||
|
|
||||||
#ifdef MG_ENTERPRISE
|
#ifdef MG_ENTERPRISE
|
||||||
User::User(const std::string &username, std::string password_hash, const Permissions &permissions,
|
User::User(const std::string &username, std::optional<HashedPassword> password_hash, const Permissions &permissions,
|
||||||
FineGrainedAccessHandler fine_grained_access_handler, Databases db_access)
|
FineGrainedAccessHandler fine_grained_access_handler, Databases db_access)
|
||||||
: username_(utils::ToLowerCase(username)),
|
: username_(utils::ToLowerCase(username)),
|
||||||
password_hash_(std::move(password_hash)),
|
password_hash_(std::move(password_hash)),
|
||||||
@@ -578,38 +604,16 @@ User::User(const std::string &username, std::string password_hash, const Permiss
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool User::CheckPassword(const std::string &password) {
|
bool User::CheckPassword(const std::string &password) {
|
||||||
if (password_hash_.empty()) return true;
|
return password_hash_ ? password_hash_->VerifyPassword(password) : true;
|
||||||
return VerifyPassword(password, password_hash_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void User::UpdatePassword(const std::optional<std::string> &password) {
|
void User::UpdatePassword(const std::optional<std::string> &password,
|
||||||
|
std::optional<PasswordHashAlgorithm> algo_override) {
|
||||||
if (!password) {
|
if (!password) {
|
||||||
if (!FLAGS_auth_password_permit_null) {
|
password_hash_.reset();
|
||||||
throw AuthException("Null passwords aren't permitted!");
|
|
||||||
}
|
|
||||||
password_hash_ = "";
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
password_hash_ = HashPassword(*password, algo_override);
|
||||||
if (FLAGS_auth_password_strength_regex != default_password_regex) {
|
|
||||||
if (const auto license_check_result = license::global_license_checker.IsEnterpriseValid(utils::global_settings);
|
|
||||||
license_check_result.HasError()) {
|
|
||||||
throw AuthException(
|
|
||||||
"Custom password regex is a Memgraph Enterprise feature. Please set the config "
|
|
||||||
"(\"--auth-password-strength-regex\") to its default value (\"{}\") or remove the flag.\n{}",
|
|
||||||
default_password_regex,
|
|
||||||
license::LicenseCheckErrorToString(license_check_result.GetError(), "password regex"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::regex re(FLAGS_auth_password_strength_regex);
|
|
||||||
if (!std::regex_match(*password, re)) {
|
|
||||||
throw AuthException(
|
|
||||||
"The user password doesn't conform to the required strength! Regex: "
|
|
||||||
"\"{}\"",
|
|
||||||
FLAGS_auth_password_strength_regex);
|
|
||||||
}
|
|
||||||
|
|
||||||
password_hash_ = EncryptPassword(*password);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void User::SetRole(const Role &role) { role_.emplace(role); }
|
void User::SetRole(const Role &role) { role_.emplace(role); }
|
||||||
@@ -626,27 +630,49 @@ Permissions User::GetPermissions() const {
|
|||||||
|
|
||||||
#ifdef MG_ENTERPRISE
|
#ifdef MG_ENTERPRISE
|
||||||
FineGrainedAccessPermissions User::GetFineGrainedAccessLabelPermissions() const {
|
FineGrainedAccessPermissions User::GetFineGrainedAccessLabelPermissions() const {
|
||||||
|
return Merge(GetUserFineGrainedAccessLabelPermissions(), GetRoleFineGrainedAccessLabelPermissions());
|
||||||
|
}
|
||||||
|
|
||||||
|
FineGrainedAccessPermissions User::GetFineGrainedAccessEdgeTypePermissions() const {
|
||||||
|
return Merge(GetUserFineGrainedAccessEdgeTypePermissions(), GetRoleFineGrainedAccessEdgeTypePermissions());
|
||||||
|
}
|
||||||
|
|
||||||
|
FineGrainedAccessPermissions User::GetUserFineGrainedAccessEdgeTypePermissions() const {
|
||||||
if (!memgraph::license::global_license_checker.IsEnterpriseValidFast()) {
|
if (!memgraph::license::global_license_checker.IsEnterpriseValidFast()) {
|
||||||
return FineGrainedAccessPermissions{};
|
return FineGrainedAccessPermissions{};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (role_) {
|
return fine_grained_access_handler_.edge_type_permissions();
|
||||||
return Merge(role()->fine_grained_access_handler().label_permissions(),
|
}
|
||||||
fine_grained_access_handler_.label_permissions());
|
|
||||||
|
FineGrainedAccessPermissions User::GetUserFineGrainedAccessLabelPermissions() const {
|
||||||
|
if (!memgraph::license::global_license_checker.IsEnterpriseValidFast()) {
|
||||||
|
return FineGrainedAccessPermissions{};
|
||||||
}
|
}
|
||||||
|
|
||||||
return fine_grained_access_handler_.label_permissions();
|
return fine_grained_access_handler_.label_permissions();
|
||||||
}
|
}
|
||||||
|
|
||||||
FineGrainedAccessPermissions User::GetFineGrainedAccessEdgeTypePermissions() const {
|
FineGrainedAccessPermissions User::GetRoleFineGrainedAccessEdgeTypePermissions() const {
|
||||||
if (!memgraph::license::global_license_checker.IsEnterpriseValidFast()) {
|
if (!memgraph::license::global_license_checker.IsEnterpriseValidFast()) {
|
||||||
return FineGrainedAccessPermissions{};
|
return FineGrainedAccessPermissions{};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (role_) {
|
if (role_) {
|
||||||
return Merge(role()->fine_grained_access_handler().edge_type_permissions(),
|
return role()->fine_grained_access_handler().edge_type_permissions();
|
||||||
fine_grained_access_handler_.edge_type_permissions());
|
|
||||||
}
|
}
|
||||||
return fine_grained_access_handler_.edge_type_permissions();
|
return FineGrainedAccessPermissions{};
|
||||||
|
}
|
||||||
|
|
||||||
|
FineGrainedAccessPermissions User::GetRoleFineGrainedAccessLabelPermissions() const {
|
||||||
|
if (!memgraph::license::global_license_checker.IsEnterpriseValidFast()) {
|
||||||
|
return FineGrainedAccessPermissions{};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (role_) {
|
||||||
|
return role()->fine_grained_access_handler().label_permissions();
|
||||||
|
}
|
||||||
|
return FineGrainedAccessPermissions{};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -668,16 +694,20 @@ const Role *User::role() const {
|
|||||||
|
|
||||||
nlohmann::json User::Serialize() const {
|
nlohmann::json User::Serialize() const {
|
||||||
nlohmann::json data = nlohmann::json::object();
|
nlohmann::json data = nlohmann::json::object();
|
||||||
data["username"] = username_;
|
data[kUsername] = username_;
|
||||||
data["password_hash"] = password_hash_;
|
if (password_hash_.has_value()) {
|
||||||
data["permissions"] = permissions_.Serialize();
|
data[kPasswordHash] = *password_hash_;
|
||||||
|
} else {
|
||||||
|
data[kPasswordHash] = nullptr;
|
||||||
|
}
|
||||||
|
data[kPermissions] = permissions_.Serialize();
|
||||||
#ifdef MG_ENTERPRISE
|
#ifdef MG_ENTERPRISE
|
||||||
if (memgraph::license::global_license_checker.IsEnterpriseValidFast()) {
|
if (memgraph::license::global_license_checker.IsEnterpriseValidFast()) {
|
||||||
data["fine_grained_access_handler"] = fine_grained_access_handler_.Serialize();
|
data[kFineGrainedAccessHandler] = fine_grained_access_handler_.Serialize();
|
||||||
data["databases"] = database_access_.Serialize();
|
data[kDatabases] = database_access_.Serialize();
|
||||||
} else {
|
} else {
|
||||||
data["fine_grained_access_handler"] = {};
|
data[kFineGrainedAccessHandler] = {};
|
||||||
data["databases"] = {};
|
data[kDatabases] = {};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// The role shouldn't be serialized here, it is stored as a foreign key.
|
// The role shouldn't be serialized here, it is stored as a foreign key.
|
||||||
@@ -688,30 +718,39 @@ User User::Deserialize(const nlohmann::json &data) {
|
|||||||
if (!data.is_object()) {
|
if (!data.is_object()) {
|
||||||
throw AuthException("Couldn't load user data!");
|
throw AuthException("Couldn't load user data!");
|
||||||
}
|
}
|
||||||
if (!data["username"].is_string() || !data["password_hash"].is_string() || !data["permissions"].is_object()) {
|
auto password_hash_json = data[kPasswordHash];
|
||||||
|
if (!data[kUsername].is_string() || !(password_hash_json.is_object() || password_hash_json.is_null()) ||
|
||||||
|
!data[kPermissions].is_object()) {
|
||||||
throw AuthException("Couldn't load user data!");
|
throw AuthException("Couldn't load user data!");
|
||||||
}
|
}
|
||||||
auto permissions = Permissions::Deserialize(data["permissions"]);
|
|
||||||
|
std::optional<HashedPassword> password_hash{};
|
||||||
|
if (password_hash_json.is_object()) {
|
||||||
|
password_hash = password_hash_json.get<HashedPassword>();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto permissions = Permissions::Deserialize(data[kPermissions]);
|
||||||
#ifdef MG_ENTERPRISE
|
#ifdef MG_ENTERPRISE
|
||||||
if (memgraph::license::global_license_checker.IsEnterpriseValidFast()) {
|
if (memgraph::license::global_license_checker.IsEnterpriseValidFast()) {
|
||||||
Databases db_access;
|
Databases db_access;
|
||||||
if (data["databases"].is_structured()) {
|
if (data[kDatabases].is_structured()) {
|
||||||
db_access = Databases::Deserialize(data["databases"]);
|
db_access = Databases::Deserialize(data[kDatabases]);
|
||||||
} else {
|
} else {
|
||||||
// Back-compatibility
|
// Back-compatibility
|
||||||
spdlog::warn("User without specified database access. Given access to the default database.");
|
spdlog::warn("User without specified database access. Given access to the default database.");
|
||||||
db_access.Add(dbms::kDefaultDB);
|
db_access.Grant(dbms::kDefaultDB);
|
||||||
db_access.SetDefault(dbms::kDefaultDB);
|
db_access.SetMain(dbms::kDefaultDB);
|
||||||
}
|
}
|
||||||
FineGrainedAccessHandler fine_grained_access_handler;
|
FineGrainedAccessHandler fine_grained_access_handler;
|
||||||
// We can have an empty fine_grained if the user was created without a valid license
|
// We can have an empty fine_grained if the user was created without a valid license
|
||||||
if (data["fine_grained_access_handler"].is_object()) {
|
if (data[kFineGrainedAccessHandler].is_object()) {
|
||||||
fine_grained_access_handler = FineGrainedAccessHandler::Deserialize(data["fine_grained_access_handler"]);
|
fine_grained_access_handler = FineGrainedAccessHandler::Deserialize(data[kFineGrainedAccessHandler]);
|
||||||
}
|
}
|
||||||
return {data["username"], data["password_hash"], permissions, std::move(fine_grained_access_handler), db_access};
|
return {data[kUsername], std::move(password_hash), permissions, std::move(fine_grained_access_handler),
|
||||||
|
std::move(db_access)};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return {data["username"], data["password_hash"], permissions};
|
return {data[kUsername], std::move(password_hash), permissions};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const User &first, const User &second) {
|
bool operator==(const User &first, const User &second) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2023 Memgraph Ltd.
|
// Copyright 2024 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Licensed as a Memgraph Enterprise file under the Memgraph Enterprise
|
// Licensed as a Memgraph Enterprise file under the Memgraph Enterprise
|
||||||
// License (the "License"); by using this file, you agree to be bound by the terms of the License, and you may not use
|
// License (the "License"); by using this file, you agree to be bound by the terms of the License, and you may not use
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
#include <json/json.hpp>
|
#include <json/json.hpp>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include "crypto.hpp"
|
||||||
#include "dbms/constants.hpp"
|
#include "dbms/constants.hpp"
|
||||||
#include "utils/logging.hpp"
|
#include "utils/logging.hpp"
|
||||||
|
|
||||||
@@ -48,6 +49,7 @@ enum class Permission : uint64_t {
|
|||||||
STORAGE_MODE = 1U << 22U,
|
STORAGE_MODE = 1U << 22U,
|
||||||
MULTI_DATABASE_EDIT = 1U << 23U,
|
MULTI_DATABASE_EDIT = 1U << 23U,
|
||||||
MULTI_DATABASE_USE = 1U << 24U,
|
MULTI_DATABASE_USE = 1U << 24U,
|
||||||
|
COORDINATOR = 1U << 25U,
|
||||||
};
|
};
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
@@ -203,50 +205,10 @@ class FineGrainedAccessHandler final {
|
|||||||
bool operator==(const FineGrainedAccessHandler &first, const FineGrainedAccessHandler &second);
|
bool operator==(const FineGrainedAccessHandler &first, const FineGrainedAccessHandler &second);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class Role final {
|
|
||||||
public:
|
|
||||||
explicit Role(const std::string &rolename);
|
|
||||||
Role(const std::string &rolename, const Permissions &permissions);
|
|
||||||
#ifdef MG_ENTERPRISE
|
|
||||||
Role(const std::string &rolename, const Permissions &permissions,
|
|
||||||
FineGrainedAccessHandler fine_grained_access_handler);
|
|
||||||
#endif
|
|
||||||
Role(const Role &) = default;
|
|
||||||
Role &operator=(const Role &) = default;
|
|
||||||
Role(Role &&) noexcept = default;
|
|
||||||
Role &operator=(Role &&) noexcept = default;
|
|
||||||
~Role() = default;
|
|
||||||
|
|
||||||
const std::string &rolename() const;
|
|
||||||
const Permissions &permissions() const;
|
|
||||||
Permissions &permissions();
|
|
||||||
#ifdef MG_ENTERPRISE
|
|
||||||
const FineGrainedAccessHandler &fine_grained_access_handler() const;
|
|
||||||
FineGrainedAccessHandler &fine_grained_access_handler();
|
|
||||||
const FineGrainedAccessPermissions &GetFineGrainedAccessLabelPermissions() const;
|
|
||||||
const FineGrainedAccessPermissions &GetFineGrainedAccessEdgeTypePermissions() const;
|
|
||||||
#endif
|
|
||||||
nlohmann::json Serialize() const;
|
|
||||||
|
|
||||||
/// @throw AuthException if unable to deserialize.
|
|
||||||
static Role Deserialize(const nlohmann::json &data);
|
|
||||||
|
|
||||||
friend bool operator==(const Role &first, const Role &second);
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::string rolename_;
|
|
||||||
Permissions permissions_;
|
|
||||||
#ifdef MG_ENTERPRISE
|
|
||||||
FineGrainedAccessHandler fine_grained_access_handler_;
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
bool operator==(const Role &first, const Role &second);
|
|
||||||
|
|
||||||
#ifdef MG_ENTERPRISE
|
#ifdef MG_ENTERPRISE
|
||||||
class Databases final {
|
class Databases final {
|
||||||
public:
|
public:
|
||||||
Databases() : grants_dbs_({dbms::kDefaultDB}), allow_all_(false), default_db_(dbms::kDefaultDB) {}
|
Databases() : grants_dbs_{std::string{dbms::kDefaultDB}}, allow_all_(false), main_db_(dbms::kDefaultDB) {}
|
||||||
|
|
||||||
Databases(const Databases &) = default;
|
Databases(const Databases &) = default;
|
||||||
Databases &operator=(const Databases &) = default;
|
Databases &operator=(const Databases &) = default;
|
||||||
@@ -259,7 +221,7 @@ class Databases final {
|
|||||||
*
|
*
|
||||||
* @param db name of the database to grant access to
|
* @param db name of the database to grant access to
|
||||||
*/
|
*/
|
||||||
void Add(const std::string &db);
|
void Grant(std::string_view db);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Remove database to the list of granted access.
|
* @brief Remove database to the list of granted access.
|
||||||
@@ -268,7 +230,7 @@ class Databases final {
|
|||||||
*
|
*
|
||||||
* @param db name of the database to grant access to
|
* @param db name of the database to grant access to
|
||||||
*/
|
*/
|
||||||
void Remove(const std::string &db);
|
void Deny(const std::string &db);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Called when database is dropped. Removes it from granted (if allow_all is false) and denied set.
|
* @brief Called when database is dropped. Removes it from granted (if allow_all is false) and denied set.
|
||||||
@@ -276,7 +238,7 @@ class Databases final {
|
|||||||
*
|
*
|
||||||
* @param db name of the database to grant access to
|
* @param db name of the database to grant access to
|
||||||
*/
|
*/
|
||||||
void Delete(const std::string &db);
|
void Revoke(const std::string &db);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set allow_all_ to true and clears grants and denied sets.
|
* @brief Set allow_all_ to true and clears grants and denied sets.
|
||||||
@@ -288,10 +250,15 @@ class Databases final {
|
|||||||
*/
|
*/
|
||||||
void DenyAll();
|
void DenyAll();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set allow_all_ to false and clears grants and denied sets.
|
||||||
|
*/
|
||||||
|
void RevokeAll();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the default database.
|
* @brief Set the default database.
|
||||||
*/
|
*/
|
||||||
bool SetDefault(const std::string &db);
|
bool SetMain(std::string_view db);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Checks if access is grated to the database.
|
* @brief Checks if access is grated to the database.
|
||||||
@@ -299,12 +266,14 @@ class Databases final {
|
|||||||
* @param db name of the database
|
* @param db name of the database
|
||||||
* @return true if allow_all and not denied or granted
|
* @return true if allow_all and not denied or granted
|
||||||
*/
|
*/
|
||||||
bool Contains(const std::string &db) const;
|
bool Contains(std::string_view db) const;
|
||||||
|
bool Denies(std::string_view db_name) const { return denies_dbs_.contains(db_name); }
|
||||||
|
bool Grants(std::string_view db_name) const { return allow_all_ || grants_dbs_.contains(db_name); }
|
||||||
|
|
||||||
bool GetAllowAll() const { return allow_all_; }
|
bool GetAllowAll() const { return allow_all_; }
|
||||||
const std::set<std::string, std::less<>> &GetGrants() const { return grants_dbs_; }
|
const std::set<std::string, std::less<>> &GetGrants() const { return grants_dbs_; }
|
||||||
const std::set<std::string, std::less<>> &GetDenies() const { return denies_dbs_; }
|
const std::set<std::string, std::less<>> &GetDenies() const { return denies_dbs_; }
|
||||||
const std::string &GetDefault() const;
|
const std::string &GetMain() const;
|
||||||
|
|
||||||
nlohmann::json Serialize() const;
|
nlohmann::json Serialize() const;
|
||||||
/// @throw AuthException if unable to deserialize.
|
/// @throw AuthException if unable to deserialize.
|
||||||
@@ -312,28 +281,82 @@ class Databases final {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Databases(bool allow_all, std::set<std::string, std::less<>> grant, std::set<std::string, std::less<>> deny,
|
Databases(bool allow_all, std::set<std::string, std::less<>> grant, std::set<std::string, std::less<>> deny,
|
||||||
std::string default_db = dbms::kDefaultDB)
|
std::string default_db = std::string{dbms::kDefaultDB})
|
||||||
: grants_dbs_(std::move(grant)),
|
: grants_dbs_(std::move(grant)),
|
||||||
denies_dbs_(std::move(deny)),
|
denies_dbs_(std::move(deny)),
|
||||||
allow_all_(allow_all),
|
allow_all_(allow_all),
|
||||||
default_db_(std::move(default_db)) {}
|
main_db_(std::move(default_db)) {}
|
||||||
|
|
||||||
std::set<std::string, std::less<>> grants_dbs_; //!< set of databases with granted access
|
std::set<std::string, std::less<>> grants_dbs_; //!< set of databases with granted access
|
||||||
std::set<std::string, std::less<>> denies_dbs_; //!< set of databases with denied access
|
std::set<std::string, std::less<>> denies_dbs_; //!< set of databases with denied access
|
||||||
bool allow_all_; //!< flag to allow access to everything (denied overrides this)
|
bool allow_all_; //!< flag to allow access to everything (denied overrides this)
|
||||||
std::string default_db_; //!< user's default database
|
std::string main_db_; //!< user's default database
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
class Role {
|
||||||
|
public:
|
||||||
|
Role() = default;
|
||||||
|
|
||||||
|
explicit Role(const std::string &rolename);
|
||||||
|
Role(const std::string &rolename, const Permissions &permissions);
|
||||||
|
#ifdef MG_ENTERPRISE
|
||||||
|
Role(const std::string &rolename, const Permissions &permissions,
|
||||||
|
FineGrainedAccessHandler fine_grained_access_handler, Databases db_access = {});
|
||||||
|
#endif
|
||||||
|
Role(const Role &) = default;
|
||||||
|
Role &operator=(const Role &) = default;
|
||||||
|
Role(Role &&) noexcept = default;
|
||||||
|
Role &operator=(Role &&) noexcept = default;
|
||||||
|
~Role() = default;
|
||||||
|
|
||||||
|
const std::string &rolename() const;
|
||||||
|
const Permissions &permissions() const;
|
||||||
|
Permissions &permissions();
|
||||||
|
Permissions GetPermissions() const { return permissions_; }
|
||||||
|
#ifdef MG_ENTERPRISE
|
||||||
|
const FineGrainedAccessHandler &fine_grained_access_handler() const;
|
||||||
|
FineGrainedAccessHandler &fine_grained_access_handler();
|
||||||
|
const FineGrainedAccessPermissions &GetFineGrainedAccessLabelPermissions() const;
|
||||||
|
const FineGrainedAccessPermissions &GetFineGrainedAccessEdgeTypePermissions() const;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef MG_ENTERPRISE
|
||||||
|
Databases &db_access() { return db_access_; }
|
||||||
|
const Databases &db_access() const { return db_access_; }
|
||||||
|
|
||||||
|
bool DeniesDB(std::string_view db_name) const { return db_access_.Denies(db_name); }
|
||||||
|
bool GrantsDB(std::string_view db_name) const { return db_access_.Grants(db_name); }
|
||||||
|
bool HasAccess(std::string_view db_name) const { return !DeniesDB(db_name) && GrantsDB(db_name); }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
nlohmann::json Serialize() const;
|
||||||
|
|
||||||
|
/// @throw AuthException if unable to deserialize.
|
||||||
|
static Role Deserialize(const nlohmann::json &data);
|
||||||
|
|
||||||
|
friend bool operator==(const Role &first, const Role &second);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string rolename_;
|
||||||
|
Permissions permissions_;
|
||||||
|
#ifdef MG_ENTERPRISE
|
||||||
|
FineGrainedAccessHandler fine_grained_access_handler_;
|
||||||
|
Databases db_access_;
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
bool operator==(const Role &first, const Role &second);
|
||||||
|
|
||||||
// TODO (mferencevic): Implement password expiry.
|
// TODO (mferencevic): Implement password expiry.
|
||||||
class User final {
|
class User final {
|
||||||
public:
|
public:
|
||||||
User();
|
User();
|
||||||
|
|
||||||
explicit User(const std::string &username);
|
explicit User(const std::string &username);
|
||||||
User(const std::string &username, std::string password_hash, const Permissions &permissions);
|
User(const std::string &username, std::optional<HashedPassword> password_hash, const Permissions &permissions);
|
||||||
#ifdef MG_ENTERPRISE
|
#ifdef MG_ENTERPRISE
|
||||||
User(const std::string &username, std::string password_hash, const Permissions &permissions,
|
User(const std::string &username, std::optional<HashedPassword> password_hash, const Permissions &permissions,
|
||||||
FineGrainedAccessHandler fine_grained_access_handler, Databases db_access = {});
|
FineGrainedAccessHandler fine_grained_access_handler, Databases db_access = {});
|
||||||
#endif
|
#endif
|
||||||
User(const User &) = default;
|
User(const User &) = default;
|
||||||
@@ -345,8 +368,18 @@ class User final {
|
|||||||
/// @throw AuthException if unable to verify the password.
|
/// @throw AuthException if unable to verify the password.
|
||||||
bool CheckPassword(const std::string &password);
|
bool CheckPassword(const std::string &password);
|
||||||
|
|
||||||
|
bool UpgradeHash(const std::string password) {
|
||||||
|
if (!password_hash_) return false;
|
||||||
|
if (password_hash_->IsSalted()) return false;
|
||||||
|
|
||||||
|
auto const algo = password_hash_->HashAlgo();
|
||||||
|
UpdatePassword(password, algo);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/// @throw AuthException if unable to set the password.
|
/// @throw AuthException if unable to set the password.
|
||||||
void UpdatePassword(const std::optional<std::string> &password = std::nullopt);
|
void UpdatePassword(const std::optional<std::string> &password = {},
|
||||||
|
std::optional<PasswordHashAlgorithm> algo_override = std::nullopt);
|
||||||
|
|
||||||
void SetRole(const Role &role);
|
void SetRole(const Role &role);
|
||||||
|
|
||||||
@@ -357,6 +390,10 @@ class User final {
|
|||||||
#ifdef MG_ENTERPRISE
|
#ifdef MG_ENTERPRISE
|
||||||
FineGrainedAccessPermissions GetFineGrainedAccessLabelPermissions() const;
|
FineGrainedAccessPermissions GetFineGrainedAccessLabelPermissions() const;
|
||||||
FineGrainedAccessPermissions GetFineGrainedAccessEdgeTypePermissions() const;
|
FineGrainedAccessPermissions GetFineGrainedAccessEdgeTypePermissions() const;
|
||||||
|
FineGrainedAccessPermissions GetUserFineGrainedAccessLabelPermissions() const;
|
||||||
|
FineGrainedAccessPermissions GetUserFineGrainedAccessEdgeTypePermissions() const;
|
||||||
|
FineGrainedAccessPermissions GetRoleFineGrainedAccessLabelPermissions() const;
|
||||||
|
FineGrainedAccessPermissions GetRoleFineGrainedAccessEdgeTypePermissions() const;
|
||||||
const FineGrainedAccessHandler &fine_grained_access_handler() const;
|
const FineGrainedAccessHandler &fine_grained_access_handler() const;
|
||||||
FineGrainedAccessHandler &fine_grained_access_handler();
|
FineGrainedAccessHandler &fine_grained_access_handler();
|
||||||
#endif
|
#endif
|
||||||
@@ -370,6 +407,18 @@ class User final {
|
|||||||
#ifdef MG_ENTERPRISE
|
#ifdef MG_ENTERPRISE
|
||||||
Databases &db_access() { return database_access_; }
|
Databases &db_access() { return database_access_; }
|
||||||
const Databases &db_access() const { return database_access_; }
|
const Databases &db_access() const { return database_access_; }
|
||||||
|
|
||||||
|
bool DeniesDB(std::string_view db_name) const {
|
||||||
|
bool denies = database_access_.Denies(db_name);
|
||||||
|
if (role_) denies |= role_->DeniesDB(db_name);
|
||||||
|
return denies;
|
||||||
|
}
|
||||||
|
bool GrantsDB(std::string_view db_name) const {
|
||||||
|
bool grants = database_access_.Grants(db_name);
|
||||||
|
if (role_) grants |= role_->GrantsDB(db_name);
|
||||||
|
return grants;
|
||||||
|
}
|
||||||
|
bool HasAccess(std::string_view db_name) const { return !DeniesDB(db_name) && GrantsDB(db_name); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
nlohmann::json Serialize() const;
|
nlohmann::json Serialize() const;
|
||||||
@@ -381,11 +430,11 @@ class User final {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::string username_;
|
std::string username_;
|
||||||
std::string password_hash_;
|
std::optional<HashedPassword> password_hash_;
|
||||||
Permissions permissions_;
|
Permissions permissions_;
|
||||||
#ifdef MG_ENTERPRISE
|
#ifdef MG_ENTERPRISE
|
||||||
FineGrainedAccessHandler fine_grained_access_handler_;
|
FineGrainedAccessHandler fine_grained_access_handler_;
|
||||||
Databases database_access_;
|
Databases database_access_{};
|
||||||
#endif
|
#endif
|
||||||
std::optional<Role> role_;
|
std::optional<Role> role_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2022 Memgraph Ltd.
|
// Copyright 2024 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Licensed as a Memgraph Enterprise file under the Memgraph Enterprise
|
// Licensed as a Memgraph Enterprise file under the Memgraph Enterprise
|
||||||
// License (the "License"); by using this file, you agree to be bound by the terms of the License, and you may not use
|
// License (the "License"); by using this file, you agree to be bound by the terms of the License, and you may not use
|
||||||
@@ -403,7 +403,7 @@ nlohmann::json Module::Call(const nlohmann::json ¶ms, int timeout_millisec)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Module::IsUsed() { return !module_executable_path_.empty(); }
|
bool Module::IsUsed() const { return !module_executable_path_.empty(); }
|
||||||
|
|
||||||
void Module::Shutdown() {
|
void Module::Shutdown() {
|
||||||
if (pid_ == -1) return;
|
if (pid_ == -1) return;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2022 Memgraph Ltd.
|
// Copyright 2024 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Licensed as a Memgraph Enterprise file under the Memgraph Enterprise
|
// Licensed as a Memgraph Enterprise file under the Memgraph Enterprise
|
||||||
// License (the "License"); by using this file, you agree to be bound by the terms of the License, and you may not use
|
// License (the "License"); by using this file, you agree to be bound by the terms of the License, and you may not use
|
||||||
@@ -49,7 +49,7 @@ class Module final {
|
|||||||
/// specified executable path and can thus be used.
|
/// specified executable path and can thus be used.
|
||||||
///
|
///
|
||||||
/// @return boolean indicating whether the module can be used
|
/// @return boolean indicating whether the module can be used
|
||||||
bool IsUsed();
|
bool IsUsed() const;
|
||||||
|
|
||||||
~Module();
|
~Module();
|
||||||
|
|
||||||
|
|||||||
190
src/auth/replication_handlers.cpp
Normal file
190
src/auth/replication_handlers.cpp
Normal file
@@ -0,0 +1,190 @@
|
|||||||
|
// Copyright 2024 Memgraph Ltd.
|
||||||
|
//
|
||||||
|
// Use of this software is governed by the Business Source License
|
||||||
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
|
// License, and you may not use this file except in compliance with the Business Source License.
|
||||||
|
//
|
||||||
|
// As of the Change Date specified in that file, in accordance with
|
||||||
|
// the Business Source License, use of this software will be governed
|
||||||
|
// by the Apache License, Version 2.0, included in the file
|
||||||
|
// licenses/APL.txt.
|
||||||
|
|
||||||
|
#include "auth/replication_handlers.hpp"
|
||||||
|
|
||||||
|
#include "auth/auth.hpp"
|
||||||
|
#include "auth/rpc.hpp"
|
||||||
|
#include "license/license.hpp"
|
||||||
|
|
||||||
|
namespace memgraph::auth {
|
||||||
|
|
||||||
|
void LogWrongMain(const std::optional<utils::UUID> ¤t_main_uuid, const utils::UUID &main_req_id,
|
||||||
|
std::string_view rpc_req) {
|
||||||
|
spdlog::error(fmt::format("Received {} with main_id: {} != current_main_uuid: {}", rpc_req, std::string(main_req_id),
|
||||||
|
current_main_uuid.has_value() ? std::string(current_main_uuid.value()) : ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef MG_ENTERPRISE
|
||||||
|
void UpdateAuthDataHandler(memgraph::system::ReplicaHandlerAccessToState &system_state_access,
|
||||||
|
const std::optional<utils::UUID> ¤t_main_uuid, auth::SynchedAuth &auth,
|
||||||
|
slk::Reader *req_reader, slk::Builder *res_builder) {
|
||||||
|
replication::UpdateAuthDataReq req;
|
||||||
|
memgraph::slk::Load(&req, req_reader);
|
||||||
|
|
||||||
|
using memgraph::replication::UpdateAuthDataRes;
|
||||||
|
UpdateAuthDataRes res(false);
|
||||||
|
|
||||||
|
if (!current_main_uuid.has_value() || req.main_uuid != current_main_uuid) [[unlikely]] {
|
||||||
|
LogWrongMain(current_main_uuid, req.main_uuid, replication::UpdateAuthDataReq::kType.name);
|
||||||
|
memgraph::slk::Save(res, res_builder);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note: No need to check epoch, recovery mechanism is done by a full uptodate snapshot
|
||||||
|
// of the set of databases. Hence no history exists to maintain regarding epoch change.
|
||||||
|
// If MAIN has changed we need to check this new group_timestamp is consistent with
|
||||||
|
// what we have so far.
|
||||||
|
|
||||||
|
if (req.expected_group_timestamp != system_state_access.LastCommitedTS()) {
|
||||||
|
spdlog::debug("UpdateAuthDataHandler: bad expected timestamp {},{}", req.expected_group_timestamp,
|
||||||
|
system_state_access.LastCommitedTS());
|
||||||
|
memgraph::slk::Save(res, res_builder);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Update
|
||||||
|
if (req.user) auth->SaveUser(*req.user);
|
||||||
|
if (req.role) auth->SaveRole(*req.role);
|
||||||
|
// Success
|
||||||
|
system_state_access.SetLastCommitedTS(req.new_group_timestamp);
|
||||||
|
res = UpdateAuthDataRes(true);
|
||||||
|
spdlog::debug("UpdateAuthDataHandler: SUCCESS updated LCTS to {}", req.new_group_timestamp);
|
||||||
|
} catch (const auth::AuthException & /* not used */) {
|
||||||
|
// Failure
|
||||||
|
}
|
||||||
|
|
||||||
|
memgraph::slk::Save(res, res_builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DropAuthDataHandler(memgraph::system::ReplicaHandlerAccessToState &system_state_access,
|
||||||
|
const std::optional<utils::UUID> ¤t_main_uuid, auth::SynchedAuth &auth,
|
||||||
|
slk::Reader *req_reader, slk::Builder *res_builder) {
|
||||||
|
replication::DropAuthDataReq req;
|
||||||
|
memgraph::slk::Load(&req, req_reader);
|
||||||
|
|
||||||
|
using memgraph::replication::DropAuthDataRes;
|
||||||
|
DropAuthDataRes res(false);
|
||||||
|
|
||||||
|
if (!current_main_uuid.has_value() || req.main_uuid != current_main_uuid) [[unlikely]] {
|
||||||
|
LogWrongMain(current_main_uuid, req.main_uuid, replication::DropAuthDataRes::kType.name);
|
||||||
|
memgraph::slk::Save(res, res_builder);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note: No need to check epoch, recovery mechanism is done by a full uptodate snapshot
|
||||||
|
// of the set of databases. Hence no history exists to maintain regarding epoch change.
|
||||||
|
// If MAIN has changed we need to check this new group_timestamp is consistent with
|
||||||
|
// what we have so far.
|
||||||
|
|
||||||
|
if (req.expected_group_timestamp != system_state_access.LastCommitedTS()) {
|
||||||
|
spdlog::debug("DropAuthDataHandler: bad expected timestamp {},{}", req.expected_group_timestamp,
|
||||||
|
system_state_access.LastCommitedTS());
|
||||||
|
memgraph::slk::Save(res, res_builder);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Remove
|
||||||
|
switch (req.type) {
|
||||||
|
case replication::DropAuthDataReq::DataType::USER:
|
||||||
|
auth->RemoveUser(req.name);
|
||||||
|
break;
|
||||||
|
case replication::DropAuthDataReq::DataType::ROLE:
|
||||||
|
auth->RemoveRole(req.name);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// Success
|
||||||
|
system_state_access.SetLastCommitedTS(req.new_group_timestamp);
|
||||||
|
res = DropAuthDataRes(true);
|
||||||
|
spdlog::debug("DropAuthDataHandler: SUCCESS updated LCTS to {}", req.new_group_timestamp);
|
||||||
|
} catch (const auth::AuthException & /* not used */) {
|
||||||
|
// Failure
|
||||||
|
}
|
||||||
|
|
||||||
|
memgraph::slk::Save(res, res_builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SystemRecoveryHandler(auth::SynchedAuth &auth, auth::Auth::Config auth_config,
|
||||||
|
const std::vector<auth::User> &users, const std::vector<auth::Role> &roles) {
|
||||||
|
return auth.WithLock([&](auto &locked_auth) {
|
||||||
|
// Update config
|
||||||
|
locked_auth.SetConfig(std::move(auth_config));
|
||||||
|
// Get all current users
|
||||||
|
auto old_users = locked_auth.AllUsernames();
|
||||||
|
// Save incoming users
|
||||||
|
for (const auto &user : users) {
|
||||||
|
// Missing users
|
||||||
|
try {
|
||||||
|
locked_auth.SaveUser(user);
|
||||||
|
} catch (const auth::AuthException &) {
|
||||||
|
spdlog::debug("SystemRecoveryHandler: Failed to save user");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const auto it = std::find(old_users.begin(), old_users.end(), user.username());
|
||||||
|
if (it != old_users.end()) old_users.erase(it);
|
||||||
|
}
|
||||||
|
// Delete all the leftover users
|
||||||
|
for (const auto &user : old_users) {
|
||||||
|
if (!locked_auth.RemoveUser(user)) {
|
||||||
|
spdlog::debug("SystemRecoveryHandler: Failed to remove user \"{}\".", user);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Roles are only supported with a license
|
||||||
|
if (license::global_license_checker.IsEnterpriseValidFast()) {
|
||||||
|
// Get all current roles
|
||||||
|
auto old_roles = locked_auth.AllRolenames();
|
||||||
|
// Save incoming users
|
||||||
|
for (const auto &role : roles) {
|
||||||
|
// Missing users
|
||||||
|
try {
|
||||||
|
locked_auth.SaveRole(role);
|
||||||
|
} catch (const auth::AuthException &) {
|
||||||
|
spdlog::debug("SystemRecoveryHandler: Failed to save user");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const auto it = std::find(old_roles.begin(), old_roles.end(), role.rolename());
|
||||||
|
if (it != old_roles.end()) old_roles.erase(it);
|
||||||
|
}
|
||||||
|
// Delete all the leftover users
|
||||||
|
for (const auto &role : old_roles) {
|
||||||
|
if (!locked_auth.RemoveRole(role)) {
|
||||||
|
spdlog::debug("SystemRecoveryHandler: Failed to remove user \"{}\".", role);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Success
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void Register(replication::RoleReplicaData const &data, system::ReplicaHandlerAccessToState &system_state_access,
|
||||||
|
auth::SynchedAuth &auth) {
|
||||||
|
// NOTE: Register even without license as the user could add a license at run-time
|
||||||
|
data.server->rpc_server_.Register<replication::UpdateAuthDataRpc>(
|
||||||
|
[&data, system_state_access, &auth](auto *req_reader, auto *res_builder) mutable {
|
||||||
|
spdlog::debug("Received UpdateAuthDataRpc");
|
||||||
|
UpdateAuthDataHandler(system_state_access, data.uuid_, auth, req_reader, res_builder);
|
||||||
|
});
|
||||||
|
data.server->rpc_server_.Register<replication::DropAuthDataRpc>(
|
||||||
|
[&data, system_state_access, &auth](auto *req_reader, auto *res_builder) mutable {
|
||||||
|
spdlog::debug("Received DropAuthDataRpc");
|
||||||
|
DropAuthDataHandler(system_state_access, data.uuid_, auth, req_reader, res_builder);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} // namespace memgraph::auth
|
||||||
37
src/auth/replication_handlers.hpp
Normal file
37
src/auth/replication_handlers.hpp
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
// Copyright 2024 Memgraph Ltd.
|
||||||
|
//
|
||||||
|
// Use of this software is governed by the Business Source License
|
||||||
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
|
// License, and you may not use this file except in compliance with the Business Source License.
|
||||||
|
//
|
||||||
|
// As of the Change Date specified in that file, in accordance with
|
||||||
|
// the Business Source License, use of this software will be governed
|
||||||
|
// by the Apache License, Version 2.0, included in the file
|
||||||
|
// licenses/APL.txt.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "auth/auth.hpp"
|
||||||
|
#include "replication/state.hpp"
|
||||||
|
#include "slk/streams.hpp"
|
||||||
|
#include "system/state.hpp"
|
||||||
|
|
||||||
|
namespace memgraph::auth {
|
||||||
|
|
||||||
|
void LogWrongMain(const std::optional<utils::UUID> ¤t_main_uuid, const utils::UUID &main_req_id,
|
||||||
|
std::string_view rpc_req);
|
||||||
|
|
||||||
|
#ifdef MG_ENTERPRISE
|
||||||
|
void UpdateAuthDataHandler(system::ReplicaHandlerAccessToState &system_state_access,
|
||||||
|
const std::optional<utils::UUID> ¤t_main_uuid, auth::SynchedAuth &auth,
|
||||||
|
slk::Reader *req_reader, slk::Builder *res_builder);
|
||||||
|
void DropAuthDataHandler(system::ReplicaHandlerAccessToState &system_state_access,
|
||||||
|
const std::optional<utils::UUID> ¤t_main_uuid, auth::SynchedAuth &auth,
|
||||||
|
slk::Reader *req_reader, slk::Builder *res_builder);
|
||||||
|
|
||||||
|
bool SystemRecoveryHandler(auth::SynchedAuth &auth, auth::Auth::Config auth_config,
|
||||||
|
const std::vector<auth::User> &users, const std::vector<auth::Role> &roles);
|
||||||
|
void Register(replication::RoleReplicaData const &data, system::ReplicaHandlerAccessToState &system_state_access,
|
||||||
|
auth::SynchedAuth &auth);
|
||||||
|
#endif
|
||||||
|
} // namespace memgraph::auth
|
||||||
180
src/auth/rpc.cpp
Normal file
180
src/auth/rpc.cpp
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
// Copyright 2024 Memgraph Ltd.
|
||||||
|
//
|
||||||
|
// Use of this software is governed by the Business Source License
|
||||||
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
|
// License, and you may not use this file except in compliance with the Business Source License.
|
||||||
|
//
|
||||||
|
// As of the Change Date specified in that file, in accordance with
|
||||||
|
// the Business Source License, use of this software will be governed
|
||||||
|
// by the Apache License, Version 2.0, included in the file
|
||||||
|
// licenses/APL.txt.
|
||||||
|
|
||||||
|
#include "auth/rpc.hpp"
|
||||||
|
|
||||||
|
#include <json/json.hpp>
|
||||||
|
#include "auth/auth.hpp"
|
||||||
|
#include "slk/serialization.hpp"
|
||||||
|
#include "slk/streams.hpp"
|
||||||
|
#include "utils/enum.hpp"
|
||||||
|
|
||||||
|
namespace memgraph::slk {
|
||||||
|
// Serialize code for auth::Role
|
||||||
|
void Save(const auth::Role &self, Builder *builder) { memgraph::slk::Save(self.Serialize().dump(), builder); }
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
auth::Role LoadAuthRole(memgraph::slk::Reader *reader) {
|
||||||
|
std::string tmp;
|
||||||
|
memgraph::slk::Load(&tmp, reader);
|
||||||
|
const auto json = nlohmann::json::parse(tmp);
|
||||||
|
return memgraph::auth::Role::Deserialize(json);
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
// Deserialize code for auth::Role
|
||||||
|
void Load(auth::Role *self, memgraph::slk::Reader *reader) { *self = LoadAuthRole(reader); }
|
||||||
|
// Special case for optional<Role>
|
||||||
|
template <>
|
||||||
|
inline void Load<auth::Role>(std::optional<auth::Role> *obj, Reader *reader) {
|
||||||
|
bool exists = false;
|
||||||
|
Load(&exists, reader);
|
||||||
|
if (exists) {
|
||||||
|
obj->emplace(LoadAuthRole(reader));
|
||||||
|
} else {
|
||||||
|
*obj = std::nullopt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Serialize code for auth::User
|
||||||
|
void Save(const auth::User &self, memgraph::slk::Builder *builder) {
|
||||||
|
memgraph::slk::Save(self.Serialize().dump(), builder);
|
||||||
|
std::optional<auth::Role> role{};
|
||||||
|
if (const auto *role_ptr = self.role(); role_ptr) {
|
||||||
|
role.emplace(*role_ptr);
|
||||||
|
}
|
||||||
|
memgraph::slk::Save(role, builder);
|
||||||
|
}
|
||||||
|
// Deserialize code for auth::User
|
||||||
|
void Load(auth::User *self, memgraph::slk::Reader *reader) {
|
||||||
|
std::string tmp;
|
||||||
|
memgraph::slk::Load(&tmp, reader);
|
||||||
|
const auto json = nlohmann::json::parse(tmp);
|
||||||
|
*self = memgraph::auth::User::Deserialize(json);
|
||||||
|
std::optional<auth::Role> role{};
|
||||||
|
memgraph::slk::Load(&role, reader);
|
||||||
|
if (role)
|
||||||
|
self->SetRole(*role);
|
||||||
|
else
|
||||||
|
self->ClearRole();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Serialize code for auth::Auth::Config
|
||||||
|
void Save(const auth::Auth::Config &self, memgraph::slk::Builder *builder) {
|
||||||
|
memgraph::slk::Save(self.name_regex_str, builder);
|
||||||
|
memgraph::slk::Save(self.password_regex_str, builder);
|
||||||
|
memgraph::slk::Save(self.password_permit_null, builder);
|
||||||
|
}
|
||||||
|
// Deserialize code for auth::Auth::Config
|
||||||
|
void Load(auth::Auth::Config *self, memgraph::slk::Reader *reader) {
|
||||||
|
std::string name_regex_str{};
|
||||||
|
std::string password_regex_str{};
|
||||||
|
bool password_permit_null{};
|
||||||
|
|
||||||
|
memgraph::slk::Load(&name_regex_str, reader);
|
||||||
|
memgraph::slk::Load(&password_regex_str, reader);
|
||||||
|
memgraph::slk::Load(&password_permit_null, reader);
|
||||||
|
|
||||||
|
*self = auth::Auth::Config{std::move(name_regex_str), std::move(password_regex_str), password_permit_null};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Serialize code for UpdateAuthDataReq
|
||||||
|
void Save(const memgraph::replication::UpdateAuthDataReq &self, memgraph::slk::Builder *builder) {
|
||||||
|
memgraph::slk::Save(self.main_uuid, builder);
|
||||||
|
memgraph::slk::Save(self.epoch_id, builder);
|
||||||
|
memgraph::slk::Save(self.expected_group_timestamp, builder);
|
||||||
|
memgraph::slk::Save(self.new_group_timestamp, builder);
|
||||||
|
memgraph::slk::Save(self.user, builder);
|
||||||
|
memgraph::slk::Save(self.role, builder);
|
||||||
|
}
|
||||||
|
void Load(memgraph::replication::UpdateAuthDataReq *self, memgraph::slk::Reader *reader) {
|
||||||
|
memgraph::slk::Load(&self->main_uuid, reader);
|
||||||
|
memgraph::slk::Load(&self->epoch_id, reader);
|
||||||
|
memgraph::slk::Load(&self->expected_group_timestamp, reader);
|
||||||
|
memgraph::slk::Load(&self->new_group_timestamp, reader);
|
||||||
|
memgraph::slk::Load(&self->user, reader);
|
||||||
|
memgraph::slk::Load(&self->role, reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Serialize code for UpdateAuthDataRes
|
||||||
|
void Save(const memgraph::replication::UpdateAuthDataRes &self, memgraph::slk::Builder *builder) {
|
||||||
|
memgraph::slk::Save(self.success, builder);
|
||||||
|
}
|
||||||
|
void Load(memgraph::replication::UpdateAuthDataRes *self, memgraph::slk::Reader *reader) {
|
||||||
|
memgraph::slk::Load(&self->success, reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Serialize code for DropAuthDataReq
|
||||||
|
void Save(const memgraph::replication::DropAuthDataReq &self, memgraph::slk::Builder *builder) {
|
||||||
|
memgraph::slk::Save(self.main_uuid, builder);
|
||||||
|
memgraph::slk::Save(self.epoch_id, builder);
|
||||||
|
memgraph::slk::Save(self.expected_group_timestamp, builder);
|
||||||
|
memgraph::slk::Save(self.new_group_timestamp, builder);
|
||||||
|
memgraph::slk::Save(utils::EnumToNum<2, uint8_t>(self.type), builder);
|
||||||
|
memgraph::slk::Save(self.name, builder);
|
||||||
|
}
|
||||||
|
void Load(memgraph::replication::DropAuthDataReq *self, memgraph::slk::Reader *reader) {
|
||||||
|
memgraph::slk::Load(&self->main_uuid, reader);
|
||||||
|
memgraph::slk::Load(&self->epoch_id, reader);
|
||||||
|
memgraph::slk::Load(&self->expected_group_timestamp, reader);
|
||||||
|
memgraph::slk::Load(&self->new_group_timestamp, reader);
|
||||||
|
uint8_t type_tmp = 0;
|
||||||
|
memgraph::slk::Load(&type_tmp, reader);
|
||||||
|
if (!utils::NumToEnum<2>(type_tmp, self->type)) {
|
||||||
|
throw SlkReaderException("Unexpected result line:{}!", __LINE__);
|
||||||
|
}
|
||||||
|
memgraph::slk::Load(&self->name, reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Serialize code for DropAuthDataRes
|
||||||
|
void Save(const memgraph::replication::DropAuthDataRes &self, memgraph::slk::Builder *builder) {
|
||||||
|
memgraph::slk::Save(self.success, builder);
|
||||||
|
}
|
||||||
|
void Load(memgraph::replication::DropAuthDataRes *self, memgraph::slk::Reader *reader) {
|
||||||
|
memgraph::slk::Load(&self->success, reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace memgraph::slk
|
||||||
|
|
||||||
|
namespace memgraph::replication {
|
||||||
|
|
||||||
|
constexpr utils::TypeInfo UpdateAuthDataReq::kType{utils::TypeId::REP_UPDATE_AUTH_DATA_REQ, "UpdateAuthDataReq",
|
||||||
|
nullptr};
|
||||||
|
|
||||||
|
constexpr utils::TypeInfo UpdateAuthDataRes::kType{utils::TypeId::REP_UPDATE_AUTH_DATA_RES, "UpdateAuthDataRes",
|
||||||
|
nullptr};
|
||||||
|
|
||||||
|
constexpr utils::TypeInfo DropAuthDataReq::kType{utils::TypeId::REP_DROP_AUTH_DATA_REQ, "DropAuthDataReq", nullptr};
|
||||||
|
|
||||||
|
constexpr utils::TypeInfo DropAuthDataRes::kType{utils::TypeId::REP_DROP_AUTH_DATA_RES, "DropAuthDataRes", nullptr};
|
||||||
|
|
||||||
|
void UpdateAuthDataReq::Save(const UpdateAuthDataReq &self, memgraph::slk::Builder *builder) {
|
||||||
|
memgraph::slk::Save(self, builder);
|
||||||
|
}
|
||||||
|
void UpdateAuthDataReq::Load(UpdateAuthDataReq *self, memgraph::slk::Reader *reader) {
|
||||||
|
memgraph::slk::Load(self, reader);
|
||||||
|
}
|
||||||
|
void UpdateAuthDataRes::Save(const UpdateAuthDataRes &self, memgraph::slk::Builder *builder) {
|
||||||
|
memgraph::slk::Save(self, builder);
|
||||||
|
}
|
||||||
|
void UpdateAuthDataRes::Load(UpdateAuthDataRes *self, memgraph::slk::Reader *reader) {
|
||||||
|
memgraph::slk::Load(self, reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DropAuthDataReq::Save(const DropAuthDataReq &self, memgraph::slk::Builder *builder) {
|
||||||
|
memgraph::slk::Save(self, builder);
|
||||||
|
}
|
||||||
|
void DropAuthDataReq::Load(DropAuthDataReq *self, memgraph::slk::Reader *reader) { memgraph::slk::Load(self, reader); }
|
||||||
|
void DropAuthDataRes::Save(const DropAuthDataRes &self, memgraph::slk::Builder *builder) {
|
||||||
|
memgraph::slk::Save(self, builder);
|
||||||
|
}
|
||||||
|
void DropAuthDataRes::Load(DropAuthDataRes *self, memgraph::slk::Reader *reader) { memgraph::slk::Load(self, reader); }
|
||||||
|
|
||||||
|
} // namespace memgraph::replication
|
||||||
127
src/auth/rpc.hpp
Normal file
127
src/auth/rpc.hpp
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
// Copyright 2024 Memgraph Ltd.
|
||||||
|
//
|
||||||
|
// Use of this software is governed by the Business Source License
|
||||||
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
|
// License, and you may not use this file except in compliance with the Business Source License.
|
||||||
|
//
|
||||||
|
// As of the Change Date specified in that file, in accordance with
|
||||||
|
// the Business Source License, use of this software will be governed
|
||||||
|
// by the Apache License, Version 2.0, included in the file
|
||||||
|
// licenses/APL.txt.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
|
#include "auth/auth.hpp"
|
||||||
|
#include "auth/models.hpp"
|
||||||
|
#include "rpc/messages.hpp"
|
||||||
|
#include "slk/streams.hpp"
|
||||||
|
|
||||||
|
namespace memgraph::replication {
|
||||||
|
|
||||||
|
struct UpdateAuthDataReq {
|
||||||
|
static const utils::TypeInfo kType;
|
||||||
|
static const utils::TypeInfo &GetTypeInfo() { return kType; }
|
||||||
|
|
||||||
|
static void Load(UpdateAuthDataReq *self, memgraph::slk::Reader *reader);
|
||||||
|
static void Save(const UpdateAuthDataReq &self, memgraph::slk::Builder *builder);
|
||||||
|
UpdateAuthDataReq() = default;
|
||||||
|
UpdateAuthDataReq(const utils::UUID &main_uuid, std::string epoch_id, uint64_t expected_ts, uint64_t new_ts,
|
||||||
|
auth::User user)
|
||||||
|
: main_uuid(main_uuid),
|
||||||
|
epoch_id{std::move(epoch_id)},
|
||||||
|
expected_group_timestamp{expected_ts},
|
||||||
|
new_group_timestamp{new_ts},
|
||||||
|
user{std::move(user)} {}
|
||||||
|
UpdateAuthDataReq(const utils::UUID &main_uuid, std::string epoch_id, uint64_t expected_ts, uint64_t new_ts,
|
||||||
|
auth::Role role)
|
||||||
|
: main_uuid(main_uuid),
|
||||||
|
epoch_id{std::move(epoch_id)},
|
||||||
|
expected_group_timestamp{expected_ts},
|
||||||
|
new_group_timestamp{new_ts},
|
||||||
|
role{std::move(role)} {}
|
||||||
|
|
||||||
|
utils::UUID main_uuid;
|
||||||
|
std::string epoch_id;
|
||||||
|
uint64_t expected_group_timestamp;
|
||||||
|
uint64_t new_group_timestamp;
|
||||||
|
std::optional<auth::User> user;
|
||||||
|
std::optional<auth::Role> role;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UpdateAuthDataRes {
|
||||||
|
static const utils::TypeInfo kType;
|
||||||
|
static const utils::TypeInfo &GetTypeInfo() { return kType; }
|
||||||
|
|
||||||
|
static void Load(UpdateAuthDataRes *self, memgraph::slk::Reader *reader);
|
||||||
|
static void Save(const UpdateAuthDataRes &self, memgraph::slk::Builder *builder);
|
||||||
|
UpdateAuthDataRes() = default;
|
||||||
|
explicit UpdateAuthDataRes(bool success) : success{success} {}
|
||||||
|
|
||||||
|
bool success;
|
||||||
|
};
|
||||||
|
|
||||||
|
using UpdateAuthDataRpc = rpc::RequestResponse<UpdateAuthDataReq, UpdateAuthDataRes>;
|
||||||
|
|
||||||
|
struct DropAuthDataReq {
|
||||||
|
static const utils::TypeInfo kType;
|
||||||
|
static const utils::TypeInfo &GetTypeInfo() { return kType; }
|
||||||
|
|
||||||
|
static void Load(DropAuthDataReq *self, memgraph::slk::Reader *reader);
|
||||||
|
static void Save(const DropAuthDataReq &self, memgraph::slk::Builder *builder);
|
||||||
|
DropAuthDataReq() = default;
|
||||||
|
|
||||||
|
enum class DataType { USER, ROLE };
|
||||||
|
|
||||||
|
DropAuthDataReq(const utils::UUID &main_uuid, std::string epoch_id, uint64_t expected_ts, uint64_t new_ts,
|
||||||
|
DataType type, std::string_view name)
|
||||||
|
: main_uuid(main_uuid),
|
||||||
|
epoch_id{std::move(epoch_id)},
|
||||||
|
expected_group_timestamp{expected_ts},
|
||||||
|
new_group_timestamp{new_ts},
|
||||||
|
type{type},
|
||||||
|
name{name} {}
|
||||||
|
|
||||||
|
utils::UUID main_uuid;
|
||||||
|
std::string epoch_id;
|
||||||
|
uint64_t expected_group_timestamp;
|
||||||
|
uint64_t new_group_timestamp;
|
||||||
|
DataType type;
|
||||||
|
std::string name;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct DropAuthDataRes {
|
||||||
|
static const utils::TypeInfo kType;
|
||||||
|
static const utils::TypeInfo &GetTypeInfo() { return kType; }
|
||||||
|
|
||||||
|
static void Load(DropAuthDataRes *self, memgraph::slk::Reader *reader);
|
||||||
|
static void Save(const DropAuthDataRes &self, memgraph::slk::Builder *builder);
|
||||||
|
DropAuthDataRes() = default;
|
||||||
|
explicit DropAuthDataRes(bool success) : success{success} {}
|
||||||
|
|
||||||
|
bool success;
|
||||||
|
};
|
||||||
|
|
||||||
|
using DropAuthDataRpc = rpc::RequestResponse<DropAuthDataReq, DropAuthDataRes>;
|
||||||
|
|
||||||
|
} // namespace memgraph::replication
|
||||||
|
|
||||||
|
namespace memgraph::slk {
|
||||||
|
|
||||||
|
void Save(const auth::Role &self, memgraph::slk::Builder *builder);
|
||||||
|
void Load(auth::Role *self, memgraph::slk::Reader *reader);
|
||||||
|
void Save(const auth::User &self, memgraph::slk::Builder *builder);
|
||||||
|
void Load(auth::User *self, memgraph::slk::Reader *reader);
|
||||||
|
void Save(const auth::Auth::Config &self, memgraph::slk::Builder *builder);
|
||||||
|
void Load(auth::Auth::Config *self, memgraph::slk::Reader *reader);
|
||||||
|
|
||||||
|
void Save(const memgraph::replication::UpdateAuthDataRes &self, memgraph::slk::Builder *builder);
|
||||||
|
void Load(memgraph::replication::UpdateAuthDataRes *self, memgraph::slk::Reader *reader);
|
||||||
|
void Save(const memgraph::replication::UpdateAuthDataReq & /*self*/, memgraph::slk::Builder * /*builder*/);
|
||||||
|
void Load(memgraph::replication::UpdateAuthDataReq * /*self*/, memgraph::slk::Reader * /*reader*/);
|
||||||
|
void Save(const memgraph::replication::DropAuthDataRes &self, memgraph::slk::Builder *builder);
|
||||||
|
void Load(memgraph::replication::DropAuthDataRes *self, memgraph::slk::Reader *reader);
|
||||||
|
void Save(const memgraph::replication::DropAuthDataReq & /*self*/, memgraph::slk::Builder * /*builder*/);
|
||||||
|
void Load(memgraph::replication::DropAuthDataReq * /*self*/, memgraph::slk::Reader * /*reader*/);
|
||||||
|
} // namespace memgraph::slk
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2023 Memgraph Ltd.
|
// Copyright 2024 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@@ -15,6 +15,9 @@
|
|||||||
#include "communication/bolt/v1/value.hpp"
|
#include "communication/bolt/v1/value.hpp"
|
||||||
#include "utils/logging.hpp"
|
#include "utils/logging.hpp"
|
||||||
|
|
||||||
|
#include "communication/bolt/v1/fmt.hpp"
|
||||||
|
#include "io/network/fmt.hpp"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
constexpr uint8_t kBoltV43Version[4] = {0x00, 0x00, 0x03, 0x04};
|
constexpr uint8_t kBoltV43Version[4] = {0x00, 0x00, 0x03, 0x04};
|
||||||
constexpr uint8_t kEmptyBoltVersion[4] = {0x00, 0x00, 0x00, 0x00};
|
constexpr uint8_t kEmptyBoltVersion[4] = {0x00, 0x00, 0x00, 0x00};
|
||||||
|
|||||||
27
src/communication/bolt/v1/fmt.hpp
Normal file
27
src/communication/bolt/v1/fmt.hpp
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
// Copyright 2024 Memgraph Ltd.
|
||||||
|
//
|
||||||
|
// Use of this software is governed by the Business Source License
|
||||||
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
|
// License, and you may not use this file except in compliance with the Business Source License.
|
||||||
|
//
|
||||||
|
// As of the Change Date specified in that file, in accordance with
|
||||||
|
// the Business Source License, use of this software will be governed
|
||||||
|
// by the Apache License, Version 2.0, included in the file
|
||||||
|
// licenses/APL.txt.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#if FMT_VERSION > 90000
|
||||||
|
#include <fmt/ostream.h>
|
||||||
|
|
||||||
|
#include "communication/bolt/v1/value.hpp"
|
||||||
|
|
||||||
|
template <>
|
||||||
|
class fmt::formatter<memgraph::communication::bolt::Value> : public fmt::ostream_formatter {};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
class fmt::formatter<std::vector<memgraph::communication::bolt::Value>> : public fmt::ostream_formatter {};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
class fmt::formatter<std::map<std::string, memgraph::communication::bolt::Value>> : public fmt::ostream_formatter {};
|
||||||
|
#endif
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2023 Memgraph Ltd.
|
// Copyright 2024 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@@ -170,6 +170,7 @@ inline State HandleFailure(TSession &session, const std::exception &e) {
|
|||||||
spdlog::trace("Error trace: {}", p->trace());
|
spdlog::trace("Error trace: {}", p->trace());
|
||||||
}
|
}
|
||||||
session.encoder_buffer_.Clear();
|
session.encoder_buffer_.Clear();
|
||||||
|
|
||||||
auto code_message = ExceptionToErrorMessage(e);
|
auto code_message = ExceptionToErrorMessage(e);
|
||||||
bool fail_sent = session.encoder_.MessageFailure({{"code", code_message.first}, {"message", code_message.second}});
|
bool fail_sent = session.encoder_.MessageFailure({{"code", code_message.first}, {"message", code_message.second}});
|
||||||
if (!fail_sent) {
|
if (!fail_sent) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2022 Memgraph Ltd.
|
// Copyright 2024 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
#include "communication/client.hpp"
|
#include "communication/client.hpp"
|
||||||
|
|
||||||
#include "communication/helpers.hpp"
|
#include "communication/helpers.hpp"
|
||||||
|
#include "io/network/network_error.hpp"
|
||||||
#include "utils/logging.hpp"
|
#include "utils/logging.hpp"
|
||||||
|
|
||||||
namespace memgraph::communication {
|
namespace memgraph::communication {
|
||||||
@@ -25,7 +26,9 @@ Client::~Client() {
|
|||||||
|
|
||||||
bool Client::Connect(const io::network::Endpoint &endpoint) {
|
bool Client::Connect(const io::network::Endpoint &endpoint) {
|
||||||
// Try to establish a socket connection.
|
// Try to establish a socket connection.
|
||||||
if (!socket_.Connect(endpoint)) return false;
|
if (!socket_.Connect(endpoint)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Enable TCP keep alive for all connections.
|
// Enable TCP keep alive for all connections.
|
||||||
// Because we manually always set the `have_more` flag to the socket
|
// Because we manually always set the `have_more` flag to the socket
|
||||||
|
|||||||
20
src/communication/fmt.hpp
Normal file
20
src/communication/fmt.hpp
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
// Copyright 2024 Memgraph Ltd.
|
||||||
|
//
|
||||||
|
// Use of this software is governed by the Business Source License
|
||||||
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
|
// License, and you may not use this file except in compliance with the Business Source License.
|
||||||
|
//
|
||||||
|
// As of the Change Date specified in that file, in accordance with
|
||||||
|
// the Business Source License, use of this software will be governed
|
||||||
|
// by the Apache License, Version 2.0, included in the file
|
||||||
|
// licenses/APL.txt.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#if FMT_VERSION > 90000
|
||||||
|
#include <fmt/ostream.h>
|
||||||
|
#include <boost/asio/ip/tcp.hpp>
|
||||||
|
|
||||||
|
template <>
|
||||||
|
class fmt::formatter<boost::asio::ip::tcp::endpoint> : public fmt::ostream_formatter {};
|
||||||
|
#endif
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2023 Memgraph Ltd.
|
// Copyright 2024 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@@ -21,6 +21,7 @@
|
|||||||
#include <boost/beast/core.hpp>
|
#include <boost/beast/core.hpp>
|
||||||
|
|
||||||
#include "communication/context.hpp"
|
#include "communication/context.hpp"
|
||||||
|
#include "communication/fmt.hpp"
|
||||||
#include "communication/http/session.hpp"
|
#include "communication/http/session.hpp"
|
||||||
#include "utils/spin_lock.hpp"
|
#include "utils/spin_lock.hpp"
|
||||||
#include "utils/synchronized.hpp"
|
#include "utils/synchronized.hpp"
|
||||||
@@ -82,7 +83,7 @@ class Listener final : public std::enable_shared_from_this<Listener<TRequestHand
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
spdlog::info("HTTP server is listening on {}:{}", endpoint.address(), endpoint.port());
|
spdlog::info("HTTP server is listening on {}", endpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoAccept() {
|
void DoAccept() {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2023 Memgraph Ltd.
|
// Copyright 2024 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@@ -107,7 +107,7 @@ class Session : public std::enable_shared_from_this<Session<TRequestHandler, TSe
|
|||||||
void DoRead() {
|
void DoRead() {
|
||||||
req_ = {};
|
req_ = {};
|
||||||
|
|
||||||
ExecuteForStream([this](auto &&stream) {
|
ExecuteForStream([this](auto &stream) {
|
||||||
boost::beast::get_lowest_layer(stream).expires_after(std::chrono::seconds(kSSLExpirySeconds));
|
boost::beast::get_lowest_layer(stream).expires_after(std::chrono::seconds(kSSLExpirySeconds));
|
||||||
|
|
||||||
boost::beast::http::async_read(
|
boost::beast::http::async_read(
|
||||||
@@ -129,7 +129,7 @@ class Session : public std::enable_shared_from_this<Session<TRequestHandler, TSe
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto async_write = [this](boost::beast::http::response<boost::beast::http::string_body> msg) {
|
auto async_write = [this](boost::beast::http::response<boost::beast::http::string_body> msg) {
|
||||||
ExecuteForStream([this, &msg](auto &&stream) {
|
ExecuteForStream([this, &msg](auto &stream) {
|
||||||
// The lifetime of the message has to extend
|
// The lifetime of the message has to extend
|
||||||
// for the duration of the async operation so
|
// for the duration of the async operation so
|
||||||
// we use a shared_ptr to manage it.
|
// we use a shared_ptr to manage it.
|
||||||
@@ -171,7 +171,7 @@ class Session : public std::enable_shared_from_this<Session<TRequestHandler, TSe
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto GetExecutor() {
|
auto GetExecutor() {
|
||||||
return std::visit(utils::Overloaded{[](auto &&stream) { return stream.get_executor(); }}, stream_);
|
return std::visit(utils::Overloaded{[](auto &stream) { return stream.get_executor(); }}, stream_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename F>
|
template <typename F>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2023 Memgraph Ltd.
|
// Copyright 2024 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
#include "communication/session.hpp"
|
#include "communication/session.hpp"
|
||||||
#include "io/network/epoll.hpp"
|
#include "io/network/epoll.hpp"
|
||||||
|
#include "io/network/fmt.hpp"
|
||||||
#include "io/network/socket.hpp"
|
#include "io/network/socket.hpp"
|
||||||
#include "utils/logging.hpp"
|
#include "utils/logging.hpp"
|
||||||
#include "utils/signals.hpp"
|
#include "utils/signals.hpp"
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class ResultStreamFaker {
|
|||||||
std::vector<memgraph::communication::bolt::Value> bvalues;
|
std::vector<memgraph::communication::bolt::Value> bvalues;
|
||||||
bvalues.reserve(values.size());
|
bvalues.reserve(values.size());
|
||||||
for (const auto &value : values) {
|
for (const auto &value : values) {
|
||||||
auto maybe_value = memgraph::glue::ToBoltValue(value, *store_, memgraph::storage::View::NEW);
|
auto maybe_value = memgraph::glue::ToBoltValue(value, store_, memgraph::storage::View::NEW);
|
||||||
MG_ASSERT(maybe_value.HasValue());
|
MG_ASSERT(maybe_value.HasValue());
|
||||||
bvalues.push_back(std::move(*maybe_value));
|
bvalues.push_back(std::move(*maybe_value));
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@ class ResultStreamFaker {
|
|||||||
void Summary(const std::map<std::string, memgraph::query::TypedValue> &summary) {
|
void Summary(const std::map<std::string, memgraph::query::TypedValue> &summary) {
|
||||||
std::map<std::string, memgraph::communication::bolt::Value> bsummary;
|
std::map<std::string, memgraph::communication::bolt::Value> bsummary;
|
||||||
for (const auto &item : summary) {
|
for (const auto &item : summary) {
|
||||||
auto maybe_value = memgraph::glue::ToBoltValue(item.second, *store_, memgraph::storage::View::NEW);
|
auto maybe_value = memgraph::glue::ToBoltValue(item.second, store_, memgraph::storage::View::NEW);
|
||||||
MG_ASSERT(maybe_value.HasValue());
|
MG_ASSERT(maybe_value.HasValue());
|
||||||
bsummary.insert({item.first, std::move(*maybe_value)});
|
bsummary.insert({item.first, std::move(*maybe_value)});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2023 Memgraph Ltd.
|
// Copyright 2024 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include "communication/init.hpp"
|
#include "communication/init.hpp"
|
||||||
#include "communication/listener.hpp"
|
#include "communication/listener.hpp"
|
||||||
|
#include "io/network/fmt.hpp"
|
||||||
#include "io/network/socket.hpp"
|
#include "io/network/socket.hpp"
|
||||||
#include "utils/logging.hpp"
|
#include "utils/logging.hpp"
|
||||||
#include "utils/message.hpp"
|
#include "utils/message.hpp"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2023 Memgraph Ltd.
|
// Copyright 2024 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@@ -26,6 +26,7 @@
|
|||||||
#include <boost/asio/ip/tcp.hpp>
|
#include <boost/asio/ip/tcp.hpp>
|
||||||
|
|
||||||
#include "communication/context.hpp"
|
#include "communication/context.hpp"
|
||||||
|
#include "communication/fmt.hpp"
|
||||||
#include "communication/init.hpp"
|
#include "communication/init.hpp"
|
||||||
#include "communication/v2/listener.hpp"
|
#include "communication/v2/listener.hpp"
|
||||||
#include "communication/v2/pool.hpp"
|
#include "communication/v2/pool.hpp"
|
||||||
@@ -129,7 +130,7 @@ bool Server<TSession, TSessionContext>::Start() {
|
|||||||
listener_->Start();
|
listener_->Start();
|
||||||
|
|
||||||
spdlog::info("{} server is fully armed and operational", service_name_);
|
spdlog::info("{} server is fully armed and operational", service_name_);
|
||||||
spdlog::info("{} listening on {}", service_name_, endpoint_.address());
|
spdlog::info("{} listening on {}", service_name_, endpoint_);
|
||||||
context_thread_pool_.Run();
|
context_thread_pool_.Run();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2023 Memgraph Ltd.
|
// Copyright 2024 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@@ -47,6 +47,7 @@
|
|||||||
#include "communication/buffer.hpp"
|
#include "communication/buffer.hpp"
|
||||||
#include "communication/context.hpp"
|
#include "communication/context.hpp"
|
||||||
#include "communication/exceptions.hpp"
|
#include "communication/exceptions.hpp"
|
||||||
|
#include "communication/fmt.hpp"
|
||||||
#include "dbms/global.hpp"
|
#include "dbms/global.hpp"
|
||||||
#include "utils/event_counter.hpp"
|
#include "utils/event_counter.hpp"
|
||||||
#include "utils/logging.hpp"
|
#include "utils/logging.hpp"
|
||||||
@@ -212,14 +213,11 @@ class WebsocketSession : public std::enable_shared_from_this<WebsocketSession<TS
|
|||||||
session_.Execute();
|
session_.Execute();
|
||||||
DoRead();
|
DoRead();
|
||||||
} catch (const SessionClosedException &e) {
|
} catch (const SessionClosedException &e) {
|
||||||
spdlog::info("{} client {}:{} closed the connection.", service_name_, remote_endpoint_.address(),
|
spdlog::info("{} client {} closed the connection.", service_name_, remote_endpoint_);
|
||||||
remote_endpoint_.port());
|
|
||||||
DoClose();
|
DoClose();
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
spdlog::error(
|
spdlog::error("Exception was thrown while processing event in {} session associated with {}", service_name_,
|
||||||
"Exception was thrown while processing event in {} session "
|
remote_endpoint_);
|
||||||
"associated with {}:{}",
|
|
||||||
service_name_, remote_endpoint_.address(), remote_endpoint_.port());
|
|
||||||
spdlog::debug("Exception message: {}", e.what());
|
spdlog::debug("Exception message: {}", e.what());
|
||||||
DoClose();
|
DoClose();
|
||||||
}
|
}
|
||||||
@@ -376,8 +374,7 @@ class Session final : public std::enable_shared_from_this<Session<TSession, TSes
|
|||||||
socket.lowest_layer().non_blocking(false);
|
socket.lowest_layer().non_blocking(false);
|
||||||
});
|
});
|
||||||
timeout_timer_.expires_at(boost::asio::steady_timer::time_point::max());
|
timeout_timer_.expires_at(boost::asio::steady_timer::time_point::max());
|
||||||
spdlog::info("Accepted a connection from {}: {}:{}", service_name_, remote_endpoint_.address(),
|
spdlog::info("Accepted a connection from {}: {}", service_name_, remote_endpoint_);
|
||||||
remote_endpoint_.port());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoRead() {
|
void DoRead() {
|
||||||
@@ -437,14 +434,11 @@ class Session final : public std::enable_shared_from_this<Session<TSession, TSes
|
|||||||
session_.Execute();
|
session_.Execute();
|
||||||
DoRead();
|
DoRead();
|
||||||
} catch (const SessionClosedException &e) {
|
} catch (const SessionClosedException &e) {
|
||||||
spdlog::info("{} client {}:{} closed the connection.", service_name_, remote_endpoint_.address(),
|
spdlog::info("{} client {} closed the connection.", service_name_, remote_endpoint_);
|
||||||
remote_endpoint_.port());
|
|
||||||
DoShutdown();
|
DoShutdown();
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
spdlog::error(
|
spdlog::error("Exception was thrown while processing event in {} session associated with {}", service_name_,
|
||||||
"Exception was thrown while processing event in {} session "
|
remote_endpoint_);
|
||||||
"associated with {}:{}",
|
|
||||||
service_name_, remote_endpoint_.address(), remote_endpoint_.port());
|
|
||||||
spdlog::debug("Exception message: {}", e.what());
|
spdlog::debug("Exception message: {}", e.what());
|
||||||
DoShutdown();
|
DoShutdown();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2022 Memgraph Ltd.
|
// Copyright 2024 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@@ -12,19 +12,44 @@
|
|||||||
#include "communication/websocket/auth.hpp"
|
#include "communication/websocket/auth.hpp"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "utils/variant_helpers.hpp"
|
||||||
|
|
||||||
namespace memgraph::communication::websocket {
|
namespace memgraph::communication::websocket {
|
||||||
|
|
||||||
bool SafeAuth::Authenticate(const std::string &username, const std::string &password) const {
|
bool SafeAuth::Authenticate(const std::string &username, const std::string &password) const {
|
||||||
return auth_->Lock()->Authenticate(username, password).has_value();
|
user_or_role_ = auth_->Lock()->Authenticate(username, password);
|
||||||
|
return user_or_role_.has_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SafeAuth::HasUserPermission(const std::string &username, const auth::Permission permission) const {
|
bool SafeAuth::HasPermission(const auth::Permission permission) const {
|
||||||
if (const auto user = auth_->ReadLock()->GetUser(username); user) {
|
auto locked_auth = auth_->ReadLock();
|
||||||
return user->GetPermissions().Has(permission) == auth::PermissionLevel::GRANT;
|
// Update if cache invalidated
|
||||||
|
if (!locked_auth->UpToDate(auth_epoch_) && user_or_role_) {
|
||||||
|
bool success = true;
|
||||||
|
std::visit(utils::Overloaded{[&](auth::User &user) {
|
||||||
|
auto tmp = locked_auth->GetUser(user.username());
|
||||||
|
if (!tmp) success = false;
|
||||||
|
user = std::move(*tmp);
|
||||||
|
},
|
||||||
|
[&](auth::Role &role) {
|
||||||
|
auto tmp = locked_auth->GetRole(role.rolename());
|
||||||
|
if (!tmp) success = false;
|
||||||
|
role = std::move(*tmp);
|
||||||
|
}},
|
||||||
|
*user_or_role_);
|
||||||
|
// Missing user/role; delete from cache
|
||||||
|
if (!success) user_or_role_.reset();
|
||||||
}
|
}
|
||||||
|
// Check permissions
|
||||||
|
if (user_or_role_) {
|
||||||
|
return std::visit(utils::Overloaded{[&](auto &user_or_role) {
|
||||||
|
return user_or_role.GetPermissions().Has(permission) == auth::PermissionLevel::GRANT;
|
||||||
|
}},
|
||||||
|
*user_or_role_);
|
||||||
|
}
|
||||||
|
// NOTE: websocket authenticates only if there is a user, so no need to check if access controlled
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SafeAuth::HasAnyUsers() const { return auth_->ReadLock()->HasUsers(); }
|
bool SafeAuth::AccessControlled() const { return auth_->ReadLock()->AccessControlled(); }
|
||||||
} // namespace memgraph::communication::websocket
|
} // namespace memgraph::communication::websocket
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2022 Memgraph Ltd.
|
// Copyright 2024 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@@ -14,8 +14,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "auth/auth.hpp"
|
#include "auth/auth.hpp"
|
||||||
#include "utils/spin_lock.hpp"
|
|
||||||
#include "utils/synchronized.hpp"
|
|
||||||
|
|
||||||
namespace memgraph::communication::websocket {
|
namespace memgraph::communication::websocket {
|
||||||
|
|
||||||
@@ -23,22 +21,24 @@ class AuthenticationInterface {
|
|||||||
public:
|
public:
|
||||||
virtual bool Authenticate(const std::string &username, const std::string &password) const = 0;
|
virtual bool Authenticate(const std::string &username, const std::string &password) const = 0;
|
||||||
|
|
||||||
virtual bool HasUserPermission(const std::string &username, auth::Permission permission) const = 0;
|
virtual bool HasPermission(auth::Permission permission) const = 0;
|
||||||
|
|
||||||
virtual bool HasAnyUsers() const = 0;
|
virtual bool AccessControlled() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SafeAuth : public AuthenticationInterface {
|
class SafeAuth : public AuthenticationInterface {
|
||||||
public:
|
public:
|
||||||
explicit SafeAuth(utils::Synchronized<auth::Auth, utils::WritePrioritizedRWLock> *auth) : auth_{auth} {}
|
explicit SafeAuth(auth::SynchedAuth *auth) : auth_{auth} {}
|
||||||
|
|
||||||
bool Authenticate(const std::string &username, const std::string &password) const override;
|
bool Authenticate(const std::string &username, const std::string &password) const override;
|
||||||
|
|
||||||
bool HasUserPermission(const std::string &username, auth::Permission permission) const override;
|
bool HasPermission(auth::Permission permission) const override;
|
||||||
|
|
||||||
bool HasAnyUsers() const override;
|
bool AccessControlled() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
utils::Synchronized<auth::Auth, utils::WritePrioritizedRWLock> *auth_;
|
auth::SynchedAuth *auth_;
|
||||||
|
mutable std::optional<auth::UserOrRole> user_or_role_;
|
||||||
|
mutable auth::Auth::Epoch auth_epoch_{};
|
||||||
};
|
};
|
||||||
} // namespace memgraph::communication::websocket
|
} // namespace memgraph::communication::websocket
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2022 Memgraph Ltd.
|
// Copyright 2024 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
// licenses/APL.txt.
|
// licenses/APL.txt.
|
||||||
|
|
||||||
#include "communication/websocket/listener.hpp"
|
#include "communication/websocket/listener.hpp"
|
||||||
|
#include "communication/fmt.hpp"
|
||||||
|
|
||||||
namespace memgraph::communication::websocket {
|
namespace memgraph::communication::websocket {
|
||||||
namespace {
|
namespace {
|
||||||
@@ -61,7 +62,7 @@ Listener::Listener(boost::asio::io_context &ioc, ServerContext *context, tcp::en
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
spdlog::info("WebSocket server is listening on {}:{}", endpoint.address(), endpoint.port());
|
spdlog::info("WebSocket server is listening on {}", endpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Listener::DoAccept() {
|
void Listener::DoAccept() {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2023 Memgraph Ltd.
|
// Copyright 2024 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@@ -80,7 +80,7 @@ bool Session::Run() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
authenticated_ = !auth_.HasAnyUsers();
|
authenticated_ = !auth_.AccessControlled();
|
||||||
connected_.store(true, std::memory_order_relaxed);
|
connected_.store(true, std::memory_order_relaxed);
|
||||||
|
|
||||||
// run on the strand
|
// run on the strand
|
||||||
@@ -162,7 +162,7 @@ utils::BasicResult<std::string> Session::Authorize(const nlohmann::json &creds)
|
|||||||
return {"Authentication failed!"};
|
return {"Authentication failed!"};
|
||||||
}
|
}
|
||||||
#ifdef MG_ENTERPRISE
|
#ifdef MG_ENTERPRISE
|
||||||
if (!auth_.HasUserPermission(creds.at("username").get<std::string>(), auth::Permission::WEBSOCKET)) {
|
if (!auth_.HasPermission(auth::Permission::WEBSOCKET)) {
|
||||||
return {"Authorization failed!"};
|
return {"Authorization failed!"};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
41
src/coordination/CMakeLists.txt
Normal file
41
src/coordination/CMakeLists.txt
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
add_library(mg-coordination STATIC)
|
||||||
|
add_library(mg::coordination ALIAS mg-coordination)
|
||||||
|
target_sources(mg-coordination
|
||||||
|
PUBLIC
|
||||||
|
include/coordination/coordinator_client.hpp
|
||||||
|
include/coordination/coordinator_state.hpp
|
||||||
|
include/coordination/coordinator_rpc.hpp
|
||||||
|
include/coordination/coordinator_server.hpp
|
||||||
|
include/coordination/coordinator_config.hpp
|
||||||
|
include/coordination/coordinator_exceptions.hpp
|
||||||
|
include/coordination/coordinator_slk.hpp
|
||||||
|
include/coordination/coordinator_instance.hpp
|
||||||
|
include/coordination/coordinator_handlers.hpp
|
||||||
|
include/coordination/instance_status.hpp
|
||||||
|
include/coordination/replication_instance.hpp
|
||||||
|
include/coordination/raft_state.hpp
|
||||||
|
include/coordination/rpc_errors.hpp
|
||||||
|
|
||||||
|
include/nuraft/coordinator_log_store.hpp
|
||||||
|
include/nuraft/coordinator_state_machine.hpp
|
||||||
|
include/nuraft/coordinator_state_manager.hpp
|
||||||
|
|
||||||
|
PRIVATE
|
||||||
|
coordinator_client.cpp
|
||||||
|
coordinator_state.cpp
|
||||||
|
coordinator_rpc.cpp
|
||||||
|
coordinator_server.cpp
|
||||||
|
coordinator_handlers.cpp
|
||||||
|
coordinator_instance.cpp
|
||||||
|
replication_instance.cpp
|
||||||
|
raft_state.cpp
|
||||||
|
|
||||||
|
coordinator_log_store.cpp
|
||||||
|
coordinator_state_machine.cpp
|
||||||
|
coordinator_state_manager.cpp
|
||||||
|
)
|
||||||
|
target_include_directories(mg-coordination PUBLIC include)
|
||||||
|
|
||||||
|
target_link_libraries(mg-coordination
|
||||||
|
PUBLIC mg::utils mg::rpc mg::slk mg::io mg::repl_coord_glue lib::rangev3 nuraft mg-replication_handler
|
||||||
|
)
|
||||||
175
src/coordination/coordinator_client.cpp
Normal file
175
src/coordination/coordinator_client.cpp
Normal file
@@ -0,0 +1,175 @@
|
|||||||
|
// Copyright 2024 Memgraph Ltd.
|
||||||
|
//
|
||||||
|
// Use of this software is governed by the Business Source License
|
||||||
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
|
// License, and you may not use this file except in compliance with the Business Source License.
|
||||||
|
//
|
||||||
|
// As of the Change Date specified in that file, in accordance with
|
||||||
|
// the Business Source License, use of this software will be governed
|
||||||
|
// by the Apache License, Version 2.0, included in the file
|
||||||
|
// licenses/APL.txt.
|
||||||
|
|
||||||
|
#include "utils/uuid.hpp"
|
||||||
|
#ifdef MG_ENTERPRISE
|
||||||
|
|
||||||
|
#include "coordination/coordinator_client.hpp"
|
||||||
|
|
||||||
|
#include "coordination/coordinator_config.hpp"
|
||||||
|
#include "coordination/coordinator_rpc.hpp"
|
||||||
|
#include "replication_coordination_glue/messages.hpp"
|
||||||
|
#include "utils/result.hpp"
|
||||||
|
|
||||||
|
namespace memgraph::coordination {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
auto CreateClientContext(memgraph::coordination::CoordinatorClientConfig const &config)
|
||||||
|
-> communication::ClientContext {
|
||||||
|
return (config.ssl) ? communication::ClientContext{config.ssl->key_file, config.ssl->cert_file}
|
||||||
|
: communication::ClientContext{};
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
CoordinatorClient::CoordinatorClient(CoordinatorInstance *coord_instance, CoordinatorClientConfig config,
|
||||||
|
HealthCheckCallback succ_cb, HealthCheckCallback fail_cb)
|
||||||
|
: rpc_context_{CreateClientContext(config)},
|
||||||
|
rpc_client_{io::network::Endpoint(io::network::Endpoint::needs_resolving, config.ip_address, config.port),
|
||||||
|
&rpc_context_},
|
||||||
|
config_{std::move(config)},
|
||||||
|
coord_instance_{coord_instance},
|
||||||
|
succ_cb_{std::move(succ_cb)},
|
||||||
|
fail_cb_{std::move(fail_cb)} {}
|
||||||
|
|
||||||
|
auto CoordinatorClient::InstanceName() const -> std::string { return config_.instance_name; }
|
||||||
|
auto CoordinatorClient::SocketAddress() const -> std::string { return rpc_client_.Endpoint().SocketAddress(); }
|
||||||
|
|
||||||
|
auto CoordinatorClient::InstanceDownTimeoutSec() const -> std::chrono::seconds {
|
||||||
|
return config_.instance_down_timeout_sec;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CoordinatorClient::InstanceGetUUIDFrequencySec() const -> std::chrono::seconds {
|
||||||
|
return config_.instance_get_uuid_frequency_sec;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoordinatorClient::StartFrequentCheck() {
|
||||||
|
if (instance_checker_.IsRunning()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MG_ASSERT(config_.instance_health_check_frequency_sec > std::chrono::seconds(0),
|
||||||
|
"Health check frequency must be greater than 0");
|
||||||
|
|
||||||
|
instance_checker_.Run(
|
||||||
|
config_.instance_name, config_.instance_health_check_frequency_sec,
|
||||||
|
[this, instance_name = config_.instance_name] {
|
||||||
|
try {
|
||||||
|
spdlog::trace("Sending frequent heartbeat to machine {} on {}", instance_name,
|
||||||
|
rpc_client_.Endpoint().SocketAddress());
|
||||||
|
{ // NOTE: This is intentionally scoped so that stream lock could get released.
|
||||||
|
auto stream{rpc_client_.Stream<memgraph::replication_coordination_glue::FrequentHeartbeatRpc>()};
|
||||||
|
stream.AwaitResponse();
|
||||||
|
}
|
||||||
|
succ_cb_(coord_instance_, instance_name);
|
||||||
|
} catch (rpc::RpcFailedException const &) {
|
||||||
|
fail_cb_(coord_instance_, instance_name);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoordinatorClient::StopFrequentCheck() { instance_checker_.Stop(); }
|
||||||
|
void CoordinatorClient::PauseFrequentCheck() { instance_checker_.Pause(); }
|
||||||
|
void CoordinatorClient::ResumeFrequentCheck() { instance_checker_.Resume(); }
|
||||||
|
|
||||||
|
auto CoordinatorClient::SetCallbacks(HealthCheckCallback succ_cb, HealthCheckCallback fail_cb) -> void {
|
||||||
|
succ_cb_ = std::move(succ_cb);
|
||||||
|
fail_cb_ = std::move(fail_cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CoordinatorClient::ReplicationClientInfo() const -> ReplClientInfo { return config_.replication_client_info; }
|
||||||
|
|
||||||
|
auto CoordinatorClient::SendPromoteReplicaToMainRpc(const utils::UUID &uuid,
|
||||||
|
ReplicationClientsInfo replication_clients_info) const -> bool {
|
||||||
|
try {
|
||||||
|
auto stream{rpc_client_.Stream<PromoteReplicaToMainRpc>(uuid, std::move(replication_clients_info))};
|
||||||
|
if (!stream.AwaitResponse().success) {
|
||||||
|
spdlog::error("Failed to receive successful PromoteReplicaToMainRpc response!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (rpc::RpcFailedException const &) {
|
||||||
|
spdlog::error("RPC error occurred while sending PromoteReplicaToMainRpc!");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CoordinatorClient::DemoteToReplica() const -> bool {
|
||||||
|
auto const &instance_name = config_.instance_name;
|
||||||
|
try {
|
||||||
|
auto stream{rpc_client_.Stream<DemoteMainToReplicaRpc>(config_.replication_client_info)};
|
||||||
|
if (!stream.AwaitResponse().success) {
|
||||||
|
spdlog::error("Failed to receive successful RPC response for setting instance {} to replica!", instance_name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
spdlog::info("Sent request RPC from coordinator to instance to set it as replica!");
|
||||||
|
return true;
|
||||||
|
} catch (rpc::RpcFailedException const &) {
|
||||||
|
spdlog::error("Failed to set instance {} to replica!", instance_name);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CoordinatorClient::SendSwapMainUUIDRpc(const utils::UUID &uuid) const -> bool {
|
||||||
|
try {
|
||||||
|
auto stream{rpc_client_.Stream<replication_coordination_glue::SwapMainUUIDRpc>(uuid)};
|
||||||
|
if (!stream.AwaitResponse().success) {
|
||||||
|
spdlog::error("Failed to receive successful RPC swapping of uuid response!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (const rpc::RpcFailedException &) {
|
||||||
|
spdlog::error("RPC error occurred while sending swapping uuid RPC!");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CoordinatorClient::SendUnregisterReplicaRpc(std::string const &instance_name) const -> bool {
|
||||||
|
try {
|
||||||
|
auto stream{rpc_client_.Stream<UnregisterReplicaRpc>(instance_name)};
|
||||||
|
if (!stream.AwaitResponse().success) {
|
||||||
|
spdlog::error("Failed to receive successful RPC response for unregistering replica!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (rpc::RpcFailedException const &) {
|
||||||
|
spdlog::error("Failed to unregister replica!");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CoordinatorClient::SendGetInstanceUUIDRpc() const
|
||||||
|
-> utils::BasicResult<GetInstanceUUIDError, std::optional<utils::UUID>> {
|
||||||
|
try {
|
||||||
|
auto stream{rpc_client_.Stream<GetInstanceUUIDRpc>()};
|
||||||
|
auto res = stream.AwaitResponse();
|
||||||
|
return res.uuid;
|
||||||
|
} catch (const rpc::RpcFailedException &) {
|
||||||
|
spdlog::error("RPC error occured while sending GetInstance UUID RPC");
|
||||||
|
return GetInstanceUUIDError::RPC_EXCEPTION;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CoordinatorClient::SendEnableWritingOnMainRpc() const -> bool {
|
||||||
|
try {
|
||||||
|
auto stream{rpc_client_.Stream<EnableWritingOnMainRpc>()};
|
||||||
|
if (!stream.AwaitResponse().success) {
|
||||||
|
spdlog::error("Failed to receive successful RPC response for enabling writing on main!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (rpc::RpcFailedException const &) {
|
||||||
|
spdlog::error("Failed to enable writing on main!");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace memgraph::coordination
|
||||||
|
#endif
|
||||||
218
src/coordination/coordinator_handlers.cpp
Normal file
218
src/coordination/coordinator_handlers.cpp
Normal file
@@ -0,0 +1,218 @@
|
|||||||
|
// Copyright 2024 Memgraph Ltd.
|
||||||
|
//
|
||||||
|
// Use of this software is governed by the Business Source License
|
||||||
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
|
// License, and you may not use this file except in compliance with the Business Source License.
|
||||||
|
//
|
||||||
|
// As of the Change Date specified in that file, in accordance with
|
||||||
|
// the Business Source License, use of this software will be governed
|
||||||
|
// by the Apache License, Version 2.0, included in the file
|
||||||
|
// licenses/APL.txt.
|
||||||
|
|
||||||
|
#ifdef MG_ENTERPRISE
|
||||||
|
#include "coordination/coordinator_handlers.hpp"
|
||||||
|
|
||||||
|
#include <range/v3/view.hpp>
|
||||||
|
|
||||||
|
#include "coordination/coordinator_rpc.hpp"
|
||||||
|
#include "coordination/include/coordination/coordinator_server.hpp"
|
||||||
|
#include "replication/state.hpp"
|
||||||
|
|
||||||
|
namespace memgraph::dbms {
|
||||||
|
|
||||||
|
void CoordinatorHandlers::Register(memgraph::coordination::CoordinatorServer &server,
|
||||||
|
replication::ReplicationHandler &replication_handler) {
|
||||||
|
server.Register<coordination::PromoteReplicaToMainRpc>(
|
||||||
|
[&](slk::Reader *req_reader, slk::Builder *res_builder) -> void {
|
||||||
|
spdlog::info("Received PromoteReplicaToMainRpc");
|
||||||
|
CoordinatorHandlers::PromoteReplicaToMainHandler(replication_handler, req_reader, res_builder);
|
||||||
|
});
|
||||||
|
|
||||||
|
server.Register<coordination::DemoteMainToReplicaRpc>(
|
||||||
|
[&replication_handler](slk::Reader *req_reader, slk::Builder *res_builder) -> void {
|
||||||
|
spdlog::info("Received DemoteMainToReplicaRpc from coordinator server");
|
||||||
|
CoordinatorHandlers::DemoteMainToReplicaHandler(replication_handler, req_reader, res_builder);
|
||||||
|
});
|
||||||
|
|
||||||
|
server.Register<replication_coordination_glue::SwapMainUUIDRpc>(
|
||||||
|
[&replication_handler](slk::Reader *req_reader, slk::Builder *res_builder) -> void {
|
||||||
|
spdlog::info("Received SwapMainUUIDRPC on coordinator server");
|
||||||
|
CoordinatorHandlers::SwapMainUUIDHandler(replication_handler, req_reader, res_builder);
|
||||||
|
});
|
||||||
|
|
||||||
|
server.Register<coordination::UnregisterReplicaRpc>(
|
||||||
|
[&replication_handler](slk::Reader *req_reader, slk::Builder *res_builder) -> void {
|
||||||
|
spdlog::info("Received UnregisterReplicaRpc on coordinator server");
|
||||||
|
CoordinatorHandlers::UnregisterReplicaHandler(replication_handler, req_reader, res_builder);
|
||||||
|
});
|
||||||
|
|
||||||
|
server.Register<coordination::EnableWritingOnMainRpc>(
|
||||||
|
[&replication_handler](slk::Reader *req_reader, slk::Builder *res_builder) -> void {
|
||||||
|
spdlog::info("Received EnableWritingOnMainRpc on coordinator server");
|
||||||
|
CoordinatorHandlers::EnableWritingOnMainHandler(replication_handler, req_reader, res_builder);
|
||||||
|
});
|
||||||
|
|
||||||
|
server.Register<coordination::GetInstanceUUIDRpc>(
|
||||||
|
[&replication_handler](slk::Reader *req_reader, slk::Builder *res_builder) -> void {
|
||||||
|
spdlog::info("Received GetInstanceUUIDRpc on coordinator server");
|
||||||
|
CoordinatorHandlers::GetInstanceUUIDHandler(replication_handler, req_reader, res_builder);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoordinatorHandlers::SwapMainUUIDHandler(replication::ReplicationHandler &replication_handler,
|
||||||
|
slk::Reader *req_reader, slk::Builder *res_builder) {
|
||||||
|
if (!replication_handler.IsReplica()) {
|
||||||
|
spdlog::error("Setting main uuid must be performed on replica.");
|
||||||
|
slk::Save(replication_coordination_glue::SwapMainUUIDRes{false}, res_builder);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
replication_coordination_glue::SwapMainUUIDReq req;
|
||||||
|
slk::Load(&req, req_reader);
|
||||||
|
spdlog::info(fmt::format("Set replica data UUID to main uuid {}", std::string(req.uuid)));
|
||||||
|
std::get<memgraph::replication::RoleReplicaData>(replication_handler.GetReplState().ReplicationData()).uuid_ =
|
||||||
|
req.uuid;
|
||||||
|
|
||||||
|
slk::Save(replication_coordination_glue::SwapMainUUIDRes{true}, res_builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoordinatorHandlers::DemoteMainToReplicaHandler(replication::ReplicationHandler &replication_handler,
|
||||||
|
slk::Reader *req_reader, slk::Builder *res_builder) {
|
||||||
|
spdlog::info("Executing DemoteMainToReplicaHandler");
|
||||||
|
|
||||||
|
coordination::DemoteMainToReplicaReq req;
|
||||||
|
slk::Load(&req, req_reader);
|
||||||
|
|
||||||
|
const replication::ReplicationServerConfig clients_config{
|
||||||
|
.ip_address = req.replication_client_info.replication_ip_address,
|
||||||
|
.port = req.replication_client_info.replication_port};
|
||||||
|
|
||||||
|
if (!replication_handler.SetReplicationRoleReplica(clients_config, std::nullopt)) {
|
||||||
|
spdlog::error("Demoting main to replica failed!");
|
||||||
|
slk::Save(coordination::DemoteMainToReplicaRes{false}, res_builder);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
slk::Save(coordination::DemoteMainToReplicaRes{true}, res_builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoordinatorHandlers::GetInstanceUUIDHandler(replication::ReplicationHandler &replication_handler,
|
||||||
|
slk::Reader * /*req_reader*/, slk::Builder *res_builder) {
|
||||||
|
spdlog::info("Executing GetInstanceUUIDHandler");
|
||||||
|
|
||||||
|
slk::Save(coordination::GetInstanceUUIDRes{replication_handler.GetReplicaUUID()}, res_builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoordinatorHandlers::PromoteReplicaToMainHandler(replication::ReplicationHandler &replication_handler,
|
||||||
|
slk::Reader *req_reader, slk::Builder *res_builder) {
|
||||||
|
if (!replication_handler.IsReplica()) {
|
||||||
|
spdlog::error("Failover must be performed on replica!");
|
||||||
|
slk::Save(coordination::PromoteReplicaToMainRes{false}, res_builder);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
coordination::PromoteReplicaToMainReq req;
|
||||||
|
slk::Load(&req, req_reader);
|
||||||
|
|
||||||
|
// This can fail because of disk. If it does, the cluster state could get inconsistent.
|
||||||
|
// We don't handle disk issues.
|
||||||
|
if (const bool success = replication_handler.DoReplicaToMainPromotion(req.main_uuid_); !success) {
|
||||||
|
spdlog::error("Promoting replica to main failed!");
|
||||||
|
slk::Save(coordination::PromoteReplicaToMainRes{false}, res_builder);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto const converter = [](const auto &repl_info_config) {
|
||||||
|
return replication::ReplicationClientConfig{
|
||||||
|
.name = repl_info_config.instance_name,
|
||||||
|
.mode = repl_info_config.replication_mode,
|
||||||
|
.ip_address = repl_info_config.replication_ip_address,
|
||||||
|
.port = repl_info_config.replication_port,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// registering replicas
|
||||||
|
for (auto const &config : req.replication_clients_info | ranges::views::transform(converter)) {
|
||||||
|
auto instance_client = replication_handler.RegisterReplica(config);
|
||||||
|
if (instance_client.HasError()) {
|
||||||
|
using enum memgraph::replication::RegisterReplicaError;
|
||||||
|
switch (instance_client.GetError()) {
|
||||||
|
// Can't happen, checked on the coordinator side
|
||||||
|
case memgraph::query::RegisterReplicaError::NAME_EXISTS:
|
||||||
|
spdlog::error("Replica with the same name already exists!");
|
||||||
|
slk::Save(coordination::PromoteReplicaToMainRes{false}, res_builder);
|
||||||
|
return;
|
||||||
|
// Can't happen, checked on the coordinator side
|
||||||
|
case memgraph::query::RegisterReplicaError::ENDPOINT_EXISTS:
|
||||||
|
spdlog::error("Replica with the same endpoint already exists!");
|
||||||
|
slk::Save(coordination::PromoteReplicaToMainRes{false}, res_builder);
|
||||||
|
return;
|
||||||
|
// We don't handle disk issues
|
||||||
|
case memgraph::query::RegisterReplicaError::COULD_NOT_BE_PERSISTED:
|
||||||
|
spdlog::error("Registered replica could not be persisted!");
|
||||||
|
slk::Save(coordination::PromoteReplicaToMainRes{false}, res_builder);
|
||||||
|
return;
|
||||||
|
case memgraph::query::RegisterReplicaError::ERROR_ACCEPTING_MAIN:
|
||||||
|
spdlog::error("Replica didn't accept change of main!");
|
||||||
|
slk::Save(coordination::PromoteReplicaToMainRes{false}, res_builder);
|
||||||
|
return;
|
||||||
|
case memgraph::query::RegisterReplicaError::CONNECTION_FAILED:
|
||||||
|
// Connection failure is not a fatal error
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
spdlog::info("Promote replica to main was success {}", std::string(req.main_uuid_));
|
||||||
|
slk::Save(coordination::PromoteReplicaToMainRes{true}, res_builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoordinatorHandlers::UnregisterReplicaHandler(replication::ReplicationHandler &replication_handler,
|
||||||
|
slk::Reader *req_reader, slk::Builder *res_builder) {
|
||||||
|
if (!replication_handler.IsMain()) {
|
||||||
|
spdlog::error("Unregistering replica must be performed on main.");
|
||||||
|
slk::Save(coordination::UnregisterReplicaRes{false}, res_builder);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
coordination::UnregisterReplicaReq req;
|
||||||
|
slk::Load(&req, req_reader);
|
||||||
|
|
||||||
|
auto res = replication_handler.UnregisterReplica(req.instance_name);
|
||||||
|
switch (res) {
|
||||||
|
using enum memgraph::query::UnregisterReplicaResult;
|
||||||
|
case SUCCESS:
|
||||||
|
slk::Save(coordination::UnregisterReplicaRes{true}, res_builder);
|
||||||
|
break;
|
||||||
|
case NOT_MAIN:
|
||||||
|
spdlog::error("Unregistering replica must be performed on main.");
|
||||||
|
slk::Save(coordination::UnregisterReplicaRes{false}, res_builder);
|
||||||
|
break;
|
||||||
|
case CAN_NOT_UNREGISTER:
|
||||||
|
spdlog::error("Could not unregister replica.");
|
||||||
|
slk::Save(coordination::UnregisterReplicaRes{false}, res_builder);
|
||||||
|
break;
|
||||||
|
case COULD_NOT_BE_PERSISTED:
|
||||||
|
spdlog::error("Could not persist replica unregistration.");
|
||||||
|
slk::Save(coordination::UnregisterReplicaRes{false}, res_builder);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoordinatorHandlers::EnableWritingOnMainHandler(replication::ReplicationHandler &replication_handler,
|
||||||
|
slk::Reader * /*req_reader*/, slk::Builder *res_builder) {
|
||||||
|
if (!replication_handler.IsMain()) {
|
||||||
|
spdlog::error("Enable writing on main must be performed on main!");
|
||||||
|
slk::Save(coordination::EnableWritingOnMainRes{false}, res_builder);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!replication_handler.GetReplState().EnableWritingOnMain()) {
|
||||||
|
spdlog::error("Enabling writing on main failed!");
|
||||||
|
slk::Save(coordination::EnableWritingOnMainRes{false}, res_builder);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
slk::Save(coordination::EnableWritingOnMainRes{true}, res_builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace memgraph::dbms
|
||||||
|
#endif
|
||||||
347
src/coordination/coordinator_instance.cpp
Normal file
347
src/coordination/coordinator_instance.cpp
Normal file
@@ -0,0 +1,347 @@
|
|||||||
|
// Copyright 2024 Memgraph Ltd.
|
||||||
|
//
|
||||||
|
// Use of this software is governed by the Business Source License
|
||||||
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
|
// License, and you may not use this file except in compliance with the Business Source License.
|
||||||
|
//
|
||||||
|
// As of the Change Date specified in that file, in accordance with
|
||||||
|
// the Business Source License, use of this software will be governed
|
||||||
|
// by the Apache License, Version 2.0, included in the file
|
||||||
|
// licenses/APL.txt.
|
||||||
|
|
||||||
|
#ifdef MG_ENTERPRISE
|
||||||
|
|
||||||
|
#include "coordination/coordinator_instance.hpp"
|
||||||
|
|
||||||
|
#include "coordination/coordinator_exceptions.hpp"
|
||||||
|
#include "coordination/fmt.hpp"
|
||||||
|
#include "nuraft/coordinator_state_machine.hpp"
|
||||||
|
#include "nuraft/coordinator_state_manager.hpp"
|
||||||
|
#include "utils/counter.hpp"
|
||||||
|
#include "utils/functional.hpp"
|
||||||
|
|
||||||
|
#include <range/v3/view.hpp>
|
||||||
|
#include <shared_mutex>
|
||||||
|
|
||||||
|
namespace memgraph::coordination {
|
||||||
|
|
||||||
|
using nuraft::ptr;
|
||||||
|
using nuraft::srv_config;
|
||||||
|
|
||||||
|
CoordinatorInstance::CoordinatorInstance()
|
||||||
|
: raft_state_(RaftState::MakeRaftState(
|
||||||
|
[this] { std::ranges::for_each(repl_instances_, &ReplicationInstance::StartFrequentCheck); },
|
||||||
|
[this] { std::ranges::for_each(repl_instances_, &ReplicationInstance::StopFrequentCheck); })) {
|
||||||
|
auto find_repl_instance = [](CoordinatorInstance *self,
|
||||||
|
std::string_view repl_instance_name) -> ReplicationInstance & {
|
||||||
|
auto repl_instance =
|
||||||
|
std::ranges::find_if(self->repl_instances_, [repl_instance_name](ReplicationInstance const &instance) {
|
||||||
|
return instance.InstanceName() == repl_instance_name;
|
||||||
|
});
|
||||||
|
|
||||||
|
MG_ASSERT(repl_instance != self->repl_instances_.end(), "Instance {} not found during callback!",
|
||||||
|
repl_instance_name);
|
||||||
|
return *repl_instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
replica_succ_cb_ = [find_repl_instance](CoordinatorInstance *self, std::string_view repl_instance_name) -> void {
|
||||||
|
auto lock = std::lock_guard{self->coord_instance_lock_};
|
||||||
|
spdlog::trace("Instance {} performing replica successful callback", repl_instance_name);
|
||||||
|
auto &repl_instance = find_repl_instance(self, repl_instance_name);
|
||||||
|
|
||||||
|
// We need to get replicas UUID from time to time to ensure replica is listening to correct main
|
||||||
|
// and that it didn't go down for less time than we could notice
|
||||||
|
// We need to get id of main replica is listening to
|
||||||
|
// and swap if necessary
|
||||||
|
if (!repl_instance.EnsureReplicaHasCorrectMainUUID(self->GetMainUUID())) {
|
||||||
|
spdlog::error("Failed to swap uuid for replica instance {} which is alive", repl_instance.InstanceName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
repl_instance.OnSuccessPing();
|
||||||
|
};
|
||||||
|
|
||||||
|
replica_fail_cb_ = [find_repl_instance](CoordinatorInstance *self, std::string_view repl_instance_name) -> void {
|
||||||
|
auto lock = std::lock_guard{self->coord_instance_lock_};
|
||||||
|
spdlog::trace("Instance {} performing replica failure callback", repl_instance_name);
|
||||||
|
auto &repl_instance = find_repl_instance(self, repl_instance_name);
|
||||||
|
repl_instance.OnFailPing();
|
||||||
|
};
|
||||||
|
|
||||||
|
main_succ_cb_ = [find_repl_instance](CoordinatorInstance *self, std::string_view repl_instance_name) -> void {
|
||||||
|
auto lock = std::lock_guard{self->coord_instance_lock_};
|
||||||
|
spdlog::trace("Instance {} performing main successful callback", repl_instance_name);
|
||||||
|
|
||||||
|
auto &repl_instance = find_repl_instance(self, repl_instance_name);
|
||||||
|
|
||||||
|
if (repl_instance.IsAlive()) {
|
||||||
|
repl_instance.OnSuccessPing();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto &repl_instance_uuid = repl_instance.GetMainUUID();
|
||||||
|
MG_ASSERT(repl_instance_uuid.has_value(), "Instance must have uuid set.");
|
||||||
|
|
||||||
|
auto const curr_main_uuid = self->GetMainUUID();
|
||||||
|
if (curr_main_uuid == repl_instance_uuid.value()) {
|
||||||
|
if (!repl_instance.EnableWritingOnMain()) {
|
||||||
|
spdlog::error("Failed to enable writing on main instance {}", repl_instance_name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
repl_instance.OnSuccessPing();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(antoniof) make demoteToReplica idempotent since main can be demoted to replica but
|
||||||
|
// swapUUID can fail
|
||||||
|
if (repl_instance.DemoteToReplica(self->replica_succ_cb_, self->replica_fail_cb_)) {
|
||||||
|
repl_instance.OnSuccessPing();
|
||||||
|
spdlog::info("Instance {} demoted to replica", repl_instance_name);
|
||||||
|
} else {
|
||||||
|
spdlog::error("Instance {} failed to become replica", repl_instance_name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!repl_instance.SendSwapAndUpdateUUID(curr_main_uuid)) {
|
||||||
|
spdlog::error(fmt::format("Failed to swap uuid for demoted main instance {}", repl_instance.InstanceName()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
main_fail_cb_ = [find_repl_instance](CoordinatorInstance *self, std::string_view repl_instance_name) -> void {
|
||||||
|
auto lock = std::lock_guard{self->coord_instance_lock_};
|
||||||
|
spdlog::trace("Instance {} performing main failure callback", repl_instance_name);
|
||||||
|
auto &repl_instance = find_repl_instance(self, repl_instance_name);
|
||||||
|
repl_instance.OnFailPing();
|
||||||
|
const auto &repl_instance_uuid = repl_instance.GetMainUUID();
|
||||||
|
MG_ASSERT(repl_instance_uuid.has_value(), "Instance must have uuid set");
|
||||||
|
|
||||||
|
if (!repl_instance.IsAlive() && self->GetMainUUID() == repl_instance_uuid.value()) {
|
||||||
|
spdlog::info("Cluster without main instance, trying automatic failover");
|
||||||
|
self->TryFailover(); // TODO: (andi) Initiate failover
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CoordinatorInstance::ShowInstances() const -> std::vector<InstanceStatus> {
|
||||||
|
auto const coord_instances = raft_state_.GetAllCoordinators();
|
||||||
|
|
||||||
|
auto const stringify_repl_role = [](ReplicationInstance const &instance) -> std::string {
|
||||||
|
if (!instance.IsAlive()) return "unknown";
|
||||||
|
if (instance.IsMain()) return "main";
|
||||||
|
return "replica";
|
||||||
|
};
|
||||||
|
|
||||||
|
auto const repl_instance_to_status = [&stringify_repl_role](ReplicationInstance const &instance) -> InstanceStatus {
|
||||||
|
return {.instance_name = instance.InstanceName(),
|
||||||
|
.coord_socket_address = instance.SocketAddress(),
|
||||||
|
.cluster_role = stringify_repl_role(instance),
|
||||||
|
.is_alive = instance.IsAlive()};
|
||||||
|
};
|
||||||
|
|
||||||
|
auto const coord_instance_to_status = [](ptr<srv_config> const &instance) -> InstanceStatus {
|
||||||
|
return {.instance_name = "coordinator_" + std::to_string(instance->get_id()),
|
||||||
|
.raft_socket_address = instance->get_endpoint(),
|
||||||
|
.cluster_role = "coordinator",
|
||||||
|
.is_alive = true}; // TODO: (andi) Get this info from RAFT and test it or when we will move
|
||||||
|
// CoordinatorState to every instance, we can be smarter about this using our RPC.
|
||||||
|
};
|
||||||
|
|
||||||
|
auto instances_status = utils::fmap(coord_instance_to_status, coord_instances);
|
||||||
|
{
|
||||||
|
auto lock = std::shared_lock{coord_instance_lock_};
|
||||||
|
std::ranges::transform(repl_instances_, std::back_inserter(instances_status), repl_instance_to_status);
|
||||||
|
}
|
||||||
|
|
||||||
|
return instances_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CoordinatorInstance::TryFailover() -> void {
|
||||||
|
auto alive_replicas = repl_instances_ | ranges::views::filter(&ReplicationInstance::IsReplica) |
|
||||||
|
ranges::views::filter(&ReplicationInstance::IsAlive);
|
||||||
|
|
||||||
|
if (ranges::empty(alive_replicas)) {
|
||||||
|
spdlog::warn("Failover failed since all replicas are down!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Smarter choice
|
||||||
|
auto new_main = ranges::begin(alive_replicas);
|
||||||
|
|
||||||
|
new_main->PauseFrequentCheck();
|
||||||
|
utils::OnScopeExit scope_exit{[&new_main] { new_main->ResumeFrequentCheck(); }};
|
||||||
|
|
||||||
|
auto const is_not_new_main = [&new_main](ReplicationInstance &instance) {
|
||||||
|
return instance.InstanceName() != new_main->InstanceName();
|
||||||
|
};
|
||||||
|
|
||||||
|
auto const new_main_uuid = utils::UUID{};
|
||||||
|
// If for some replicas swap fails, for others on successful ping we will revert back on next change
|
||||||
|
// or we will do failover first again and then it will be consistent again
|
||||||
|
for (auto &other_replica_instance : alive_replicas | ranges::views::filter(is_not_new_main)) {
|
||||||
|
if (!other_replica_instance.SendSwapAndUpdateUUID(new_main_uuid)) {
|
||||||
|
spdlog::error(fmt::format("Failed to swap uuid for instance {} which is alive, aborting failover",
|
||||||
|
other_replica_instance.InstanceName()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto repl_clients_info = repl_instances_ | ranges::views::filter(is_not_new_main) |
|
||||||
|
ranges::views::transform(&ReplicationInstance::ReplicationClientInfo) |
|
||||||
|
ranges::to<ReplicationClientsInfo>();
|
||||||
|
|
||||||
|
if (!new_main->PromoteToMain(new_main_uuid, std::move(repl_clients_info), main_succ_cb_, main_fail_cb_)) {
|
||||||
|
spdlog::warn("Failover failed since promoting replica to main failed!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// TODO: (andi) This should be replicated across all coordinator instances with Raft log
|
||||||
|
SetMainUUID(new_main_uuid);
|
||||||
|
spdlog::info("Failover successful! Instance {} promoted to main.", new_main->InstanceName());
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: (andi) Make sure you cannot put coordinator instance to the main
|
||||||
|
auto CoordinatorInstance::SetReplicationInstanceToMain(std::string instance_name)
|
||||||
|
-> SetInstanceToMainCoordinatorStatus {
|
||||||
|
auto lock = std::lock_guard{coord_instance_lock_};
|
||||||
|
|
||||||
|
if (std::ranges::any_of(repl_instances_, &ReplicationInstance::IsMain)) {
|
||||||
|
return SetInstanceToMainCoordinatorStatus::MAIN_ALREADY_EXISTS;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto const is_new_main = [&instance_name](ReplicationInstance const &instance) {
|
||||||
|
return instance.InstanceName() == instance_name;
|
||||||
|
};
|
||||||
|
auto new_main = std::ranges::find_if(repl_instances_, is_new_main);
|
||||||
|
|
||||||
|
if (new_main == repl_instances_.end()) {
|
||||||
|
spdlog::error("Instance {} not registered. Please register it using REGISTER INSTANCE {}", instance_name,
|
||||||
|
instance_name);
|
||||||
|
return SetInstanceToMainCoordinatorStatus::NO_INSTANCE_WITH_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
new_main->PauseFrequentCheck();
|
||||||
|
utils::OnScopeExit scope_exit{[&new_main] { new_main->ResumeFrequentCheck(); }};
|
||||||
|
|
||||||
|
auto const is_not_new_main = [&instance_name](ReplicationInstance const &instance) {
|
||||||
|
return instance.InstanceName() != instance_name;
|
||||||
|
};
|
||||||
|
|
||||||
|
auto const new_main_uuid = utils::UUID{};
|
||||||
|
|
||||||
|
for (auto &other_instance : repl_instances_ | ranges::views::filter(is_not_new_main)) {
|
||||||
|
if (!other_instance.SendSwapAndUpdateUUID(new_main_uuid)) {
|
||||||
|
spdlog::error(
|
||||||
|
fmt::format("Failed to swap uuid for instance {}, aborting failover", other_instance.InstanceName()));
|
||||||
|
return SetInstanceToMainCoordinatorStatus::SWAP_UUID_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ReplicationClientsInfo repl_clients_info;
|
||||||
|
repl_clients_info.reserve(repl_instances_.size() - 1);
|
||||||
|
std::ranges::transform(repl_instances_ | ranges::views::filter(is_not_new_main),
|
||||||
|
std::back_inserter(repl_clients_info), &ReplicationInstance::ReplicationClientInfo);
|
||||||
|
|
||||||
|
if (!new_main->PromoteToMain(new_main_uuid, std::move(repl_clients_info), main_succ_cb_, main_fail_cb_)) {
|
||||||
|
return SetInstanceToMainCoordinatorStatus::COULD_NOT_PROMOTE_TO_MAIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: (andi) This should be replicated across all coordinator instances with Raft log
|
||||||
|
SetMainUUID(new_main_uuid);
|
||||||
|
spdlog::info("Instance {} promoted to main", instance_name);
|
||||||
|
return SetInstanceToMainCoordinatorStatus::SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CoordinatorInstance::RegisterReplicationInstance(CoordinatorClientConfig config)
|
||||||
|
-> RegisterInstanceCoordinatorStatus {
|
||||||
|
auto lock = std::lock_guard{coord_instance_lock_};
|
||||||
|
|
||||||
|
auto instance_name = config.instance_name;
|
||||||
|
|
||||||
|
auto const name_matches = [&instance_name](ReplicationInstance const &instance) {
|
||||||
|
return instance.InstanceName() == instance_name;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (std::ranges::any_of(repl_instances_, name_matches)) {
|
||||||
|
return RegisterInstanceCoordinatorStatus::NAME_EXISTS;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto const socket_address_matches = [&config](ReplicationInstance const &instance) {
|
||||||
|
return instance.SocketAddress() == config.SocketAddress();
|
||||||
|
};
|
||||||
|
|
||||||
|
if (std::ranges::any_of(repl_instances_, socket_address_matches)) {
|
||||||
|
return RegisterInstanceCoordinatorStatus::ENDPOINT_EXISTS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!raft_state_.RequestLeadership()) {
|
||||||
|
return RegisterInstanceCoordinatorStatus::NOT_LEADER;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto const res = raft_state_.AppendRegisterReplicationInstance(instance_name);
|
||||||
|
if (!res->get_accepted()) {
|
||||||
|
spdlog::error(
|
||||||
|
"Failed to accept request for registering instance {}. Most likely the reason is that the instance is not "
|
||||||
|
"the "
|
||||||
|
"leader.",
|
||||||
|
config.instance_name);
|
||||||
|
return RegisterInstanceCoordinatorStatus::RAFT_COULD_NOT_ACCEPT;
|
||||||
|
}
|
||||||
|
|
||||||
|
spdlog::info("Request for registering instance {} accepted", instance_name);
|
||||||
|
try {
|
||||||
|
repl_instances_.emplace_back(this, std::move(config), replica_succ_cb_, replica_fail_cb_);
|
||||||
|
} catch (CoordinatorRegisterInstanceException const &) {
|
||||||
|
return RegisterInstanceCoordinatorStatus::RPC_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (res->get_result_code() != nuraft::cmd_result_code::OK) {
|
||||||
|
spdlog::error("Failed to register instance {} with error code {}", instance_name, res->get_result_code());
|
||||||
|
return RegisterInstanceCoordinatorStatus::RAFT_COULD_NOT_APPEND;
|
||||||
|
}
|
||||||
|
|
||||||
|
spdlog::info("Instance {} registered", instance_name);
|
||||||
|
return RegisterInstanceCoordinatorStatus::SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CoordinatorInstance::UnregisterReplicationInstance(std::string instance_name)
|
||||||
|
-> UnregisterInstanceCoordinatorStatus {
|
||||||
|
auto lock = std::lock_guard{coord_instance_lock_};
|
||||||
|
|
||||||
|
auto const name_matches = [&instance_name](ReplicationInstance const &instance) {
|
||||||
|
return instance.InstanceName() == instance_name;
|
||||||
|
};
|
||||||
|
|
||||||
|
auto inst_to_remove = std::ranges::find_if(repl_instances_, name_matches);
|
||||||
|
if (inst_to_remove == repl_instances_.end()) {
|
||||||
|
return UnregisterInstanceCoordinatorStatus::NO_INSTANCE_WITH_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inst_to_remove->IsMain() && inst_to_remove->IsAlive()) {
|
||||||
|
return UnregisterInstanceCoordinatorStatus::IS_MAIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
inst_to_remove->StopFrequentCheck();
|
||||||
|
auto curr_main = std::ranges::find_if(repl_instances_, &ReplicationInstance::IsMain);
|
||||||
|
MG_ASSERT(curr_main != repl_instances_.end(), "There must be a main instance when unregistering a replica");
|
||||||
|
if (!curr_main->SendUnregisterReplicaRpc(instance_name)) {
|
||||||
|
inst_to_remove->StartFrequentCheck();
|
||||||
|
return UnregisterInstanceCoordinatorStatus::RPC_FAILED;
|
||||||
|
}
|
||||||
|
std::erase_if(repl_instances_, name_matches);
|
||||||
|
|
||||||
|
return UnregisterInstanceCoordinatorStatus::SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CoordinatorInstance::AddCoordinatorInstance(uint32_t raft_server_id, uint32_t raft_port, std::string raft_address)
|
||||||
|
-> void {
|
||||||
|
raft_state_.AddCoordinatorInstance(raft_server_id, raft_port, std::move(raft_address));
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CoordinatorInstance::GetMainUUID() const -> utils::UUID { return main_uuid_; }
|
||||||
|
|
||||||
|
// TODO: (andi) Add to the RAFT log.
|
||||||
|
auto CoordinatorInstance::SetMainUUID(utils::UUID new_uuid) -> void { main_uuid_ = new_uuid; }
|
||||||
|
|
||||||
|
} // namespace memgraph::coordination
|
||||||
|
#endif
|
||||||
201
src/coordination/coordinator_log_store.cpp
Normal file
201
src/coordination/coordinator_log_store.cpp
Normal file
@@ -0,0 +1,201 @@
|
|||||||
|
// Copyright 2024 Memgraph Ltd.
|
||||||
|
//
|
||||||
|
// Use of this software is governed by the Business Source License
|
||||||
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
|
// License, and you may not use this file except in compliance with the Business Source License.
|
||||||
|
//
|
||||||
|
// As of the Change Date specified in that file, in accordance with
|
||||||
|
// the Business Source License, use of this software will be governed
|
||||||
|
// by the Apache License, Version 2.0, included in the file
|
||||||
|
// licenses/APL.txt.
|
||||||
|
|
||||||
|
#ifdef MG_ENTERPRISE
|
||||||
|
|
||||||
|
#include "nuraft/coordinator_log_store.hpp"
|
||||||
|
|
||||||
|
#include "coordination/coordinator_exceptions.hpp"
|
||||||
|
#include "utils/logging.hpp"
|
||||||
|
|
||||||
|
namespace memgraph::coordination {
|
||||||
|
|
||||||
|
using nuraft::cs_new;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
ptr<log_entry> MakeClone(const ptr<log_entry> &entry) {
|
||||||
|
return cs_new<log_entry>(entry->get_term(), buffer::clone(entry->get_buf()), entry->get_val_type(),
|
||||||
|
entry->get_timestamp());
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
CoordinatorLogStore::CoordinatorLogStore() : start_idx_(1) {
|
||||||
|
ptr<buffer> buf = buffer::alloc(sizeof(uint64_t));
|
||||||
|
logs_[0] = cs_new<log_entry>(0, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
CoordinatorLogStore::~CoordinatorLogStore() {}
|
||||||
|
|
||||||
|
auto CoordinatorLogStore::FindOrDefault_(uint64_t index) const -> ptr<log_entry> {
|
||||||
|
auto entry = logs_.find(index);
|
||||||
|
if (entry == logs_.end()) {
|
||||||
|
entry = logs_.find(0);
|
||||||
|
}
|
||||||
|
return entry->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t CoordinatorLogStore::next_slot() const {
|
||||||
|
auto lock = std::lock_guard{logs_lock_};
|
||||||
|
return start_idx_ + logs_.size() - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t CoordinatorLogStore::start_index() const { return start_idx_; }
|
||||||
|
|
||||||
|
ptr<log_entry> CoordinatorLogStore::last_entry() const {
|
||||||
|
auto lock = std::lock_guard{logs_lock_};
|
||||||
|
|
||||||
|
uint64_t const last_idx = start_idx_ + logs_.size() - 1;
|
||||||
|
auto const last_src = FindOrDefault_(last_idx - 1);
|
||||||
|
|
||||||
|
return MakeClone(last_src);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t CoordinatorLogStore::append(ptr<log_entry> &entry) {
|
||||||
|
ptr<log_entry> clone = MakeClone(entry);
|
||||||
|
uint64_t next_slot{0};
|
||||||
|
{
|
||||||
|
auto lock = std::lock_guard{logs_lock_};
|
||||||
|
next_slot = start_idx_ + logs_.size() - 1;
|
||||||
|
logs_[next_slot] = clone;
|
||||||
|
}
|
||||||
|
return next_slot;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoordinatorLogStore::write_at(uint64_t index, ptr<log_entry> &entry) {
|
||||||
|
ptr<log_entry> clone = MakeClone(entry);
|
||||||
|
|
||||||
|
// Discard all logs equal to or greater than `index.
|
||||||
|
{
|
||||||
|
auto lock = std::lock_guard{logs_lock_};
|
||||||
|
auto itr = logs_.lower_bound(index);
|
||||||
|
while (itr != logs_.end()) {
|
||||||
|
itr = logs_.erase(itr);
|
||||||
|
}
|
||||||
|
logs_[index] = clone;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ptr<std::vector<ptr<log_entry>>> CoordinatorLogStore::log_entries(uint64_t start, uint64_t end) {
|
||||||
|
auto ret = cs_new<std::vector<ptr<log_entry>>>();
|
||||||
|
ret->resize(end - start);
|
||||||
|
|
||||||
|
for (uint64_t i = start, curr_index = 0; i < end; ++i, ++curr_index) {
|
||||||
|
ptr<log_entry> src = nullptr;
|
||||||
|
{
|
||||||
|
auto lock = std::lock_guard{logs_lock_};
|
||||||
|
if (auto const entry = logs_.find(i); entry != logs_.end()) {
|
||||||
|
src = entry->second;
|
||||||
|
} else {
|
||||||
|
throw RaftCouldNotFindEntryException("Could not find entry at index {}", i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(*ret)[curr_index] = MakeClone(src);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
ptr<log_entry> CoordinatorLogStore::entry_at(uint64_t index) {
|
||||||
|
ptr<log_entry> src = nullptr;
|
||||||
|
{
|
||||||
|
auto lock = std::lock_guard{logs_lock_};
|
||||||
|
src = FindOrDefault_(index);
|
||||||
|
}
|
||||||
|
return MakeClone(src);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t CoordinatorLogStore::term_at(uint64_t index) {
|
||||||
|
uint64_t term = 0;
|
||||||
|
{
|
||||||
|
auto lock = std::lock_guard{logs_lock_};
|
||||||
|
term = FindOrDefault_(index)->get_term();
|
||||||
|
}
|
||||||
|
return term;
|
||||||
|
}
|
||||||
|
|
||||||
|
ptr<buffer> CoordinatorLogStore::pack(uint64_t index, int32 cnt) {
|
||||||
|
std::vector<ptr<buffer>> logs;
|
||||||
|
|
||||||
|
size_t size_total = 0;
|
||||||
|
uint64_t const end_index = index + cnt;
|
||||||
|
for (uint64_t i = index; i < end_index; ++i) {
|
||||||
|
ptr<log_entry> le = nullptr;
|
||||||
|
{
|
||||||
|
auto lock = std::lock_guard{logs_lock_};
|
||||||
|
le = logs_[i];
|
||||||
|
}
|
||||||
|
MG_ASSERT(le.get(), "Could not find log entry at index {}", i);
|
||||||
|
auto buf = le->serialize();
|
||||||
|
size_total += buf->size();
|
||||||
|
logs.push_back(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto buf_out = buffer::alloc(sizeof(int32) + cnt * sizeof(int32) + size_total);
|
||||||
|
buf_out->pos(0);
|
||||||
|
buf_out->put((int32)cnt);
|
||||||
|
|
||||||
|
for (auto &entry : logs) {
|
||||||
|
buf_out->put(static_cast<int32>(entry->size()));
|
||||||
|
buf_out->put(*entry);
|
||||||
|
}
|
||||||
|
return buf_out;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoordinatorLogStore::apply_pack(uint64_t index, buffer &pack) {
|
||||||
|
pack.pos(0);
|
||||||
|
int32 const num_logs = pack.get_int();
|
||||||
|
|
||||||
|
for (int32 i = 0; i < num_logs; ++i) {
|
||||||
|
uint64_t cur_idx = index + i;
|
||||||
|
int32 buf_size = pack.get_int();
|
||||||
|
|
||||||
|
ptr<buffer> buf_local = buffer::alloc(buf_size);
|
||||||
|
pack.get(buf_local);
|
||||||
|
|
||||||
|
ptr<log_entry> le = log_entry::deserialize(*buf_local);
|
||||||
|
{
|
||||||
|
auto lock = std::lock_guard{logs_lock_};
|
||||||
|
logs_[cur_idx] = le;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
auto lock = std::lock_guard{logs_lock_};
|
||||||
|
auto const entry = logs_.upper_bound(0);
|
||||||
|
if (entry != logs_.end()) {
|
||||||
|
start_idx_ = entry->first;
|
||||||
|
} else {
|
||||||
|
start_idx_ = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: Remove all logs up to given 'last_log_index' (inclusive).
|
||||||
|
bool CoordinatorLogStore::compact(uint64_t last_log_index) {
|
||||||
|
auto lock = std::lock_guard{logs_lock_};
|
||||||
|
for (uint64_t ii = start_idx_; ii <= last_log_index; ++ii) {
|
||||||
|
auto const entry = logs_.find(ii);
|
||||||
|
if (entry != logs_.end()) {
|
||||||
|
logs_.erase(entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (start_idx_ <= last_log_index) {
|
||||||
|
start_idx_ = last_log_index + 1;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CoordinatorLogStore::flush() { return true; }
|
||||||
|
|
||||||
|
} // namespace memgraph::coordination
|
||||||
|
#endif
|
||||||
220
src/coordination/coordinator_rpc.cpp
Normal file
220
src/coordination/coordinator_rpc.cpp
Normal file
@@ -0,0 +1,220 @@
|
|||||||
|
// Copyright 2024 Memgraph Ltd.
|
||||||
|
//
|
||||||
|
// Use of this software is governed by the Business Source License
|
||||||
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
|
// License, and you may not use this file except in compliance with the Business Source License.
|
||||||
|
//
|
||||||
|
// As of the Change Date specified in that file, in accordance with
|
||||||
|
// the Business Source License, use of this software will be governed
|
||||||
|
// by the Apache License, Version 2.0, included in the file
|
||||||
|
// licenses/APL.txt.
|
||||||
|
|
||||||
|
#ifdef MG_ENTERPRISE
|
||||||
|
|
||||||
|
#include "coordination/coordinator_rpc.hpp"
|
||||||
|
|
||||||
|
#include "coordination/coordinator_slk.hpp"
|
||||||
|
#include "slk/serialization.hpp"
|
||||||
|
|
||||||
|
namespace memgraph {
|
||||||
|
|
||||||
|
namespace coordination {
|
||||||
|
|
||||||
|
void PromoteReplicaToMainReq::Save(const PromoteReplicaToMainReq &self, memgraph::slk::Builder *builder) {
|
||||||
|
memgraph::slk::Save(self, builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PromoteReplicaToMainReq::Load(PromoteReplicaToMainReq *self, memgraph::slk::Reader *reader) {
|
||||||
|
memgraph::slk::Load(self, reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PromoteReplicaToMainRes::Save(const PromoteReplicaToMainRes &self, memgraph::slk::Builder *builder) {
|
||||||
|
memgraph::slk::Save(self, builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PromoteReplicaToMainRes::Load(PromoteReplicaToMainRes *self, memgraph::slk::Reader *reader) {
|
||||||
|
memgraph::slk::Load(self, reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DemoteMainToReplicaReq::Save(const DemoteMainToReplicaReq &self, memgraph::slk::Builder *builder) {
|
||||||
|
memgraph::slk::Save(self, builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DemoteMainToReplicaReq::Load(DemoteMainToReplicaReq *self, memgraph::slk::Reader *reader) {
|
||||||
|
memgraph::slk::Load(self, reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DemoteMainToReplicaRes::Save(const DemoteMainToReplicaRes &self, memgraph::slk::Builder *builder) {
|
||||||
|
memgraph::slk::Save(self, builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DemoteMainToReplicaRes::Load(DemoteMainToReplicaRes *self, memgraph::slk::Reader *reader) {
|
||||||
|
memgraph::slk::Load(self, reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnregisterReplicaReq::Save(UnregisterReplicaReq const &self, memgraph::slk::Builder *builder) {
|
||||||
|
memgraph::slk::Save(self, builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnregisterReplicaReq::Load(UnregisterReplicaReq *self, memgraph::slk::Reader *reader) {
|
||||||
|
memgraph::slk::Load(self, reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnregisterReplicaRes::Save(UnregisterReplicaRes const &self, memgraph::slk::Builder *builder) {
|
||||||
|
memgraph::slk::Save(self, builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnregisterReplicaRes::Load(UnregisterReplicaRes *self, memgraph::slk::Reader *reader) {
|
||||||
|
memgraph::slk::Load(self, reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EnableWritingOnMainRes::Save(EnableWritingOnMainRes const &self, memgraph::slk::Builder *builder) {
|
||||||
|
memgraph::slk::Save(self, builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EnableWritingOnMainRes::Load(EnableWritingOnMainRes *self, memgraph::slk::Reader *reader) {
|
||||||
|
memgraph::slk::Load(self, reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EnableWritingOnMainReq::Save(EnableWritingOnMainReq const &self, memgraph::slk::Builder *builder) {}
|
||||||
|
|
||||||
|
void EnableWritingOnMainReq::Load(EnableWritingOnMainReq *self, memgraph::slk::Reader *reader) {}
|
||||||
|
|
||||||
|
// GetInstanceUUID
|
||||||
|
void GetInstanceUUIDReq::Save(const GetInstanceUUIDReq &self, memgraph::slk::Builder *builder) {
|
||||||
|
memgraph::slk::Save(self, builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GetInstanceUUIDReq::Load(GetInstanceUUIDReq *self, memgraph::slk::Reader *reader) {
|
||||||
|
memgraph::slk::Load(self, reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GetInstanceUUIDRes::Save(const GetInstanceUUIDRes &self, memgraph::slk::Builder *builder) {
|
||||||
|
memgraph::slk::Save(self, builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GetInstanceUUIDRes::Load(GetInstanceUUIDRes *self, memgraph::slk::Reader *reader) {
|
||||||
|
memgraph::slk::Load(self, reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace coordination
|
||||||
|
|
||||||
|
constexpr utils::TypeInfo coordination::PromoteReplicaToMainReq::kType{utils::TypeId::COORD_FAILOVER_REQ,
|
||||||
|
"CoordPromoteReplicaToMainReq", nullptr};
|
||||||
|
|
||||||
|
constexpr utils::TypeInfo coordination::PromoteReplicaToMainRes::kType{utils::TypeId::COORD_FAILOVER_RES,
|
||||||
|
"CoordPromoteReplicaToMainRes", nullptr};
|
||||||
|
|
||||||
|
constexpr utils::TypeInfo coordination::DemoteMainToReplicaReq::kType{utils::TypeId::COORD_SET_REPL_MAIN_REQ,
|
||||||
|
"CoordDemoteToReplicaReq", nullptr};
|
||||||
|
|
||||||
|
constexpr utils::TypeInfo coordination::DemoteMainToReplicaRes::kType{utils::TypeId::COORD_SET_REPL_MAIN_RES,
|
||||||
|
|
||||||
|
"CoordDemoteToReplicaRes", nullptr};
|
||||||
|
|
||||||
|
constexpr utils::TypeInfo coordination::UnregisterReplicaReq::kType{utils::TypeId::COORD_UNREGISTER_REPLICA_REQ,
|
||||||
|
"UnregisterReplicaReq", nullptr};
|
||||||
|
|
||||||
|
constexpr utils::TypeInfo coordination::UnregisterReplicaRes::kType{utils::TypeId::COORD_UNREGISTER_REPLICA_RES,
|
||||||
|
"UnregisterReplicaRes", nullptr};
|
||||||
|
|
||||||
|
constexpr utils::TypeInfo coordination::EnableWritingOnMainReq::kType{utils::TypeId::COORD_ENABLE_WRITING_ON_MAIN_REQ,
|
||||||
|
"CoordEnableWritingOnMainReq", nullptr};
|
||||||
|
|
||||||
|
constexpr utils::TypeInfo coordination::EnableWritingOnMainRes::kType{utils::TypeId::COORD_ENABLE_WRITING_ON_MAIN_RES,
|
||||||
|
"CoordEnableWritingOnMainRes", nullptr};
|
||||||
|
|
||||||
|
constexpr utils::TypeInfo coordination::GetInstanceUUIDReq::kType{utils::TypeId::COORD_GET_UUID_REQ, "CoordGetUUIDReq",
|
||||||
|
nullptr};
|
||||||
|
|
||||||
|
constexpr utils::TypeInfo coordination::GetInstanceUUIDRes::kType{utils::TypeId::COORD_GET_UUID_RES, "CoordGetUUIDRes",
|
||||||
|
nullptr};
|
||||||
|
|
||||||
|
namespace slk {
|
||||||
|
|
||||||
|
// PromoteReplicaToMainRpc
|
||||||
|
|
||||||
|
void Save(const memgraph::coordination::PromoteReplicaToMainRes &self, memgraph::slk::Builder *builder) {
|
||||||
|
memgraph::slk::Save(self.success, builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Load(memgraph::coordination::PromoteReplicaToMainRes *self, memgraph::slk::Reader *reader) {
|
||||||
|
memgraph::slk::Load(&self->success, reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Save(const memgraph::coordination::PromoteReplicaToMainReq &self, memgraph::slk::Builder *builder) {
|
||||||
|
memgraph::slk::Save(self.main_uuid_, builder);
|
||||||
|
memgraph::slk::Save(self.replication_clients_info, builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Load(memgraph::coordination::PromoteReplicaToMainReq *self, memgraph::slk::Reader *reader) {
|
||||||
|
memgraph::slk::Load(&self->main_uuid_, reader);
|
||||||
|
memgraph::slk::Load(&self->replication_clients_info, reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
// DemoteMainToReplicaRpc
|
||||||
|
void Save(const memgraph::coordination::DemoteMainToReplicaReq &self, memgraph::slk::Builder *builder) {
|
||||||
|
memgraph::slk::Save(self.replication_client_info, builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Load(memgraph::coordination::DemoteMainToReplicaReq *self, memgraph::slk::Reader *reader) {
|
||||||
|
memgraph::slk::Load(&self->replication_client_info, reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Save(const memgraph::coordination::DemoteMainToReplicaRes &self, memgraph::slk::Builder *builder) {
|
||||||
|
memgraph::slk::Save(self.success, builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Load(memgraph::coordination::DemoteMainToReplicaRes *self, memgraph::slk::Reader *reader) {
|
||||||
|
memgraph::slk::Load(&self->success, reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnregisterReplicaRpc
|
||||||
|
|
||||||
|
void Save(memgraph::coordination::UnregisterReplicaReq const &self, memgraph::slk::Builder *builder) {
|
||||||
|
memgraph::slk::Save(self.instance_name, builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Load(memgraph::coordination::UnregisterReplicaReq *self, memgraph::slk::Reader *reader) {
|
||||||
|
memgraph::slk::Load(&self->instance_name, reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Save(memgraph::coordination::UnregisterReplicaRes const &self, memgraph::slk::Builder *builder) {
|
||||||
|
memgraph::slk::Save(self.success, builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Load(memgraph::coordination::UnregisterReplicaRes *self, memgraph::slk::Reader *reader) {
|
||||||
|
memgraph::slk::Load(&self->success, reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Save(memgraph::coordination::EnableWritingOnMainRes const &self, memgraph::slk::Builder *builder) {
|
||||||
|
memgraph::slk::Save(self.success, builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Load(memgraph::coordination::EnableWritingOnMainRes *self, memgraph::slk::Reader *reader) {
|
||||||
|
memgraph::slk::Load(&self->success, reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetInstanceUUIDRpc
|
||||||
|
|
||||||
|
void Save(const memgraph::coordination::GetInstanceUUIDReq & /*self*/, memgraph::slk::Builder * /*builder*/) {
|
||||||
|
/* nothing to serialize*/
|
||||||
|
}
|
||||||
|
|
||||||
|
void Load(memgraph::coordination::GetInstanceUUIDReq * /*self*/, memgraph::slk::Reader * /*reader*/) {
|
||||||
|
/* nothing to serialize*/
|
||||||
|
}
|
||||||
|
|
||||||
|
void Save(const memgraph::coordination::GetInstanceUUIDRes &self, memgraph::slk::Builder *builder) {
|
||||||
|
memgraph::slk::Save(self.uuid, builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Load(memgraph::coordination::GetInstanceUUIDRes *self, memgraph::slk::Reader *reader) {
|
||||||
|
memgraph::slk::Load(&self->uuid, reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace slk
|
||||||
|
|
||||||
|
} // namespace memgraph
|
||||||
|
|
||||||
|
#endif
|
||||||
57
src/coordination/coordinator_server.cpp
Normal file
57
src/coordination/coordinator_server.cpp
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
// Copyright 2024 Memgraph Ltd.
|
||||||
|
//
|
||||||
|
// Use of this software is governed by the Business Source License
|
||||||
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
|
// License, and you may not use this file except in compliance with the Business Source License.
|
||||||
|
//
|
||||||
|
// As of the Change Date specified in that file, in accordance with
|
||||||
|
// the Business Source License, use of this software will be governed
|
||||||
|
// by the Apache License, Version 2.0, included in the file
|
||||||
|
// licenses/APL.txt.
|
||||||
|
|
||||||
|
#ifdef MG_ENTERPRISE
|
||||||
|
|
||||||
|
#include "coordination/coordinator_server.hpp"
|
||||||
|
#include "replication_coordination_glue/handler.hpp"
|
||||||
|
|
||||||
|
namespace memgraph::coordination {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
auto CreateServerContext(const memgraph::coordination::CoordinatorServerConfig &config)
|
||||||
|
-> communication::ServerContext {
|
||||||
|
return (config.ssl) ? communication::ServerContext{config.ssl->key_file, config.ssl->cert_file, config.ssl->ca_file,
|
||||||
|
config.ssl->verify_peer}
|
||||||
|
: communication::ServerContext{};
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: The coordinator server doesn't more than 1 processing thread - each replica can
|
||||||
|
// have only a single coordinator server. Also, the single-threaded guarantee
|
||||||
|
// simplifies the rest of the implementation.
|
||||||
|
constexpr auto kCoordinatorServerThreads = 1;
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
CoordinatorServer::CoordinatorServer(const CoordinatorServerConfig &config)
|
||||||
|
: rpc_server_context_{CreateServerContext(config)},
|
||||||
|
rpc_server_{io::network::Endpoint{config.ip_address, config.port}, &rpc_server_context_,
|
||||||
|
kCoordinatorServerThreads} {
|
||||||
|
rpc_server_.Register<replication_coordination_glue::FrequentHeartbeatRpc>([](auto *req_reader, auto *res_builder) {
|
||||||
|
spdlog::debug("Received FrequentHeartbeatRpc on coordinator server");
|
||||||
|
replication_coordination_glue::FrequentHeartbeatHandler(req_reader, res_builder);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
CoordinatorServer::~CoordinatorServer() {
|
||||||
|
if (rpc_server_.IsRunning()) {
|
||||||
|
auto const &endpoint = rpc_server_.endpoint();
|
||||||
|
spdlog::trace("Closing coordinator server on {}:{}", endpoint.address, endpoint.port);
|
||||||
|
rpc_server_.Shutdown();
|
||||||
|
}
|
||||||
|
rpc_server_.AwaitShutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CoordinatorServer::Start() { return rpc_server_.Start(); }
|
||||||
|
|
||||||
|
} // namespace memgraph::coordination
|
||||||
|
#endif
|
||||||
107
src/coordination/coordinator_state.cpp
Normal file
107
src/coordination/coordinator_state.cpp
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
// Copyright 2024 Memgraph Ltd.
|
||||||
|
//
|
||||||
|
// Use of this software is governed by the Business Source License
|
||||||
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
|
// License, and you may not use this file except in compliance with the Business Source License.
|
||||||
|
//
|
||||||
|
// As of the Change Date specified in that file, in accordance with
|
||||||
|
// the Business Source License, use of this software will be governed
|
||||||
|
// by the Apache License, Version 2.0, included in the file
|
||||||
|
// licenses/APL.txt.
|
||||||
|
|
||||||
|
#ifdef MG_ENTERPRISE
|
||||||
|
|
||||||
|
#include "coordination/coordinator_state.hpp"
|
||||||
|
|
||||||
|
#include "coordination/coordinator_config.hpp"
|
||||||
|
#include "coordination/register_main_replica_coordinator_status.hpp"
|
||||||
|
#include "flags/replication.hpp"
|
||||||
|
#include "spdlog/spdlog.h"
|
||||||
|
#include "utils/logging.hpp"
|
||||||
|
#include "utils/variant_helpers.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace memgraph::coordination {
|
||||||
|
|
||||||
|
CoordinatorState::CoordinatorState() {
|
||||||
|
MG_ASSERT(!(FLAGS_raft_server_id && FLAGS_coordinator_server_port),
|
||||||
|
"Instance cannot be a coordinator and have registered coordinator server.");
|
||||||
|
|
||||||
|
spdlog::info("Executing coordinator constructor");
|
||||||
|
if (FLAGS_coordinator_server_port) {
|
||||||
|
spdlog::info("Coordinator server port set");
|
||||||
|
auto const config = CoordinatorServerConfig{
|
||||||
|
.ip_address = kDefaultReplicationServerIp,
|
||||||
|
.port = static_cast<uint16_t>(FLAGS_coordinator_server_port),
|
||||||
|
};
|
||||||
|
spdlog::info("Executing coordinator constructor main replica");
|
||||||
|
|
||||||
|
data_ = CoordinatorMainReplicaData{.coordinator_server_ = std::make_unique<CoordinatorServer>(config)};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CoordinatorState::RegisterReplicationInstance(CoordinatorClientConfig config)
|
||||||
|
-> RegisterInstanceCoordinatorStatus {
|
||||||
|
MG_ASSERT(std::holds_alternative<CoordinatorInstance>(data_),
|
||||||
|
"Coordinator cannot register replica since variant holds wrong alternative");
|
||||||
|
|
||||||
|
return std::visit(
|
||||||
|
memgraph::utils::Overloaded{[](const CoordinatorMainReplicaData & /*coordinator_main_replica_data*/) {
|
||||||
|
return RegisterInstanceCoordinatorStatus::NOT_COORDINATOR;
|
||||||
|
},
|
||||||
|
[config](CoordinatorInstance &coordinator_instance) {
|
||||||
|
return coordinator_instance.RegisterReplicationInstance(config);
|
||||||
|
}},
|
||||||
|
data_);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CoordinatorState::UnregisterReplicationInstance(std::string instance_name) -> UnregisterInstanceCoordinatorStatus {
|
||||||
|
MG_ASSERT(std::holds_alternative<CoordinatorInstance>(data_),
|
||||||
|
"Coordinator cannot unregister instance since variant holds wrong alternative");
|
||||||
|
|
||||||
|
return std::visit(
|
||||||
|
memgraph::utils::Overloaded{[](const CoordinatorMainReplicaData & /*coordinator_main_replica_data*/) {
|
||||||
|
return UnregisterInstanceCoordinatorStatus::NOT_COORDINATOR;
|
||||||
|
},
|
||||||
|
[&instance_name](CoordinatorInstance &coordinator_instance) {
|
||||||
|
return coordinator_instance.UnregisterReplicationInstance(instance_name);
|
||||||
|
}},
|
||||||
|
data_);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CoordinatorState::SetReplicationInstanceToMain(std::string instance_name) -> SetInstanceToMainCoordinatorStatus {
|
||||||
|
MG_ASSERT(std::holds_alternative<CoordinatorInstance>(data_),
|
||||||
|
"Coordinator cannot register replica since variant holds wrong alternative");
|
||||||
|
|
||||||
|
return std::visit(
|
||||||
|
memgraph::utils::Overloaded{[](const CoordinatorMainReplicaData & /*coordinator_main_replica_data*/) {
|
||||||
|
return SetInstanceToMainCoordinatorStatus::NOT_COORDINATOR;
|
||||||
|
},
|
||||||
|
[&instance_name](CoordinatorInstance &coordinator_instance) {
|
||||||
|
return coordinator_instance.SetReplicationInstanceToMain(instance_name);
|
||||||
|
}},
|
||||||
|
data_);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CoordinatorState::ShowInstances() const -> std::vector<InstanceStatus> {
|
||||||
|
MG_ASSERT(std::holds_alternative<CoordinatorInstance>(data_),
|
||||||
|
"Can't call show instances on data_, as variant holds wrong alternative");
|
||||||
|
return std::get<CoordinatorInstance>(data_).ShowInstances();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CoordinatorState::GetCoordinatorServer() const -> CoordinatorServer & {
|
||||||
|
MG_ASSERT(std::holds_alternative<CoordinatorMainReplicaData>(data_),
|
||||||
|
"Cannot get coordinator server since variant holds wrong alternative");
|
||||||
|
return *std::get<CoordinatorMainReplicaData>(data_).coordinator_server_;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CoordinatorState::AddCoordinatorInstance(uint32_t raft_server_id, uint32_t raft_port, std::string raft_address)
|
||||||
|
-> void {
|
||||||
|
MG_ASSERT(std::holds_alternative<CoordinatorInstance>(data_),
|
||||||
|
"Coordinator cannot register replica since variant holds wrong alternative");
|
||||||
|
return std::get<CoordinatorInstance>(data_).AddCoordinatorInstance(raft_server_id, raft_port, raft_address);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace memgraph::coordination
|
||||||
|
#endif
|
||||||
111
src/coordination/coordinator_state_machine.cpp
Normal file
111
src/coordination/coordinator_state_machine.cpp
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
// Copyright 2024 Memgraph Ltd.
|
||||||
|
//
|
||||||
|
// Use of this software is governed by the Business Source License
|
||||||
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
|
// License, and you may not use this file except in compliance with the Business Source License.
|
||||||
|
//
|
||||||
|
// As of the Change Date specified in that file, in accordance with
|
||||||
|
// the Business Source License, use of this software will be governed
|
||||||
|
// by the Apache License, Version 2.0, included in the file
|
||||||
|
// licenses/APL.txt.
|
||||||
|
|
||||||
|
#ifdef MG_ENTERPRISE
|
||||||
|
|
||||||
|
#include "nuraft/coordinator_state_machine.hpp"
|
||||||
|
|
||||||
|
namespace memgraph::coordination {
|
||||||
|
|
||||||
|
auto CoordinatorStateMachine::EncodeRegisterReplicationInstance(const std::string &name) -> ptr<buffer> {
|
||||||
|
std::string str_log = name + "_replica";
|
||||||
|
ptr<buffer> log = buffer::alloc(sizeof(uint32_t) + str_log.size());
|
||||||
|
buffer_serializer bs(log);
|
||||||
|
bs.put_str(str_log);
|
||||||
|
return log;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CoordinatorStateMachine::DecodeRegisterReplicationInstance(buffer &data) -> std::string {
|
||||||
|
buffer_serializer bs(data);
|
||||||
|
return bs.get_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CoordinatorStateMachine::pre_commit(ulong const log_idx, buffer &data) -> ptr<buffer> {
|
||||||
|
buffer_serializer bs(data);
|
||||||
|
std::string str = bs.get_str();
|
||||||
|
|
||||||
|
spdlog::info("pre_commit {} : {}", log_idx, str);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CoordinatorStateMachine::commit(ulong const log_idx, buffer &data) -> ptr<buffer> {
|
||||||
|
buffer_serializer bs(data);
|
||||||
|
std::string str = bs.get_str();
|
||||||
|
|
||||||
|
spdlog::info("commit {} : {}", log_idx, str);
|
||||||
|
|
||||||
|
last_committed_idx_ = log_idx;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CoordinatorStateMachine::commit_config(ulong const log_idx, ptr<cluster_config> & /*new_conf*/) -> void {
|
||||||
|
last_committed_idx_ = log_idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CoordinatorStateMachine::rollback(ulong const log_idx, buffer &data) -> void {
|
||||||
|
buffer_serializer bs(data);
|
||||||
|
std::string str = bs.get_str();
|
||||||
|
|
||||||
|
spdlog::info("rollback {} : {}", log_idx, str);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CoordinatorStateMachine::read_logical_snp_obj(snapshot & /*snapshot*/, void *& /*user_snp_ctx*/, ulong /*obj_id*/,
|
||||||
|
ptr<buffer> &data_out, bool &is_last_obj) -> int {
|
||||||
|
// Put dummy data.
|
||||||
|
data_out = buffer::alloc(sizeof(int32));
|
||||||
|
buffer_serializer bs(data_out);
|
||||||
|
bs.put_i32(0);
|
||||||
|
|
||||||
|
is_last_obj = true;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CoordinatorStateMachine::save_logical_snp_obj(snapshot &s, ulong &obj_id, buffer & /*data*/, bool /*is_first_obj*/,
|
||||||
|
bool /*is_last_obj*/) -> void {
|
||||||
|
spdlog::info("save snapshot {} term {} object ID", s.get_last_log_idx(), s.get_last_log_term(), obj_id);
|
||||||
|
// Request next object.
|
||||||
|
obj_id++;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CoordinatorStateMachine::apply_snapshot(snapshot &s) -> bool {
|
||||||
|
spdlog::info("apply snapshot {} term {}", s.get_last_log_idx(), s.get_last_log_term());
|
||||||
|
{
|
||||||
|
auto lock = std::lock_guard{last_snapshot_lock_};
|
||||||
|
ptr<buffer> snp_buf = s.serialize();
|
||||||
|
last_snapshot_ = snapshot::deserialize(*snp_buf);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CoordinatorStateMachine::free_user_snp_ctx(void *&user_snp_ctx) -> void {}
|
||||||
|
|
||||||
|
auto CoordinatorStateMachine::last_snapshot() -> ptr<snapshot> {
|
||||||
|
auto lock = std::lock_guard{last_snapshot_lock_};
|
||||||
|
return last_snapshot_;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CoordinatorStateMachine::last_commit_index() -> ulong { return last_committed_idx_; }
|
||||||
|
|
||||||
|
auto CoordinatorStateMachine::create_snapshot(snapshot &s, async_result<bool>::handler_type &when_done) -> void {
|
||||||
|
spdlog::info("create snapshot {} term {}", s.get_last_log_idx(), s.get_last_log_term());
|
||||||
|
// Clone snapshot from `s`.
|
||||||
|
{
|
||||||
|
auto lock = std::lock_guard{last_snapshot_lock_};
|
||||||
|
ptr<buffer> snp_buf = s.serialize();
|
||||||
|
last_snapshot_ = snapshot::deserialize(*snp_buf);
|
||||||
|
}
|
||||||
|
ptr<std::exception> except(nullptr);
|
||||||
|
bool ret = true;
|
||||||
|
when_done(ret, except);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace memgraph::coordination
|
||||||
|
#endif
|
||||||
68
src/coordination/coordinator_state_manager.cpp
Normal file
68
src/coordination/coordinator_state_manager.cpp
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
// Copyright 2024 Memgraph Ltd.
|
||||||
|
//
|
||||||
|
// Use of this software is governed by the Business Source License
|
||||||
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
|
// License, and you may not use this file except in compliance with the Business Source License.
|
||||||
|
//
|
||||||
|
// As of the Change Date specified in that file, in accordance with
|
||||||
|
// the Business Source License, use of this software will be governed
|
||||||
|
// by the Apache License, Version 2.0, included in the file
|
||||||
|
// licenses/APL.txt.
|
||||||
|
|
||||||
|
#ifdef MG_ENTERPRISE
|
||||||
|
|
||||||
|
#include "nuraft/coordinator_state_manager.hpp"
|
||||||
|
|
||||||
|
namespace memgraph::coordination {
|
||||||
|
|
||||||
|
using nuraft::cluster_config;
|
||||||
|
using nuraft::cs_new;
|
||||||
|
using nuraft::srv_config;
|
||||||
|
using nuraft::srv_state;
|
||||||
|
using nuraft::state_mgr;
|
||||||
|
|
||||||
|
CoordinatorStateManager::CoordinatorStateManager(int srv_id, std::string const &endpoint)
|
||||||
|
: my_id_(srv_id), my_endpoint_(endpoint), cur_log_store_(cs_new<CoordinatorLogStore>()) {
|
||||||
|
my_srv_config_ = cs_new<srv_config>(srv_id, endpoint);
|
||||||
|
|
||||||
|
// Initial cluster config: contains only one server (myself).
|
||||||
|
cluster_config_ = cs_new<cluster_config>();
|
||||||
|
cluster_config_->get_servers().push_back(my_srv_config_);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CoordinatorStateManager::load_config() -> ptr<cluster_config> {
|
||||||
|
// Just return in-memory data in this example.
|
||||||
|
// May require reading from disk here, if it has been written to disk.
|
||||||
|
return cluster_config_;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CoordinatorStateManager::save_config(cluster_config const &config) -> void {
|
||||||
|
// Just keep in memory in this example.
|
||||||
|
// Need to write to disk here, if want to make it durable.
|
||||||
|
ptr<buffer> buf = config.serialize();
|
||||||
|
cluster_config_ = cluster_config::deserialize(*buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CoordinatorStateManager::save_state(srv_state const &state) -> void {
|
||||||
|
// Just keep in memory in this example.
|
||||||
|
// Need to write to disk here, if want to make it durable.
|
||||||
|
ptr<buffer> buf = state.serialize();
|
||||||
|
saved_state_ = srv_state::deserialize(*buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CoordinatorStateManager::read_state() -> ptr<srv_state> {
|
||||||
|
// Just return in-memory data in this example.
|
||||||
|
// May require reading from disk here, if it has been written to disk.
|
||||||
|
return saved_state_;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CoordinatorStateManager::load_log_store() -> ptr<log_store> { return cur_log_store_; }
|
||||||
|
|
||||||
|
auto CoordinatorStateManager::server_id() -> int32 { return my_id_; }
|
||||||
|
|
||||||
|
auto CoordinatorStateManager::system_exit(int const exit_code) -> void {}
|
||||||
|
|
||||||
|
auto CoordinatorStateManager::GetSrvConfig() const -> ptr<srv_config> { return my_srv_config_; }
|
||||||
|
|
||||||
|
} // namespace memgraph::coordination
|
||||||
|
#endif
|
||||||
60
src/coordination/fmt.hpp
Normal file
60
src/coordination/fmt.hpp
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
// Copyright 2024 Memgraph Ltd.
|
||||||
|
//
|
||||||
|
// Use of this software is governed by the Business Source License
|
||||||
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
|
// License, and you may not use this file except in compliance with the Business Source License.
|
||||||
|
//
|
||||||
|
// As of the Change Date specified in that file, in accordance with
|
||||||
|
// the Business Source License, use of this software will be governed
|
||||||
|
// by the Apache License, Version 2.0, included in the file
|
||||||
|
// licenses/APL.txt.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#if FMT_VERSION > 90000
|
||||||
|
#include <fmt/ostream.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <libnuraft/nuraft.hxx>
|
||||||
|
#include "utils/logging.hpp"
|
||||||
|
|
||||||
|
inline std::string ToString(const nuraft::cmd_result_code &code) {
|
||||||
|
switch (code) {
|
||||||
|
case nuraft::cmd_result_code::OK:
|
||||||
|
return "OK";
|
||||||
|
case nuraft::cmd_result_code::FAILED:
|
||||||
|
return "FAILED";
|
||||||
|
case nuraft::cmd_result_code::RESULT_NOT_EXIST_YET:
|
||||||
|
return "RESULT_NOT_EXIST_YET";
|
||||||
|
case nuraft::cmd_result_code::TERM_MISMATCH:
|
||||||
|
return "TERM_MISMATCH";
|
||||||
|
case nuraft::cmd_result_code::SERVER_IS_LEAVING:
|
||||||
|
return "SERVER_IS_LEAVING";
|
||||||
|
case nuraft::cmd_result_code::CANNOT_REMOVE_LEADER:
|
||||||
|
return "CANNOT_REMOVE_LEADER";
|
||||||
|
case nuraft::cmd_result_code::SERVER_NOT_FOUND:
|
||||||
|
return "SERVER_NOT_FOUND";
|
||||||
|
case nuraft::cmd_result_code::SERVER_IS_JOINING:
|
||||||
|
return "SERVER_IS_JOINING";
|
||||||
|
case nuraft::cmd_result_code::CONFIG_CHANGING:
|
||||||
|
return "CONFIG_CHANGING";
|
||||||
|
case nuraft::cmd_result_code::SERVER_ALREADY_EXISTS:
|
||||||
|
return "SERVER_ALREADY_EXISTS";
|
||||||
|
case nuraft::cmd_result_code::BAD_REQUEST:
|
||||||
|
return "BAD_REQUEST";
|
||||||
|
case nuraft::cmd_result_code::NOT_LEADER:
|
||||||
|
return "NOT_LEADER";
|
||||||
|
case nuraft::cmd_result_code::TIMEOUT:
|
||||||
|
return "TIMEOUT";
|
||||||
|
case nuraft::cmd_result_code::CANCELLED:
|
||||||
|
return "CANCELLED";
|
||||||
|
}
|
||||||
|
LOG_FATAL("ToString of a nuraft::cmd_result_code -> check missing switch case");
|
||||||
|
}
|
||||||
|
inline std::ostream &operator<<(std::ostream &os, const nuraft::cmd_result_code &code) {
|
||||||
|
os << ToString(code);
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
template <>
|
||||||
|
class fmt::formatter<nuraft::cmd_result_code> : public fmt::ostream_formatter {};
|
||||||
|
#endif
|
||||||
90
src/coordination/include/coordination/coordinator_client.hpp
Normal file
90
src/coordination/include/coordination/coordinator_client.hpp
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
// Copyright 2024 Memgraph Ltd.
|
||||||
|
//
|
||||||
|
// Use of this software is governed by the Business Source License
|
||||||
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
|
// License, and you may not use this file except in compliance with the Business Source License.
|
||||||
|
//
|
||||||
|
// As of the Change Date specified in that file, in accordance with
|
||||||
|
// the Business Source License, use of this software will be governed
|
||||||
|
// by the Apache License, Version 2.0, included in the file
|
||||||
|
// licenses/APL.txt.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef MG_ENTERPRISE
|
||||||
|
|
||||||
|
#include "coordination/coordinator_config.hpp"
|
||||||
|
#include "rpc/client.hpp"
|
||||||
|
#include "rpc_errors.hpp"
|
||||||
|
#include "utils/result.hpp"
|
||||||
|
#include "utils/scheduler.hpp"
|
||||||
|
#include "utils/uuid.hpp"
|
||||||
|
|
||||||
|
namespace memgraph::coordination {
|
||||||
|
|
||||||
|
class CoordinatorInstance;
|
||||||
|
using HealthCheckCallback = std::function<void(CoordinatorInstance *, std::string_view)>;
|
||||||
|
using ReplicationClientsInfo = std::vector<ReplClientInfo>;
|
||||||
|
|
||||||
|
class CoordinatorClient {
|
||||||
|
public:
|
||||||
|
explicit CoordinatorClient(CoordinatorInstance *coord_instance, CoordinatorClientConfig config,
|
||||||
|
HealthCheckCallback succ_cb, HealthCheckCallback fail_cb);
|
||||||
|
|
||||||
|
~CoordinatorClient() = default;
|
||||||
|
|
||||||
|
CoordinatorClient(CoordinatorClient &) = delete;
|
||||||
|
CoordinatorClient &operator=(CoordinatorClient const &) = delete;
|
||||||
|
|
||||||
|
CoordinatorClient(CoordinatorClient &&) noexcept = delete;
|
||||||
|
CoordinatorClient &operator=(CoordinatorClient &&) noexcept = delete;
|
||||||
|
|
||||||
|
void StartFrequentCheck();
|
||||||
|
void StopFrequentCheck();
|
||||||
|
void PauseFrequentCheck();
|
||||||
|
void ResumeFrequentCheck();
|
||||||
|
|
||||||
|
auto InstanceName() const -> std::string;
|
||||||
|
auto SocketAddress() const -> std::string;
|
||||||
|
|
||||||
|
[[nodiscard]] auto DemoteToReplica() const -> bool;
|
||||||
|
|
||||||
|
auto SendPromoteReplicaToMainRpc(const utils::UUID &uuid, ReplicationClientsInfo replication_clients_info) const
|
||||||
|
-> bool;
|
||||||
|
|
||||||
|
auto SendSwapMainUUIDRpc(const utils::UUID &uuid) const -> bool;
|
||||||
|
|
||||||
|
auto SendUnregisterReplicaRpc(std::string const &instance_name) const -> bool;
|
||||||
|
|
||||||
|
auto SendEnableWritingOnMainRpc() const -> bool;
|
||||||
|
|
||||||
|
auto SendGetInstanceUUIDRpc() const -> memgraph::utils::BasicResult<GetInstanceUUIDError, std::optional<utils::UUID>>;
|
||||||
|
|
||||||
|
auto ReplicationClientInfo() const -> ReplClientInfo;
|
||||||
|
|
||||||
|
auto SetCallbacks(HealthCheckCallback succ_cb, HealthCheckCallback fail_cb) -> void;
|
||||||
|
|
||||||
|
auto RpcClient() -> rpc::Client & { return rpc_client_; }
|
||||||
|
|
||||||
|
auto InstanceDownTimeoutSec() const -> std::chrono::seconds;
|
||||||
|
|
||||||
|
auto InstanceGetUUIDFrequencySec() const -> std::chrono::seconds;
|
||||||
|
|
||||||
|
friend bool operator==(CoordinatorClient const &first, CoordinatorClient const &second) {
|
||||||
|
return first.config_ == second.config_;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
utils::Scheduler instance_checker_;
|
||||||
|
|
||||||
|
communication::ClientContext rpc_context_;
|
||||||
|
mutable rpc::Client rpc_client_;
|
||||||
|
|
||||||
|
CoordinatorClientConfig config_;
|
||||||
|
CoordinatorInstance *coord_instance_;
|
||||||
|
HealthCheckCallback succ_cb_;
|
||||||
|
HealthCheckCallback fail_cb_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace memgraph::coordination
|
||||||
|
#endif
|
||||||
79
src/coordination/include/coordination/coordinator_config.hpp
Normal file
79
src/coordination/include/coordination/coordinator_config.hpp
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
// Copyright 2024 Memgraph Ltd.
|
||||||
|
//
|
||||||
|
// Use of this software is governed by the Business Source License
|
||||||
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
|
// License, and you may not use this file except in compliance with the Business Source License.
|
||||||
|
//
|
||||||
|
// As of the Change Date specified in that file, in accordance with
|
||||||
|
// the Business Source License, use of this software will be governed
|
||||||
|
// by the Apache License, Version 2.0, included in the file
|
||||||
|
// licenses/APL.txt.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef MG_ENTERPRISE
|
||||||
|
|
||||||
|
#include "replication_coordination_glue/mode.hpp"
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <optional>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace memgraph::coordination {
|
||||||
|
|
||||||
|
inline constexpr auto *kDefaultReplicationServerIp = "0.0.0.0";
|
||||||
|
|
||||||
|
struct CoordinatorClientConfig {
|
||||||
|
std::string instance_name;
|
||||||
|
std::string ip_address;
|
||||||
|
uint16_t port{};
|
||||||
|
std::chrono::seconds instance_health_check_frequency_sec{1};
|
||||||
|
std::chrono::seconds instance_down_timeout_sec{5};
|
||||||
|
std::chrono::seconds instance_get_uuid_frequency_sec{10};
|
||||||
|
|
||||||
|
auto SocketAddress() const -> std::string { return ip_address + ":" + std::to_string(port); }
|
||||||
|
|
||||||
|
struct ReplicationClientInfo {
|
||||||
|
std::string instance_name;
|
||||||
|
replication_coordination_glue::ReplicationMode replication_mode{};
|
||||||
|
std::string replication_ip_address;
|
||||||
|
uint16_t replication_port{};
|
||||||
|
|
||||||
|
friend bool operator==(ReplicationClientInfo const &, ReplicationClientInfo const &) = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
ReplicationClientInfo replication_client_info;
|
||||||
|
|
||||||
|
struct SSL {
|
||||||
|
std::string key_file;
|
||||||
|
std::string cert_file;
|
||||||
|
|
||||||
|
friend bool operator==(const SSL &, const SSL &) = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::optional<SSL> ssl;
|
||||||
|
|
||||||
|
friend bool operator==(CoordinatorClientConfig const &, CoordinatorClientConfig const &) = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
using ReplClientInfo = CoordinatorClientConfig::ReplicationClientInfo;
|
||||||
|
|
||||||
|
struct CoordinatorServerConfig {
|
||||||
|
std::string ip_address;
|
||||||
|
uint16_t port{};
|
||||||
|
struct SSL {
|
||||||
|
std::string key_file;
|
||||||
|
std::string cert_file;
|
||||||
|
std::string ca_file;
|
||||||
|
bool verify_peer{};
|
||||||
|
friend bool operator==(SSL const &, SSL const &) = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::optional<SSL> ssl;
|
||||||
|
|
||||||
|
friend bool operator==(CoordinatorServerConfig const &, CoordinatorServerConfig const &) = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace memgraph::coordination
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
// Copyright 2024 Memgraph Ltd.
|
||||||
|
//
|
||||||
|
// Use of this software is governed by the Business Source License
|
||||||
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
|
// License, and you may not use this file except in compliance with the Business Source License.
|
||||||
|
//
|
||||||
|
// As of the Change Date specified in that file, in accordance with
|
||||||
|
// the Business Source License, use of this software will be governed
|
||||||
|
// by the Apache License, Version 2.0, included in the file
|
||||||
|
// licenses/APL.txt.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef MG_ENTERPRISE
|
||||||
|
|
||||||
|
#include "utils/exceptions.hpp"
|
||||||
|
|
||||||
|
namespace memgraph::coordination {
|
||||||
|
class CoordinatorRegisterInstanceException final : public utils::BasicException {
|
||||||
|
public:
|
||||||
|
explicit CoordinatorRegisterInstanceException(const std::string_view what) noexcept
|
||||||
|
: BasicException("Failed to create instance: " + std::string(what)) {}
|
||||||
|
|
||||||
|
template <class... Args>
|
||||||
|
explicit CoordinatorRegisterInstanceException(fmt::format_string<Args...> fmt, Args &&...args) noexcept
|
||||||
|
: CoordinatorRegisterInstanceException(fmt::format(fmt, std::forward<Args>(args)...)) {}
|
||||||
|
|
||||||
|
SPECIALIZE_GET_EXCEPTION_NAME(CoordinatorRegisterInstanceException)
|
||||||
|
};
|
||||||
|
|
||||||
|
class RaftServerStartException final : public utils::BasicException {
|
||||||
|
public:
|
||||||
|
explicit RaftServerStartException(std::string_view what) noexcept : BasicException(what) {}
|
||||||
|
|
||||||
|
template <class... Args>
|
||||||
|
explicit RaftServerStartException(fmt::format_string<Args...> fmt, Args &&...args) noexcept
|
||||||
|
: RaftServerStartException(fmt::format(fmt, std::forward<Args>(args)...)) {}
|
||||||
|
|
||||||
|
SPECIALIZE_GET_EXCEPTION_NAME(RaftServerStartException)
|
||||||
|
};
|
||||||
|
|
||||||
|
class RaftAddServerException final : public utils::BasicException {
|
||||||
|
public:
|
||||||
|
explicit RaftAddServerException(std::string_view what) noexcept : BasicException(what) {}
|
||||||
|
|
||||||
|
template <class... Args>
|
||||||
|
explicit RaftAddServerException(fmt::format_string<Args...> fmt, Args &&...args) noexcept
|
||||||
|
: RaftAddServerException(fmt::format(fmt, std::forward<Args>(args)...)) {}
|
||||||
|
|
||||||
|
SPECIALIZE_GET_EXCEPTION_NAME(RaftAddServerException)
|
||||||
|
};
|
||||||
|
|
||||||
|
class RaftBecomeLeaderException final : public utils::BasicException {
|
||||||
|
public:
|
||||||
|
explicit RaftBecomeLeaderException(std::string_view what) noexcept : BasicException(what) {}
|
||||||
|
|
||||||
|
template <class... Args>
|
||||||
|
explicit RaftBecomeLeaderException(fmt::format_string<Args...> fmt, Args &&...args) noexcept
|
||||||
|
: RaftBecomeLeaderException(fmt::format(fmt, std::forward<Args>(args)...)) {}
|
||||||
|
|
||||||
|
SPECIALIZE_GET_EXCEPTION_NAME(RaftBecomeLeaderException)
|
||||||
|
};
|
||||||
|
|
||||||
|
class RaftCouldNotFindEntryException final : public utils::BasicException {
|
||||||
|
public:
|
||||||
|
explicit RaftCouldNotFindEntryException(std::string_view what) noexcept : BasicException(what) {}
|
||||||
|
|
||||||
|
template <class... Args>
|
||||||
|
explicit RaftCouldNotFindEntryException(fmt::format_string<Args...> fmt, Args &&...args) noexcept
|
||||||
|
: RaftCouldNotFindEntryException(fmt::format(fmt, std::forward<Args>(args)...)) {}
|
||||||
|
|
||||||
|
SPECIALIZE_GET_EXCEPTION_NAME(RaftCouldNotFindEntryException)
|
||||||
|
};
|
||||||
|
|
||||||
|
class RaftCouldNotParseFlagsException final : public utils::BasicException {
|
||||||
|
public:
|
||||||
|
explicit RaftCouldNotParseFlagsException(std::string_view what) noexcept : BasicException(what) {}
|
||||||
|
|
||||||
|
template <class... Args>
|
||||||
|
explicit RaftCouldNotParseFlagsException(fmt::format_string<Args...> fmt, Args &&...args) noexcept
|
||||||
|
: RaftCouldNotParseFlagsException(fmt::format(fmt, std::forward<Args>(args)...)) {}
|
||||||
|
|
||||||
|
SPECIALIZE_GET_EXCEPTION_NAME(RaftCouldNotParseFlagsException)
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace memgraph::coordination
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
// Copyright 2024 Memgraph Ltd.
|
||||||
|
//
|
||||||
|
// Use of this software is governed by the Business Source License
|
||||||
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
|
// License, and you may not use this file except in compliance with the Business Source License.
|
||||||
|
//
|
||||||
|
// As of the Change Date specified in that file, in accordance with
|
||||||
|
// the Business Source License, use of this software will be governed
|
||||||
|
// by the Apache License, Version 2.0, included in the file
|
||||||
|
// licenses/APL.txt.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef MG_ENTERPRISE
|
||||||
|
|
||||||
|
#include "coordination/coordinator_server.hpp"
|
||||||
|
#include "replication_handler/replication_handler.hpp"
|
||||||
|
#include "slk/streams.hpp"
|
||||||
|
|
||||||
|
namespace memgraph::dbms {
|
||||||
|
|
||||||
|
class DbmsHandler;
|
||||||
|
|
||||||
|
class CoordinatorHandlers {
|
||||||
|
public:
|
||||||
|
static void Register(memgraph::coordination::CoordinatorServer &server,
|
||||||
|
replication::ReplicationHandler &replication_handler);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static void PromoteReplicaToMainHandler(replication::ReplicationHandler &replication_handler, slk::Reader *req_reader,
|
||||||
|
slk::Builder *res_builder);
|
||||||
|
static void DemoteMainToReplicaHandler(replication::ReplicationHandler &replication_handler, slk::Reader *req_reader,
|
||||||
|
slk::Builder *res_builder);
|
||||||
|
static void SwapMainUUIDHandler(replication::ReplicationHandler &replication_handler, slk::Reader *req_reader,
|
||||||
|
slk::Builder *res_builder);
|
||||||
|
|
||||||
|
static void UnregisterReplicaHandler(replication::ReplicationHandler &replication_handler, slk::Reader *req_reader,
|
||||||
|
slk::Builder *res_builder);
|
||||||
|
static void EnableWritingOnMainHandler(replication::ReplicationHandler &replication_handler, slk::Reader *req_reader,
|
||||||
|
slk::Builder *res_builder);
|
||||||
|
|
||||||
|
static void GetInstanceUUIDHandler(replication::ReplicationHandler &replication_handler, slk::Reader *req_reader,
|
||||||
|
slk::Builder *res_builder);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace memgraph::dbms
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
// Copyright 2024 Memgraph Ltd.
|
||||||
|
//
|
||||||
|
// Use of this software is governed by the Business Source License
|
||||||
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
|
// License, and you may not use this file except in compliance with the Business Source License.
|
||||||
|
//
|
||||||
|
// As of the Change Date specified in that file, in accordance with
|
||||||
|
// the Business Source License, use of this software will be governed
|
||||||
|
// by the Apache License, Version 2.0, included in the file
|
||||||
|
// licenses/APL.txt.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef MG_ENTERPRISE
|
||||||
|
|
||||||
|
#include "coordination/coordinator_server.hpp"
|
||||||
|
#include "coordination/instance_status.hpp"
|
||||||
|
#include "coordination/raft_state.hpp"
|
||||||
|
#include "coordination/register_main_replica_coordinator_status.hpp"
|
||||||
|
#include "coordination/replication_instance.hpp"
|
||||||
|
#include "utils/rw_lock.hpp"
|
||||||
|
#include "utils/thread_pool.hpp"
|
||||||
|
|
||||||
|
#include <list>
|
||||||
|
|
||||||
|
namespace memgraph::coordination {
|
||||||
|
|
||||||
|
class CoordinatorInstance {
|
||||||
|
public:
|
||||||
|
CoordinatorInstance();
|
||||||
|
|
||||||
|
[[nodiscard]] auto RegisterReplicationInstance(CoordinatorClientConfig config) -> RegisterInstanceCoordinatorStatus;
|
||||||
|
[[nodiscard]] auto UnregisterReplicationInstance(std::string instance_name) -> UnregisterInstanceCoordinatorStatus;
|
||||||
|
|
||||||
|
[[nodiscard]] auto SetReplicationInstanceToMain(std::string instance_name) -> SetInstanceToMainCoordinatorStatus;
|
||||||
|
|
||||||
|
auto ShowInstances() const -> std::vector<InstanceStatus>;
|
||||||
|
|
||||||
|
auto TryFailover() -> void;
|
||||||
|
|
||||||
|
auto AddCoordinatorInstance(uint32_t raft_server_id, uint32_t raft_port, std::string raft_address) -> void;
|
||||||
|
|
||||||
|
auto GetMainUUID() const -> utils::UUID;
|
||||||
|
|
||||||
|
auto SetMainUUID(utils::UUID new_uuid) -> void;
|
||||||
|
|
||||||
|
private:
|
||||||
|
HealthCheckCallback main_succ_cb_, main_fail_cb_, replica_succ_cb_, replica_fail_cb_;
|
||||||
|
|
||||||
|
// NOTE: Must be std::list because we rely on pointer stability
|
||||||
|
std::list<ReplicationInstance> repl_instances_;
|
||||||
|
mutable utils::RWLock coord_instance_lock_{utils::RWLock::Priority::READ};
|
||||||
|
|
||||||
|
utils::UUID main_uuid_;
|
||||||
|
|
||||||
|
RaftState raft_state_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace memgraph::coordination
|
||||||
|
#endif
|
||||||
197
src/coordination/include/coordination/coordinator_rpc.hpp
Normal file
197
src/coordination/include/coordination/coordinator_rpc.hpp
Normal file
@@ -0,0 +1,197 @@
|
|||||||
|
// Copyright 2024 Memgraph Ltd.
|
||||||
|
//
|
||||||
|
// Use of this software is governed by the Business Source License
|
||||||
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
|
// License, and you may not use this file except in compliance with the Business Source License.
|
||||||
|
//
|
||||||
|
// As of the Change Date specified in that file, in accordance with
|
||||||
|
// the Business Source License, use of this software will be governed
|
||||||
|
// by the Apache License, Version 2.0, included in the file
|
||||||
|
// licenses/APL.txt.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "utils/uuid.hpp"
|
||||||
|
#ifdef MG_ENTERPRISE
|
||||||
|
|
||||||
|
#include "coordination/coordinator_config.hpp"
|
||||||
|
#include "rpc/messages.hpp"
|
||||||
|
#include "slk/serialization.hpp"
|
||||||
|
|
||||||
|
namespace memgraph::coordination {
|
||||||
|
|
||||||
|
struct PromoteReplicaToMainReq {
|
||||||
|
static const utils::TypeInfo kType;
|
||||||
|
static const utils::TypeInfo &GetTypeInfo() { return kType; }
|
||||||
|
|
||||||
|
static void Load(PromoteReplicaToMainReq *self, memgraph::slk::Reader *reader);
|
||||||
|
static void Save(const PromoteReplicaToMainReq &self, memgraph::slk::Builder *builder);
|
||||||
|
|
||||||
|
explicit PromoteReplicaToMainReq(const utils::UUID &uuid,
|
||||||
|
std::vector<CoordinatorClientConfig::ReplicationClientInfo> replication_clients_info)
|
||||||
|
: main_uuid_(uuid), replication_clients_info(std::move(replication_clients_info)) {}
|
||||||
|
PromoteReplicaToMainReq() = default;
|
||||||
|
|
||||||
|
// get uuid here
|
||||||
|
utils::UUID main_uuid_;
|
||||||
|
std::vector<CoordinatorClientConfig::ReplicationClientInfo> replication_clients_info;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PromoteReplicaToMainRes {
|
||||||
|
static const utils::TypeInfo kType;
|
||||||
|
static const utils::TypeInfo &GetTypeInfo() { return kType; }
|
||||||
|
|
||||||
|
static void Load(PromoteReplicaToMainRes *self, memgraph::slk::Reader *reader);
|
||||||
|
static void Save(const PromoteReplicaToMainRes &self, memgraph::slk::Builder *builder);
|
||||||
|
|
||||||
|
explicit PromoteReplicaToMainRes(bool success) : success(success) {}
|
||||||
|
PromoteReplicaToMainRes() = default;
|
||||||
|
|
||||||
|
bool success;
|
||||||
|
};
|
||||||
|
|
||||||
|
using PromoteReplicaToMainRpc = rpc::RequestResponse<PromoteReplicaToMainReq, PromoteReplicaToMainRes>;
|
||||||
|
|
||||||
|
struct DemoteMainToReplicaReq {
|
||||||
|
static const utils::TypeInfo kType;
|
||||||
|
static const utils::TypeInfo &GetTypeInfo() { return kType; }
|
||||||
|
|
||||||
|
static void Load(DemoteMainToReplicaReq *self, memgraph::slk::Reader *reader);
|
||||||
|
static void Save(const DemoteMainToReplicaReq &self, memgraph::slk::Builder *builder);
|
||||||
|
|
||||||
|
explicit DemoteMainToReplicaReq(CoordinatorClientConfig::ReplicationClientInfo replication_client_info)
|
||||||
|
: replication_client_info(std::move(replication_client_info)) {}
|
||||||
|
|
||||||
|
DemoteMainToReplicaReq() = default;
|
||||||
|
|
||||||
|
CoordinatorClientConfig::ReplicationClientInfo replication_client_info;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct DemoteMainToReplicaRes {
|
||||||
|
static const utils::TypeInfo kType;
|
||||||
|
static const utils::TypeInfo &GetTypeInfo() { return kType; }
|
||||||
|
|
||||||
|
static void Load(DemoteMainToReplicaRes *self, memgraph::slk::Reader *reader);
|
||||||
|
static void Save(const DemoteMainToReplicaRes &self, memgraph::slk::Builder *builder);
|
||||||
|
|
||||||
|
explicit DemoteMainToReplicaRes(bool success) : success(success) {}
|
||||||
|
DemoteMainToReplicaRes() = default;
|
||||||
|
|
||||||
|
bool success;
|
||||||
|
};
|
||||||
|
|
||||||
|
using DemoteMainToReplicaRpc = rpc::RequestResponse<DemoteMainToReplicaReq, DemoteMainToReplicaRes>;
|
||||||
|
|
||||||
|
struct UnregisterReplicaReq {
|
||||||
|
static const utils::TypeInfo kType;
|
||||||
|
static const utils::TypeInfo &GetTypeInfo() { return kType; }
|
||||||
|
|
||||||
|
static void Load(UnregisterReplicaReq *self, memgraph::slk::Reader *reader);
|
||||||
|
static void Save(UnregisterReplicaReq const &self, memgraph::slk::Builder *builder);
|
||||||
|
|
||||||
|
explicit UnregisterReplicaReq(std::string instance_name) : instance_name(std::move(instance_name)) {}
|
||||||
|
|
||||||
|
UnregisterReplicaReq() = default;
|
||||||
|
|
||||||
|
std::string instance_name;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UnregisterReplicaRes {
|
||||||
|
static const utils::TypeInfo kType;
|
||||||
|
static const utils::TypeInfo &GetTypeInfo() { return kType; }
|
||||||
|
|
||||||
|
static void Load(UnregisterReplicaRes *self, memgraph::slk::Reader *reader);
|
||||||
|
static void Save(const UnregisterReplicaRes &self, memgraph::slk::Builder *builder);
|
||||||
|
|
||||||
|
explicit UnregisterReplicaRes(bool success) : success(success) {}
|
||||||
|
UnregisterReplicaRes() = default;
|
||||||
|
|
||||||
|
bool success;
|
||||||
|
};
|
||||||
|
|
||||||
|
using UnregisterReplicaRpc = rpc::RequestResponse<UnregisterReplicaReq, UnregisterReplicaRes>;
|
||||||
|
|
||||||
|
struct EnableWritingOnMainReq {
|
||||||
|
static const utils::TypeInfo kType;
|
||||||
|
static const utils::TypeInfo &GetTypeInfo() { return kType; }
|
||||||
|
|
||||||
|
static void Load(EnableWritingOnMainReq *self, memgraph::slk::Reader *reader);
|
||||||
|
static void Save(EnableWritingOnMainReq const &self, memgraph::slk::Builder *builder);
|
||||||
|
|
||||||
|
EnableWritingOnMainReq() = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct EnableWritingOnMainRes {
|
||||||
|
static const utils::TypeInfo kType;
|
||||||
|
static const utils::TypeInfo &GetTypeInfo() { return kType; }
|
||||||
|
|
||||||
|
static void Load(EnableWritingOnMainRes *self, memgraph::slk::Reader *reader);
|
||||||
|
static void Save(EnableWritingOnMainRes const &self, memgraph::slk::Builder *builder);
|
||||||
|
|
||||||
|
explicit EnableWritingOnMainRes(bool success) : success(success) {}
|
||||||
|
EnableWritingOnMainRes() = default;
|
||||||
|
|
||||||
|
bool success;
|
||||||
|
};
|
||||||
|
|
||||||
|
using EnableWritingOnMainRpc = rpc::RequestResponse<EnableWritingOnMainReq, EnableWritingOnMainRes>;
|
||||||
|
|
||||||
|
struct GetInstanceUUIDReq {
|
||||||
|
static const utils::TypeInfo kType;
|
||||||
|
static const utils::TypeInfo &GetTypeInfo() { return kType; }
|
||||||
|
|
||||||
|
static void Load(GetInstanceUUIDReq *self, memgraph::slk::Reader *reader);
|
||||||
|
static void Save(const GetInstanceUUIDReq &self, memgraph::slk::Builder *builder);
|
||||||
|
|
||||||
|
GetInstanceUUIDReq() = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct GetInstanceUUIDRes {
|
||||||
|
static const utils::TypeInfo kType;
|
||||||
|
static const utils::TypeInfo &GetTypeInfo() { return kType; }
|
||||||
|
|
||||||
|
static void Load(GetInstanceUUIDRes *self, memgraph::slk::Reader *reader);
|
||||||
|
static void Save(const GetInstanceUUIDRes &self, memgraph::slk::Builder *builder);
|
||||||
|
|
||||||
|
explicit GetInstanceUUIDRes(std::optional<utils::UUID> uuid) : uuid(uuid) {}
|
||||||
|
GetInstanceUUIDRes() = default;
|
||||||
|
|
||||||
|
std::optional<utils::UUID> uuid;
|
||||||
|
};
|
||||||
|
|
||||||
|
using GetInstanceUUIDRpc = rpc::RequestResponse<GetInstanceUUIDReq, GetInstanceUUIDRes>;
|
||||||
|
|
||||||
|
} // namespace memgraph::coordination
|
||||||
|
|
||||||
|
// SLK serialization declarations
|
||||||
|
namespace memgraph::slk {
|
||||||
|
|
||||||
|
// PromoteReplicaToMainRpc
|
||||||
|
void Save(const memgraph::coordination::PromoteReplicaToMainRes &self, memgraph::slk::Builder *builder);
|
||||||
|
void Load(memgraph::coordination::PromoteReplicaToMainRes *self, memgraph::slk::Reader *reader);
|
||||||
|
void Save(const memgraph::coordination::PromoteReplicaToMainReq &self, memgraph::slk::Builder *builder);
|
||||||
|
void Load(memgraph::coordination::PromoteReplicaToMainReq *self, memgraph::slk::Reader *reader);
|
||||||
|
|
||||||
|
// DemoteMainToReplicaRpc
|
||||||
|
void Save(const memgraph::coordination::DemoteMainToReplicaRes &self, memgraph::slk::Builder *builder);
|
||||||
|
void Load(memgraph::coordination::DemoteMainToReplicaRes *self, memgraph::slk::Reader *reader);
|
||||||
|
void Save(const memgraph::coordination::DemoteMainToReplicaReq &self, memgraph::slk::Builder *builder);
|
||||||
|
void Load(memgraph::coordination::DemoteMainToReplicaReq *self, memgraph::slk::Reader *reader);
|
||||||
|
|
||||||
|
// GetInstanceUUIDRpc
|
||||||
|
void Save(const memgraph::coordination::GetInstanceUUIDReq &self, memgraph::slk::Builder *builder);
|
||||||
|
void Load(memgraph::coordination::GetInstanceUUIDReq *self, memgraph::slk::Reader *reader);
|
||||||
|
void Save(const memgraph::coordination::GetInstanceUUIDRes &self, memgraph::slk::Builder *builder);
|
||||||
|
void Load(memgraph::coordination::GetInstanceUUIDRes *self, memgraph::slk::Reader *reader);
|
||||||
|
// UnregisterReplicaRpc
|
||||||
|
void Save(memgraph::coordination::UnregisterReplicaRes const &self, memgraph::slk::Builder *builder);
|
||||||
|
void Load(memgraph::coordination::UnregisterReplicaRes *self, memgraph::slk::Reader *reader);
|
||||||
|
void Save(memgraph::coordination::UnregisterReplicaReq const &self, memgraph::slk::Builder *builder);
|
||||||
|
void Load(memgraph::coordination::UnregisterReplicaReq *self, memgraph::slk::Reader *reader);
|
||||||
|
|
||||||
|
void Save(memgraph::coordination::EnableWritingOnMainRes const &self, memgraph::slk::Builder *builder);
|
||||||
|
void Load(memgraph::coordination::EnableWritingOnMainRes *self, memgraph::slk::Reader *reader);
|
||||||
|
|
||||||
|
} // namespace memgraph::slk
|
||||||
|
|
||||||
|
#endif
|
||||||
44
src/coordination/include/coordination/coordinator_server.hpp
Normal file
44
src/coordination/include/coordination/coordinator_server.hpp
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
// Copyright 2024 Memgraph Ltd.
|
||||||
|
//
|
||||||
|
// Use of this software is governed by the Business Source License
|
||||||
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
|
// License, and you may not use this file except in compliance with the Business Source License.
|
||||||
|
//
|
||||||
|
// As of the Change Date specified in that file, in accordance with
|
||||||
|
// the Business Source License, use of this software will be governed
|
||||||
|
// by the Apache License, Version 2.0, included in the file
|
||||||
|
// licenses/APL.txt.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef MG_ENTERPRISE
|
||||||
|
|
||||||
|
#include "coordination/coordinator_config.hpp"
|
||||||
|
#include "rpc/server.hpp"
|
||||||
|
|
||||||
|
namespace memgraph::coordination {
|
||||||
|
|
||||||
|
class CoordinatorServer {
|
||||||
|
public:
|
||||||
|
explicit CoordinatorServer(const CoordinatorServerConfig &config);
|
||||||
|
CoordinatorServer(const CoordinatorServer &) = delete;
|
||||||
|
CoordinatorServer(CoordinatorServer &&) = delete;
|
||||||
|
CoordinatorServer &operator=(const CoordinatorServer &) = delete;
|
||||||
|
CoordinatorServer &operator=(CoordinatorServer &&) = delete;
|
||||||
|
|
||||||
|
virtual ~CoordinatorServer();
|
||||||
|
|
||||||
|
bool Start();
|
||||||
|
|
||||||
|
template <typename TRequestResponse, typename F>
|
||||||
|
void Register(F &&callback) {
|
||||||
|
rpc_server_.Register<TRequestResponse>(std::forward<F>(callback));
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
communication::ServerContext rpc_server_context_;
|
||||||
|
rpc::Server rpc_server_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace memgraph::coordination
|
||||||
|
#endif
|
||||||
38
src/coordination/include/coordination/coordinator_slk.hpp
Normal file
38
src/coordination/include/coordination/coordinator_slk.hpp
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
// Copyright 2024 Memgraph Ltd.
|
||||||
|
//
|
||||||
|
// Use of this software is governed by the Business Source License
|
||||||
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
|
// License, and you may not use this file except in compliance with the Business Source License.
|
||||||
|
//
|
||||||
|
// As of the Change Date specified in that file, in accordance with
|
||||||
|
// the Business Source License, use of this software will be governed
|
||||||
|
// by the Apache License, Version 2.0, included in the file
|
||||||
|
// licenses/APL.txt.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef MG_ENTERPRISE
|
||||||
|
|
||||||
|
#include "coordination/coordinator_config.hpp"
|
||||||
|
#include "slk/serialization.hpp"
|
||||||
|
#include "slk/streams.hpp"
|
||||||
|
|
||||||
|
namespace memgraph::slk {
|
||||||
|
|
||||||
|
using ReplicationClientInfo = coordination::CoordinatorClientConfig::ReplicationClientInfo;
|
||||||
|
|
||||||
|
inline void Save(const ReplicationClientInfo &obj, Builder *builder) {
|
||||||
|
Save(obj.instance_name, builder);
|
||||||
|
Save(obj.replication_mode, builder);
|
||||||
|
Save(obj.replication_ip_address, builder);
|
||||||
|
Save(obj.replication_port, builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void Load(ReplicationClientInfo *obj, Reader *reader) {
|
||||||
|
Load(&obj->instance_name, reader);
|
||||||
|
Load(&obj->replication_mode, reader);
|
||||||
|
Load(&obj->replication_ip_address, reader);
|
||||||
|
Load(&obj->replication_port, reader);
|
||||||
|
}
|
||||||
|
} // namespace memgraph::slk
|
||||||
|
#endif
|
||||||
57
src/coordination/include/coordination/coordinator_state.hpp
Normal file
57
src/coordination/include/coordination/coordinator_state.hpp
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
// Copyright 2024 Memgraph Ltd.
|
||||||
|
//
|
||||||
|
// Use of this software is governed by the Business Source License
|
||||||
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
|
// License, and you may not use this file except in compliance with the Business Source License.
|
||||||
|
//
|
||||||
|
// As of the Change Date specified in that file, in accordance with
|
||||||
|
// the Business Source License, use of this software will be governed
|
||||||
|
// by the Apache License, Version 2.0, included in the file
|
||||||
|
// licenses/APL.txt.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef MG_ENTERPRISE
|
||||||
|
|
||||||
|
#include "coordination/coordinator_instance.hpp"
|
||||||
|
#include "coordination/coordinator_server.hpp"
|
||||||
|
#include "coordination/instance_status.hpp"
|
||||||
|
#include "coordination/register_main_replica_coordinator_status.hpp"
|
||||||
|
|
||||||
|
#include <variant>
|
||||||
|
|
||||||
|
namespace memgraph::coordination {
|
||||||
|
|
||||||
|
class CoordinatorState {
|
||||||
|
public:
|
||||||
|
CoordinatorState();
|
||||||
|
~CoordinatorState() = default;
|
||||||
|
|
||||||
|
CoordinatorState(CoordinatorState const &) = delete;
|
||||||
|
CoordinatorState &operator=(CoordinatorState const &) = delete;
|
||||||
|
|
||||||
|
CoordinatorState(CoordinatorState &&) noexcept = delete;
|
||||||
|
CoordinatorState &operator=(CoordinatorState &&) noexcept = delete;
|
||||||
|
|
||||||
|
[[nodiscard]] auto RegisterReplicationInstance(CoordinatorClientConfig config) -> RegisterInstanceCoordinatorStatus;
|
||||||
|
[[nodiscard]] auto UnregisterReplicationInstance(std::string instance_name) -> UnregisterInstanceCoordinatorStatus;
|
||||||
|
|
||||||
|
[[nodiscard]] auto SetReplicationInstanceToMain(std::string instance_name) -> SetInstanceToMainCoordinatorStatus;
|
||||||
|
|
||||||
|
auto ShowInstances() const -> std::vector<InstanceStatus>;
|
||||||
|
|
||||||
|
auto AddCoordinatorInstance(uint32_t raft_server_id, uint32_t raft_port, std::string raft_address) -> void;
|
||||||
|
|
||||||
|
// NOTE: The client code must check that the server exists before calling this method.
|
||||||
|
auto GetCoordinatorServer() const -> CoordinatorServer &;
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct CoordinatorMainReplicaData {
|
||||||
|
std::unique_ptr<CoordinatorServer> coordinator_server_;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::variant<CoordinatorInstance, CoordinatorMainReplicaData> data_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace memgraph::coordination
|
||||||
|
#endif
|
||||||
34
src/coordination/include/coordination/instance_status.hpp
Normal file
34
src/coordination/include/coordination/instance_status.hpp
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
// Copyright 2024 Memgraph Ltd.
|
||||||
|
//
|
||||||
|
// Use of this software is governed by the Business Source License
|
||||||
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
|
// License, and you may not use this file except in compliance with the Business Source License.
|
||||||
|
//
|
||||||
|
// As of the Change Date specified in that file, in accordance with
|
||||||
|
// the Business Source License, use of this software will be governed
|
||||||
|
// by the Apache License, Version 2.0, included in the file
|
||||||
|
// licenses/APL.txt.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef MG_ENTERPRISE
|
||||||
|
|
||||||
|
#include "io/network/endpoint.hpp"
|
||||||
|
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
|
namespace memgraph::coordination {
|
||||||
|
|
||||||
|
// TODO: (andi) For phase IV. Some instances won't have raft_socket_address, coord_socket_address, replication_role and
|
||||||
|
// cluster role... At the end, all instances will have everything.
|
||||||
|
struct InstanceStatus {
|
||||||
|
std::string instance_name;
|
||||||
|
std::string raft_socket_address;
|
||||||
|
std::string coord_socket_address;
|
||||||
|
std::string cluster_role;
|
||||||
|
bool is_alive;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace memgraph::coordination
|
||||||
|
|
||||||
|
#endif
|
||||||
79
src/coordination/include/coordination/raft_state.hpp
Normal file
79
src/coordination/include/coordination/raft_state.hpp
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
// Copyright 2024 Memgraph Ltd.
|
||||||
|
//
|
||||||
|
// Use of this software is governed by the Business Source License
|
||||||
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
|
// License, and you may not use this file except in compliance with the Business Source License.
|
||||||
|
//
|
||||||
|
// As of the Change Date specified in that file, in accordance with
|
||||||
|
// the Business Source License, use of this software will be governed
|
||||||
|
// by the Apache License, Version 2.0, included in the file
|
||||||
|
// licenses/APL.txt.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef MG_ENTERPRISE
|
||||||
|
|
||||||
|
#include <flags/replication.hpp>
|
||||||
|
|
||||||
|
#include <libnuraft/nuraft.hxx>
|
||||||
|
|
||||||
|
namespace memgraph::coordination {
|
||||||
|
|
||||||
|
using BecomeLeaderCb = std::function<void()>;
|
||||||
|
using BecomeFollowerCb = std::function<void()>;
|
||||||
|
|
||||||
|
using nuraft::buffer;
|
||||||
|
using nuraft::logger;
|
||||||
|
using nuraft::ptr;
|
||||||
|
using nuraft::raft_launcher;
|
||||||
|
using nuraft::raft_server;
|
||||||
|
using nuraft::srv_config;
|
||||||
|
using nuraft::state_machine;
|
||||||
|
using nuraft::state_mgr;
|
||||||
|
using raft_result = nuraft::cmd_result<ptr<buffer>>;
|
||||||
|
|
||||||
|
class RaftState {
|
||||||
|
private:
|
||||||
|
explicit RaftState(BecomeLeaderCb become_leader_cb, BecomeFollowerCb become_follower_cb, uint32_t raft_server_id,
|
||||||
|
uint32_t raft_port, std::string raft_address);
|
||||||
|
|
||||||
|
auto InitRaftServer() -> void;
|
||||||
|
|
||||||
|
public:
|
||||||
|
RaftState() = delete;
|
||||||
|
RaftState(RaftState const &other) = default;
|
||||||
|
RaftState &operator=(RaftState const &other) = default;
|
||||||
|
RaftState(RaftState &&other) noexcept = default;
|
||||||
|
RaftState &operator=(RaftState &&other) noexcept = default;
|
||||||
|
~RaftState();
|
||||||
|
|
||||||
|
static auto MakeRaftState(BecomeLeaderCb become_leader_cb, BecomeFollowerCb become_follower_cb) -> RaftState;
|
||||||
|
|
||||||
|
auto InstanceName() const -> std::string;
|
||||||
|
auto RaftSocketAddress() const -> std::string;
|
||||||
|
|
||||||
|
auto AddCoordinatorInstance(uint32_t raft_server_id, uint32_t raft_port, std::string raft_address) -> void;
|
||||||
|
auto GetAllCoordinators() const -> std::vector<ptr<srv_config>>;
|
||||||
|
|
||||||
|
auto RequestLeadership() -> bool;
|
||||||
|
auto IsLeader() const -> bool;
|
||||||
|
|
||||||
|
auto AppendRegisterReplicationInstance(std::string const &instance) -> ptr<raft_result>;
|
||||||
|
|
||||||
|
// TODO: (andi) I think variables below can be abstracted
|
||||||
|
uint32_t raft_server_id_;
|
||||||
|
uint32_t raft_port_;
|
||||||
|
std::string raft_address_;
|
||||||
|
|
||||||
|
ptr<state_machine> state_machine_;
|
||||||
|
ptr<state_mgr> state_manager_;
|
||||||
|
ptr<raft_server> raft_server_;
|
||||||
|
ptr<logger> logger_;
|
||||||
|
raft_launcher launcher_;
|
||||||
|
|
||||||
|
BecomeLeaderCb become_leader_cb_;
|
||||||
|
BecomeFollowerCb become_follower_cb_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace memgraph::coordination
|
||||||
|
#endif
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user