Skip to content

Commit babaaf6

Browse files
committed
Merge branch 'main' into CBG-4411
2 parents e38a8fc + ec13943 commit babaaf6

16 files changed

+188
-91
lines changed

db/blip.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ package db
1212

1313
import (
1414
"context"
15+
"fmt"
1516
"regexp"
1617
"strings"
1718

@@ -84,11 +85,13 @@ func defaultBlipLogger(ctx context.Context) blip.LogFn {
8485
}
8586

8687
// blipRevMessageProperties returns a set of BLIP message properties for the given parameters.
87-
func blipRevMessageProperties(revisionHistory []string, deleted bool, seq SequenceID, replacedRevID string, revTreeProperty []string) blip.Properties {
88+
func blipRevMessageProperties(revisionHistory []string, deleted bool, seq SequenceID, replacedRevID string, revTreeProperty []string) (blip.Properties, error) {
8889
properties := make(blip.Properties)
8990

90-
// TODO: Assert? db.SequenceID.MarshalJSON can never error
91-
seqJSON, _ := base.JSONMarshal(seq)
91+
seqJSON, err := base.JSONMarshal(seq)
92+
if err != nil {
93+
return nil, fmt.Errorf("could not marshal sequence %v: %v", seq, err)
94+
}
9295
properties[RevMessageSequence] = string(seqJSON)
9396

9497
if len(revisionHistory) > 0 {
@@ -107,7 +110,7 @@ func blipRevMessageProperties(revisionHistory []string, deleted bool, seq Sequen
107110
properties[RevMessageReplacedRev] = replacedRevID
108111
}
109112

110-
return properties
113+
return properties, nil
111114
}
112115

113116
// Returns true if this attachment is worth trying to compress.

db/blip_handler.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,10 @@ func (bsc *BlipSyncContext) sendRevAsDelta(ctx context.Context, sender *blip.Sen
937937
revTreeProperty = append(revTreeProperty, toHistory(redactedRev.History, knownRevs, maxHistory)...)
938938
}
939939

940-
properties := blipRevMessageProperties(history, redactedRev.Deleted, seq, "", revTreeProperty)
940+
properties, err := blipRevMessageProperties(history, redactedRev.Deleted, seq, "", revTreeProperty)
941+
if err != nil {
942+
return err
943+
}
941944
return bsc.sendRevisionWithProperties(ctx, sender, docID, revID, collectionIdx, redactedRev.BodyBytes, nil, properties, seq, nil)
942945
}
943946

db/blip_sync_context.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,10 @@ func (bsc *BlipSyncContext) sendDelta(ctx context.Context, sender *blip.Sender,
597597
revTreeProperty = append(revTreeProperty, revDelta.ToRevID)
598598
revTreeProperty = append(revTreeProperty, revDelta.RevisionHistory...)
599599
}
600-
properties := blipRevMessageProperties(history, revDelta.ToDeleted, seq, "", revTreeProperty)
600+
properties, err := blipRevMessageProperties(history, revDelta.ToDeleted, seq, "", revTreeProperty)
601+
if err != nil {
602+
return err
603+
}
601604
properties[RevMessageDeltaSrc] = deltaSrcRevID
602605

603606
if bsc.useHLV() {
@@ -629,7 +632,10 @@ func (bsc *BlipSyncContext) sendNoRev(sender *blip.Sender, docID, revID string,
629632
if bsc.activeCBMobileSubprotocol <= CBMobileReplicationV2 && bsc.clientType == BLIPClientTypeSGR2 {
630633
noRevRq.SetSeq(seq)
631634
} else {
632-
noRevRq.SetSequence(seq)
635+
err := noRevRq.SetSequence(seq)
636+
if err != nil {
637+
return err
638+
}
633639
}
634640

635641
status, reason := base.ErrorAsHTTPStatus(err)
@@ -785,7 +791,10 @@ func (bsc *BlipSyncContext) sendRevision(ctx context.Context, sender *blip.Sende
785791
revTreeHistoryProperty = append(revTreeHistoryProperty, toHistory(docRev.History, knownRevs, maxHistory)...)
786792
}
787793

788-
properties := blipRevMessageProperties(history, docRev.Deleted, seq, replacedRevID, revTreeHistoryProperty)
794+
properties, err := blipRevMessageProperties(history, docRev.Deleted, seq, replacedRevID, revTreeHistoryProperty)
795+
if err != nil {
796+
return err
797+
}
789798
if base.LogDebugEnabled(ctx, base.KeySync) {
790799
replacedRevMsg := ""
791800
if replacedRevID != "" {

db/blip_sync_messages.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,13 @@ func (nrm *noRevMessage) SetSeq(seq SequenceID) {
508508
nrm.Properties[NorevMessageSeq] = seq.String()
509509
}
510510

511-
func (nrm *noRevMessage) SetSequence(sequence SequenceID) {
512-
nrm.Properties[NorevMessageSequence] = sequence.String()
511+
func (nrm *noRevMessage) SetSequence(sequence SequenceID) error {
512+
s, err := base.JSONMarshal(sequence)
513+
if err != nil {
514+
return err
515+
}
516+
nrm.Properties[NorevMessageSequence] = string(s)
517+
return nil
513518
}
514519

515520
func (nrm *noRevMessage) SetReason(reason string) {

db/blip_sync_messages_test.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Copyright 2025-Present Couchbase, Inc.
2+
//
3+
// Use of this software is governed by the Business Source License included
4+
// in the file licenses/BSL-Couchbase.txt. As of the Change Date specified
5+
// in that file, in accordance with the Business Source License, use of this
6+
// software will be governed by the Apache License, Version 2.0, included in
7+
// the file licenses/APL2.txt.
8+
9+
package db
10+
11+
import (
12+
"fmt"
13+
"testing"
14+
15+
"github.com/couchbase/sync_gateway/base"
16+
"github.com/stretchr/testify/require"
17+
)
18+
19+
func TestBlipSequenceProperty(t *testing.T) {
20+
testCases := []struct {
21+
name string
22+
seq SequenceID
23+
expectedString string
24+
expectedISGRV2String string
25+
}{
26+
{
27+
name: "Simple SequenceID",
28+
seq: SequenceID{Seq: 1},
29+
expectedString: `1`,
30+
expectedISGRV2String: `1`,
31+
},
32+
{
33+
name: "compound sequenceID",
34+
seq: SequenceID{LowSeq: 5, TriggeredBy: 10, Seq: 15},
35+
expectedString: `"5:10:15"`,
36+
expectedISGRV2String: `5:10:15`,
37+
},
38+
{
39+
name: "TriggeredBy only",
40+
seq: SequenceID{TriggeredBy: 20, Seq: 25},
41+
expectedString: `"20:25"`,
42+
expectedISGRV2String: `20:25`,
43+
},
44+
{
45+
name: "LowSeq and Seq",
46+
seq: SequenceID{LowSeq: 30, Seq: 35},
47+
expectedString: `"30::35"`,
48+
expectedISGRV2String: `30::35`,
49+
},
50+
}
51+
for _, tc := range testCases {
52+
t.Run(tc.name, func(t *testing.T) {
53+
// test norev sequence property
54+
norevMessage := NewNoRevMessage()
55+
require.NoError(t, norevMessage.SetSequence(tc.seq))
56+
require.Equal(t, tc.expectedString, norevMessage.Properties[NorevMessageSequence])
57+
// this string is only used by ISGR when CB_Mobile < 3
58+
norevMessage.SetSeq(tc.seq)
59+
require.Equal(t, tc.expectedISGRV2String, norevMessage.Properties[NorevMessageSeq])
60+
61+
// test rev sequence property
62+
properties, err := blipRevMessageProperties(nil, false, tc.seq, "", nil)
63+
require.NoError(t, err)
64+
require.Equal(t, tc.expectedString, properties[RevMessageSequence])
65+
changeEntry := &ChangeEntry{
66+
Seq: tc.seq,
67+
ID: "docID",
68+
}
69+
// changes message format
70+
ctx := base.TestCtx(t)
71+
bh := &blipHandler{
72+
loggingCtx: ctx,
73+
BlipSyncContext: &BlipSyncContext{},
74+
}
75+
changeRow := bh.buildChangesRow(changeEntry, ChangeByVersionType{"rev": "1-abc"})
76+
rowString, err := base.JSONMarshal(changeRow)
77+
require.NoError(t, err)
78+
require.Equal(t, fmt.Sprintf(`[%s,"docID","1-abc"]`, tc.expectedString), string(rowString))
79+
})
80+
}
81+
82+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ require (
3737
golang.org/x/crypto v0.45.0
3838
golang.org/x/exp v0.0.0-20250606033433-dcc06ee1d476
3939
golang.org/x/net v0.47.0
40-
golang.org/x/oauth2 v0.33.0
40+
golang.org/x/oauth2 v0.34.0
4141
gopkg.in/natefinch/lumberjack.v2 v2.2.1
4242
)
4343

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY
270270
golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY=
271271
golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU=
272272
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
273-
golang.org/x/oauth2 v0.33.0 h1:4Q+qn+E5z8gPRJfmRy7C2gGG3T4jIprK6aSYgTXGRpo=
274-
golang.org/x/oauth2 v0.33.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA=
273+
golang.org/x/oauth2 v0.34.0 h1:hqK/t4AKgbqWkdkcAeI8XLmbK+4m4G5YeQRrmiotGlw=
274+
golang.org/x/oauth2 v0.34.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA=
275275
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
276276
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
277277
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=

manifest/3.3.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ licenses/APL2.txt.
1818
<!-- Build Scripts (required on CI servers) -->
1919
<project name="product-texts" path="product-texts" remote="couchbase"/>
2020
<project name="build" path="cbbuild" remote="couchbase" revision="b1dc2359603ab411ce0788854ea879ce804c9055">
21-
<annotation name="VERSION" value="3.3.2" keep="true"/>
21+
<annotation name="VERSION" value="3.3.2.1" keep="true"/>
2222
<annotation name="BLD_NUM" value="@BLD_NUM@" keep="true"/>
2323
<annotation name="RELEASE" value="@RELEASE@" keep="true"/>
2424
</project>
2525

2626

2727
<!-- Sync Gateway -->
28-
<project name="sync_gateway" path="sync_gateway" remote="couchbase" revision="release/3.3.2"/>
28+
<project name="sync_gateway" path="sync_gateway" remote="couchbase" revision="release/3.3.2.1"/>
2929

3030
</manifest>

manifest/3.3/3.3.2.xml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
Copyright 2016-Present Couchbase, Inc.
5+
6+
Use of this software is governed by the Business Source License included in
7+
the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that
8+
file, in accordance with the Business Source License, use of this software will
9+
be governed by the Apache License, Version 2.0, included in the file
10+
licenses/APL2.txt.
11+
-->
12+
13+
<manifest>
14+
15+
<remote fetch="https://github.com/couchbase/" name="couchbase"/>
16+
<default remote="couchbase" revision="master"/>
17+
18+
<!-- Build Scripts (required on CI servers) -->
19+
<project name="product-texts" path="product-texts" remote="couchbase"/>
20+
<project name="build" path="cbbuild" remote="couchbase" revision="b1dc2359603ab411ce0788854ea879ce804c9055">
21+
<annotation name="VERSION" value="3.3.2" keep="true"/>
22+
<annotation name="BLD_NUM" value="@BLD_NUM@" keep="true"/>
23+
<annotation name="RELEASE" value="@RELEASE@" keep="true"/>
24+
</project>
25+
26+
27+
<!-- Sync Gateway -->
28+
<project name="sync_gateway" path="sync_gateway" remote="couchbase" revision="9e24bf6eaf4ee890752f60b38ddf475772afd8e5"/>
29+
30+
</manifest>

manifest/product-config.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,8 +722,8 @@
722722
"go_version": "1.24.4",
723723
"interval": 120,
724724
"production": true,
725-
"release": "3.3.2",
726-
"release_name": "Couchbase Sync Gateway 3.3.2",
725+
"release": "3.3.2.1",
726+
"release_name": "Couchbase Sync Gateway 3.3.2.1",
727727
"start_build": 1,
728728
"trigger_blackduck": true
729729
},
@@ -767,6 +767,16 @@
767767
"start_build": 3,
768768
"trigger_blackduck": true
769769
},
770+
"manifest/3.3/3.3.2.xml": {
771+
"do-build": false,
772+
"go_version": "1.24.4",
773+
"interval": 1440,
774+
"production": true,
775+
"release": "3.3.2",
776+
"release_name": "Couchbase Sync Gateway 3.3.2",
777+
"start_build": 3,
778+
"trigger_blackduck": true
779+
},
770780
"manifest/4.0.xml": {
771781
"go_version": "1.24.4",
772782
"interval": 120,

0 commit comments

Comments
 (0)