Skip to content

JAMES-4231 PostgreSQL: Implement PostgresBlobIdUpdater for S3 compaction support - #3216

Open
HesandaLiyanage wants to merge 1 commit into
apache:masterfrom
HesandaLiyanage:postgres-blobid-updater
Open

HesandaLiyanage wants to merge 1 commit into
apache:masterfrom
HesandaLiyanage:postgres-blobid-updater

Conversation

@HesandaLiyanage

@HesandaLiyanage HesandaLiyanage commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

JIRA: https://issues.apache.org/jira/browse/JAMES-4231

Note

Dependency: This PR is branched off master and depends on #3193 for the BlobIdUpdater SPI (server/blob/blob-api). CI compile checks will succeed once #3193 is merged to master.

Proposed Changes

This PR provides PostgreSQL support for S3 Object Compaction by implementing PostgresBlobIdUpdater and binding it in PostgresMailboxModule.

Context & Motivation

In #3193, BlobIdUpdater was introduced to decouple blob storage from database reference updating during S3 object compaction. While Cassandra was implemented initially in #3193 (CassandraBlobIdUpdater), PostgreSQL deployments also require a BlobIdUpdater implementation to support compaction when using PostgreSQL metadata with S3 blob storage.

This change brings PostgreSQL to feature parity:

  • PostgresBlobIdUpdater:
    • Implements BlobIdUpdater and BlobIdUpdater.Factory.
    • Reference Scanning: Scans message (body_blob_id) and attachment (blob_id) tables using keyset paginated queries via PostgresExecutor.executeRowsPaginated.
    • Generation Tracking: Observes all live references and records candidate IDs matching the target generation condition.
    • Atomic Batched Updates: Replaces references in batches of 500 targeting primary keys (message_id UUID and attachment.id) with conditional guards (body_blob_id = oldId / blob_id = oldId).
  • PostgresMailboxModule:
    • Binds BlobIdUpdater.Factory to PostgresBlobIdUpdater.Factory in singleton scope.
  • Tests:
    • PostgresBlobIdUpdaterTest runs against PostgreSQL Testcontainers verifying:
      • Message body blob ID replacement
      • Attachment blob ID replacement
      • Generation predicate filtering
      • Idempotency when replacing non-existent references
@Arsnael

Arsnael commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Hello, some ocmpilation issue reported by the CI:

08:24:41,160 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.14.0:compile (default-compile) on project apache-james-mailbox-postgres: Compilation failure: Compilation failure:
08:24:41,161 [ERROR] /home/jenkins/jenkins-agent/workspace/james_ApacheJames_PR-3216/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/PostgresBlobIdUpdater.java:[38,33] cannot find symbol
08:24:41,161 [ERROR] symbol: class BlobIdUpdater
08:24:41,161 [ERROR] location: package org.apache.james.blob.api
08:24:41,161 [ERROR] /home/jenkins/jenkins-agent/workspace/james_ApacheJames_PR-3216/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/PostgresBlobIdUpdater.java:[47,47] cannot find symbol
08:24:41,161 [ERROR] symbol: class BlobIdUpdater
08:24:41,161 [ERROR] /home/jenkins/jenkins-agent/workspace/james_ApacheJames_PR-3216/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/PostgresBlobIdUpdater.java:[48,57] package BlobIdUpdater does not exist
08:24:41,161 [ERROR] /home/jenkins/jenkins-agent/workspace/james_ApacheJames_PR-3216/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/PostgresBlobIdUpdater.java:[61,21] cannot find symbol
08:24:41,161 [ERROR] symbol: class BlobIdUpdater
08:24:41,161 [ERROR] location: class org.apache.james.mailbox.postgres.mail.PostgresBlobIdUpdater.Factory
08:24:41,161 [ERROR] /home/jenkins/jenkins-agent/workspace/james_ApacheJames_PR-3216/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/PostgresBlobIdUpdater.java:[60,9] method does not override or implement a method from a supertype
08:24:41,161 [ERROR] /home/jenkins/jenkins-agent/workspace/james_ApacheJames_PR-3216/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/PostgresBlobIdUpdater.java:[121,5] method does not override or implement a method from a supertype
08:24:41,161 [ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execut

@HesandaLiyanage

Copy link
Copy Markdown
Contributor Author

Hello, some ocmpilation issue reported by the CI:

08:24:41,160 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.14.0:compile (default-compile) on project apache-james-mailbox-postgres: Compilation failure: Compilation failure: 08:24:41,161 [ERROR] /home/jenkins/jenkins-agent/workspace/james_ApacheJames_PR-3216/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/PostgresBlobIdUpdater.java:[38,33] cannot find symbol 08:24:41,161 [ERROR] symbol: class BlobIdUpdater 08:24:41,161 [ERROR] location: package org.apache.james.blob.api 08:24:41,161 [ERROR] /home/jenkins/jenkins-agent/workspace/james_ApacheJames_PR-3216/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/PostgresBlobIdUpdater.java:[47,47] cannot find symbol 08:24:41,161 [ERROR] symbol: class BlobIdUpdater 08:24:41,161 [ERROR] /home/jenkins/jenkins-agent/workspace/james_ApacheJames_PR-3216/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/PostgresBlobIdUpdater.java:[48,57] package BlobIdUpdater does not exist 08:24:41,161 [ERROR] /home/jenkins/jenkins-agent/workspace/james_ApacheJames_PR-3216/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/PostgresBlobIdUpdater.java:[61,21] cannot find symbol 08:24:41,161 [ERROR] symbol: class BlobIdUpdater 08:24:41,161 [ERROR] location: class org.apache.james.mailbox.postgres.mail.PostgresBlobIdUpdater.Factory 08:24:41,161 [ERROR] /home/jenkins/jenkins-agent/workspace/james_ApacheJames_PR-3216/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/PostgresBlobIdUpdater.java:[60,9] method does not override or implement a method from a supertype 08:24:41,161 [ERROR] /home/jenkins/jenkins-agent/workspace/james_ApacheJames_PR-3216/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/PostgresBlobIdUpdater.java:[121,5] method does not override or implement a method from a supertype 08:24:41,161 [ERROR] -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execut

Yes there is a dependency issue
Dependency: This PR is branched off master and depends on #3193 for the BlobIdUpdater SPI (server/blob/blob-api). CI compile checks will succeed once #3193 is merged to master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants