[3.3.6 Backport] CBG-5393: Document channel history compaction#8334
Conversation
Redocly previews |
There was a problem hiding this comment.
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
GetDocChannelHistoryandCompactDocChannelHistoryonDatabaseCollection, 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. |
| if doc == nil { | ||
| return nil, fmt.Errorf("skipping compaction of document %s, %v ", base.UD(docid), base.ErrNotFound) | ||
| } |
| // 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{ |
| type: object | ||
| additionalProperties: | ||
| type: array | ||
| items: | ||
| type: integer |
| 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. |
| 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 |
| tags: | ||
| - Document | ||
| operationId: post_keyspace-_history-compact |
| description: |- | ||
| Channel history having end sequences earlier than this sequence will be removed from the specified document's metadata. | ||
| type: integer |
| if req.Seq == 0 { | ||
| return base.HTTPErrorf(http.StatusBadRequest, "missing seq") | ||
| } |
adamcfraser
left a comment
There was a problem hiding this comment.
Backport looks good - one comment about unnecessary (?) retrieval of userXattr.
| } | ||
|
|
||
| xattrKeys := []string{base.SyncXattrName, base.MouXattrName} | ||
| userXattrKey := c.UserXattrKey() |
There was a problem hiding this comment.
CompactDocChannelHistory doesn't actually need the user xattr, does it?
There was a problem hiding this comment.
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.
CBG-5393
Describe your PR here...
Pre-review checklist
fmt.Print,log.Print, ...)base.UD(docID),base.MD(dbName))docs/apiDependencies (if applicable)
Integration Tests