Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of ancestors in the google app engine datastore?

I have been playing around with google app engine and its datastore recently and created a datamodel and relationships using reference properties.

However I am unclear about the concept of ancestors wrt the datastore. What is their purpose and why should I use them? How do they relate to reference properties of datastore entities?

like image 315
deltanine Avatar asked Oct 11 '12 05:10

deltanine


1 Answers

Another benefit of entity groups/ancestors is to create islands of strong consistency (as opposed to eventual consistency).

For instance, you could have a project and its tasks. Without ancestors, you could 'close' a task, go back to the tasks list screen for the project, and do a query for open tasks. The task you just closed could still show up because of eventual consistency. The query may have been resolved against a server where the update still hasn't been replicated.

However, with ancestors you get strong consistency. So, instead of a simple foreign key from task to project, you make the the project the ancestor for the project tasks. Now, when querying for tasks, you make it an ancestor query by also providing the project key. The result will be strongly consistent and the task you just closed won't ever be part of the result.

like image 56
Starman Avatar answered Oct 04 '22 00:10

Starman