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

Add concurrent adding columns (ALTER TABLE ADD COLUMN) test to BaseConnectorTest #12483

Merged
merged 1 commit into from
May 24, 2022

Conversation

ebyhr
Copy link
Member

@ebyhr ebyhr commented May 20, 2022

Description

Add concurrent adding columns test to BaseConnectorTest

Documentation

(x) No documentation is needed.

Release notes

(x) No release notes entries required.

@ebyhr ebyhr added the no-release-notes This pull request does not require release notes entry label May 20, 2022
@cla-bot cla-bot bot added the cla-signed label May 20, 2022
@ebyhr ebyhr marked this pull request as ready for review May 20, 2022 05:58
@ebyhr ebyhr marked this pull request as draft May 20, 2022 06:21
@ebyhr ebyhr force-pushed the ebi/test-concurrent-add-column branch 2 times, most recently from 20bd646 to c4c227b Compare May 20, 2022 09:50
@ebyhr ebyhr changed the title Add concurrent adding columns test to BaseConnectorTest Add concurrent adding columns (ALTER TABLE ADD COLUMN) test to BaseConnectorTest May 20, 2022
@ebyhr ebyhr marked this pull request as ready for review May 23, 2022 00:25
@ebyhr ebyhr requested review from findepi and hashhar May 23, 2022 00:25
@ebyhr
Copy link
Member Author

ebyhr commented May 23, 2022

CI hit #11634

@Override
public void testAddColumnConcurrently()
{
// Difficult to determine whether the exception is concurrent issue or not from the error message
Copy link
Member

Choose a reason for hiding this comment

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

Let it render as a TODO in an IDE

Suggested change
// Difficult to determine whether the exception is concurrent issue or not from the error message
// TODO: Difficult to determine whether the exception is concurrent issue or not from the error message

@@ -255,6 +255,14 @@ protected String errorMessageForInsertIntoNotNullColumn(String columnName)
return format("NULL not allowed for column \"%s\"(?s).*", columnName.toUpperCase(ENGLISH));
}

@Test(enabled = false)
Copy link
Member

Choose a reason for hiding this comment

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

redundant over throw new SkipException in override

Suggested change
@Test(enabled = false)

@Override
public void testAddColumnConcurrently()
{
// Default storage engine doesn't support adding new columns
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Default storage engine doesn't support adding new columns
// TODO: Default storage engine doesn't support adding new columns

protected void verifyConcurrentAddColumnFailurePermissible(Exception e)
{
assertThat(e)
.hasMessageContaining("Cannot update Iceberg table: supplied previous location does not match current location");
Copy link
Member

Choose a reason for hiding this comment

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

This probably should be "Failed to commit Iceberg .."
but is fine for now.

cc @alexjo2144

@Override
public void testAddColumnConcurrently()
{
throw new SkipException("TODO: Enable after supporting multi-document transaction https://www.mongodb.com/docs/manual/core/transactions/");
Copy link
Member

Choose a reason for hiding this comment

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

remove @Test(enabled = false) (redundant)
and add a // TODO: ... comment so that an IDE can highlight this as a TODO

Comment on lines +889 to +894
.hasMessageContaining("Failed to perform metadata operation")
.getCause()
.hasMessageMatching(
"(?s).*SQLIntegrityConstraintViolationException.*" +
"|.*Unique index or primary key violation.*" +
"|.*Deadlock found when trying to get lock; try restarting transaction.*");
Copy link
Member

Choose a reason for hiding this comment

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

Nice!

.mapToObj(threadNumber -> executor.submit(() -> {
barrier.await(30, SECONDS);
try {
getQueryRunner().execute("ALTER TABLE " + tableName + " ADD COLUMN col" + threadNumber + " integer");
Copy link
Member

Choose a reason for hiding this comment

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

Declare String columnName = "col" + threadNumber;
and make the Future a Future<Optional<String>> by retuning the columnName on success

}))
.collect(toImmutableList());

List<Integer> values = futures.stream()
Copy link
Member

Choose a reason for hiding this comment

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

List<Integer> values -> List<String> addedColumns

Comment on lines 2895 to 2908
if (values.isEmpty()) {
assertThat(query("DESCRIBE " + tableName))
.projected(0)
.skippingTypesCheck()
.matches("VALUES ('col')");
}
else {
assertThat(query("DESCRIBE " + tableName))
.projected(0)
.skippingTypesCheck()
.matches(values.stream()
.map(value -> format("('col%s')", value))
.collect(joining(",", "VALUES ('col'),", "")));
}
Copy link
Member

Choose a reason for hiding this comment

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

You can handle both cases with single assert using Stream.concat:

.matches(Stream.concat(Stream.of("col"), addedColumns.stream())
                            .map(value -> format("'%s'", value))
                            .collect(joining(",", "VALUES ", "")));

verifyConcurrentAddColumnFailurePermissible(trinoException);
}
catch (Throwable verifyFailure) {
if (trinoException != e && verifyFailure != e) {
Copy link
Member

Choose a reason for hiding this comment

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

i don't know why we have trinoException != e &&

i think it comes from earlier tests with similar pattern, but i don't remember why the first one (mine) has this

Copy link
Member

Choose a reason for hiding this comment

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

.map(OptionalInt::getAsInt)
.collect(toImmutableList());

if (values.isEmpty()) {
Copy link
Member

Choose a reason for hiding this comment

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

Should at least one of these always succeed?

Copy link
Member

Choose a reason for hiding this comment

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

We can require at least one success, but then we may need to provide a connector a way to opt-out.
(i am fine not requiring this, and fine requiring this; and opt-out can be added later, if not needed now)

@ebyhr ebyhr force-pushed the ebi/test-concurrent-add-column branch from 230f829 to 3a4168d Compare May 24, 2022 00:25
@ebyhr ebyhr merged commit 7c69c7d into master May 24, 2022
@ebyhr ebyhr deleted the ebi/test-concurrent-add-column branch May 24, 2022 01:45
@github-actions github-actions bot added this to the 382 milestone May 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed no-release-notes This pull request does not require release notes entry
Development

Successfully merging this pull request may close these issues.

3 participants