Skip to content

Commit

Permalink
Merge branch 'develop' into sam/pgroonga-update
Browse files Browse the repository at this point in the history
  • Loading branch information
samrose authored Jan 30, 2025
2 parents dadb895 + 5ccf795 commit db18510
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Set PostgreSQL versions
id: set-versions
run: |
VERSIONS=$(nix run nixpkgs#yq -- '.postgres_major[] | select(. != "orioledb-17")' ansible/vars.yml | nix run nixpkgs#jq -- -R -s -c 'split("\n")[:-1]')
VERSIONS=$(nix run nixpkgs#yq -- '.postgres_major[]' ansible/vars.yml | nix run nixpkgs#jq -- -R -s -c "split(\"\n\")[:-1]")
echo "postgres_versions=$VERSIONS" >> $GITHUB_OUTPUT
build:
needs: prepare
Expand Down
14 changes: 14 additions & 0 deletions ansible/tasks/setup-system.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,17 @@
ansible.posix.sysctl:
name: 'net.ipv4.ip_local_port_range'
value: '1025 65000'

#Set Sysctl params specific to keepalives
- name: Set net.ipv4.tcp_keepalive_time=1800
ansible.builtin.sysctl:
name: net.ipv4.tcp_keepalive_time
value: 1800
state: present
when: debpkg_mode or nixpkg_mode
- name: Set net.ipv4.tcp_keepalive_intvl=60
ansible.builtin.sysctl:
name: net.ipv4.tcp_keepalive_intvl
value: 60
state: present
when: debpkg_mode or nixpkg_mode
4 changes: 2 additions & 2 deletions ansible/vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ postgres_major:

# Full version strings for each major version
postgres_release:
postgresorioledb-17: "17.0.1.022-orioledb-pgroonga-1"
postgres15: "15.8.1.032-pgroonga-1"
postgresorioledb-17: "17.0.1.022-orioledb"
postgres15: "15.8.1.032"

# Non Postgres Extensions
pgbouncer_release: "1.19.0"
Expand Down
79 changes: 63 additions & 16 deletions nix/tools/dbmate-tool.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,31 @@ STAT_EXTENSION_SQL=@STAT_EXTENSION_SQL@
cleanup() {
echo "Cleaning up..."

# Kill overmind processes first
# Kill postgres processes first
if pgrep -f "postgres" >/dev/null; then
pkill -TERM postgres || true
sleep 2
fi

# Then kill overmind
if [ -S "./.overmind.sock" ]; then
overmind kill || true
sleep 2
fi

# Kill any remaining postgres processes
echo "Killing any remaining postgres processes..."
pkill -9 postgres || true
pkill -9 -f "tmux.*overmind.*postgresql" || true

# Extra cleanup for tmux sessions
# Kill tmux sessions explicitly
pkill -f "tmux.*overmind.*postgresql" || true
tmux ls 2>/dev/null | grep 'overmind' | cut -d: -f1 | xargs -I{} tmux kill-session -t {} || true

# Force kill any stragglers
pkill -9 -f "(postgres|tmux.*overmind.*postgresql)" || true

# Remove socket and Procfile
rm -f .overmind.sock Procfile

# Verify cleanup
remaining=$(ps aux | grep -E "(postgres|overmind|tmux.*postgresql)" | grep -v grep || true)
if [ ! -z "$remaining" ]; then
echo "Warning: Some processes might still be running:"
echo "$remaining"

# Final verification
if ps aux | grep -E "(postgres|overmind|tmux.*postgresql)" | grep -v grep >/dev/null; then
ps aux | grep -E "(postgres|overmind|tmux.*postgresql)" | grep -v grep
return 1
fi
}

Expand Down Expand Up @@ -143,6 +146,24 @@ wait_for_postgres() {
return 1
}

check_orioledb_ready() {
local max_attempts=30
local attempt=1

while [ $attempt -le $max_attempts ]; do
if "${PSQLBIN}/psql" -v ON_ERROR_STOP=1 -U "$PGSQL_SUPERUSER" -p "$PORTNO" -h localhost -d postgres -c "SELECT * FROM pg_am WHERE amname = 'orioledb'" | grep -q orioledb; then
echo "Orioledb extension is ready!"
return 0
fi
echo "Waiting for orioledb to be ready (attempt $attempt/$max_attempts)..."
sleep 2
attempt=$((attempt + 1))
done

echo "Orioledb failed to initialize after $max_attempts attempts"
return 1
}

trim_schema() {
case "$CURRENT_SYSTEM" in
"x86_64-darwin"|"aarch64-darwin")
Expand All @@ -165,7 +186,7 @@ EOF
while [ $count -lt $max_wait ]; do
if [ -S "./.overmind.sock" ]; then
# Found the socket, give it a moment to be ready
sleep 2
sleep 5
echo "Socket file found and ready"
break
fi
Expand All @@ -174,6 +195,25 @@ EOF
count=$((count + 1))
done
}
perform_dump() {
local max_attempts=3
local attempt=1

while [ $attempt -le $max_attempts ]; do
echo "Attempting dbmate dump (attempt $attempt/$max_attempts)"

if dbmate dump; then
return 0
fi

echo "Dump attempt $attempt failed, waiting before retry..."
sleep 5
attempt=$((attempt + 1))
done

echo "All dump attempts failed"
return 1
}
migrate_version() {
echo "PSQL_VERSION: $PSQL_VERSION"
overmind kill || true
Expand All @@ -193,6 +233,13 @@ migrate_version() {
echo "Failed to connect to PostgreSQL server"
exit 1
fi

if [ "$PSQL_VERSION" = "orioledb-17" ]; then
if ! check_orioledb_ready; then
echo "Failed to initialize orioledb extension"
exit 1
fi
fi

echo "PostgreSQL server is ready"

Expand Down Expand Up @@ -233,7 +280,7 @@ EOSQL
fi

echo "Running dbmate dump with $PSQLBIN"
dbmate dump
perform_dump

echo "CURRENT_SYSTEM: $CURRENT_SYSTEM"
if [ -f "./db/schema.sql" ]; then
Expand Down

0 comments on commit db18510

Please sign in to comment.