Skip to content

[CBRD-27429] Read and write only the current catalog statistics layout - #7957

Open
soheejung-cs wants to merge 3 commits into
CUBRID:developfrom
soheejung-cs:CBRD-27429
Open

soheejung-cs wants to merge 3 commits into
CUBRID:developfrom
soheejung-cs:CBRD-27429

Conversation

@soheejung-cs

@soheejung-cs soheejung-cs commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

http://jira.cubrid.org/browse/CBRD-27429

Purpose

CBRD-27140(#7856) 이 통계 체인을 INT64 로 넓히면서 카탈로그 BTREE_STATS 레코드에 레이아웃이 둘 생겼습니다 — V0 는 기존 80바이트 32비트, V1 은 120바이트 INT64. 쓰는 쪽은 항상 V1 이고 읽는 쪽만 둘 다 받는데, 이는 백포트를 대비해 구 레코드도 읽을 수 있게 둔 것 입니다.

그런데 V0 레코드를 가진 데이터베이스는 CBRD-27140 이전의 11.5 개발 빌드가 만든 것뿐입니다. 11.5 는 아직 출시되지 않았고(최신 태그 v11.4.5.1906), disk_compatibility_level 이 정확히 같은 레벨만 통과시키므로 11.4 이하 데이터베이스는 11.5 바이너리로 열리지 않습니다. 백포트 대비가 실제로 쓰일 자리가 없어 제거합니다.

프리즈 전에만 가능합니다. 통계는 읽어 온 표현을 통해 다시 쓰이므로(xstats_update_statistics()catalog_get_representation()), V0 파서를 지운 뒤에는 그런 데이터베이스를 제자리에서 옮길 수 없습니다.

Implementation

  • V0 파싱과 레이아웃 의존 레코드 크기(CATALOG_BT_STATS_SIZE_OF) 제거 — 크기를 다시 상수로. catalog_fetch_btree_statistics()·catalog_assign_attribute()stats_layout 인자도 제거했습니다.
  • BTREE_STATS·CLS_INFO 의 32비트 슬롯 포화 사본 기록 중단, CLS_INFO 의 "tail 이 0 이면 32비트 필드를 읽는다" 폴백 제거.
  • 레이아웃이 하나뿐이므로 버전 표시도 제거 — DISK_REPR.stats_layout, CATALOG_STATS_LAYOUT_*, 레코드의 버전 기록(예약 슬롯은 다시 0).
  • 에러 코드·메시지는 추가하지 않았습니다.

Remarks

  • 3파일 +28/-63 순감소. 빌드·코드스타일 확인 완료.
  • CBRD-27140 이전 개발 빌드로 만든 데이터베이스는 재생성이 필요하며, 버전 표시가 없어 자동 감지되지 않습니다.

CBRD-27140 left the catalog able to read two BTREE_STATS layouts: V0, the
80-byte record with 32-bit counts, and V1, the 120-byte record with INT64
ones. Only V1 is ever written, and a V0 record can exist only in a database
built by an 11.5 development build from before that change -- 11.5 has not
shipped, and disk_compatibility_level admits a database only at exactly its
own level, so no 11.4 or older database is ever opened here. The reader has
to go before the release freeze: statistics are rewritten through the
representation they are read from, so once V0 parsing is gone there is no
way to migrate such a database in place, and keeping the reader means
carrying a record whose size depends on a runtime value through every
sequential walk of the catalog.

- catalog_get_btree_statistics() reads the INT64 counts only, and the record
  size is a constant again; the stats_layout parameter is gone from
  catalog_fetch_btree_statistics() and catalog_assign_attribute().
- The 32-bit slots that used to carry a saturated copy of the counts, in
  both BTREE_STATS and CLS_INFO, are written as zero and are not read.
- catalog_get_disk_representation() refuses anything but V1 with
  ER_CT_UNSUPPORTED_STATS_LAYOUT instead of asserting, which a release build
  ignored before walking off the shorter record.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BKTXWecvewf6QWaMoxtz39

# 제목: 변경 요약 (50자 이내)  (refactor, hotfix, feature)

# 본문: 변경 사항에 대한 자세한 설명
# - 주요 변경 사항 1
# - 주요 변경 사항 2

# 참고: 이 라인 아래의 내용은 커밋 메시지에서 제거됩니다.
@github-actions

github-actions Bot commented Sep 16, 2026

Copy link
Copy Markdown

❌ TC Merge Gate — Merge Blocked

One or more TC PRs are still open. Please merge or close them before merging this PR.

TC Repositories & Branches:

  • cubrid-testcases: TC PR tc/pr-7957 is open (draft) — must be merged or closed first
  • cubrid-testcases-private-ex: TC PR tc/pr-7957 is open (draft) — must be merged or closed first

Steps to unblock:

  1. Merge or close all TC PRs listed above.
  2. Re-run this check: Actions tab → TC Merge Gate → Re-run failed jobs

@github-actions

Copy link
Copy Markdown

🧪 TC Test Environment Ready

CircleCI Testing:

  • CircleCI will automatically test using the branches below.

TC Repositories & Branches:

Next Steps:

  1. Wait for CircleCI tests to complete
  2. If CircleCI tests failed, please check the test results and fix the issues.
  3. When ready to merge this PR, please merge the TC PR first, then merge this PR.

@greptile-apps

greptile-apps Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Retrigger

지원하지 않는 개발 DB를 처리할 때 서버가 중단되거나 legacy CLS_INFO의 행 수가 0으로 조용히 해석될 수 있으므로 현재 상태로는 병합하기 안전하지 않습니다.

Reviews (1) · Last reviewed commit: "[CBRD-27429] Read and write only the cur..."

Comment thread src/storage/system_catalog.c Outdated
Comment on lines +421 to +426
if (disk_repr_p->stats_layout != CATALOG_STATS_LAYOUT_V1)
{
assert (false);
er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_CT_UNSUPPORTED_STATS_LAYOUT, 1, disk_repr_p->stats_layout);
return ER_FAILED;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 오류 전에 프로세스 중단

지원하지 않는 V0 레이아웃을 읽으면 er_set()보다 assert(false)가 먼저 실행됩니다. 기본 Debug 빌드와 assert가 활성화된 OptDebug 빌드에서는 서버 프로세스가 즉시 중단되어 ER_CT_UNSUPPORTED_STATS_LAYOUT 오류가 설정·전파되지 않습니다. 이 입력은 명시적으로 거부해야 하는 경우이므로, 빌드 유형과 무관하게 DB 재생성 안내를 반환하도록 assert 없이 오류 경로로 처리해야 합니다.

Suggested change
if (disk_repr_p->stats_layout != CATALOG_STATS_LAYOUT_V1)
{
assert (false);
er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_CT_UNSUPPORTED_STATS_LAYOUT, 1, disk_repr_p->stats_layout);
return ER_FAILED;
}
if (disk_repr_p->stats_layout != CATALOG_STATS_LAYOUT_V1)
{
er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_CT_UNSUPPORTED_STATS_LAYOUT, 1, disk_repr_p->stats_layout);
return ER_FAILED;
}

@@ -539,11 +530,6 @@ catalog_get_class_info_from_record (CLS_INFO * class_info_p, char *rec_p)

class_info_p->ci_tot_pages = OR_GET_INT (rec_p + CATALOG_CLS_INFO_TOT_PAGES_OFF);
OR_GET_INT64 (rec_p + CATALOG_CLS_INFO_TOT_OBJS64_OFF, &class_info_p->ci_tot_objects);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 CLS_INFO 레이아웃 검증 누락

이전 11.5 개발 빌드가 기록한 CLS_INFO를 읽으면 64비트 tail은 0이지만, 이번 변경은 실제 행 수가 있는 32비트 필드로의 fallback을 제거합니다. CLS_INFO에는 stats_layout 표식이 없고 catalog_get_class_info()catalog_get_rep_dir()는 DISK_REPR 검증 없이 이 레코드를 직접 읽으므로, 해당 경로에서는 unsupported-layout 오류 대신 ci_tot_objects == 0이 조용히 반환되어 잘못된 통계가 사용될 수 있습니다. CLS_INFO에도 명시적인 레이아웃 거부 수단을 마련하거나 이 fallback을 유지해야 합니다.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bc017f3766

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/storage/system_catalog.c Outdated
assert (disk_repr_p->stats_layout == CATALOG_STATS_LAYOUT_V0 || disk_repr_p->stats_layout == CATALOG_STATS_LAYOUT_V1);
if (disk_repr_p->stats_layout != CATALOG_STATS_LAYOUT_V1)
{
assert (false);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Return the unsupported-layout error in debug builds

When opening a database created by a pre-CBRD-27140 development build, its V0 layout deliberately takes this branch. In debug builds, assert (false) terminates the server before the following er_set can return ER_CT_UNSUPPORTED_STATS_LAYOUT, so users receive a process abort rather than the intended actionable recreate-database error. This assertion should be removed or made non-fatal for this expected compatibility rejection.

Useful? React with 👍 / 👎.

@soheejung-cs soheejung-cs self-assigned this Sep 16, 2026
SOHEE_JUNG added 2 commits September 16, 2026 13:56
Refusing an old layout does not need an error code of its own: the
database really is incompatible with this release, which is what
ER_LOG_INCOMPATIBLE_DATABASE says. The layout value goes to the server
error log through er_log_debug for diagnosis.

Reverts the error code and the two message catalog entries added in the
previous commit.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BKTXWecvewf6QWaMoxtz39

# 제목: 변경 요약 (50자 이내)  (refactor, hotfix, feature)

# 본문: 변경 사항에 대한 자세한 설명
# - 주요 변경 사항 1
# - 주요 변경 사항 2

# 참고: 이 라인 아래의 내용은 커밋 메시지에서 제거됩니다.
With only one layout left there is nothing to select between, so the
version marker goes too: DISK_REPR loses stats_layout, the reserved slot
in the catalog record goes back to being written as zero, and the two
CATALOG_STATS_LAYOUT_* constants are gone.

This also drops the refusal added earlier in this branch -- a database
written before CBRD-27140 can no longer be recognised as such. It cannot
exist once 11.5 ships, since 11.5 has not been released and no database
at a different compatibility level is ever opened here.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BKTXWecvewf6QWaMoxtz39

# 제목: 변경 요약 (50자 이내)  (refactor, hotfix, feature)

# 본문: 변경 사항에 대한 자세한 설명
# - 주요 변경 사항 1
# - 주요 변경 사항 2

# 참고: 이 라인 아래의 내용은 커밋 메시지에서 제거됩니다.
@hornetmj
hornetmj removed their request for review September 21, 2026 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant