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

Fault tolerant execution for Mongo connector #15062

Merged
merged 3 commits into from
Nov 24, 2022

Conversation

mwd410
Copy link
Contributor

@mwd410 mwd410 commented Nov 16, 2022

Description

This provides support for FTE with the Mongo connector. It uses the same paradigm as my previous PR. We only use this new paradigm with retries enabled, otherwise we use the old paradigm. This is important because this also increases our minimum mongo version from 4.0 to 4.2, but only when FTE is enabled - this allows clients using Mongo on 4.0 to continue upgrading their trino version without having to upgrade their mongo, so long as they can live without FTE.

Non-technical explanation

This provides support for fault tolerant execution on MongoDB. If you want to enable FTE, we require a minimum of Mongo version 4.2, otherwise we still support 4.0.

Release notes

( ) This is not user-visible or docs only and no release notes are required.
( ) Release notes are required, please propose a release note for me.
(x) Release notes are required, with the following suggested text:

# MongoDB
* Upgrade minimum required MongoDB version to 4.2. ({issue}`15062`)
* Add support for writes when [fault-tolerant
  execution](/admin/fault-tolerant-execution) is enabled. ({issue}`15062`)

@cla-bot cla-bot bot added the cla-signed label Nov 16, 2022
@mwd410 mwd410 requested review from ebyhr and losipiuk November 16, 2022 20:00
@mwd410 mwd410 force-pushed the mdeady-mongo-fte-3877 branch from 87e28de to 772653b Compare November 16, 2022 20:02
@github-actions github-actions bot added the docs label Nov 16, 2022
@mwd410 mwd410 force-pushed the mdeady-mongo-fte-3877 branch from 772653b to 65c4fce Compare November 16, 2022 21:03
@mwd410 mwd410 force-pushed the mdeady-mongo-fte-3877 branch from 65c4fce to 9f263b2 Compare November 17, 2022 16:26
@@ -14,7 +14,7 @@ Requirements

To connect to MongoDB, you need:

* MongoDB 4.0 or higher.
* MongoDB 4.2 or higher.
Copy link
Member

Choose a reason for hiding this comment

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

This should go into release notes @colebow

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there something I need to do for that?

Copy link
Member

Choose a reason for hiding this comment

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

Nope, you're good! You've ticked the box in the PR template, so I've got it from here. 😄

@mwd410 mwd410 force-pushed the mdeady-mongo-fte-3877 branch 2 times, most recently from 0360f33 to 78aa2b7 Compare November 21, 2022 18:40
Map<String, String> properties = ImmutableMap.of(
"mongodb.case-insensitive-name-matching", "true",
"mongodb.connection-url", server.getConnectionString().toString());
connectorProperties = new HashMap(ImmutableMap.copyOf(connectorProperties));
Copy link
Member

Choose a reason for hiding this comment

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

Why HashMap? I would stick to the pattern and use ImmutableMap.Builder here,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PostgreSqlQueryRunner uses a HashMap, but OK.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using HashMap makes it possible to override the default connectorProperties. If i used an ImmutableMap.builder(), the builder doesn't have a putIfAbsent, and our style checks require i use buildOrThrow() rather than build(), so it'd be very awkward to allow that.

Comment on lines +44 to +45
this.temporaryTableName = requireNonNull(temporaryTableName, "temporaryTableName is null");
this.pageSinkIdColumnName = requireNonNull(pageSinkIdColumnName, "pageSinkIdColumnName is null");
Copy link
Member

Choose a reason for hiding this comment

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

verify either both or none set. Those always come in pairs, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

gah - i added that to MongoInsertTableHandle and forgot to here.

.addAll(columns)
.add(pageSinkIdColumn)
.build();
SchemaTableName tempTable = SchemaTableName.schemaTableName(tableMetadata.getTable().getSchemaName(), generateTemporaryTableName());
Copy link
Member

Choose a reason for hiding this comment

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

nit: s/temp/temporary/


MongoTableHandle table = (MongoTableHandle) tableHandle;
List<MongoColumnHandle> columns = mongoSession.getTable(table.getSchemaTableName()).getColumns();
SchemaTableName tempTable = SchemaTableName.schemaTableName(handle.getSchemaTableName().getSchemaName(), generateTemporaryTableName());
Copy link
Member

Choose a reason for hiding this comment

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

same


try {
// Create the temporary page sink ID table
SchemaTableName pageSinkTable = SchemaTableName.schemaTableName(tempTable.getSchemaName(), generateTemporaryTableName());
Copy link
Member

Choose a reason for hiding this comment

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

pageSinkIdsTable?

return Optional.empty();
}

private void finishInsert(
SchemaTableName targetTable,
SchemaTableName tempTable,
Copy link
Member

Choose a reason for hiding this comment

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

temporary

closer.register(() -> mongoSession.dropTable(pageSinkTable));

// Insert all the page sink IDs into the page sink ID table
MongoCollection<Document> pageSinkCollection = mongoSession.getCollection(pageSinkTable);
Copy link
Member

Choose a reason for hiding this comment

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

pageSinkIds?

.collect(toImmutableList());
pageSinkCollection.insertMany(pageSinkIds);

MongoCollection<Document> tempCollection = mongoSession.getCollection(tempTable);
Copy link
Member

Choose a reason for hiding this comment

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

unfilteredInsertedRows?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

stuck with temporaryCollection

Copy link
Member

@losipiuk losipiuk left a comment

Choose a reason for hiding this comment

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

LGTM - some naming suggestions.
@ebyhr do you have some more actual comments or is it good to go?

@mwd410 mwd410 force-pushed the mdeady-mongo-fte-3877 branch from 78aa2b7 to 0208bd9 Compare November 22, 2022 15:40
Copy link
Member

@ebyhr ebyhr left a comment

Choose a reason for hiding this comment

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

Could you rebase on upstream and resolve conflicts?

@mwd410 mwd410 force-pushed the mdeady-mongo-fte-3877 branch from 0208bd9 to e85eb93 Compare November 23, 2022 20:24
@mwd410 mwd410 force-pushed the mdeady-mongo-fte-3877 branch from e85eb93 to 8af798e Compare November 24, 2022 03:28
@losipiuk losipiuk merged commit 6547e26 into trinodb:master Nov 24, 2022
@losipiuk
Copy link
Member

🎉

@github-actions github-actions bot added this to the 404 milestone Nov 24, 2022
@ebyhr ebyhr mentioned this pull request Nov 24, 2022
@mwd410 mwd410 deleted the mdeady-mongo-fte-3877 branch November 28, 2022 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

5 participants