Python 2.7 ha raggiunto la fine del supporto
e verrà
ritirato
il 31 gennaio 2026. Dopo il ritiro, non potrai eseguire il deployment di applicazioni Python 2.7, anche se la tua organizzazione ha utilizzato in precedenza un criterio dell'organizzazione per riattivare i deployment di runtime legacy. Le tue applicazioni Python 2.7 esistenti continueranno a essere eseguite e a ricevere traffico dopo la
data di ritiro. Ti consigliamo di
eseguire la migrazione all'ultima versione supportata di Python.
Coerenza dei dati nelle query Datastore
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Livelli di coerenza dei dati
Le query del datastore possono restituire i risultati a due livelli di coerenza:
- Le query molto coerenti garantiscono i risultati più recenti, ma potrebbero richiedere più tempo per essere completate.
- Le query coerenti in modo asintotico in genere vengono eseguite più rapidamente, ma a volte possono restituire risultati non aggiornati.
In una query con coerenza finale, anche gli indici utilizzati per raccogliere i risultati sono accessibili con coerenza finale. Di conseguenza, a volte queste query possono restituire entità che non corrispondono più ai criteri della query originale, mentre le query fortemente coerenti sono sempre coerenti a livello di transazioni.
Coerenza dei dati delle query di Datastore
Le query restituiscono i risultati con diversi livelli di garanzia di coerenza, a seconda della loro natura:
- Le query sugli antenati (quelle all'interno di un
gruppo di entità)
sono fortemente coerenti per impostazione predefinita, ma possono essere rese coerenti
in modo definitivo impostando il criterio di lettura di Datastore (vedi di seguito).
- Le query non relative agli antenati sono sempre coerenti in modo definitivo.
Il recupero di un'entità tramite chiave, chiamato anche "ricerca tramite chiave", è fortemente coerente.
Impostazione del criterio di lettura di Datastore
Per migliorare le prestazioni, puoi impostare il criterio di lettura di Datastore in modo che tutte le letture e le query siano eventualmente coerenti. L'API consente anche di impostare esplicitamente un criterio di coerenza forte, ma questa impostazione non avrà alcun effetto pratico, poiché le query non antecedenti sono sempre eventualmente coerenti indipendentemente dal criterio.
Puoi anche impostare la
scadenza della chiamata di Datastore, ovvero il tempo massimo, in secondi, che l'applicazione attenderà che Datastore restituisca un risultato prima di abortire con un errore. Il termine per impostazione predefinita è di 60 secondi. Al momento non è possibile impostarlo su un valore superiore, ma puoi modificarlo verso il basso per assicurarti che una determinata operazione non vada a buon fine rapidamente (ad esempio, per restituire una risposta più rapida all'utente).
Per impostare il criterio di lettura e la scadenza della chiamata di Datastore in Python, li passi come argomenti ai metodi
run()
,
get()
,
fetch()
e
count()
della classe
Query
o
GqlQuery
. Ad esempio:
for result in Employee.all().run(limit=5,
read_policy=db.EVENTUAL_CONSISTENCY,
deadline=5):
# Body of iterative loop
Passaggi successivi
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
Ultimo aggiornamento 2025-09-04 UTC.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-04 UTC."],[[["\u003cp\u003eDatastore queries operate at two consistency levels: strongly consistent, which guarantees the freshest data but may take longer, and eventually consistent, which is generally faster but might return stale data.\u003c/p\u003e\n"],["\u003cp\u003eAncestor queries, which occur within an entity group, are strongly consistent by default but can be made eventually consistent by adjusting the Datastore read policy, whereas non-ancestor queries are always eventually consistent.\u003c/p\u003e\n"],["\u003cp\u003eFetching an entity by key, also known as "lookup by key", provides strong consistency in retrieving data.\u003c/p\u003e\n"],["\u003cp\u003eThe Datastore read policy can be set to ensure all reads and queries are eventually consistent, optimizing performance, and while a strong consistency policy can be set, it has no effect on non-ancestor queries, as they remain eventually consistent.\u003c/p\u003e\n"],["\u003cp\u003eThe Datastore call deadline, the maximum time an application waits for a result, defaults to 60 seconds but can be reduced to ensure faster operation failures, thus allowing the possibility of faster user responses.\u003c/p\u003e\n"]]],[],null,["# Data Consistency in Datastore Queries\n\nData consistency levels\n-----------------------\n\nDatastore queries can deliver their results at either of two consistency\nlevels:\n\n- [*Strongly consistent*](https://en.wikipedia.org/wiki/Strong_consistency) queries guarantee the freshest results, but may take longer to complete.\n- [*Eventually consistent*](https://en.wikipedia.org/wiki/Eventual_consistency) queries generally run faster, but may occasionally return stale results.\n\nIn an eventually consistent query, the indexes used to gather the results are also accessed with eventual consistency. Consequently, such queries may sometimes return entities that no longer match the original query criteria, while strongly consistent queries are always transactionally consistent.\n\nDatastore query data consistency\n--------------------------------\n\nQueries return their results with different levels of consistency guarantee, depending on the nature of the query:\n\n- [Ancestor queries](/appengine/docs/legacy/standard/python/datastore/queries#ancestor_queries) (those within an [entity group](/appengine/docs/legacy/standard/python/datastore/entities#Ancestor_paths)) are strongly consistent by default, but can instead be made eventually consistent by setting the Datastore read policy (see below).\n- Non-ancestor queries are always eventually consistent.\n\nFetching an entity by key, which is also called \"lookup by key\", is strongly\nconsistent.\n\n\u003cbr /\u003e\n\nSetting the Datastore read policy\n---------------------------------\n\nTo improve performance, you can set the Datastore *read policy* so that all reads and queries are eventually consistent. (The API also allows you to explicitly set a strong consistency policy, but this setting will have no practical effect, since non-ancestor queries are always eventually consistent regardless of policy.)\nYou can also set the Datastore *call deadline* , which is the maximum time, in seconds, that the application will wait for Datastore to return a result before aborting with an error. The default deadline is 60 seconds; it is not currently possible to set it higher, but you can adjust it downward to ensure that a particular operation fails quickly (for instance, to return a faster response to the user).\n\n\u003cbr /\u003e\n\nTo set the Datastore read policy and call deadline in Python, you pass them as arguments to the [`run()`](/appengine/docs/legacy/standard/python/datastore/queryclass#Query_run), [`get()`](/appengine/docs/legacy/standard/python/datastore/queryclass#Query_get), [`fetch()`](/appengine/docs/legacy/standard/python/datastore/queryclass#Query_fetch), and [`count()`](/appengine/docs/legacy/standard/python/datastore/queryclass#Query_count) methods of class [`Query`](/appengine/docs/legacy/standard/python/datastore/queryclass) or [`GqlQuery`](/appengine/docs/legacy/standard/python/datastore/gqlqueryclass). For example:\n\n\u003cbr /\u003e\n\n for result in Employee.all().run(limit=5,\n read_policy=db.EVENTUAL_CONSISTENCY,\n deadline=5):\n # Body of iterative loop\n\nWhat's next?\n------------\n\n- [Learn how to specify what a query returns and further control query results](/appengine/docs/legacy/standard/python/datastore/retrieving-query-results).\n- Learn the [common restrictions](/appengine/docs/legacy/standard/python/datastore/query-restrictions) for queries on Datastore.\n- Learn about [query cursors](/appengine/docs/legacy/standard/python/datastore/query-cursors), which allow an application to retrieve a query's results in convenient batches.\n- Learn the [basic syntax and structure of queries](/appengine/docs/legacy/standard/python/datastore/queries) for Datastore."]]