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

JavaBinUpdateRequestCodec: Dead code removal #3207

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

dsmiley
Copy link
Contributor

@dsmiley dsmiley commented Feb 24, 2025

This PR removes some dead code in JavaBinUpdateRequestCodec (no test exercises it), and simplifies related logic.

Disclaimer It's possible and maybe likely that an old SolrJ might have sent data encoded with these types. It's also possible a user is using JavaBinCodec directly to do the same. Henceforth, they will get an error. As we have very little / inadequate backwards compatibility tests, I can't know for sure. The disclaimer is so vague and frankly kind of expected for a major version (that this targets) that I'm not sure anything meaningful could be said in upgrade notes.

I plan to merge for 10.

Context:

While working on something nearby, I noticed that JavaBinUpdateRequestCodec.readOuterMostDocIterator (server side, processes an update request that's JavaBin formatted) reads the outer most object checking for a variety of possibilities. I'm suspicious of them so added some asserts and found out when some were added.
https://issues.apache.org/jira/browse/SOLR-2904 weird
https://issues.apache.org/jira/browse/SOLR-13731 this one is actually tested but not realistically to how users use javabin.

Even if we just end up leaving some comments, it'd be helpful.

@github-actions github-actions bot added the tests label Mar 2, 2025
@dsmiley dsmiley marked this pull request as ready for review March 2, 2025 01:47
@@ -49,15 +42,6 @@
* @since solr 1.4
*/
public class JavaBinUpdateRequestCodec {
private boolean readStringAsCharSeq = false;

public JavaBinUpdateRequestCodec setReadStringAsCharSeq(boolean flag) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

unused; always false

@@ -69,32 +53,32 @@ public JavaBinUpdateRequestCodec setReadStringAsCharSeq(boolean flag) {
*/
public void marshal(UpdateRequest updateRequest, OutputStream os) throws IOException {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

simply moving code around for clarity in this method


// we don't add any docs, because they were already processed
// deletes are handled later, and must be passed back on the UpdateRequest
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the code improvements made this comment needless

Comment on lines +106 to +107
try (var codec = new StreamingCodec(handler)) {
namedList = codec.unmarshal(is);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

big improvement, simplifying the request/response contract here with the internal StreamingCodec. No need to have the array of NamedList or pass that in or pass an UpdateRequest. Now a simple NamedList response.

Comment on lines -304 to -307
if (o instanceof List) {
@SuppressWarnings("unchecked")
List<NamedList<?>> list = (List<NamedList<?>>) o;
sdoc = listToSolrInputDocument(list);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

Comment on lines -308 to -311
} else if (o instanceof NamedList) {
UpdateRequest req = new UpdateRequest();
req.setParams(new ModifiableSolrParams(((NamedList) o).toSolrParams()));
handler.update(null, req, null, null);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

} else if (o instanceof Map<?, ?> m) { // doc. To imitate JSON style. SOLR-13731
sdoc = convertMapToSolrInputDoc(m);
} else {
throw new IllegalStateException("Unexpected data type: " + o.getClass());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not being silent about the unexpected! I'll change this to SolrException(ErrorCode.BAD_REQUEST

UpdateRequest updateUnmarshalled =
new JavaBinUpdateRequestCodec()
.unmarshal(
is,
(document, req, commitWithin, override) -> {
if (commitWithin == null) {
req.add(document);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test needed an update because JavaBinUpdateRequestCodec no longer uses the same UpdateRequest between the add-docs and delete-docs parts, which doesn't matter. Arguably, the callback shouldn't even take an UpdateRequest anyway.

@dsmiley dsmiley changed the title JavaBinUpdateRequestCodec: Dead code? JavaBinUpdateRequestCodec: Dead code removal Mar 2, 2025
@dsmiley
Copy link
Contributor Author

dsmiley commented Mar 4, 2025

Plan to merge Friday to main; no changes.txt / JIRA. Merge commit message:

Dead code removal in JavaBinUpdateRequestCodec.
Compatibility: It's probable that an old SolrJ might sometimes send data encoded in a way that's no longer understood. It's also possible a user is using JavaBinCodec directly to do the same. Henceforth, they will get an error. As we have very little backwards compatibility tests, I can't know for sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant