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

[aYPLiTQG] Remove isSchema check to be more performant #4150

Merged
merged 2 commits into from
Aug 29, 2024

Conversation

gem-neo4j
Copy link
Contributor

RunFile is not allowed to run schema operations, in 4.4.0.9 the validation check for this was a regex that was very basic, then in 4.4.0.11 this was updated to be more accurate, what happens is that every query gets run through an explain which checks if the query is a Schema operation, and if it is, it will ignore it.

The problem I see with this is that it will now run this potentially time consuming check for every query in the file as well as actually running the query.

This PR removes this check and instead checks the errors thrown, if a schema error is thrown then it will handle this there to keep old behaviour.

@gem-neo4j gem-neo4j added 4.4 team-cypher-surface Cypher Surface team should review the PR labels Jul 24, 2024
@gem-neo4j gem-neo4j force-pushed the 4.4_run_files_updates branch from 693a83a to 7ad6b42 Compare July 24, 2024 11:38
} else {
// Periodic operations cannot be schema operations, so no need to check that here (will fail as invalid
// query)
if (isPeriodicOperation(stmt)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This check is not fool proof (it's another query string regex). Could we remove this branch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is 4.4 extended, so I was just leaving the behaviour as it was to not break anything

Util.inTx(db, pools, threadTx -> {
try (Result result = threadTx.execute(stmt, params)) {
return consumeResult(result, queue, addStatistics, tx, fileName);
} catch (Exception e) {
collectError(queue, reportError, e, fileName);
// APOC historically skips schema operations
if (!e.getMessage().contains("Schema operations on database 'neo4j' are not allowed")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice if we could use the error code here instead of parsing the message, but I assume it's not possible?

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 error code was just for "forbidden" things, which felt kinda broad, I guess once the GQL status codes start we will be able to do that more :D

Util.inTx(db, pools, threadTx -> {
try (Result result = threadTx.execute(stmt, params)) {
return consumeResult(result, queue, addStatistics, tx, fileName);
} catch (Exception e) {
collectError(queue, reportError, e, fileName);
// APOC historically skips schema operations
if (!e.getMessage().contains("Schema operations on database 'neo4j' are not allowed")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

on database 'neo4j', what about databases that has another name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yes 🙈

@loveleif loveleif self-assigned this Jul 29, 2024
@gem-neo4j gem-neo4j force-pushed the 4.4_run_files_updates branch from 7ad6b42 to b6d57a9 Compare July 29, 2024 08:47
@gem-neo4j gem-neo4j requested a review from loveleif July 30, 2024 07:36
@gem-neo4j
Copy link
Contributor Author

cc @loveleif :)

Comment on lines +275 to +276
if (!(e.getMessage().contains("Schema operations on database")
&& e.getMessage().contains("are not allowed"))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

YOLO

@gem-neo4j gem-neo4j merged commit 7e6cf18 into 4.4 Aug 29, 2024
12 checks passed
@gem-neo4j gem-neo4j deleted the 4.4_run_files_updates branch August 29, 2024 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.4 team-cypher-surface Cypher Surface team should review the PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants