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

Resolves #1663: Add .map variant to RecordCursor that supports changing a result's continuation #1664

Merged
merged 5 commits into from May 19, 2022

Conversation

alecgrieser
Copy link
Contributor

This adds a variant to RecordCursor.map that allows the caller to adjust the continuations returned by a RecordCursor. This would allow, for example, for someone to wrap the continuations with new data, or otherwise adjust the continuations returned.

This resolves #1663.

@foundationdb-ci
Copy link
Contributor

AWS CodeBuild CI Report for Linux CentOS 7

  • CodeBuild project: fdb-record-layer-pr-proto3
  • Commit ID: b77a310
  • Result: SUCCEEDED
  • Error: N/A
  • Build Logs (available for 30 days)

@foundationdb-ci
Copy link
Contributor

AWS CodeBuild CI Report for Linux CentOS 7

  • CodeBuild project: fdb-record-layer-pr-proto2
  • Commit ID: b77a310
  • Result: SUCCEEDED
  • Error: N/A
  • Build Logs (available for 30 days)

// Stripping away the prefix and resuming the cursor should produce the rest of the list
byte[] continuation = result.getContinuation().toBytes();
assertNotNull(continuation);
RecordCursor<Integer> tailCursor = RecordCursor.fromList(ints, Arrays.copyOfRange(continuation, prefix.size(), continuation.length));
Copy link
Contributor

Choose a reason for hiding this comment

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

If only to provide an example, it would probably be good to have this also map the continuation.

Copy link
Contributor

Choose a reason for hiding this comment

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

I do wonder whether this is a problematic api, since:

RecordCursor.fromList(ints, continuation).mapContinuation(continuation -> { ... });

could be surprising, since the continuation does not line up.
This is similar to flatMapPipelined, and perhaps this should be a static method like that, but doing so would require providing a ContinuationConverter class (or two lambdas) that can do bidirectional conversion.

Potentially more importantly, the code as you have it might make it harder to decouple the code creating the continuation from the one mapping the continuation. Maybe, it's not a real issue, I'm having trouble thinking of a situation where there isn't something that passes the continuation into the code creating cursor, and also calls mapContinuation.

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, the way that it's the caller's responsibility to manipulate the continuation does feel like it could be a bit of a foot-gun. The alternative using a static method might look something like this:

    interface ContinuationConvertor {
        @Nullable
        byte[] unwrapContinuation(@Nullable byte[] continuation);

        RecordCursorContinuation wrapContinuation(@Nonnull RecordCursorContinuation continuation);
    }

    static <T> RecordCursor<T> mapContinuation(@Nonnull Function<byte[], RecordCursor<T>> cursorFunction, @Nonnull ContinuationConvertor convertor, @Nullable byte[] continuation) {
        byte[] innerContinuation = convertor.unwrapContinuation(continuation);
        return cursorFunction.apply(innerContinuation)
                .mapContinuation(convertor::wrapContinuation);
    }

(Note that it uses the current .mapContinuation value in its implementation, but that could theoretically be rewritten.)

Which...maybe isn't too bad, but it doesn't feel great.

@foundationdb-ci
Copy link
Contributor

AWS CodeBuild CI Report for Linux CentOS 7

  • CodeBuild project: fdb-record-layer-pr-proto2
  • Commit ID: 3ae777b
  • Result: SUCCEEDED
  • Error: N/A
  • Build Logs (available for 30 days)

@foundationdb-ci
Copy link
Contributor

AWS CodeBuild CI Report for Linux CentOS 7

  • CodeBuild project: fdb-record-layer-pr-proto3
  • Commit ID: 3ae777b
  • Result: SUCCEEDED
  • Error: N/A
  • Build Logs (available for 30 days)

}

/**
* Get a new cursor by applying transforming the continuation of each result. This function creates
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Get a new cursor by applying transforming the continuation of each result. This function creates
* Get a new cursor by applying a transformation to the continuation of each result. This function creates

@alecgrieser
Copy link
Contributor Author

Rebase addresses merge conflict

@foundationdb-ci
Copy link
Contributor

AWS CodeBuild CI Report for Linux CentOS 7

  • CodeBuild project: fdb-record-layer-pr-proto2
  • Commit ID: 1a74148
  • Result: FAILED
  • Error: Error while executing command: ./gradlew --no-daemon --console=plain -b ./build.gradle build destructiveTest sonarqube -PcoreNotStrict -PreleaseBuild=false -PpublishBuild=false -PspotbugsEnableHtmlReport. Reason: exit status 1
  • Build Logs (available for 30 days)

@foundationdb-ci
Copy link
Contributor

AWS CodeBuild CI Report for Linux CentOS 7

  • CodeBuild project: fdb-record-layer-pr-proto3
  • Commit ID: 1a74148
  • Result: FAILED
  • Error: Error while executing command: ./gradlew --no-daemon --console=plain -b ./build.gradle build destructiveTest sonarqube -PcoreNotStrict -PreleaseBuild=false -PpublishBuild=false -PspotbugsEnableHtmlReport. Reason: exit status 1
  • Build Logs (available for 30 days)

…ports changing a result's continuation

This adds a variant to `RecordCursor.map` that allows the caller to adjust the continuations returned by a `RecordCursor`. This would allow, for example, for someone to wrap the continuations with new data, or otherwise adjust the continuations returned.

This resolves FoundationDB#1663.
… the user think about both wrapping and unwrapping the continuation
@foundationdb-ci
Copy link
Contributor

AWS CodeBuild CI Report for Linux CentOS 7

  • CodeBuild project: fdb-record-layer-pr-proto3
  • Commit ID: 844ee07
  • Result: FAILED
  • Error: Error while executing command: ./gradlew --no-daemon --console=plain -b ./build.gradle build destructiveTest sonarqube -PcoreNotStrict -PreleaseBuild=false -PpublishBuild=false -PspotbugsEnableHtmlReport. Reason: exit status 1
  • Build Logs (available for 30 days)

@foundationdb-ci
Copy link
Contributor

AWS CodeBuild CI Report for Linux CentOS 7

  • CodeBuild project: fdb-record-layer-pr-proto2
  • Commit ID: 844ee07
  • Result: SUCCEEDED
  • Error: N/A
  • Build Logs (available for 30 days)

@foundationdb-ci
Copy link
Contributor

AWS CodeBuild CI Report for Linux CentOS 7

  • CodeBuild project: fdb-record-layer-pr-proto3
  • Commit ID: 08b1be3
  • Result: SUCCEEDED
  • Error: N/A
  • Build Logs (available for 30 days)

@foundationdb-ci
Copy link
Contributor

AWS CodeBuild CI Report for Linux CentOS 7

  • CodeBuild project: fdb-record-layer-pr-proto2
  • Commit ID: 08b1be3
  • Result: SUCCEEDED
  • Error: N/A
  • Build Logs (available for 30 days)

ScottDugas
ScottDugas previously approved these changes May 17, 2022
@alecgrieser
Copy link
Contributor Author

Made a trivial commit (changing commit date) to cause PRBs to re-run

@foundationdb-ci
Copy link
Contributor

AWS CodeBuild CI Report for Linux CentOS 7

  • CodeBuild project: fdb-record-layer-pr-proto2
  • Commit ID: d04a5a5
  • Result: SUCCEEDED
  • Error: N/A
  • Build Logs (available for 30 days)

@sonarcloud
Copy link

sonarcloud bot commented May 17, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 3 Code Smells

0.0% 0.0% Coverage
5.4% 5.4% Duplication

@foundationdb-ci
Copy link
Contributor

AWS CodeBuild CI Report for Linux CentOS 7

  • CodeBuild project: fdb-record-layer-pr-proto3
  • Commit ID: d04a5a5
  • Result: SUCCEEDED
  • Error: N/A
  • Build Logs (available for 30 days)

@ScottDugas ScottDugas merged commit f0bda52 into FoundationDB:main May 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add .map variant to RecordCursor that supports changing a result's continuation
3 participants