Skip to content

Commit 0da2115

Browse files
REALMC-8848: upgrade to latest go driver release (#4)
* REALMC-5872 merging topology changes to v1.4.1 driver (#1) * Update version to v1.3.1+prerelease * Change w value for unsatisfiable write concern in tests (mongodb#301) - Addresses test failures that started after by SERVER-45920 * GODRIVER-895 check if strLength is 0 in ReadCodeWithScope (mongodb#311) * GODRIVER-1487 fix adding UnknownTransactionCommitResult (mongodb#307) * GODRIVER-1488 turn off DecodeDeepZeroInline for mgocompat.Registry (mongodb#312) * Fix primitive.Regex Equal method (mongodb#318) * GODRIVER-1507 Correctly pass URI to topology (mongodb#320) * Update version to 1.3.1 * Update version to v1.3.2+prerelease * GODRIVER-1522 Ignore read preference for aggregations with output stages (mongodb#327) * GODRIVER-1520 Fix panics for lone scope (mongodb#331) * GODRIVER-1532 Remove check when decoding invalid UTF-8 strings (mongodb#333) * Fix typo in objectid.go (mongodb#335) * GODRIVER-1502 Fix variable shadowing in parsing (mongodb#332) * GODRIVER-1506 Fix error checking for invalid extjson timestamp values (mongodb#337) * GODRIVER-1504 Restrict top-level keys from being parsed as extjson (mongodb#340) * GODRIVER-1513 Disallow escaped single quotes in extjson keys (mongodb#342) * GODRIVER-1535 Fix session IDs batching in Disconnect * GODRIVER-1540 fix deadlock in connection (mongodb#348) * GODRIVER-1549 Select all servers when an empty tag set is given (mongodb#352) * GODRIVER-1431 Add explicit encryption examples (mongodb#350) * Update version to v1.3.2 * STITCH-4296: Export contextWithSession * STITCH-4296: Export sessionFromContext * STITCH-4680 - expose topology consistency * STITCH-4841: Add FullDocumentBeforeChange option to Mongo-go-driver * GODRIVER-672 Change session IDs to be stored as bson.Raw (mongodb#339) (cherry picked from commit d080bd0) * do not leak cancelConnectContext * REALMC-5872 renaming NewSessionContext to ContextWithSession * REALMC-5872 adding back size check in pool test * REALMC-5872 removing unused IsConsistent topology function and renaming changed vars Co-authored-by: Divjot Arora <[email protected]> Co-authored-by: iwysiu <[email protected]> Co-authored-by: mengskysama <[email protected]> Co-authored-by: Luca(Wei) Chen <[email protected]> Co-authored-by: Haley Owen <[email protected]> Co-authored-by: Eric Daniels <[email protected]> Co-authored-by: Tyler Kaye <[email protected]> Co-authored-by: Jonathan Reams <[email protected]> Co-authored-by: mike o'brien <[email protected]> (cherry picked from commit c59bda0) * REALMC-6991: add topology check Co-authored-by: Kush Patel <[email protected]>
1 parent 2f0d7d1 commit 0da2115

File tree

5 files changed

+85
-0
lines changed

5 files changed

+85
-0
lines changed

mongo/change_stream.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,14 @@ func (cs *ChangeStream) createPipelineOptionsDoc() bsoncore.Document {
362362
plDoc = bsoncore.AppendStringElement(plDoc, "fullDocument", string(*cs.options.FullDocument))
363363
}
364364

365+
if cs.options.FullDocumentBeforeChange != nil {
366+
plDoc = bsoncore.AppendStringElement(
367+
plDoc,
368+
"fullDocumentBeforeChange",
369+
string(*cs.options.FullDocumentBeforeChange),
370+
)
371+
}
372+
365373
if cs.options.ResumeAfter != nil {
366374
var raDoc bsoncore.Document
367375
raDoc, cs.err = transformBsoncoreDocument(cs.registry, cs.options.ResumeAfter, true, "resumeAfter")

mongo/client.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,3 +933,13 @@ func (c *Client) createBaseCursorOptions() driver.CursorOptions {
933933
Crypt: c.cryptFLE,
934934
}
935935
}
936+
937+
// IsTopologyConsistent returns false when we have a replica set that claims to
938+
// have no primary but there exists a primary with all other nodes as secondaries. This
939+
// specifically works around HELP-13825.
940+
func (c *Client) IsTopologyConsistent() bool {
941+
if topo, ok := c.deployment.(*topology.Topology); ok {
942+
return topo.IsConsistent()
943+
}
944+
return true
945+
}

mongo/options/changestreamoptions.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ type ChangeStreamOptions struct {
2727
// the updated document will not be included in the change notification.
2828
FullDocument *FullDocument
2929

30+
// When set to ‘whenAvailable’ or ‘required’ will have both the delta and the full document before the change was applied
31+
FullDocumentBeforeChange *FullDocumentBeforeChange
32+
3033
// The maximum amount of time that the server should wait for new documents to satisfy a tailable cursor query.
3134
MaxAwaitTime *time.Duration
3235

@@ -79,6 +82,12 @@ func (cso *ChangeStreamOptions) SetMaxAwaitTime(d time.Duration) *ChangeStreamOp
7982
return cso
8083
}
8184

85+
// SetFullDocumentBeforeChange sets the value for the FullDocumentBeforeChange field.
86+
func (cso *ChangeStreamOptions) SetFullDocumentBeforeChange(fdbc FullDocumentBeforeChange) *ChangeStreamOptions {
87+
cso.FullDocumentBeforeChange = &fdbc
88+
return cso
89+
}
90+
8291
// SetResumeAfter sets the value for the ResumeAfter field.
8392
func (cso *ChangeStreamOptions) SetResumeAfter(rt interface{}) *ChangeStreamOptions {
8493
cso.ResumeAfter = rt
@@ -114,6 +123,9 @@ func MergeChangeStreamOptions(opts ...*ChangeStreamOptions) *ChangeStreamOptions
114123
if cso.FullDocument != nil {
115124
csOpts.FullDocument = cso.FullDocument
116125
}
126+
if cso.FullDocumentBeforeChange != nil {
127+
csOpts.FullDocumentBeforeChange = cso.FullDocumentBeforeChange
128+
}
117129
if cso.MaxAwaitTime != nil {
118130
csOpts.MaxAwaitTime = cso.MaxAwaitTime
119131
}

mongo/options/mongooptions.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,23 @@ const (
101101
UpdateLookup FullDocument = "updateLookup"
102102
)
103103

104+
// FullDocumentBeforeChange specifies whether a change stream should include a copy of the entire document that was changed from
105+
// the time at which the update is applied
106+
type FullDocumentBeforeChange string
107+
108+
const (
109+
// Default / off does not include a document copy
110+
FullDocumentBeforeChangeOff FullDocumentBeforeChange = "off"
111+
112+
// whenAvailable includes a delta describing the changes to the document and a copy of the entire document that
113+
// was changed when it is available
114+
FullDocumentBeforeChangeWhenAvailable FullDocumentBeforeChange = "whenAvailable"
115+
116+
// required includes a delta describing the changes to the document and a copy of the entire document that
117+
// was changed
118+
FullDocumentBeforeChangeRequired FullDocumentBeforeChange = "required"
119+
)
120+
104121
// ArrayFilters is used to hold filters for the array filters CRUD option. If a registry is nil, bson.DefaultRegistry
105122
// will be used when converting the filter interfaces to BSON.
106123
type ArrayFilters struct {

x/mongo/driver/topology/topology.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,3 +770,41 @@ func (t *Topology) publishTopologyClosedEvent() {
770770
t.cfg.serverMonitor.TopologyClosed(topologyClosed)
771771
}
772772
}
773+
774+
// isTopologyConsistent returns false when we have a replica set that claims to
775+
// have no primary but there exists a primary with all other nodes as secondaries. This
776+
// specifically works around HELP-13825.
777+
func (t *Topology) IsConsistent() bool {
778+
desc := t.Description()
779+
780+
if desc.Kind != description.ReplicaSetNoPrimary {
781+
return true
782+
}
783+
784+
t.serversLock.Lock()
785+
serversCopy := make([]*Server, 0, len(t.servers))
786+
for _, s := range t.servers {
787+
serversCopy = append(serversCopy, s)
788+
}
789+
t.serversLock.Unlock()
790+
791+
if len(serversCopy) == 0 || len(serversCopy) == 1 {
792+
return true
793+
}
794+
var foundPrimary bool
795+
for _, server := range serversCopy {
796+
serverDesc := server.Description()
797+
switch serverDesc.Kind {
798+
case description.RSPrimary:
799+
if foundPrimary {
800+
return true
801+
}
802+
foundPrimary = true
803+
case description.RSSecondary:
804+
default:
805+
return true
806+
}
807+
}
808+
809+
return !foundPrimary
810+
}

0 commit comments

Comments
 (0)