python - Strongly consistent queries for root entities in GAE? -


I am the best way to read / write a strongly consistent in Google App Engine.

My data is stored in a square like this. I

  class UserGroupData (ndb.model): users_in_group = ndb.StringProperty (repeated = true) data = ndb StringProperty (Repeated = true)   

I want to write a safe update method for this data as far as I understand, I need to avoid getting read continuously because they do not have data loss Take the risk of For example, the following code is unsafe because it uses the vanilla query that is ultimately compatible:

  def update_data (user_id, extra_data): unit = UserGroupData.query (UserGroupData.users_in_group == User_id) .get () entity.data.append (extra_data) entity.put ()   

If the unit given by the query is stale, the data is lost.

To achieve strong stability in these, it seems that I have a few different options, I want to know which option is best:

Options 1:

use get_by_id () , which is always consistent though strongly, there is no systematic way to do this. There is not a clear way to get the key from user_id directly to UserGroupData , because the relationships are many-in-one, it also gives me access to my external customers for user group data The key to send and send seems to be brittle and risky.

Option 2: Keep my institutions in an ancestral group, and the prognostic question is something like this:

  def update_data (user_id, extra_data): Unit = usergroups.com (UserGroupData.users_in_group == user_id, ancestor = ancestor_for_gel_good_tags ()). Get () entity.data.append (I think this should work, but it seems like an extreme thing to put all  UserGroupData  entities in a single ancestor group. While writing, being limited to ~ 1 / sec seems like a misconception, because every  user group is actually logical independent what I really want to do, a firmness for a root unit Continuous inquiries from Is there any way to do this? I saw a suggestion to push the ancestors group inevitably. Is it best that can be done?  

Option 3:

def update_data (user_id, additional_data): entity_key = UserGroupData.query (UserGroupData.users_in_group == user_id,) .get (keys_only = true) unit = entity_key.get () entity.data.append (extra_data) entity.put ( )

As far as I give Can this method data is protected from loss, because you can not change my keys and find () although the strongly consistent results, I have not seen this approach elsewhere. Is it a proper thing to do? Do I Need To Understand?

I think you are also explaining the issue of incompatible questions with the safe update of the data < / P>

A question like one of your examples UserGroupData.query (UserGroupData.users_in_group == user_id) .get () will always return an entity, if the user_id is in the group.

If this is only added and the index is not up to date then you will not get a record and therefore you will not update the record.

Regardless of any updates, to ensure the method of acquiring the unit, it should be demonstrated inside the transaction, to ensure that it can ensure continuity.

According to the ancestors, the consistency of the query improves, it is not clear if you are having multiple user-grouped organizations in what position you are receiving ().

Then option 3 is probably your best bet, only because keys do, then key.get () inside the transaction and update that cross group transactions are limited to 5 entity groups.

In view of this approach, if index-based query is based then 1 out of 3 things may happen,

  1. The records you want are not found because new ones were added. The user-index is not reflected in the index.
  2. The record you want is received, received () will bring it continuously
  3. You want the record, but the user has actually been removed and the index is old. Received () will continuously recover the index and the user ID is not present.

    You can decide the code as to what type of action should be

    What are the use cases to inquire from all user group units, Are there members of the user who will need an update?

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -