I am trying to figure out what the maximum length for an AppEngine key name is in the Java API.
This question has been asked in much less depth before:
How long (max characters) can a datastore entity key_name be? Is it bad to haver very long key_names?
and received two conflicting answers (with the one that seems less credible to me being the accepted one...)
@ryan was able to provide links to the relevant Python API source in his answer and I've been trying to find something similar in the Java API.
But neither Key.java, nor KeyFactory.java, nor KeyTranslator.java seem to enforce any limits on the name
property of a key. So, if there is a limit, it is implemented elsewhere. KeyTranslator
calls com.google.storage.onestore.v3.OnestoreEntity.Path.Element.setName()
, which could be the place where the limit is implemented, but unfortunately I can't find the source for this class anywhere...
Specifically, I would like to know:
- Is the 500 character limit a hard limit specifically imposed for key names somewhere in the backend or is it simply a recommendation that should be sufficient to make sure the full key-string never exceeds the 1500-byte limit of a short text property (long text properties with more bytes cannot be indexed, if I understand correctly).
If it is a hard limit:
- Is it 500 characters or 500 bytes (i.e. the length after some encoding)?
- Are the full 500 bytes/characters available for the name of the key or do the other key-components (kind, parent, app-id, ...) deduct from this number?
If it is a recommendation:
- Is it sufficient in all cases?
- What is the maximum I can use if all keys are located in the root of my application and the kind is only one letter long? In other words: Is there a formula I can use to calculate the real limit given the other key components?
Lastly, if I simply try to measure this limit by attempting to store keys of increasing length until I get some exception, will I be able to rely on the limit that I find if I only create keys with identical ancestor paths and same-length kinds in the same application? Or are there other variable-length components to a key that might get added and reduce the available key-name-length in some cases? Should it be the same for the Development and the Production Servers?