[DRIVERS-547] Causal Consistency Examples for the Manual Created: 25/Jul/18  Updated: 02/Mar/21

Status: Implementing
Project: Drivers
Component/s: Docs Examples
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Kay Kim (Inactive) Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on NODE-1615 Causal Consistency Examples for the M... Backlog
depends on CDRIVER-2790 Causal Consistency Examples for the M... Closed
depends on CSHARP-2351 Causal Consistency Examples for the M... Closed
depends on CXX-1630 Causal Consistency Examples for the M... Closed
depends on GODRIVER-517 Causal Consistency Examples for the M... Closed
depends on JAVA-2921 Causal Consistency Examples for the M... Closed
depends on MOTOR-265 Causal Consistency Examples for the M... Closed
depends on PYTHON-1623 Causal Consistency Examples for the M... Closed
depends on RUBY-1429 Causal Consistency Examples for the M... Backlog
depends on PHPLIB-382 Causal Consistency Examples for the M... Closed
Related
related to DOCS-11882 New examples for causally consistent... Closed
Driver Compliance:
Key Status/Resolution FixVersion
PHPLIB-382 Fixed
SWIFT-190 Fixed 0.2.0
NODE-1615 Backlog
PYTHON-1623 Fixed 3.8
CSHARP-2351 Fixed
PERL-986 Fixed 2.1.0
RUBY-1429 Backlog
JAVA-2921 Fixed
CXX-1630 Fixed 3.7.0, 3.7.0-beta1
MOTOR-265 Fixed 2.1
GODRIVER-517 Done
CDRIVER-2790 Fixed 1.14.0

 Description   

Hi –
could we get the following causal consistency examples for the various drivers?
I mocked up the template in python

 
   # Start Causal Consistency Example 1
 
    with client.start_session(causal_consistency=True) as s1:
        current_date = datetime.datetime.today()
        items = client.get_database('test', 
                                    read_concern=ReadConcern("majority"),
                                    write_concern=WriteConcern(w='majority', wtimeout=1000)).items
        items.update_one({'sku': "111", 'end': None }, {'$set': {'end': current_date}}, session=s1)
        items.insert_one({'sku': "nuts-111", 'name': "Pecans", 'start': current_date}, session=s1)
 
   # End Causal Consistency Example 1
 
   # Start Causal Consistency Example 2
 
    with client.start_session(causal_consistency=True) as s2:
        s2.advance_cluster_time(s1.cluster_time)
        s2.advance_operation_time(s1.operation_time)
 
        items = client.get_database('test', read_preference=ReadPreference.SECONDARY,
                                    read_concern=ReadConcern("majority"),
                                    write_concern=WriteConcern(w='majority', wtimeout=1000)).items
        for item in items.find({'end': None}, session=s2):
            print(item)
 
   # End Causal Consistency Example 2



 Comments   
Comment by Kay Kim (Inactive) [ 13/Aug/18 ]

Apologies prashant.mital derick – but could we tweak the examples to explicitly state the read concern majority and write concern majority? We don't guarantee causal consistency unless people use both read concern majority and write concern majority, so it's been requested that we explicitly show the read/write concern used instead of only blurbing on the docs to use them.

I've tweaked the examples in this ticket where we specify the read/write concern at the database level (although I suppose we could have set at collection level – heh, too bad we can't set at session level).

cc: rathi.gnanasekaran, behackett

Comment by Derick Rethans [ 07/Aug/18 ]

I've added the examples to the PHP documentation tests file. I would recommend to change the $currentDate/datetime.datetime.today() combination to both use datetime.datetime.today() assigned (once) to a variable, previous to their use in the update_one/insert_one, as the time on the server $currentDate and on the client datetime.datetime.today() could differ due to clock skew.

Generated at Thu Feb 08 08:21:47 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.