Skip to content

Expose Firestore Bundles #2369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Feb 2, 2021

Conversation

schmidt-sebastian
Copy link
Contributor

WE HAVE REACHED THE END!

This PR adds the API endpoints, the SyncEngine logic and the integration tests for Bundles.

Some notable changes:

I rewrote EventAccumulator to support assertNoAdditionalEvents().
I added totalBytes/totalDocuments back to BundleMetadata as it made plumbing these values through much easier.

This moves the Bundle files to the their own package and deletes the duplicate Bundle class (the same class exists as BundleMetadata, but was merged incorrecly).

BundleCache stays in local along with the other persistence classes.
BundleLoader is a port from Web, the tests are new since BundleLoader on Web only has integration tests. To make testing possible, I also added BundleListener
@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jan 27, 2021

Coverage Report

Affected SDKs

  • firebase-firestore

    SDK overall coverage changed from ? (b9d0318) to 48.62% (eb792adb) by ?.

    Click to show coverage changes in 279 files.
    Filename Base (b9d0318) Head (eb792adb) Diff
    AbstractStream.java ? 36.90% ?
    ActivityScope.java ? 0.00% ?
    AndroidConnectivityMonitor.java ? 40.00% ?
    ApiUtil.java ? 12.50% ?
    ArrayContainsAnyFilter.java ? 100.00% ?
    ArrayContainsFilter.java ? 100.00% ?
    ArrayTransformOperation.java ? 86.49% ?
    ArrayValue.java ? 48.60% ?
    ArrayValueOrBuilder.java ? 0.00% ?
    Assert.java ? 57.14% ?
    AsyncEventListener.java ? 0.00% ?
    AsyncQueue.java ? 76.88% ?
    BackgroundQueue.java ? 100.00% ?
    BasePath.java ? 98.08% ?
    BatchGetDocumentsRequest.java ? 0.00% ?
    BatchGetDocumentsRequestOrBuilder.java ? 0.00% ?
    BatchGetDocumentsResponse.java ? 0.00% ?
    BatchGetDocumentsResponseOrBuilder.java ? 0.00% ?
    BeginTransactionRequest.java ? 0.00% ?
    BeginTransactionRequestOrBuilder.java ? 0.00% ?
    BeginTransactionResponse.java ? 0.00% ?
    BeginTransactionResponseOrBuilder.java ? 0.00% ?
    Blob.java ? 76.92% ?
    Bound.java ? 47.83% ?
    BundleCache.java ? 0.00% ?
    BundleDocument.java ? 90.00% ?
    BundleElement.java ? 0.00% ?
    BundleListener.java ? 0.00% ?
    BundleLoader.java ? 100.00% ?
    BundleMetadata.java ? 76.92% ?
    BundleReader.java ? 94.87% ?
    BundleSerializer.java ? 88.98% ?
    BundledDocumentMetadata.java ? 77.27% ?
    BundledQuery.java ? 78.57% ?
    ByteBufferInputStream.java ? 90.91% ?
    CollectionReference.java ? 13.64% ?
    CommitRequest.java ? 0.00% ?
    CommitRequestOrBuilder.java ? 0.00% ?
    CommitResponse.java ? 0.00% ?
    CommitResponseOrBuilder.java ? 0.00% ?
    CommonProto.java ? 0.00% ?
    ComponentProvider.java ? 100.00% ?
    ConnectivityMonitor.java ? 0.00% ?
    Consumer.java ? 0.00% ?
    CreateDocumentRequest.java ? 0.00% ?
    CreateDocumentRequestOrBuilder.java ? 0.00% ?
    CredentialsProvider.java ? 100.00% ?
    Cursor.java ? 35.29% ?
    CursorOrBuilder.java ? 0.00% ?
    CustomClassMapper.java ? 84.37% ?
    DatabaseId.java ? 69.23% ?
    DatabaseInfo.java ? 90.91% ?
    Datastore.java ? 33.78% ?
    DefaultQueryEngine.java ? 95.74% ?
    DeleteDocumentRequest.java ? 0.00% ?
    DeleteDocumentRequestOrBuilder.java ? 0.00% ?
    DeleteMutation.java ? 83.33% ?
    Document.java ? 30.34% ?
    DocumentChange.java ? 35.17% ?
    DocumentChangeOrBuilder.java ? 0.00% ?
    DocumentCollections.java ? 83.33% ?
    DocumentDelete.java ? 34.62% ?
    DocumentDeleteOrBuilder.java ? 0.00% ?
    DocumentId.java ? 0.00% ?
    DocumentKey.java ? 100.00% ?
    DocumentMask.java ? 40.66% ?
    DocumentMaskOrBuilder.java ? 0.00% ?
    DocumentOrBuilder.java ? 0.00% ?
    DocumentProto.java ? 0.00% ?
    DocumentReference.java ? 13.14% ?
    DocumentRemove.java ? 29.23% ?
    DocumentRemoveOrBuilder.java ? 0.00% ?
    DocumentSet.java ? 83.56% ?
    DocumentSnapshot.java ? 36.84% ?
    DocumentTransform.java ? 29.44% ?
    DocumentTransformOrBuilder.java ? 0.00% ?
    DocumentViewChange.java ? 90.48% ?
    DocumentViewChangeSet.java ? 87.88% ?
    EmptyCredentialsProvider.java ? 37.50% ?
    EncodedPath.java ? 93.22% ?
    EventListener.java ? 0.00% ?
    EventManager.java ? 96.15% ?
    Exclude.java ? 0.00% ?
    Executors.java ? 100.00% ?
    ExistenceFilter.java ? 0.00% ?
    ExistenceFilterOrBuilder.java ? 0.00% ?
    ExponentialBackoff.java ? 30.43% ?
    FieldFilter.java ? 88.46% ?
    FieldMask.java ? 55.56% ?
    FieldPath.java ? 89.66% ?
    FieldTransform.java ? 64.71% ?
    FieldValue.java ? 82.14% ?
    FileUtil.java ? 0.00% ?
    Filter.java ? 100.00% ?
    FirebaseAuthCredentialsProvider.java ? 41.67% ?
    FirebaseClientGrpcMetadataProvider.java ? 44.00% ?
    FirebaseFirestore.java ? 44.08% ?
    FirebaseFirestoreException.java ? 83.72% ?
    FirebaseFirestoreSettings.java ? 68.63% ?
    FirestoreCallCredentials.java ? 19.23% ?
    FirestoreChannel.java ? 16.07% ?
    FirestoreClient.java ? 30.08% ?
    FirestoreGrpc.java ? 8.73% ?
    FirestoreMultiDbComponent.java ? 100.00% ?
    FirestoreProto.java ? 0.00% ?
    FirestoreRegistrar.java ? 100.00% ?
    Function.java ? 0.00% ?
    GarbageCollectionScheduler.java ? 0.00% ?
    GeoPoint.java ? 91.67% ?
    GetDocumentRequest.java ? 0.00% ?
    GetDocumentRequestOrBuilder.java ? 0.00% ?
    GrpcCallProvider.java ? 68.18% ?
    GrpcMetadataProvider.java ? 0.00% ?
    IgnoreExtraProperties.java ? 0.00% ?
    InFilter.java ? 100.00% ?
    IncomingStreamObserver.java ? 0.00% ?
    IndexCursor.java ? 0.00% ?
    IndexManager.java ? 0.00% ?
    IndexNumberDecoder.java ? 0.00% ?
    IndexNumberEncoder.java ? 0.00% ?
    IndexRange.java ? 88.89% ?
    IndexedQueryEngine.java ? 62.69% ?
    KeyFieldFilter.java ? 66.67% ?
    KeyFieldInFilter.java ? 0.00% ?
    KeyFieldNotInFilter.java ? 0.00% ?
    LimboDocumentChange.java ? 70.59% ?
    ListCollectionIdsRequest.java ? 0.00% ?
    ListCollectionIdsRequestOrBuilder.java ? 0.00% ?
    ListCollectionIdsResponse.java ? 0.00% ?
    ListCollectionIdsResponseOrBuilder.java ? 0.00% ?
    ListDocumentsRequest.java ? 0.00% ?
    ListDocumentsRequestOrBuilder.java ? 0.00% ?
    ListDocumentsResponse.java ? 0.00% ?
    ListDocumentsResponseOrBuilder.java ? 0.00% ?
    ListenRequest.java ? 10.77% ?
    ListenRequestOrBuilder.java ? 0.00% ?
    ListenResponse.java ? 32.64% ?
    ListenResponseOrBuilder.java ? 0.00% ?
    ListenSequence.java ? 100.00% ?
    Listener.java ? 0.00% ?
    ListenerRegistration.java ? 0.00% ?
    ListenerRegistrationImpl.java ? 0.00% ?
    LoadBundleTask.java ? 83.16% ?
    LoadBundleTaskProgress.java ? 81.40% ?
    LocalDocumentsView.java ? 100.00% ?
    LocalSerializer.java ? 97.66% ?
    LocalStore.java ? 98.93% ?
    LocalViewChanges.java ? 100.00% ?
    LocalWriteResult.java ? 100.00% ?
    Logger.java ? 75.00% ?
    LruDelegate.java ? 0.00% ?
    LruGarbageCollector.java ? 84.11% ?
    MapValue.java ? 53.00% ?
    MapValueOrBuilder.java ? 0.00% ?
    MaybeDocument.java ? 100.00% ?
    MemoryBundleCache.java ? 100.00% ?
    MemoryComponentProvider.java ? 100.00% ?
    MemoryEagerReferenceDelegate.java ? 100.00% ?
    MemoryIndexManager.java ? 100.00% ?
    MemoryLruReferenceDelegate.java ? 96.00% ?
    MemoryMutationQueue.java ? 98.58% ?
    MemoryPersistence.java ? 100.00% ?
    MemoryRemoteDocumentCache.java ? 100.00% ?
    MemoryTargetCache.java ? 100.00% ?
    MetadataChanges.java ? 100.00% ?
    Mutation.java ? 98.41% ?
    MutationBatch.java ? 89.55% ?
    MutationBatchResult.java ? 100.00% ?
    MutationQueue.java ? 0.00% ?
    MutationResult.java ? 100.00% ?
    NamedQuery.java ? 77.78% ?
    NoDocument.java ? 57.14% ?
    NotInFilter.java ? 85.71% ?
    NumberComparisonHelper.java ? 100.00% ?
    NumberIndexEncoder.java ? 0.00% ?
    NumberParts.java ? 0.00% ?
    NumericIncrementTransformOperation.java ? 87.50% ?
    ObjectValue.java ? 99.02% ?
    OnProgressListener.java ? 0.00% ?
    OnlineState.java ? 100.00% ?
    OnlineStateTracker.java ? 100.00% ?
    OrderBy.java ? 96.55% ?
    PatchMutation.java ? 92.31% ?
    Persistence.java ? 100.00% ?
    Precondition.java ? 38.46% ?
    PreconditionOrBuilder.java ? 0.00% ?
    Preconditions.java ? 53.85% ?
    PropertyName.java ? 0.00% ?
    Query.java ? 4.06% ?
    QueryDocumentSnapshot.java ? 64.71% ?
    QueryEngine.java ? 0.00% ?
    QueryListener.java ? 100.00% ?
    QueryProto.java ? 0.00% ?
    QueryPurpose.java ? 100.00% ?
    QueryResult.java ? 100.00% ?
    QuerySnapshot.java ? 76.36% ?
    QueryView.java ? 100.00% ?
    ReferenceDelegate.java ? 0.00% ?
    ReferenceSet.java ? 92.45% ?
    RemoteDocumentCache.java ? 0.00% ?
    RemoteEvent.java ? 92.31% ?
    RemoteSerializer.java ? 83.96% ?
    RemoteStore.java ? 92.15% ?
    ResourcePath.java ? 94.74% ?
    RollbackRequest.java ? 0.00% ?
    RollbackRequestOrBuilder.java ? 0.00% ?
    RunQueryRequest.java ? 0.00% ?
    RunQueryRequestOrBuilder.java ? 0.00% ?
    RunQueryResponse.java ? 0.00% ?
    RunQueryResponseOrBuilder.java ? 0.00% ?
    SQLiteBundleCache.java ? 90.00% ?
    SQLiteCollectionIndex.java ? 57.14% ?
    SQLiteComponentProvider.java ? 100.00% ?
    SQLiteIndexManager.java ? 100.00% ?
    SQLiteLruReferenceDelegate.java ? 98.63% ?
    SQLiteMutationQueue.java ? 82.66% ?
    SQLitePersistence.java ? 83.06% ?
    SQLiteRemoteDocumentCache.java ? 95.24% ?
    SQLiteSchema.java ? 93.09% ?
    SQLiteTargetCache.java ? 98.47% ?
    ServerTimestamp.java ? 0.00% ?
    ServerTimestampOperation.java ? 100.00% ?
    ServerTimestamps.java ? 79.17% ?
    SetMutation.java ? 84.85% ?
    SetOptions.java ? 0.00% ?
    SnapshotMetadata.java ? 68.75% ?
    SnapshotVersion.java ? 93.75% ?
    Source.java ? 0.00% ?
    Stream.java ? 100.00% ?
    StructuredQuery.java ? 32.90% ?
    StructuredQueryOrBuilder.java ? 0.00% ?
    Supplier.java ? 0.00% ?
    SyncEngine.java ? 93.49% ?
    Target.java ? 28.83% ?
    TargetCache.java ? 0.00% ?
    TargetChange.java ? 35.35% ?
    TargetChangeOrBuilder.java ? 0.00% ?
    TargetData.java ? 77.50% ?
    TargetIdGenerator.java ? 100.00% ?
    TargetOrBuilder.java ? 0.00% ?
    TargetState.java ? 97.78% ?
    ThrottledForwardingExecutor.java ? 100.00% ?
    ThrowOnExtraProperties.java ? 0.00% ?
    Timestamp.java ? 90.20% ?
    Token.java ? 0.00% ?
    Transaction.java ? 0.00% ?
    TransactionOptions.java ? 0.00% ?
    TransactionOptionsOrBuilder.java ? 0.00% ?
    TransactionRunner.java ? 0.00% ?
    TransformOperation.java ? 0.00% ?
    UnknownDocument.java ? 53.85% ?
    UpdateDocumentRequest.java ? 0.00% ?
    UpdateDocumentRequestOrBuilder.java ? 0.00% ?
    User.java ? 78.57% ?
    UserData.java ? 66.00% ?
    UserDataReader.java ? 70.48% ?
    UserDataWriter.java ? 51.02% ?
    Util.java ? 49.35% ?
    Value.java ? 45.65% ?
    ValueOrBuilder.java ? 0.00% ?
    Values.java ? 96.50% ?
    VerifyMutation.java ? 50.00% ?
    View.java ? 96.99% ?
    ViewChange.java ? 100.00% ?
    ViewSnapshot.java ? 88.33% ?
    WatchChange.java ? 70.51% ?
    WatchChangeAggregator.java ? 98.17% ?
    WatchStream.java ? 19.23% ?
    Write.java ? 36.25% ?
    WriteBatch.java ? 0.00% ?
    WriteOrBuilder.java ? 0.00% ?
    WriteProto.java ? 0.00% ?
    WriteRequest.java ? 10.41% ?
    WriteRequestOrBuilder.java ? 0.00% ?
    WriteResponse.java ? 11.70% ?
    WriteResponseOrBuilder.java ? 0.00% ?
    WriteResult.java ? 0.00% ?
    WriteResultOrBuilder.java ? 0.00% ?
    WriteStream.java ? 31.82% ?

Test Logs

Notes

HTML coverage reports can be produced locally with ./gradlew <product>:checkCoverage.
Report files are located at <product-build-dir>/reports/jacoco/.

Head commit (eb792adb) is created by Prow via merging commits: b9d0318 11936cc.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jan 27, 2021

Binary Size Report

Affected SDKs

  • firebase-firestore

    Type Base (b9d0318) Head (eb792adb) Diff
    aar 1.07 MB 1.08 MB +5.51 kB (+0.5%)
    apk (release) 3.17 MB 3.17 MB +2.36 kB (+0.1%)

Test Logs

Notes

Head commit (eb792adb) is created by Prow via merging commits: b9d0318 11936cc.

Base automatically changed from mrschmidt/bundle/loader to mrschmidt/bundle/master February 1, 2021 17:31
Copy link
Contributor

@wu-hui wu-hui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very close to finish!

@@ -51,7 +51,7 @@
import org.json.JSONObject;

/** A JSON serializer to deserialize Firestore Bundles. */
class BundleSerializer {
public class BundleSerializer {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this line, in decodeDocument createTime is omitted..I think we don't use it in our SDK, but maybe we should include? Or is this intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use createTime in the Mobile SDKs. The version we use is derived from updateTime.

+ "schema_version INTEGER)");
+ "schema_version INTEGER, "
+ "total_documents INTEGER, "
+ "total_bytes INTEGER)");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

total_documents and total_bytes are only used during loading, they are not of much use after it is loaded, and we should not persist them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added and removed these fields quite a few times now. Unfortunately, it seems easier to just include them in BundleMetadata, as the combined state can then be passed around in one object. Note that unlike JS, the BundleLoader cannot just grab these values from the JSON stream since they need to be deserialized first. If we want to omit these values from persistence, I think they are only two strategies:

  • We create a BundleMetadata and a BundleMetadataDuringLoading and only use BundleMetadata in Storage
  • We don't write these values to persistence and use -1 or similar values to populate BundleMetadata when we deserialize

Both of these options seems much less clean to me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SG.

@@ -501,6 +506,20 @@ private void doUnlisten(JSONArray unlistenSpec) throws Exception {
queue.runSync(() -> eventManager.removeQueryListener(listener));
}

private void doLoadBundle(String json) throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This confuses me, how did spec tests run before this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They have "no-android" tags and didn't run before they were removed in this PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks.

@schmidt-sebastian
Copy link
Contributor Author

/retest

1 similar comment
@schmidt-sebastian
Copy link
Contributor Author

/retest

@google-oss-bot
Copy link
Contributor

@schmidt-sebastian: The following tests failed, say /retest to rerun them all:

Test name Commit Details Rerun command
copyright-check f9f0cf5 link /test copyright-check
api-information f9f0cf5 link /test api-information
check-changed f9f0cf5 link /test check-changed
device-check-changed f9f0cf5 link /test device-check-changed

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

Copy link
Contributor

@wu-hui wu-hui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wu-hui wu-hui assigned schmidt-sebastian and unassigned wu-hui Feb 2, 2021
@schmidt-sebastian schmidt-sebastian merged commit 1e24541 into mrschmidt/bundle/master Feb 2, 2021
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/bundle/last branch February 2, 2021 16:52
@firebase firebase locked and limited conversation to collaborators Mar 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants