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

feat: Add support for multiple CopyData messages #40

Merged
merged 20 commits into from
Feb 22, 2022

Conversation

Vizerai
Copy link
Collaborator

@Vizerai Vizerai commented Feb 17, 2022

No description provided.

@Vizerai
Copy link
Collaborator Author

Vizerai commented Feb 17, 2022

I will add some additional tests to check row splitting between multiple CopyData messages.

Copy link
Collaborator

@tinaspark tinaspark left a comment

Choose a reason for hiding this comment

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

It's hard to me to track all the different things going on, why they depend on each other, and if all the changes are adequately tested. I'm seeing a few things here

  1. Instead of parsing the CopyData payloads as they come in, put them all in a buffer and parse when we receive a CopyDone -- this looks reasonable to me and fits the goal of this PR
  2. Move parseCommand from IntermediateStatement to StatementParser -- this looks reasonable but should probably in another PR
  3. Error checking for COPY_IN in ControlMessage.java and some status handling in QueryMessage.java -- this should probably be in another PR

@Vizerai
Copy link
Collaborator Author

Vizerai commented Feb 18, 2022

I broke off the other changes into separate PRs.

}

@Test
public void testMultipleCopyDataMessages() throws Exception {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I assume that this is a placeholder for a test that is coming in a next PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated now.

@Vizerai Vizerai changed the title Adding support for multiple CopyData messages within a single Copy. Adding support for multiple CopyData messages Feb 21, 2022
@olavloite
Copy link
Collaborator

I think the current build errors might be caused by b/217744569

@olavloite
Copy link
Collaborator

I think the current build errors might be caused by b/217744569

That assumption was wrong. It's caused by another issue.

@olavloite olavloite changed the title Adding support for multiple CopyData messages feat: Add support for multiple CopyData messages Feb 22, 2022
* @return True if current payload will fit within COMMIT_LIMIT. This is only an estimate and the
* actual commit size may still be rejected by Spanner.
*/
private boolean payloadFitsInCurrentBatch() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we name this commitSizeIsWithinLimit to match the naming of mutationCountIsWithinLimit? Also because the batching has been removed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

rollback(connectionHandler, payload);
long mutationCount = this.mutationCount + records.size() * records.get(0).size();
long commitSize = this.batchSize + payload.length;
public void addMutations(ConnectionHandler connectionHandler, byte[] payload) throws Exception {
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you name this addCopyData since we aren't doing anything with mutations yet

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

} else {
System.err.println("File " + unsuccessfulCopy.getName() + " already exists");
}
this.fileWriter = new FileWriter(unsuccessfulCopy, false);
}

public void writeToErrorFile(byte[] payload) throws IOException {
Copy link
Collaborator

Choose a reason for hiding this comment

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

rename to: writeCopyDataToErrorFile

add a comment that this is used if there are problems while collecting CopyData messages or building the mutation list

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

}
this.fileWriter.write(new String(payload, StandardCharsets.UTF_8).trim() + "\n");
}

public void writeMutationsToErrorFile() throws IOException {
Copy link
Collaborator

Choose a reason for hiding this comment

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

add a comment that this is used if Spanner returns an error when we try to commit the mutations

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

Copy link
Collaborator

Choose a reason for hiding this comment

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

actually, I'm thinking about this again and why are we writing the mutations to the file at all? The original intention of the error file was for the user to look through the copy data that they sent to PGAdapter, fix it, and try again. I think we should always be writing the payload data, not the mutation data

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed to write the copy data instead.

if (this.fileWriter == null) {
createErrorFile();
}
this.fileWriter.write(new String(payload, StandardCharsets.UTF_8).trim() + "\n");
}

/**
* The list of mutaitons will be written to the error file if a problem was encountered while
Copy link
Collaborator

Choose a reason for hiding this comment

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

mutations

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Reworded comment.

}
this.fileWriter.write(new String(payload, StandardCharsets.UTF_8).trim() + "\n");
}

public void writeMutationsToErrorFile() throws IOException {
Copy link
Collaborator

Choose a reason for hiding this comment

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

actually, I'm thinking about this again and why are we writing the mutations to the file at all? The original intention of the error file was for the user to look through the copy data that they sent to PGAdapter, fix it, and try again. I think we should always be writing the payload data, not the mutation data

for (Mutation mutation : this.mutations) {
this.fileWriter.write(mutation.toString());
}
public void writeCopyDataToErrorFile() throws IOException {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think every time we write to the error file we write the full payload so you can just have a single version of writeCopyDataToErrorFile() without having a payload argument

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@Vizerai Vizerai merged commit 24eeedc into postgresql-dialect Feb 22, 2022
@olavloite olavloite deleted the copydata branch March 6, 2022 16:05
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.

3 participants