Skip to content

feat: object deletion support — Delete(), GroupWriter.DeleteAttribute(), allocator Free() (Issue #51) - #57

Merged
kolkov merged 1 commit into
mainfrom
feat/deletion-support
Jun 25, 2026
Merged

kolkov merged 1 commit into
mainfrom
feat/deletion-support

Conversation

@kolkov

@kolkov kolkov commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements full object deletion support per ADR-002, following the HDF5 C reference implementation.

Closes #51

New public API

// Delete an object (dataset, group, or link) from the file.
// Unlinks from parent, decrements refcount, cascade deletes when nlink=0.
fw.Delete("/path/to/object")

// Delete attribute from group (already existed on DatasetWriter).
group.DeleteAttribute("key")

What's implemented

Component Description
GroupWriter.DeleteAttribute() Delegates to existing deleteAttribute() — compact + dense storage
Allocator.Free(offset, size) Free space tracking with best-fit reuse, adjacent block coalescing, EOF shrink
unlinkFromParent() Reverse of linkToParent() — removes SNOD entry, rewrites B-tree v1
fw.Delete(path) Public API: unlink + refcount decrement + cascade delete (contiguous + chunked data, group structures, OHDR)

C reference functions implemented

  • H5Ldelete → fw.Delete() (unlink from parent)
  • H5O_link(adjust=-1) → refcount decrement
  • H5O_delete → cascade delete when nlink=0
  • H5O__layout_delete → free contiguous data / walk chunked index
  • H5MF_xfree → Allocator.Free() with FSM-style reuse

Changes

  • delete_write.go — new file, fw.Delete() public API (+397)
  • delete_write_test.go — 12 test functions (+480)
  • group_write.go — GroupWriter.DeleteAttribute() + unlinkFromParent() (+182)
  • internal/writer/allocator.go — Free(), coalescing, best-fit reuse (+190)
  • internal/writer/allocator_free_test.go — 10 tests + benchmark (+256)
  • group.go — minor lint fix (+1/-1)

Total: +1486/-20

Test plan

  • Delete contiguous dataset — verify freed, surviving objects intact
  • Delete first/middle/last dataset from multi-dataset file
  • Delete all datasets from file
  • Delete empty group
  • Delete dataset with attributes
  • Non-empty group rejection (error)
  • Error cases: non-existent path, root "/", empty path
  • Nested group bottom-up deletion
  • Round-trip: create → delete → close → reopen → Walk()
  • Allocator: free/reuse, coalescing, EOF shrink, best-fit, multi-cycle
  • go test ./... — 100% pass
  • golangci-lint run ./... — 0 issues
  • go fmt clean

…ocator Free()

Implement full object deletion for the HDF5 library (Issue #51, ADR-002):

- GroupWriter.DeleteAttribute(): delegates to existing deleteAttribute()
- Allocator.Free(): best-fit reuse, adjacent coalescing, EOF shrink
- unlinkFromParent(): reverse of linkToParent, B-tree/SNOD rebuild
- FileWriter.Delete(path): public API with reference counting and
  cascade delete (contiguous data, chunked B-tree walk, group structures)

Error cases: empty/invalid path, root group, non-existent path,
non-empty groups. 22 new tests covering all paths.
@kolkov kolkov added type: feature New capability priority: high Important for next release area: allocator Free space management area: symboltable Symbol table (legacy groups) effort: 8 Very large, ~1 week labels Jun 25, 2026
@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 57.93103% with 122 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
delete_write.go 38.40% 78 Missing and 7 partials ⚠️
group_write.go 61.17% 19 Missing and 14 partials ⚠️
internal/writer/allocator.go 93.93% 2 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@kolkov
kolkov merged commit a304617 into main Jun 25, 2026
6 checks passed
@kolkov kolkov mentioned this pull request Jun 25, 2026
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: allocator Free space management area: symboltable Symbol table (legacy groups) effort: 8 Very large, ~1 week priority: high Important for next release type: feature New capability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Deletion of Attributes/Groups/Datasets

1 participant