Fixed
Status Update
Comments
cl...@google.com <cl...@google.com>
cl...@google.com <cl...@google.com> #2
Change from exception class to a third LoadResult.Invalid return type within LoadResult class in PagingSource.
Note that it is binary compatible but source-incompatible.
Note that it is binary compatible but source-incompatible.
ap...@google.com <ap...@google.com> #3
Project: platform/frameworks/support
Branch: androidx-main
commit 6bd2347ff259c28b34789c8569b7a298d2a8fd8d
Author: Clara Fok <clarafok@google.com>
Date: Fri Jul 09 12:53:22 2021
Implement Invalid return type in PagingSource
Added third return type for LoadResult sealed class in PagingSource. It
was added as a support feature to handle race scenarios between data loads
and database invalidations, such as if Room's InvalidationTracker does
not propagate invalidation signal to the PagingSource in time and the
PagingSource continues querying an updated database. This can result in
data being loaded onto a stale PageFetcherSnapshot causing duplicated or
missing data. Related bug regarding race scenario in Room b/191806126 .
For example, if data was deleted and items shifted positions,
positionally-keyed paging sources can end up loading duplicated items.
Paging handles this return type by discarding the loaded data and
invalidating the paging source. This will trigger a new paging source to
be generated. This return type is also supported for Paging2 APIs
leveraging PagingSource such as LivePagedList and RxPagedList.
Aside from handling invalid data due to races, this return type can be
leveraged in general where the database or network returns potentially
invalid or stale data that needs to be discarded.
Bug: 192013267
Test: ./gradlew :paging:paging-common:test
Relnote: "A third LoadResult return type LoadResult.Invalid is added to
PagingSource. When a PagingSource.load returns
LoadResult.Invalid, paging will discard the loaded data and
invalidate the PagingSource. This return type is designed to
handle potentially invalid or stale data that can be returned
from the database or network.
For example, if the underlying database gets written into but
the PagingSource does not invalidate in time, it may return
inconsistent results if its implementation depends on the
immutability of the backing dataset it loads from (e.g., LIMIT
OFFSET style db implementations). In this scenario, it is
recommended to check for invalidation after loading and to
return LoadResult.Invalid, which causes Paging to discard any
pending or future load requests to this PagingSource and
invalidate it.
This return type is also supported by Paging2 API that leverages
LivePagedList or RxPagedList. When using a PagingSource with
Paging2's PagedList APIs, the PagedList is immediately detached,
stopping further attempts to load data on this PagedList and
triggers invalidation on the PagingSource.
LoadResult is a sealed class, which means this is a
source-incomptabile change such that use cases directly using
PagingSource.load results will have to handle LoadResult.Invalid
at compile time. For example, Kotlin users leveraging
exhaustive-when to check return type will have to add a check
for Invalid type."
Change-Id: Id6bd3f2544f1ba97a95a0d590353438a95fedf2a
M paging/common/api/current.txt
M paging/common/api/public_plus_experimental_current.txt
M paging/common/api/restricted_current.txt
M paging/common/src/main/kotlin/androidx/paging/PageFetcherSnapshot.kt
M paging/common/src/main/kotlin/androidx/paging/PagedList.kt
M paging/common/src/main/kotlin/androidx/paging/PagingSource.kt
M paging/common/src/test/kotlin/androidx/paging/PageFetcherSnapshotTest.kt
M paging/common/src/test/kotlin/androidx/paging/PageFetcherTest.kt
M paging/common/src/test/kotlin/androidx/paging/PagedListTest.kt
M paging/common/src/test/kotlin/androidx/paging/PagingDataDifferTest.kt
M paging/common/src/test/kotlin/androidx/paging/PagingSourceTest.kt
M paging/integration-tests/testapp/src/main/java/androidx/paging/integration/testapp/v3room/V3RemoteMediator.kt
M paging/integration-tests/testapp/src/main/java/androidx/paging/integration/testapp/v3room/V3RoomViewModel.kt
https://android-review.googlesource.com/1747297
Branch: androidx-main
commit 6bd2347ff259c28b34789c8569b7a298d2a8fd8d
Author: Clara Fok <clarafok@google.com>
Date: Fri Jul 09 12:53:22 2021
Implement Invalid return type in PagingSource
Added third return type for LoadResult sealed class in PagingSource. It
was added as a support feature to handle race scenarios between data loads
and database invalidations, such as if Room's InvalidationTracker does
not propagate invalidation signal to the PagingSource in time and the
PagingSource continues querying an updated database. This can result in
data being loaded onto a stale PageFetcherSnapshot causing duplicated or
missing data. Related bug regarding race scenario in Room
For example, if data was deleted and items shifted positions,
positionally-keyed paging sources can end up loading duplicated items.
Paging handles this return type by discarding the loaded data and
invalidating the paging source. This will trigger a new paging source to
be generated. This return type is also supported for Paging2 APIs
leveraging PagingSource such as LivePagedList and RxPagedList.
Aside from handling invalid data due to races, this return type can be
leveraged in general where the database or network returns potentially
invalid or stale data that needs to be discarded.
Bug: 192013267
Test: ./gradlew :paging:paging-common:test
Relnote: "A third LoadResult return type LoadResult.Invalid is added to
PagingSource. When a PagingSource.load returns
LoadResult.Invalid, paging will discard the loaded data and
invalidate the PagingSource. This return type is designed to
handle potentially invalid or stale data that can be returned
from the database or network.
For example, if the underlying database gets written into but
the PagingSource does not invalidate in time, it may return
inconsistent results if its implementation depends on the
immutability of the backing dataset it loads from (e.g., LIMIT
OFFSET style db implementations). In this scenario, it is
recommended to check for invalidation after loading and to
return LoadResult.Invalid, which causes Paging to discard any
pending or future load requests to this PagingSource and
invalidate it.
This return type is also supported by Paging2 API that leverages
LivePagedList or RxPagedList. When using a PagingSource with
Paging2's PagedList APIs, the PagedList is immediately detached,
stopping further attempts to load data on this PagedList and
triggers invalidation on the PagingSource.
LoadResult is a sealed class, which means this is a
source-incomptabile change such that use cases directly using
PagingSource.load results will have to handle LoadResult.Invalid
at compile time. For example, Kotlin users leveraging
exhaustive-when to check return type will have to add a check
for Invalid type."
Change-Id: Id6bd3f2544f1ba97a95a0d590353438a95fedf2a
M paging/common/api/current.txt
M paging/common/api/public_plus_experimental_current.txt
M paging/common/api/restricted_current.txt
M paging/common/src/main/kotlin/androidx/paging/PageFetcherSnapshot.kt
M paging/common/src/main/kotlin/androidx/paging/PagedList.kt
M paging/common/src/main/kotlin/androidx/paging/PagingSource.kt
M paging/common/src/test/kotlin/androidx/paging/PageFetcherSnapshotTest.kt
M paging/common/src/test/kotlin/androidx/paging/PageFetcherTest.kt
M paging/common/src/test/kotlin/androidx/paging/PagedListTest.kt
M paging/common/src/test/kotlin/androidx/paging/PagingDataDifferTest.kt
M paging/common/src/test/kotlin/androidx/paging/PagingSourceTest.kt
M paging/integration-tests/testapp/src/main/java/androidx/paging/integration/testapp/v3room/V3RemoteMediator.kt
M paging/integration-tests/testapp/src/main/java/androidx/paging/integration/testapp/v3room/V3RoomViewModel.kt
ap...@google.com <ap...@google.com> #4
Project: platform/frameworks/support
Branch: androidx-main
commit 24ac03f503425f05acfc9c2a1627cf179ab8de16
Author: Clara Fok <clarafok@google.com>
Date: Mon Jul 12 10:47:27 2021
Add LoadResult.Invalid support for Paging2
This change adds LoadResult.Invalid support for Paging2 leveraging
PagingSource, such as LivePagedList and RxPagedList.
In the event of a PagingSource returning LoadResult.Invalid to its
PagedList, paging will detach the PagedList to stop attempts to load
on this PagedList and invalidate the PagingSource.
If no initial page is provided to PagedList.Builder and the initial
load fails with a LoadResult.Invalid, an IllegalStateException
will be thrown. To use a PagingSource that supports invalidation, use a
PagedList builder that accepts a factory method for PagingSource or
DataSource.Factory such as LivePagedList.
Bug: 192013267
Test: ./gradlew :paging:paging-common:test
Test: ./gradlew :paging:paging-runtime:cC
Test: ./gradlew :paging:paging-rxjava2:test
Test: ./gradlew :paging:paging-rxjava3:test
Change-Id: I97de7e67cc5fe01b2c5c5a8e13bd1926c5ca2cde
M paging/common/src/main/kotlin/androidx/paging/LegacyPageFetcher.kt
M paging/common/src/test/kotlin/androidx/paging/ContiguousPagedListTest.kt
M paging/common/src/test/kotlin/androidx/paging/LegacyPageFetcherTest.kt
M paging/runtime/src/androidTest/java/androidx/paging/LivePagedListBuilderTest.kt
M paging/runtime/src/androidTest/java/androidx/paging/LivePagedListTest.kt
M paging/runtime/src/main/java/androidx/paging/LivePagedList.kt
M paging/rxjava2/build.gradle
M paging/rxjava2/src/main/java/androidx/paging/RxPagedListBuilder.kt
M paging/rxjava2/src/test/java/androidx/paging/RxPagedListBuilderTest.kt
M paging/rxjava3/build.gradle
M paging/rxjava3/src/main/java/androidx/paging/rxjava3/RxPagedListBuilder.kt
M paging/rxjava3/src/test/java/androidx/paging/RxPagedListBuilderTest.kt
https://android-review.googlesource.com/1758714
Branch: androidx-main
commit 24ac03f503425f05acfc9c2a1627cf179ab8de16
Author: Clara Fok <clarafok@google.com>
Date: Mon Jul 12 10:47:27 2021
Add LoadResult.Invalid support for Paging2
This change adds LoadResult.Invalid support for Paging2 leveraging
PagingSource, such as LivePagedList and RxPagedList.
In the event of a PagingSource returning LoadResult.Invalid to its
PagedList, paging will detach the PagedList to stop attempts to load
on this PagedList and invalidate the PagingSource.
If no initial page is provided to PagedList.Builder and the initial
load fails with a LoadResult.Invalid, an IllegalStateException
will be thrown. To use a PagingSource that supports invalidation, use a
PagedList builder that accepts a factory method for PagingSource or
DataSource.Factory such as LivePagedList.
Bug: 192013267
Test: ./gradlew :paging:paging-common:test
Test: ./gradlew :paging:paging-runtime:cC
Test: ./gradlew :paging:paging-rxjava2:test
Test: ./gradlew :paging:paging-rxjava3:test
Change-Id: I97de7e67cc5fe01b2c5c5a8e13bd1926c5ca2cde
M paging/common/src/main/kotlin/androidx/paging/LegacyPageFetcher.kt
M paging/common/src/test/kotlin/androidx/paging/ContiguousPagedListTest.kt
M paging/common/src/test/kotlin/androidx/paging/LegacyPageFetcherTest.kt
M paging/runtime/src/androidTest/java/androidx/paging/LivePagedListBuilderTest.kt
M paging/runtime/src/androidTest/java/androidx/paging/LivePagedListTest.kt
M paging/runtime/src/main/java/androidx/paging/LivePagedList.kt
M paging/rxjava2/build.gradle
M paging/rxjava2/src/main/java/androidx/paging/RxPagedListBuilder.kt
M paging/rxjava2/src/test/java/androidx/paging/RxPagedListBuilderTest.kt
M paging/rxjava3/build.gradle
M paging/rxjava3/src/main/java/androidx/paging/rxjava3/RxPagedListBuilder.kt
M paging/rxjava3/src/test/java/androidx/paging/RxPagedListBuilderTest.kt
Description
This is partially in response to
A sample use case is when db write happens but the paging source does not invalidate in time, resulting in paging source loading wrong data.