Skip to content

[3.3.6 Backport] CBG-5393: Document channel history compaction#8334

Merged
adamcfraser merged 7 commits into
release/3.3.6from
CBG-5393
Jun 8, 2026
Merged

[3.3.6 Backport] CBG-5393: Document channel history compaction#8334
adamcfraser merged 7 commits into
release/3.3.6from
CBG-5393

Conversation

@RIT3shSapata

@RIT3shSapata RIT3shSapata commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

CBG-5393

Describe your PR here...

  • Backport changes for Document channel history compaction

Pre-review checklist

  • Removed debug logging (fmt.Print, log.Print, ...)
  • Logging sensitive data? Make sure it's tagged (e.g. base.UD(docID), base.MD(dbName))
  • Updated relevant information in the API specifications (such as endpoint descriptions, schemas, ...) in docs/api

Dependencies (if applicable)

  • Link upstream PRs
  • Update Go module dependencies when merged

Integration Tests

@RIT3shSapata RIT3shSapata requested a review from adamcfraser June 3, 2026 09:28
Copilot AI review requested due to automatic review settings June 3, 2026 09:28
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown

Redocly previews

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Backports support for inspecting and compacting per-document channel revocation history, including new admin REST endpoints, underlying DB compaction logic, audit logging, OpenAPI documentation, and test coverage.

Changes:

  • Add admin endpoints to fetch a document’s channel revocation history and to compact that history up to a specified sequence.
  • Implement GetDocChannelHistory and CompactDocChannelHistory on DatabaseCollection, including on-demand import handling and xattr updates.
  • Add an audit event for channel-history compaction and document the endpoints in the Admin OpenAPI spec, with accompanying tests.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
rest/routing.go Wires new admin routes for _channel_history GET and /compact POST under keyspace routing.
rest/doc_api.go Implements REST handlers for reading and compacting doc channel history and emits audit events.
rest/audit_test.go Adds audit test coverage for the new compaction audit event.
rest/api_test.go Adds functional tests for channel history retrieval and compaction (collection + REST).
docs/api/paths/admin/keyspace-_channel_history.yaml Documents the new GET endpoint returning channel-to-sequence history.
docs/api/paths/admin/keyspace-_channel_history-compact.yaml Documents the new POST compaction endpoint and response payload.
docs/api/admin.yaml Registers the new admin paths in the Admin OpenAPI root spec.
db/crud.go Adds core channel history collection/compaction logic, including xattr mutation to persist compaction.
base/audit_events.go Introduces AuditIDDocumentChannelHistoryCompact audit event definition.
base/audit_events_fields.go Adds AuditFieldSequence field name for the new audit event payload.

Comment thread db/crud.go
Comment on lines +291 to +293
if doc == nil {
return nil, fmt.Errorf("skipping compaction of document %s, %v ", base.UD(docid), base.ErrNotFound)
}
Comment thread db/crud.go
Comment on lines +339 to +342
// build macro expansion for sync data. This will avoid the update to xattrs causing an extra import event (i.e. sync cas will be == to doc cas)
opts := &sgbucket.MutateInOptions{}
// Only update _sync.cas and _mou.cas if the pre-compaction doc had already been imported by SGW
opts.MacroExpansion = []sgbucket.MacroExpansionSpec{
Comment on lines +36 to +40
type: object
additionalProperties:
type: array
items:
type: integer
Comment on lines +14 to +18
Compacts channel history for a specified document. Channel history older than the specified sequence will be removed.

This endpoint removes all channel entries (for sequences before the specified sequence number where the document left the channel),
effectively cleaning up historical channel membership information while preserving active channels and recent changes.
This can be useful for reducing metadata size for documents that frequently gain and lose access to channels.
Comment on lines +48 to +62
schema:
type: object
additionalProperties:
x-additionalPropertiesName: doc_id
type: array
items:
type: string
description: |-
Array of channel names that were compacted.
description: |-
A array of all the compacted channels
example:
compacted_channels:
- channel1
- channel2
Comment on lines +72 to +74
tags:
- Document
operationId: post_keyspace-_history-compact
Comment on lines +32 to +34
description: |-
Channel history having end sequences earlier than this sequence will be removed from the specified document's metadata.
type: integer
Comment thread rest/doc_api.go
Comment on lines +792 to +794
if req.Seq == 0 {
return base.HTTPErrorf(http.StatusBadRequest, "missing seq")
}

@adamcfraser adamcfraser left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backport looks good - one comment about unnecessary (?) retrieval of userXattr.

Comment thread db/crud.go Outdated
}

xattrKeys := []string{base.SyncXattrName, base.MouXattrName}
userXattrKey := c.UserXattrKey()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CompactDocChannelHistory doesn't actually need the user xattr, does it?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to be consistent with the xattr retrieval function used for convenience on the 4.1 implementation, since that function doesn't exist here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@adamcfraser adamcfraser merged commit 1921b13 into release/3.3.6 Jun 8, 2026
47 checks passed
@adamcfraser adamcfraser deleted the CBG-5393 branch June 8, 2026 16:02
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.

3 participants