Skip to content

Commit d1a2624

Browse files
committed
CBG-4782: new rev tree property for ISGR replications
1 parent 6396718 commit d1a2624

File tree

5 files changed

+47
-4
lines changed

5 files changed

+47
-4
lines changed

db/active_replicator.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ func connect(arc *activeReplicatorCommon, idSuffix string) (blipSender *blip.Sen
258258
return nil, nil, err
259259
}
260260

261+
// set client type to SGW on active peer
262+
bsc.SetClientType(BLIPClientTypeSGR2)
263+
261264
// set active subprotocol after handshake
262265
err = bsc.SetActiveCBMobileSubprotocol(blipContext.ActiveSubprotocol())
263266
if err != nil {

db/blip.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func defaultBlipLogger(ctx context.Context) blip.LogFn {
8484
}
8585

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

9090
// TODO: Assert? db.SequenceID.MarshalJSON can never error
@@ -95,6 +95,10 @@ func blipRevMessageProperties(revisionHistory []string, deleted bool, seq Sequen
9595
properties[RevMessageHistory] = strings.Join(revisionHistory, ",")
9696
}
9797

98+
if len(revTreeProperty) > 0 {
99+
properties[RevMessageTreeHistory] = strings.Join(revTreeProperty, ",")
100+
}
101+
98102
if deleted {
99103
properties[RevMessageDeleted] = "1"
100104
}

db/blip_handler.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,12 +908,18 @@ func (bsc *BlipSyncContext) sendRevAsDelta(ctx context.Context, sender *blip.Sen
908908

909909
if redactedRev != nil {
910910
var history []string
911+
var revTreeProperty []string
911912
if !bsc.useHLV() {
912913
history = toHistory(redactedRev.History, knownRevs, maxHistory)
913914
} else {
914915
history = append(history, redactedRev.hlvHistory)
915916
}
916-
properties := blipRevMessageProperties(history, redactedRev.Deleted, seq, "")
917+
if bsc.sendRevTreeProperty() {
918+
revTreeProperty = append(revTreeProperty, redactedRev.RevID)
919+
revTreeProperty = append(revTreeProperty, toHistory(redactedRev.History, knownRevs, maxHistory)...)
920+
}
921+
922+
properties := blipRevMessageProperties(history, redactedRev.Deleted, seq, "", revTreeProperty)
917923
return bsc.sendRevisionWithProperties(ctx, sender, docID, revID, collectionIdx, redactedRev.BodyBytes, nil, properties, seq, nil)
918924
}
919925

@@ -1078,6 +1084,9 @@ func (bh *blipHandler) processRev(rq *blip.Message, stats *processRevStats) (err
10781084
var incomingHLV *HybridLogicalVector
10791085
// Build history/HLV
10801086
var legacyRevList []string
1087+
// we can probably use legacyRevList instead of this but to avoid hooking this up to write code we will use
1088+
// separate list for now, pending CBG-4790
1089+
var revTreeProperty []string
10811090
changeIsVector := strings.Contains(rev, "@")
10821091
if !bh.useHLV() || !changeIsVector {
10831092
newDoc.RevID = rev
@@ -1103,6 +1112,14 @@ func (bh *blipHandler) processRev(rq *blip.Message, stats *processRevStats) (err
11031112
newDoc.HLV = incomingHLV
11041113
}
11051114

1115+
// if the client is SGW and there are no legacy revs being sent (i.e. doc is no pre upgraded doc) check the rev tree property
1116+
if bh.clientType == BLIPClientTypeSGR2 && len(legacyRevList) == 0 {
1117+
revTree, ok := rq.Properties[RevMessageTreeHistory]
1118+
if ok {
1119+
revTreeProperty = append(revTreeProperty, strings.Split(revTree, ",")...)
1120+
}
1121+
}
1122+
11061123
newDoc.UpdateBodyBytes(bodyBytes)
11071124

11081125
injectedAttachmentsForDelta := false

db/blip_sync_context.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,12 +605,17 @@ func (bsc *BlipSyncContext) setUseDeltas(clientCanUseDeltas bool) {
605605
func (bsc *BlipSyncContext) sendDelta(ctx context.Context, sender *blip.Sender, docID string, collectionIdx *int, deltaSrcRevID string, revDelta *RevisionDelta, seq SequenceID, resendFullRevisionFunc func() error) error {
606606

607607
var history []string
608+
var revTreeProperty []string
608609
if bsc.useHLV() {
609610
history = append(history, revDelta.HlvHistory)
610611
} else {
611612
history = revDelta.RevisionHistory
612613
}
613-
properties := blipRevMessageProperties(history, revDelta.ToDeleted, seq, "")
614+
if bsc.sendRevTreeProperty() {
615+
revTreeProperty = append(revTreeProperty, revDelta.ToRevID)
616+
revTreeProperty = append(revTreeProperty, revDelta.RevisionHistory...)
617+
}
618+
properties := blipRevMessageProperties(history, revDelta.ToDeleted, seq, "", revTreeProperty)
614619
properties[RevMessageDeltaSrc] = deltaSrcRevID
615620

616621
base.DebugfCtx(ctx, base.KeySync, "Sending rev %q %s as delta. DeltaSrc:%s", base.UD(docID), revDelta.ToRevID, deltaSrcRevID)
@@ -768,14 +773,20 @@ func (bsc *BlipSyncContext) sendRevision(ctx context.Context, sender *blip.Sende
768773
history = append(history, docRev.hlvHistory)
769774
}
770775
}
776+
777+
var revTreeHistoryProperty []string
771778
if legacyRev {
772779
// append current revID and rest of rev tree after hlv history
773780
revTreeHistory := toHistory(docRev.History, knownRevs, maxHistory)
774781
history = append(history, docRev.RevID)
775782
history = append(history, revTreeHistory...)
783+
} else if bsc.sendRevTreeProperty() {
784+
// if no legacy revs being sent and we are communicating with SGW client we should send revision history in the rev message
785+
revTreeHistoryProperty = append(revTreeHistoryProperty, docRev.RevID) // we need current rev
786+
revTreeHistoryProperty = append(revTreeHistoryProperty, toHistory(docRev.History, knownRevs, maxHistory)...)
776787
}
777788

778-
properties := blipRevMessageProperties(history, docRev.Deleted, seq, replacedRevID)
789+
properties := blipRevMessageProperties(history, docRev.Deleted, seq, replacedRevID, revTreeHistoryProperty)
779790
if base.LogDebugEnabled(ctx, base.KeySync) {
780791
replacedRevMsg := ""
781792
if replacedRevID != "" {
@@ -851,3 +862,10 @@ func (bsc *BlipSyncContext) reportStats(updateImmediately bool) {
851862
func (bsc *BlipSyncContext) useHLV() bool {
852863
return bsc.activeCBMobileSubprotocol >= CBMobileReplicationV4
853864
}
865+
866+
// sendRevTreeProperty returns true if the rev tree property should be sent in the rev message. That is if we are
867+
// replicating with version vectors and the client we're communicating with is a SGW peer
868+
func (bsc *BlipSyncContext) sendRevTreeProperty() bool {
869+
return bsc.activeCBMobileSubprotocol >= CBMobileReplicationV4 && bsc.clientType == BLIPClientTypeSGR2
870+
}
871+

db/blip_sync_messages.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ const (
7777
RevMessageDeleted = "deleted"
7878
RevMessageSequence = "sequence"
7979
RevMessageHistory = "history"
80+
RevMessageTreeHistory = "revTree"
8081
RevMessageNoConflicts = "noconflicts"
8182
RevMessageDeltaSrc = "deltaSrc"
8283
RevMessageReplacedRev = "replacedRev"

0 commit comments

Comments
 (0)