Skip to content

Commit

Permalink
feat(storage): Improve Redis version checking and error handling
Browse files Browse the repository at this point in the history
- Add IsVersionCompatible static method for version comparison
- Add comprehensive version checking documentation
- Add test cases for version checking with retries
- Add test case for version checking with invalid server
- Improve error handling in version checking logic
  • Loading branch information
devin-ai-integration[bot] committed Nov 22, 2024
1 parent 9ed32c9 commit 1ce8453
Show file tree
Hide file tree
Showing 16 changed files with 1,263 additions and 24 deletions.
61 changes: 57 additions & 4 deletions .github/workflows/conan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@ on: [push]

jobs:
build-on-windows:

runs-on: windows-latest
services:
redis:
image: redis
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
Expand All @@ -29,15 +38,55 @@ jobs:
echo "[requires]" > ${{github.workspace}}/conanfile.txt
echo boost/1.86.0 >> ${{github.workspace}}/conanfile.txt
echo leveldb/1.23 >> ${{github.workspace}}/conanfile.txt
echo hiredis/1.0.2 >> ${{github.workspace}}/conanfile.txt
echo "[generators]" >> ${{github.workspace}}/conanfile.txt
echo CMakeDeps >> ${{github.workspace}}/conanfile.txt
echo CMakeToolchain >> ${{github.workspace}}/conanfile.txt
- name: Verify Redis Service
timeout-minutes: 2
run: |
$maxAttempts = 20
$attempt = 1
do {
Write-Host "Attempt $attempt/$maxAttempts: Checking Redis..."
try {
$result = redis-cli -h 127.0.0.1 ping
if ($result -eq 'PONG') {
Write-Host "Redis responded successfully with PONG"
break
}
Write-Host "Redis responded but unexpected result: $result"
} catch {
Write-Host "Redis check failed: $_"
if ($attempt % 5 -eq 0) {
Write-Host "Checking Redis server status..."
redis-cli -h 127.0.0.1 info server
netstat -an | findstr "6379"
}
}
Start-Sleep -Seconds 2
$attempt++
} while ($attempt -lt $maxAttempts)
if ($attempt -ge $maxAttempts) {
Write-Error "Redis failed to start after $maxAttempts attempts"
redis-cli -h 127.0.0.1 info server
exit 1
}
Write-Host "Redis is ready"
redis-cli -h 127.0.0.1 info server
- name: Configure
working-directory: ${{github.workspace}}/build
env:
CC: cl
run: cmake ${{github.workspace}} -DOPENMIND_USE_CONAN=ON -DOPENMIND_USE_VCPKG=NO -DOPENMIND_BUILD_SAMPLES=NO -DOPENMIND_BUILD_TESTS=ON -D CMAKE_C_COMPILER="cl.exe" -D CMAKE_CXX_COMPILER="cl.exe" -DOPENMIND_MATH_USE_LEVELDB_CACHE=NO -DOPENMIND_STORAGE_LEVELDB=NO
OPENMIND_TEST_REDIS_HOST: "127.0.0.1"
OPENMIND_TEST_REDIS_PORT: 6379
OPENMIND_TEST_REDIS_RETRY_COUNT: 3
OPENMIND_TEST_REDIS_RETRY_DELAY: 500
run: cmake ${{github.workspace}} -DOPENMIND_USE_CONAN=ON -DOPENMIND_USE_VCPKG=NO -DOPENMIND_BUILD_SAMPLES=NO -DOPENMIND_BUILD_TESTS=ON -D CMAKE_C_COMPILER="cl.exe" -D CMAKE_CXX_COMPILER="cl.exe" -DOPENMIND_MATH_USE_LEVELDB_CACHE=NO -DOPENMIND_STORAGE_LEVELDB=NO -DOPENMIND_STORAGE_REDIS=ON
- name: Install prerequisites with conan
working-directory: ${{github.workspace}}/build
run: cmake --build ${{github.workspace}}/build --target Install__Conan --config Release
Expand All @@ -52,5 +101,9 @@ jobs:
id: cpu-cores
- name: check
working-directory: ${{github.workspace}}/build
run: ctest . --timeout 2400 -C Debug -j ${{steps.cpu-cores.outputs.count}} -E "ts" --output-on-failure
# --rerun-failed --output-on-failure
env:
OPENMIND_TEST_REDIS_HOST: "127.0.0.1"
OPENMIND_TEST_REDIS_PORT: 6379
OPENMIND_TEST_REDIS_RETRY_COUNT: 3
OPENMIND_TEST_REDIS_RETRY_DELAY: 500
run: ctest . --timeout 2400 -C Debug -j ${{steps.cpu-cores.outputs.count}} -E "ts" --output-on-failure --rerun-failed
58 changes: 54 additions & 4 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,70 @@ on: [push]

jobs:
build:

runs-on: ubuntu-latest
container:
image: ohhmm/openmind:latest
image: ohhmm/openmind:latest

services:
redis:
image: redis
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
--redis-server-config "maxclients 10000"
steps:
- uses: actions/checkout@v3
- name: Check for dockerenv file
run: (ls /.dockerenv && echo Found dockerenv && which clang++) || (echo No dockerenv)

- name: Install Redis dependencies
run: |
emerge --quiet '>=dev-libs/hiredis-0.13.0'
emerge --info dev-libs/hiredis
redis-cli -h redis ping || echo "Redis not responding yet"
- name: Wait for Redis
timeout-minutes: 2
run: |
max_attempts=20
attempt=1
until redis-cli -h redis ping || [ $attempt -ge $max_attempts ]; do
echo "Attempt $attempt/$max_attempts: Waiting for Redis..."
if [ $attempt -eq 1 ] || [ $((attempt % 5)) -eq 0 ]; then
echo "Checking Redis server status..."
redis-cli -h redis info server || echo "Could not get server info"
netstat -an | grep 6379 || echo "Port 6379 not found in netstat"
fi
sleep 1
((attempt++))
done
if [ $attempt -ge $max_attempts ]; then
echo "Redis service failed to start after $max_attempts attempts"
redis-cli -h redis info server || echo "Could not get server info"
exit 1
fi
echo "Redis is ready"
redis-cli -h redis info server
- name: Create Build Dir
run: cmake -E make_directory ./build

- name: Configure
working-directory: ./build
env:
OPENMIND_TEST_REDIS_HOST: redis
OPENMIND_TEST_REDIS_PORT: 6379
OPENMIND_TEST_REDIS_RETRY_COUNT: 3
OPENMIND_TEST_REDIS_RETRY_DELAY: 1000
run: cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_COMPILER=/usr/lib/llvm/17/bin/clang-17 -DCMAKE_C_COMPILER=/usr/lib/llvm/17/bin/clang-17 \
-DOPENMIND_BUILD_SAMPLES=OFF
-DOPENMIND_BUILD_SAMPLES=OFF \
-DOPENMIND_STORAGE_REDIS=ON

# - name: Install prerequisites
# working-directory: ./build
Expand All @@ -36,5 +82,9 @@ jobs:

- name: Check
working-directory: ./build
env:
OPENMIND_TEST_REDIS_HOST: redis
OPENMIND_TEST_REDIS_PORT: 6379
OPENMIND_TEST_REDIS_RETRY_COUNT: 3
OPENMIND_TEST_REDIS_RETRY_DELAY: 500
run: ctest . -j`nproc` -E ts --rerun-failed --output-on-failure

65 changes: 59 additions & 6 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,66 @@ on: [push]

jobs:
build-in-macos:

runs-on: macos-latest

env:
OPENMIND_TEST_REDIS_HOST: "127.0.0.1"
OPENMIND_TEST_REDIS_PORT: 6379
OPENMIND_TEST_REDIS_RETRY_COUNT: 3
OPENMIND_TEST_REDIS_RETRY_DELAY: 1000

services:
redis:
image: redis
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v3
- name: Create Build Dir
run: cmake -E make_directory ${{github.workspace}}/build
- name: Pre-Install Boost, LevelDB
run: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" && ( brew install boost-python3 snappy leveldb || brew install boost-python3 snappy leveldb )
- name: Pre-Install Dependencies
run: |
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" && \
( brew install boost-python3 snappy leveldb hiredis redis || brew install boost-python3 snappy leveldb hiredis redis )
- name: Verify Redis Service
timeout-minutes: 2
run: |
echo "Starting Redis service verification..."
max_attempts=20
attempt=1
until redis-cli -h 127.0.0.1 ping || [ $attempt -ge $max_attempts ]; do
echo "Attempt $attempt/$max_attempts: Waiting for Redis..."
if [ $attempt -eq 1 ] || [ $((attempt % 5)) -eq 0 ]; then
echo "=== Diagnostic Information ==="
echo "1. Redis Server Status:"
redis-cli -h 127.0.0.1 info server || echo "Could not get server info"
echo "2. Network Status:"
netstat -an | grep 6379 || echo "Port 6379 not found in netstat"
echo "3. Brew Services:"
brew services list | grep redis || echo "Redis service not found in brew services"
echo "4. Redis Memory Info:"
redis-cli -h 127.0.0.1 info memory || echo "Could not get memory info"
echo "5. Redis Clients:"
redis-cli -h 127.0.0.1 client list || echo "Could not get client list"
echo "=========================="
fi
sleep 2
((attempt++))
done
if [ $attempt -ge $max_attempts ]; then
echo "Redis service failed to start after $max_attempts attempts"
exit 1
fi
echo "Redis is fully operational"
redis-cli -h 127.0.0.1 info server
- name: Configure
working-directory: ${{github.workspace}}/build
run: cmake ${{github.workspace}} -GXcode -DOPENMIND_BUILD_SAMPLES=OFF -DOPENMIND_BUILD_TESTS=ON -Dleveldb_TAG:STRING="1.23" -DOPENMIND_MATH_USE_LEVELDB_CACHE=OFF -DOPENMIND_STORAGE_LEVELDB=OFF
run: cmake ${{github.workspace}} -GXcode -DOPENMIND_BUILD_SAMPLES=OFF -DOPENMIND_BUILD_TESTS=ON -Dleveldb_TAG:STRING="1.23" -DOPENMIND_MATH_USE_LEVELDB_CACHE=OFF -DOPENMIND_STORAGE_LEVELDB=OFF -DOPENMIND_STORAGE_REDIS=ON
- name: Install prerequisites
working-directory: ${{github.workspace}}/build
run: cmake --build ${{github.workspace}}/build --target prerequisites -j `sysctl -n hw.ncpu` --config Release
Expand All @@ -27,4 +75,9 @@ jobs:
run: cmake --build ${{github.workspace}}/build -j `sysctl -n hw.ncpu` --config Release
- name: Check
working-directory: ${{github.workspace}}/build
run: ctest --timeout 120 -C Release -j `sysctl -n hw.ncpu` -E ts
env:
OPENMIND_TEST_REDIS_HOST: "127.0.0.1"
OPENMIND_TEST_REDIS_PORT: 6379
OPENMIND_TEST_REDIS_RETRY_COUNT: 3
OPENMIND_TEST_REDIS_RETRY_DELAY: 500
run: ctest --timeout 120 -C Release -j `sysctl -n hw.ncpu` -E ts --rerun-failed --output-on-failure
89 changes: 89 additions & 0 deletions .github/workflows/msvc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: C/C++ CI MSVC

on: [push]

jobs:
build:
runs-on: windows-latest
env:
OPENMIND_TEST_REDIS_HOST: "127.0.0.1"
OPENMIND_TEST_REDIS_PORT: 6379
OPENMIND_TEST_REDIS_RETRY_COUNT: 3
OPENMIND_TEST_REDIS_RETRY_DELAY: 1000
services:
redis:
image: redis
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
--redis-server-config "maxclients 10000"
steps:
- uses: actions/checkout@v3

- name: Set up vcpkg
uses: lukka/run-vcpkg@v11
with:
vcpkgGitCommitId: '3508985146f1b1d248c67ead13f8f54be5b4f5da'

- name: Create Build Directory
run: cmake -E make_directory ${{github.workspace}}/build

- name: Verify Redis Service
run: |
choco install redis-64
$env:PATH = "$env:PATH;C:\Program Files\Redis"
$maxAttempts = 30
$attempts = 0
do {
$attempts++
Write-Host "Attempt $attempts of $maxAttempts: Checking Redis availability..."
try {
Write-Host "1. Checking Redis ping..."
$result = redis-cli -h 127.0.0.1 ping
if ($result -eq 'PONG') {
Write-Host "2. Getting Redis info..."
redis-cli -h 127.0.0.1 info server
Write-Host "3. Checking memory info..."
redis-cli -h 127.0.0.1 info memory
Write-Host "4. Checking client connections..."
redis-cli -h 127.0.0.1 client list
Write-Host "5. Configuring Redis..."
redis-cli -h 127.0.0.1 config set maxclients 10000
Write-Host "Redis is fully operational!"
break
}
} catch {
Write-Host "Redis check failed: $_"
}
if ($attempts -eq $maxAttempts) {
Write-Error "Redis failed to become available after $maxAttempts attempts"
exit 1
}
Start-Sleep -Seconds 2
} while ($true)
- name: Configure CMake
working-directory: ${{github.workspace}}/build
run: |
cmake .. -DCMAKE_TOOLCHAIN_FILE=$env:VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake `
-DOPENMIND_BUILD_SAMPLES=OFF `
-DOPENMIND_STORAGE_REDIS=ON
- name: Build
working-directory: ${{github.workspace}}/build
run: cmake --build . --config Release

- name: Test
working-directory: ${{github.workspace}}/build
env:
OPENMIND_TEST_REDIS_HOST: "127.0.0.1"
OPENMIND_TEST_REDIS_PORT: 6379
OPENMIND_TEST_REDIS_RETRY_COUNT: 3
OPENMIND_TEST_REDIS_RETRY_DELAY: 1000
run: ctest -C Release -E ts --rerun-failed --output-on-failure
Loading

0 comments on commit 1ce8453

Please sign in to comment.