Java 8은 지원이 종료되었으며 2026년 1월 31일에
지원 중단됩니다. 지원 중단 후에는 조직에서 이전에 조직 정책을 사용하여 레거시 런타임의 배포를 다시 사용 설정한 경우에도 Java 8 애플리케이션을 배포할 수 없습니다. 기존 Java 8 애플리케이션은
지원 중단 날짜 이후에도 계속 실행되고 트래픽을 수신합니다.
지원되는 최신 Java 버전으로 마이그레이션하는 것이 좋습니다.
Datastore 쿼리의 데이터 일관성
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
데이터 일관성 레벨
Datastore 쿼리는 두 가지 일관성 레벨 중 하나로 결과를 제공합니다.
Eventual Consistency를 가진 쿼리에서는 결과를 수집하는 데 사용되는 색인에 액세스할 때도 eventual consistency가 적용됩니다. 결과적으로 이러한 쿼리는 원래의 기준에 더 이상 일치하지 않는 항목을 반환하는 경우가 있는 반면 strong consistency를 가진 쿼리는 항상 트랜잭션에서 일관적입니다.
Datastore 쿼리 데이터 일관성
쿼리는 각각의 특성에 따라 다양한 레벨의 일관성을 보장하는 결과를 반환합니다.
- 상위 쿼리(항목 그룹 내 쿼리)는 기본적으로 strong consistency를 갖지만 Datastore 읽기 정책을 설정하여 eventual consistency를 갖도록 구성할 수 있습니다(아래 참조).
- 상위 쿼리가 아닌 쿼리는 항상 eventual consistency를 가집니다.
'키로 조회'라고도 부르는 키를 사용한 항목 가져오기는 strong consistency를 가집니다.
Datastore 읽기 정책 설정
성능 향상을 위해 모든 읽기 및 쿼리가 eventual consistency를 가지도록 Datastore 읽기 정책을 설정할 수 있습니다. (이 API를 통해 strong consistency 정책을 명시적으로 설정할 수도 있지만 비 상위 쿼리가 정책에 관계없이 항상 eventual consistency를 가지므로 이 설정은 실제 영향을 주지 않습니다.)
Datastore
호출 기한도 설정할 수 있습니다. 이 값은 애플리케이션이 Datastore에서 결과를 반환하고 오류가 발생하여 중단될 때까지 기다리는 최대 시간을 초 단위로 나타낸 것입니다. 기본 기한은 60초이며 현재는 이보다 더 높게 설정할 수 없습니다. 하지만 특정 작업이 빠르게 실패해서 사용자에게 더 빠른 응답을 반환하도록 더 낮게 조정할 수는 있습니다.
자바에서 Datastore 읽기 정책을 설정하려면 중첩된 도우미 클래스
DatastoreServiceConfig.Builder
를 사용하여
Datastore 서비스 구성(
DatastoreServiceConfig
)을 생성하고 여기에
ReadPolicy
클래스 인스턴스를 전달합니다. 다음 예시에서는 읽기 정책, 호출 기한 또는 두 가지를 모두 설정하는 방법을 보여줍니다.
다음 단계
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-09-04(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-09-04(UTC)"],[[["\u003cp\u003eThis API supports first-generation runtimes and is relevant when upgrading to second-generation runtimes, while migration to Java 11/17 requires a separate migration guide.\u003c/p\u003e\n"],["\u003cp\u003eDatastore queries offer two consistency levels: strongly consistent queries, which guarantee the freshest results but may be slower, and eventually consistent queries, which are generally faster but may return stale results.\u003c/p\u003e\n"],["\u003cp\u003eAncestor queries are strongly consistent by default but can be set to eventually consistent, while non-ancestor queries are always eventually consistent.\u003c/p\u003e\n"],["\u003cp\u003eThe Datastore read policy can be set to eventually consistent to improve performance, and the call deadline can be adjusted to control the maximum wait time for a Datastore operation.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can use the \u003ccode\u003eDatastoreServiceConfig\u003c/code\u003e to set the read policy and/or the call deadline for Datastore operations, using the \u003ccode\u003eReadPolicy\u003c/code\u003e for consistency and \u003ccode\u003ewithDeadline\u003c/code\u003e for the time limit, and can use the \u003ccode\u003eDatastoreServiceFactory\u003c/code\u003e to get a \u003ccode\u003eDatastoreService\u003c/code\u003e instance with the desired configuration.\u003c/p\u003e\n"]]],[],null,["# Data Consistency in Datastore Queries\n\n| This API is supported for first-generation runtimes and can be used when [upgrading to corresponding second-generation runtimes](/appengine/docs/standard/\n| java-gen2\n|\n| /services/access). If you are updating to the App Engine Java 11/17 runtime, refer to the [migration guide](/appengine/migration-center/standard/migrate-to-second-gen/java-differences) to learn about your migration options for legacy bundled services.\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/java/datastore/queries#ancestor_queries) (those within an [entity group](/appengine/docs/legacy/standard/java/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 in Java, you construct a *Datastore service configuration* ([`DatastoreServiceConfig`](/appengine/docs/legacy/standard/java/javadoc/com/google/appengine/api/datastore/DatastoreServiceConfig)), using the nested helper class [`DatastoreServiceConfig.Builder`](/appengine/docs/legacy/standard/java/javadoc/com/google/appengine/api/datastore/DatastoreServiceConfig.Builder), and pass it an instance of class [`ReadPolicy`](/appengine/docs/legacy/standard/java/javadoc/com/google/appengine/api/datastore/ReadPolicy). The following example shows how to set the read policy, the call deadline, or both:\n\n\u003cbr /\u003e\n\n double deadline = 5.0;\n\n // Construct a read policy for eventual consistency\n ReadPolicy policy = new ReadPolicy(ReadPolicy.Consistency.EVENTUAL);\n\n // Set the read policy\n DatastoreServiceConfig eventuallyConsistentConfig =\n DatastoreServiceConfig.Builder.withReadPolicy(policy);\n\n // Set the call deadline\n DatastoreServiceConfig deadlineConfig = DatastoreServiceConfig.Builder.withDeadline(deadline);\n\n // Set both the read policy and the call deadline\n DatastoreServiceConfig datastoreConfig =\n DatastoreServiceConfig.Builder.withReadPolicy(policy).deadline(deadline);\n\n // Get Datastore service with the given configuration\n DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(datastoreConfig);\n\nWhat's next?\n------------\n\n- [Learn how to specify what a query returns and further control query results](/appengine/docs/legacy/standard/java/datastore/retrieving-query-results).\n- Learn the [common restrictions](/appengine/docs/legacy/standard/java/datastore/query-restrictions) for queries on Datastore.\n- Learn about [query cursors](/appengine/docs/legacy/standard/java/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/java/datastore/queries) for Datastore."]]