Repository navigation
Conversation
Redocly previews |
|
Droid finished @RIT3shSapata's task —— View job Review summaryThis PR's overall approach (mutual exclusivity between seq and channels, plus tests and OpenAPI updates) looks solid. The main correctness edge case is that compaction can currently delete Channels-map entries with Seq==0, even though those entries are treated as current memberships by getCurrentChannels. |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Channel matching introduces quadratic processing for large documents and channel lists.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Adds channel-name-based document channel-history compaction alongside sequence-based compaction.
Changes:
- Adds mutually exclusive
seqandchannelsrequest modes. - Implements channel-name filtering while preserving active memberships.
- Updates API documentation and parameterizes compaction tests.
| File | Description |
|---|---|
db/crud.go |
Implements channel-based compaction. |
rest/doc_api.go |
Validates and handles the new request mode. |
rest/api_test.go |
Tests both compaction modes. |
rest/doc_api_test.go |
Tests request validation. |
docs/api/paths/admin/keyspace-_channel_history-compact.yaml |
Documents the new API option. |
db/import_test.go |
Updates the compaction call signature. |
db/hybrid_logical_vector_test.go |
Updates the compaction call signature. |
db/attachment_test.go |
Updates the compaction call signature. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| return del | ||
| }) | ||
|
|
||
| for chanName, chanEntry := range doc.SyncData.Channels { |
There was a problem hiding this comment.
[P1] Avoid compacting Channels entries with Seq==0
SyncData.getCurrentChannels treats both nil removals and non-nil removals with Seq==0 as current channel memberships. CompactDocChannelHistory currently deletes non-nil entries whenever chanEntry.Seq <= seq (seq mode) or when the channel name is listed (channels mode), which can drop a channel that is still considered current and change the effective channel set.
Consider skipping deletions for chanEntry.Seq==0 (consistent with GetDocChannelHistory, which only reports removals where Seq != 0), for example:
| for chanName, chanEntry := range doc.SyncData.Channels { | |
| var del bool | |
| if seq != 0 { | |
| del = chanEntry.Seq != 0 && chanEntry.Seq <= seq | |
| } else if len(channels) > 0 { | |
| del = chanEntry.Seq != 0 && slices.Contains(channels, chanName) | |
| } |
There was a problem hiding this comment.
Is this comment accurate? That without the check on chanEntry.Seq != 0, this has the potential to remove active channels as well (which we don't want).
Please review and add a test for coverage of this case if we don't already have one.
There was a problem hiding this comment.
So the thing is chanEntry.Seq can never be set to 0? I don't see in any scenario a channel removal will have an entry of 0. Because if a channel is assigned then it will have a non zero value, then on removal I don't see SGW assigning a sequence of 0. The condition that I added in the function that droid pointed out is more of a defensive check.
This will not remove active channels because active channels usually have chanEntry is of type ChannelRemoval, and its nil for active channels.
I modified the test "multiple channels with mixed history" to test this scenario out better. Please let me know if this is okay
|
|
||
| type CompactDocChannelHistoryRequest struct { | ||
| Seq uint64 `json:"seq"` | ||
| Seq uint64 `json:"seq"` |
There was a problem hiding this comment.
I realize it was the previous handling, but why didn't we allow setting seq=0 for users that wanted to delete all channel history? They needed to use seq=1 for that?
There was a problem hiding this comment.
Since I've set the type of seq to uint64, there is no definitive way to distinguish between no seq value being passed and setting the seq value to 0. Another thing is while implementing this initially, there was no discussion of completely deleting the channel history. All the requirements pointed to removing history before a certain sequence.
There was a problem hiding this comment.
Oh that's my mistake - I'd forgotten that this API compacts everything older than a given sequence, not everything newer. There isn't really a use case for setting 0, then.
d3f23fb to
3646cc8
Compare
|
|
||
| type CompactDocChannelHistoryRequest struct { | ||
| Seq uint64 `json:"seq"` | ||
| Seq uint64 `json:"seq"` |
There was a problem hiding this comment.
Oh that's my mistake - I'd forgotten that this API compacts everything older than a given sequence, not everything newer. There isn't really a use case for setting 0, then.
| return del | ||
| }) | ||
|
|
||
| for chanName, chanEntry := range doc.SyncData.Channels { |
There was a problem hiding this comment.
Is this comment accurate? That without the check on chanEntry.Seq != 0, this has the potential to remove active channels as well (which we don't want).
Please review and add a test for coverage of this case if we don't already have one.
- compact channel history with channel names - parameterize the existing tests to test for channel name based compaction - update the REST API Endpoint - update the API spec - update inline comments and documentation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- change channels to compact from set to a map - modify test case
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
8360999 to
f06181b
Compare

CBG-5900
Add a
channelsoption to the document channel history compact endpoint,POST /{keyspace}/_channel_history/{docid}/compact. You can now name the channels to compact. Before, you could only give a sequence number.channelsarray toCompactDocChannelHistoryRequest. A request must set exactly one ofseqorchannels.channelsarray counts as not set.channelsparameter toCompactDocChannelHistory. Withseqset to zero, the function removes the history of the named channels.channelsmode, SG removes every history entry for the named channels, even if the document is still in one of them. The document's current channel membership does not change.oneOfrule, and the 400 description.Pre-review checklist
base.UD(docID),base.MD(dbName))docs/apiDependencies (if applicable)
Integration Tests