Datastore クエリのデータ整合性
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
データ整合性レベル
Datastore のクエリでは、次の 2 つの整合性レベルのいずれかで結果を返すことができます。
- 強整合クエリは、結果が最新であることが保証されますが、完了までに時間がかかる場合があります。
- 結果整合性クエリは、一般的により高速に実行されます。ただし、最新ではない結果が返される場合があります。
結果整合クエリでは、結果の収集に使用されるインデックスも、結果整合性に基づいてアクセスされます。その結果、元のクエリ条件と一致しなくなったエンティティが返される場合があります。一方、強整合クエリでは常にトランザクション上の整合性が維持されます。
Datastore クエリのデータ整合性
クエリでは各クエリの特性に基づき、異なる整合性レベルを保証した結果が返されます。
- 祖先クエリ(1 つのエンティティ グループ内のクエリ)は、デフォルトでは強整合性ですが、Datastore の読み取りポリシーを設定することで(後述)、結果整合性にできます。
- 非祖先クエリは常に結果整合になります。
キーによるエンティティの取得(「キーによる検索」とも呼ばれる)は強整合になります。
Datastore の読み取りポリシーの設定
パフォーマンスを向上させるために、すべての読み取りとクエリが結果整合になるように、Datastore の読み取りポリシーを設定できます(API を使用して強整合性のポリシーを明示的に設定することもできますが、現実的な効果はありません。これは、ポリシーに関係なく、非祖先クエリは常に結果整合になるためです)。
Datastore の呼び出し期限
を設定し、Datastore から結果が返されるのを待機する時間の最大値(秒)を指定することもできます。この時間が経過するとアプリケーションは処理を中止し、エラーを返します。期限のデフォルト値は 60 秒です。現時点ではデフォルト値を超える値は設定できませんが、デフォルトより短い値に設定することは可能です。これにより、特定のオペレーションが失敗と判定されるまでの時間を短くできます(ユーザーへのレスポンスの迅速化などの目的に利用できます)。
Python で Datastore 読み取りポリシーと呼び出し期限を設定するには、
run()
、
get()
、
fetch()
、
count()
クラスの
Query
または
GqlQuery
メソッドに引数として渡します。例:
for result in Employee.all().run(limit=5,
read_policy=db.EVENTUAL_CONSISTENCY,
deadline=5):
# Body of iterative loop
次のステップ
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-03-06 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-03-06 UTC。"],[[["Datastore 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."],["Ancestor 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."],["Fetching an entity by key, also known as \"lookup by key\", provides strong consistency in retrieving data."],["The 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."],["The 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."]]],[]]