hotfix: DB EC2 MySQL 초기화 OOM 방지#59
Conversation
📝 WalkthroughWalkthroughMySQL 설정 스크립트가 Docker 시작 전에 Changes스왑 초기화
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Terraform Plan:
|
Terraform Plan:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
modules/app_stack/scripts/mysql_setup.sh.tftpl (1)
21-22: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value
command -v검사가 결과를 사용하지 않습니다.
swapon/mkswap존재 여부를 확인하지만 실패 시 아무 동작도 하지 않아 사실상 dead code입니다. 명령이 없는 경우 이후 단계에서 더 불분명한 에러가 발생합니다. 제거하거나 실패 시exit/경고 처리를 추가하는 것을 고려해 보세요.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@modules/app_stack/scripts/mysql_setup.sh.tftpl` around lines 21 - 22, Remove the unused command -v checks for swapon and mkswap, or make them enforce prerequisites by emitting a clear error and terminating before swap setup proceeds when either command is unavailable.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@modules/app_stack/scripts/mysql_setup.sh.tftpl`:
- Around line 40-41: In the fstab guard, the regex in the swap-entry check
incorrectly consumes the first character of the swap path, so duplicate entries
are appended. Update the grep pattern used by the fstab registration block to
match optional leading whitespace followed by the full $swap_file path, while
still excluding commented lines and matching the existing none/swap fields.
---
Nitpick comments:
In `@modules/app_stack/scripts/mysql_setup.sh.tftpl`:
- Around line 21-22: Remove the unused command -v checks for swapon and mkswap,
or make them enforce prerequisites by emitting a clear error and terminating
before swap setup proceeds when either command is unavailable.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 9a8c249b-caba-4258-a916-878c0a80d87a
📒 Files selected for processing (1)
modules/app_stack/scripts/mysql_setup.sh.tftpl
| if ! grep -Eq "^[^#][[:space:]]*$swap_file[[:space:]]+none[[:space:]]+swap[[:space:]]" /etc/fstab; then | ||
| printf '%s none swap sw 0 0\n' "$swap_file" >> /etc/fstab |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🔴 Critical | ⚡ Quick win
fstab 중복 등록 버그 — regex가 의도한 대로 매칭되지 않습니다.
[^#]가 /swapfile의 첫 글자 /를 소비한 뒤, 패턴의 리터럴 /swapfile는 잔여 텍스트 swapfile ...와 매칭을 시도하므로 항상 실패합니다. 결과적으로 swap이 이미 활성화된 상태에서도(라인 27 가드 바깥에 있음) 매 실행 시마다 /etc/fstab에 중복 엔트리가 추가됩니다.
🐛 Proposed fix
- if ! grep -Eq "^[^#][[:space:]]*$swap_file[[:space:]]+none[[:space:]]+swap[[:space:]]" /etc/fstab; then
+ if ! grep -Eq "^[[:space:]]*${swap_file}[[:space:]]+none[[:space:]]+swap" /etc/fstab; then
printf '%s none swap sw 0 0\n' "$swap_file" >> /etc/fstab
fi/swapfile은 /로 시작하므로 # 주석 라인과 자연히 구분되며, ^[[:space:]]*로 선행 공백도 허용합니다.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if ! grep -Eq "^[^#][[:space:]]*$swap_file[[:space:]]+none[[:space:]]+swap[[:space:]]" /etc/fstab; then | |
| printf '%s none swap sw 0 0\n' "$swap_file" >> /etc/fstab | |
| if ! grep -Eq "^[[:space:]]*${swap_file}[[:space:]]+none[[:space:]]+swap" /etc/fstab; then | |
| printf '%s none swap sw 0 0\n' "$swap_file" >> /etc/fstab |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@modules/app_stack/scripts/mysql_setup.sh.tftpl` around lines 40 - 41, In the
fstab guard, the regex in the swap-entry check incorrectly consumes the first
character of the swap path, so duplicate entries are appended. Update the grep
pattern used by the fstab registration block to match optional leading
whitespace followed by the full $swap_file path, while still excluding commented
lines and matching the existing none/swap fields.
관련 이슈
작업 내용
/swapfile2GiB를 생성하고 활성화하도록 수정했습니다./swapfile이 존재하는 경우 중복 생성하지 않도록 처리했습니다./etc/fstab에 등록합니다.특이 사항
mysql:8.4.8초기화 중mysqld가 OOM으로 종료되며 컨테이너가 정상 기동하지 못하는 문제가 확인되어 반영한 hotfix입니다.리뷰 요구사항 (선택)
t4g.nano환경에서 MySQL 8.4.8 초기화 안정성을 위해 2GiB swap을 두는 방향이 적절한지 확인 부탁드립니다.bash -n modules/app_stack/scripts/mysql_setup.sh.tftpl,git diff --check, prodterraform plan확인 완료 (Plan: 3 to add, 0 to change, 0 to destroy).Summary by CodeRabbit