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

Allow to create before_ prefixed columns in Consensus Commit #844

Conversation

brfrn169
Copy link
Collaborator

Currently, when we create a non-primary key column with a name that starts with before_, the column is not handled correctly. Specifically, the before column is not updated correctly in the prepare phase, as explained in the following comment:
#841 (comment)

This PR fixes the issue. Please take a look!

@brfrn169 brfrn169 self-assigned this Apr 20, 2023
Comment on lines +157 to +158
return !metadata.getPrimaryKeyColumnNames().contains(columnName)
&& metadata.getAfterImageColumnNames().contains(columnName);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

When the column is not primary key column and is an after image column, update the before column of the column.

With this change, users can create before_ prefixed columns as normal columns. If the column name is before_x, the before column name is before_before_x.

Copy link
Contributor

@komamitsu komamitsu Apr 20, 2023

Choose a reason for hiding this comment

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

Why don't you use just com.scalar.db.transaction.consensuscommit.TransactionTableMetadata#getBeforeImageColumnNames() ?

(added)^ Sorry, I meant return !metadata.getBeforeImageColumnNames().contains(columnName).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But return !metadata.getBeforeImageColumnNames().contains(columnName) contains the primary key columns? Or we can use return !metadata.getPrimaryKeyColumnNames().contains(columnName) && !metadata.getBeforeImageColumnNames().contains(columnName), but it looks like the current one is more straightforward. What do you think?

Copy link
Contributor

@komamitsu komamitsu Apr 20, 2023

Choose a reason for hiding this comment

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

Oops, got it. I had a wrong idea, and cluster key has before column while partition key doesn't have. Please ignore the previous comment.

Comment on lines +157 to +158
return !metadata.getPrimaryKeyColumnNames().contains(columnName)
&& metadata.getAfterImageColumnNames().contains(columnName);
Copy link
Contributor

@komamitsu komamitsu Apr 20, 2023

Choose a reason for hiding this comment

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

Why don't you use just com.scalar.db.transaction.consensuscommit.TransactionTableMetadata#getBeforeImageColumnNames() ?

(added)^ Sorry, I meant return !metadata.getBeforeImageColumnNames().contains(columnName).

@@ -70,6 +78,10 @@ public Set<String> getSecondaryIndexNames() {
return tableMetadata.getSecondaryIndexNames();
}

public LinkedHashSet<String> getPrimaryKeyColumnNames() {
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 very off-topic question and just out of curiosity, but why LinkedHashSet is used not just more abstract Set? I've not looked over all the usages. But it doesn't seem to need to be the concrete class type (sorry if I'm missing something)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

LinkedHashSet contains the context of the fixed iteration order (the insertion order). But Set doesn't have any context of the iteration order. We wanted to add the context of the iteration order to the return type.

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. So, List would be a simpler? It has contains() and ImmutableLinkedHashSet's contains() seems O(n) as well as List's one

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, using List is another possible idea. But the difference is that Set doesn't allow to have the same element, but List does. But, if I re-design this class, I would use List. Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, that makes sense 😉

Copy link
Contributor

@komamitsu komamitsu left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you!

Copy link
Contributor

@jnmt jnmt left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you for your quick fix. I also confirmed the issue did not happen in my local environment.

Copy link
Contributor

@Torch3333 Torch3333 left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

Copy link
Contributor

@feeblefakie feeblefakie left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you!

@feeblefakie feeblefakie merged commit 74dd32b into master Apr 24, 2023
12 checks passed
@feeblefakie feeblefakie deleted the allow-to-create-before-prefixed-columns-in-consensus-commit branch April 24, 2023 03:01
@brfrn169 brfrn169 added this to Done in 3.9.0 Apr 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
3.9.0
Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants