Skip to content
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

Adding FieldValue.numericAdd() #105

Merged
merged 19 commits into from
Mar 6, 2019
Merged

Conversation

schmidt-sebastian
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian commented Nov 1, 2018

This PR adds support for the Numeric Add transform and follows the semantics of the backend implementation. To avoid flicker with latency compensation, it adds the concept of "base values", which are stored as a list of patch mutations along with the transform mutations in a mutation batch. The base mutations are applied first and are used to overwrite values from the remote document cache.

This PR also simplifies some plumbing in regards to the "previous value", which is used when rendering Server Timestamps. Before, if two server timestamps replaced the same value in sequence, each timestamp would point to this previous value. Now, the previous value is chained, and the second timestamp obtains its previous value by asking the first timestamp for its previous value. This is slightly less optimal, but simplifies the changes that this PR introduces to Local Store.

As an additional benefit, and to get this PR passed 1000 lines of code, I added a flag to run the Integration Tests against Hexa. Because I don't know how to add custom configurations in gradle, this is for now hardcoded.

@googlebot googlebot added the cla: yes Override cla label Nov 1, 2018
@schmidt-sebastian schmidt-sebastian force-pushed the mrschmidt-numericincrement branch 2 times, most recently from f3e1ff8 to 59e73c2 Compare November 1, 2018 23:09
@schmidt-sebastian schmidt-sebastian force-pushed the mrschmidt-numericincrement branch 2 times, most recently from 0d26c0e to 1ca97b4 Compare November 2, 2018 00:25
@schmidt-sebastian
Copy link
Contributor Author

Hm, looks like this broke testServerTimestampsCanReturnPreviousValue. I'll take a look.

@schmidt-sebastian
Copy link
Contributor Author

Hm, looks like this broke testServerTimestampsCanReturnPreviousValue. I'll take a look.

I reverted the change that simplified the plumbing as this broke updates for transforms that were nested inside of a map.

Copy link
Contributor

@mikelehen mikelehen left a comment

Choose a reason for hiding this comment

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

On the whole, this looks fantastic. The baseMutations approach made this much less disruptive than I expected. Nice work! I have one potential concern about merge-set behavior, but we can perhaps punt on that. Otherwise, just lots of minor nits.

Copy link
Contributor Author

@schmidt-sebastian schmidt-sebastian left a comment

Choose a reason for hiding this comment

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

Addressed most feedback. Feel free to push back on some of my decisions :)

Copy link
Contributor

@mikelehen mikelehen left a comment

Choose a reason for hiding this comment

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

Thanks! Mild pushback / clarification on a couple things.

* @return The mutations that are used to populate the base values when this mutation batch is
* applied locally.
*/
public List<Mutation> getBaseMutations() {
Copy link
Contributor

Choose a reason for hiding this comment

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

"There may be more suitable use cases for this in the future, in which case the more general name may make more sense." Can you provide an example of such a use case?

Offhand I strongly suspect this will never be used for anything else, and so I'd err towards present naming clarity rather than futureproof-ing the name. I can be convinced otherwise though.

// Note: Theoretically, we should only include non-idempotent fields in this field mask as this
// mask is used to populate the base state for all DocumentTransforms. By including all
// fields, we incorrectly prevent rebasing of idempotent transforms (such as `arrayUnion()`)
// when any non-idempotent transforms are present.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a good comment, but it may not make sense out-of-context (it assumes knowledge of how this method is going to be used). I'd actually move it into LocalStore where getFieldMask() is called rather than having it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that makes sense. It's basically the same reason as to why I don't want to exclude the idempotent fields here.

@@ -968,6 +968,9 @@ public void testHandlesSetMutationThenTransformMutationThenTransformMutation() {
@Test
public void testHandlesSetMutationThenAckThenTransformMutationThenAckThenTransformMutation() {
if (garbageCollectorIsEager()) {
// Since this test doesn't open a Query, Eager GC removes the documents from the cache as soon
Copy link
Contributor

Choose a reason for hiding this comment

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

"open a Query" => "start a listen" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@mikelehen mikelehen left a comment

Choose a reason for hiding this comment

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

Oh... nice.

* @return The mutations that are used to populate the base values when this mutation batch is
* applied locally.
*/
public List<Mutation> getBaseMutations() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh... nice.

assertNotContains("foo/bar");

applyRemoteEvent(addedRemoteEvent(doc("foo/bar", 1, map("sum", 1337)), asList(2), emptyList()));
assertChanged(doc("foo/bar", 1, map("sum", 1), Document.DocumentState.LOCAL_MUTATIONS));
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh... nice.

mutation.getKey(),
ObjectValue.emptyObject(),
fieldMask,
mutation.getPrecondition()));
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh... nice.

Copy link
Contributor

@wilhuff wilhuff left a comment

Choose a reason for hiding this comment

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

proto changes: oh... nice!

@wilhuff wilhuff assigned schmidt-sebastian and unassigned wilhuff Nov 12, 2018
@schmidt-sebastian schmidt-sebastian changed the title Adding FieldValue.numericAdd() DO NOT MERGE Adding FieldValue.numericAdd() Nov 12, 2018
Copy link
Contributor

@wilhuff wilhuff left a comment

Choose a reason for hiding this comment

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

LGTM

@schmidt-sebastian
Copy link
Contributor Author

FYI: Pushed commit to rename this to "increment" as per the API Council.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Dec 26, 2018

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

Test name Commit Details Rerun command
connected-check bb10ecb link /test connected-check
connected-check-changed 991fb7c link /test connected-check-changed
smoke-tests-release 991fb7c link /test smoke-tests-release

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.

@schmidt-sebastian schmidt-sebastian changed the title DO NOT MERGE Adding FieldValue.numericAdd() Adding FieldValue.numericAdd() Mar 6, 2019
@google-oss-bot
Copy link
Contributor

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

Test name Commit Details Rerun command
smoke-tests-release 468c282 link /test smoke-tests-release

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.

@google-oss-bot
Copy link
Contributor

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

Test name Commit Details Rerun command
smoke-tests-debug 468c282 link /test smoke-tests-debug

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.

@schmidt-sebastian schmidt-sebastian merged commit 3823f1d into master Mar 6, 2019
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt-numericincrement branch March 12, 2019 23:59
@firebase firebase locked and limited conversation to collaborators Oct 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants