I’m creating and editing groups. I need to check to see if a group name is already in use before creating a new group with that name or changing an existing group name to that name.
The problem is that two parallel threads could both check for the group name at the same time, and then each thread could go ahead and add its own group. Duplicate names!
I don’t think I can use the built-in transactions, because these groups should be in different entity groups and the name is not part of the key. What can I do?
Would it make sense to make a sort of index entity that uses the group name in the key, so that I can do an ancestor query to fetch and create the name atomically? Success creating the index entity would serve as permission for the non-transactional code to execute. I would hope for a simpler solution that doesn’t require a whole new type of entity.
An ‘index entity’ as you describe is a standard approach to this, though I don’t know what you mean about using an ancestor query – the index entity should neither be a child of any other entity, nor have any children.
Bear in mind the transactional implications of doing this: unexpected failures can lead to names that are reserved but not used.