Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

bug: InMemoryCatalog skips the namespace existence check in CreateTable and RegisterTable

未关闭 适合新手
#977 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

@LuciferYang 已经在做这个了。

开始于 2026年10月1日。

  • #980 来自 @LuciferYang —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
cpp
领域
databases

调研方向

从 src/iceberg/catalog/memory/in_memory_catalog.cc 开始,检查 CreateTable 和 RegisterTable,然后将 namespace 的处理方式与 SqlCatalog::CreateTable 进行比较。完成的标准是:在写入元数据之前,将缺失的 namespace 拒绝为 kNoSuchNamespace,同时不改变超出范围的重复注册行为。

由索引模型根据 Issue 内容生成。

描述

Summary

InMemoryCatalog fails to validate that a table's namespace exists before acting, in two methods.

CreateTable writes the table metadata file through FileIO before it checks the namespace. Creating a table under a namespace that does not exist returns kNoSuchNamespace, but on an object-store FileIO the call first writes an orphaned 00000-<uuid>.metadata.json that nothing ever removes (DropTable's purge only touches registered tables). On the default local FileIO the stray write fails first, so the caller gets a misleading kIOError instead of kNoSuchNamespace.

RegisterTable guards with if (!root_namespace_->NamespaceExists(identifier.ns)). NamespaceExists returns Result<bool> (std::expected<bool, Error>); !result tests has_value(), not the contained bool, and a missing namespace is reported as a value false, never an error. The guard therefore never fires, so registering under a missing namespace falls through and surfaces as kUnknownError ("The registry failed.") instead of kNoSuchNamespace.

Root Cause

CreateTable (src/iceberg/catalog/memory/in_memory_catalog.cc): the namespace is only enforced inside UpdateTableMetadataLocation, which runs after TableMetadataUtil::Write has already persisted the file. TableExists(identifier).value_or(false) ahead of the write swallows the kNoSuchNamespace from the namespace lookup and reports "table absent", so control falls through to the write.

RegisterTable: if (!root_namespace_->NamespaceExists(identifier.ns)) reads as if (!result.has_value()). NamespaceExists maps a missing namespace to Ok(false), so the branch is dead code; the error later comes out of the inner RegisterTable and is rewritten to kUnknownError.

Impact

CreateTable leaks an orphan metadata file on object-store FileIO and returns the wrong error kind (kIOError) on local FileIO. InMemoryCatalog is documented as not for production use (unit tests, prototyping, demonstration), so this is a correctness and robustness issue, not a security one.

RegisterTable returns kUnknownError for a missing namespace instead of kNoSuchNamespace. SqlCatalog::RegisterTable and the REST error handler both return kNoSuchNamespace, so InMemoryCatalog is the outlier here.

Proposed Fix

Unwrap NamespaceExists and return kNoSuchNamespace before any metadata write, in both methods, mirroring SqlCatalog::CreateTable.

Out of scope

  • RegisterTable still masks kAlreadyExists as kUnknownError on the duplicate-registration path (if (!root_namespace_->RegisterTable(...))); the clean fix is ICEBERG_RETURN_UNEXPECTED(...), as RenameTable already does. Follow-up.
  • StageCreateTable and UpdateTable's create branch share the same write-before-validate pattern. Follow-up.
主要语言
C++
星标
226
派生
132
平均合并
1 天 18 小时
30 天内合并 PR
26

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

apache/iceberg-cpp 的其他 Issue

查看 apache/iceberg-cpp 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。