I'm working on a Google App Engine project that's written in Java.
Whenever I add an entity into the datastore I use a transaction:
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Transaction transaction = datastore.beginTransaction();
datastore.put(entity);
transaction.commit();
I then count the number of entities that are in the datastore:
Query query = new Query(kind);
query.setFilter(filter);
PreparedQuery preparedQuery = datastore.prepare(query);
int count = preparedQuery.countEntities(FetchOptions.Builder.withDefaults());
System.out.println("count = " + count);
I've noticed that sometimes the datastore can be inconsistent. Like sometimes I'll add an entity, but the count doesn't show up. If I then add another entity the count goes up by 2.
Why does this happen? How do I stop it from happening?