Skip to content

NDB: Achieving strong read consistency #338

@blk-josecols

Description

@blk-josecols

I'm trying to achieve Strong Consistency in a query that is not inside a transaction and does not have a parent as described in https://cloud.google.com/datastore/docs/concepts/structuring_for_strong_consistency. However, I'm not sure if that is even possible, this issue is to clarify that.

Environment details

  1. OS type and version: macOS Catalina 10.15.2
  2. Python version and virtual environment information: Python 3.7
  3. google-cloud-cloud version: 1.0.1

Steps to reproduce

  1. Define a class with an IntegerProperty like a counter. (I acknowledge this may be an antipattern according to Datastore.)
  2. Queries that rely on getting the entity with the smallest/highest counter value aren't consistent.

Code example

class A(ndb.Model):
    i_counter = ndb.IntegerProperty()

# I was hopping something like this would work.
if __name__ == "__main__":
    foo = A.query().order(-A.i_counter).get(read_consistency=ndb.STRONG)

Stack trace

Traceback (most recent call last):
  ...
  File "google/cloud/ndb/query.py", line 1236, in wrapper
    return wrapped(self, *dummy_args, _options=query_options)
  File "google/cloud/ndb/utils.py", line 78, in wrapper
    return wrapped(*args, **new_kwargs)
  File "google/cloud/ndb/utils.py", line 110, in positional_wrapper
    return wrapped(*args, **kwds)
  File "google/cloud/ndb/query.py", line 2110, in get
    return self.get_async(_options=kwargs["_options"]).result()
  File "google/cloud/ndb/tasklets.py", line 190, in result
    self.check_success()
  File "google/cloud/ndb/tasklets.py", line 137, in check_success
    raise self._exception
  File "google/cloud/ndb/tasklets.py", line 309, in _advance_tasklet
    self.generator.throw(type(error), error, traceback)
  File "google/cloud/ndb/query.py", line 2144, in get_async
    results = yield _datastore_query.fetch(options)
  File "google/cloud/ndb/tasklets.py", line 309, in _advance_tasklet
    self.generator.throw(type(error), error, traceback)
  File "google/cloud/ndb/_datastore_query.py", line 105, in fetch
    while (yield results.has_next_async()):
  File "google/cloud/ndb/tasklets.py", line 309, in _advance_tasklet
    self.generator.throw(type(error), error, traceback)
  File "google/cloud/ndb/_datastore_query.py", line 264, in has_next_async
    yield self._next_batch()  # First time
  File "google/cloud/ndb/tasklets.py", line 309, in _advance_tasklet
    self.generator.throw(type(error), error, traceback)
  File "google/cloud/ndb/_datastore_query.py", line 291, in _next_batch
    response = yield _datastore_run_query(query)
  File "google/cloud/ndb/tasklets.py", line 309, in _advance_tasklet
    self.generator.throw(type(error), error, traceback)
  File "google/cloud/ndb/_datastore_query.py", line 847, in _datastore_run_query
    "RunQuery", request, timeout=query.timeout
  File "google/cloud/ndb/tasklets.py", line 309, in _advance_tasklet
    self.generator.throw(type(error), error, traceback)
  File "google/cloud/ndb/_retry.py", line 78, in retry_wrapper
    raise error
  File "google/cloud/ndb/_retry.py", line 73, in retry_wrapper
    result = yield result
  File "google/cloud/ndb/tasklets.py", line 309, in _advance_tasklet
    self.generator.throw(type(error), error, traceback)
  File "google/cloud/ndb/_datastore_api.py", line 113, in rpc_call
    result = yield rpc
grpc._channel._MultiThreadedRendezvous: <_MultiThreadedRendezvous of RPC that terminated with:
	status = StatusCode.INVALID_ARGUMENT
	details = "global queries do not support strong consistency"
	debug_error_string = "{"created":"@1582054944.079620000","description":"Error received from peer ipv4:216.58.192.42:443","file":"src/core/lib/surface/call.cc","file_line":1056,"grpc_message":"global queries do not support strong consistency","grpc_status":3}

Thanks!

Metadata

Metadata

Assignees

Labels

🚨This issue needs some love.triage meI really want to be triaged.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions