Repository navigation
Commit bbc2359
authored
fix(catalog): validate namespace existence in InMemoryCatalog create and register (#980)
## What
`InMemoryCatalog` did not correctly check that a table's namespace exists, in two methods.
`CreateTable` wrote the table metadata file before validating the namespace. Creating a table under a missing namespace returned `kNoSuchNamespace`, but on object-store `FileIO` it first left an orphaned `00000-<uuid>.metadata.json` that nothing later removes, and on the default local `FileIO` the stray write failed with a misleading `kIOError`.
`RegisterTable` guarded with `if (!root_namespace_->NamespaceExists(identifier.ns))`. `NamespaceExists` returns `Result<bool>`, so `!result` tests `has_value()` rather than the bool, and a missing namespace is a value `false`, not an error. The branch was dead code, and a missing namespace surfaced as `kUnknownError` instead of `kNoSuchNamespace`.
Closes #977.
## How
`CreateTable` now validates the namespace before writing any metadata, matching `SqlCatalog::CreateTable`. `RegisterTable` reads the metadata outside the lock, then validates the namespace and registers under a single lock: the dead `if (!NamespaceExists(...))` check (which tested the `Result<bool>`'s `has_value()` rather than the contained bool) becomes an unwrap that returns `kNoSuchNamespace`. Keeping the namespace check and the registration in one critical section leaves them atomic, and the metadata read stays off the lock. The empty (root) namespace still resolves to `true`, so ordinary table creation is unaffected.
## Testing
Two new tests in `in_memory_catalog_test.cc`:
- `CreateTableNonexistentNamespace` — creating a table under a missing namespace returns `kNoSuchNamespace` and leaves no metadata file behind. It passes an explicit location whose `metadata/` directory already exists, so the pre-fix write lands a detectable orphan there; the zero-file assertion is what fails without the fix. The error-kind assertion alone would still pass pre-fix, because the later `UpdateTableMetadataLocation` also returns `kNoSuchNamespace` after the orphan is written.
- `RegisterTableNonexistentNamespace` — registering under a missing namespace returns `kNoSuchNamespace`; without the fix the dead `Result<bool>` check let it fall through to `kUnknownError`.1 parent db796cb commit bbc2359
2 files changed
Lines changed: 55 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
422 | 422 | | |
423 | 423 | | |
424 | 424 | | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
425 | 430 | | |
426 | 431 | | |
427 | 432 | | |
| |||
609 | 614 | | |
610 | 615 | | |
611 | 616 | | |
612 | | - | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
613 | 620 | | |
614 | 621 | | |
615 | 622 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
161 | 208 | | |
162 | 209 | | |
163 | 210 | | |
| |||
0 commit comments