Skip to content

Kanban 2292: Route all attachments through core.AttachmentPointers - #8381

Open
labkey-adam wants to merge 8 commits into
developfrom
fb_manual_unified_attachments_2228
Open

labkey-adam wants to merge 8 commits into
developfrom
fb_manual_unified_attachments_2228

Conversation

@labkey-adam

@labkey-adam labkey-adam commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Rationale

This PR routes every attachment through core.AttachmentPointers, so new uploads are deduplicated by content hash across the whole server. It is Phase 2, Step 2 of the unified attachment service (Kanban 2228). Existing attachments each get one pointer and aren't deduplicated yet, so the upgrade is safe on any database; background deduplication follows in Step 3.

Resolves https://github.com/LabKey/kanban/issues/2292

Related Pull Requests

Changes

  • The upgrade script renames core.Documents to core.Attachments and core.AttachmentPointer to core.AttachmentPointers, gives every existing attachment a pointer, adds a nullable unique Hash column, and drops the columns the pointers now carry
  • AttachmentService reads and writes through pointers and always checks the parent's container; deletes remove only pointers, and a new maintenance task deletes content no pointer references
  • New uploads are hashed outside the transaction and share any existing content with the same hash
  • Concurrent uploads of the same name, and renames onto a name that's already taken, report a duplicate filename instead of a database error; concurrent uploads also can't overwrite each other's files in a file directory
  • New API methods for ELN: adding attachments named by hash, copying attachments between parents without copying bytes, and deleting records without touching files on disk
  • The admin queries are now core.Attachments and core.AttachmentsGroupedByParentType
  • Removed the temporary attachment hashing task and its metrics
  • Fixed two sources of orphaned attachments: unregistering a file directory left its attachments behind, and attachments in a folder's default file root were always reported as orphans
  • A follow-up upgrade step reruns the parent type backfill, so default file root attachments on databases that upgraded earlier get their type instead of showing as orphans
  • The upgrade gives no pointer to legacy attachments that have no name, leaving them to the cleanup task, and renames PostgreSQL 18 constraints so upgraded databases match fresh installs
  • The cleanup task reports real database errors instead of treating every failure as a lost race
  • Database migration copies only each attachment type's own pointers, so types that share container parents aren't copied twice
  • Large IN clauses against the migration source database no longer reuse temp tables created in the target database
  • The orphan check also reports attachments whose container doesn't match their parent's

Tested by upgrading a clone of a development database and a 26.11 database, and by a fresh install: the attachment, notebook, and workflow junit tests pass, every pointer has a known parent type, and no orphans or container mismatches are reported. On TeamCity, every suite this branch triggers passes, including upgrade validation from 25.7 through 26.11; Biologics ELN's two failures also occur on develop.

Every attachment now gets a pointer, new uploads are deduplicated by hash, and core.Documents becomes core.Attachments with core.AttachmentPointers alongside it.
@labkey-adam labkey-adam changed the title Kanban 2228: Route all attachments through core.AttachmentPointers Kanban 2292: Route all attachments through core.AttachmentPointers Nov 24, 2026
…rrent adds

Migration copies each type's pointers by ParentType and filters look-and-feel files on Name; the backfill runs FileSystem last on unlabeled rows and reruns in 26.016; concurrent same-name adds raise DuplicateFilenameException.
copyAttachments now checks for duplicate names and audits each copy, like copyAttachment, which now delegates to the shared path.
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.

2 participants