Add startup check for missing database indexes#48696
Conversation
|
ps. I haven't tested it out yet, just to run the testsuite. |
ahus1
left a comment
There was a problem hiding this comment.
Hello Pedro, great to see this progressing!
See below for some suggested changes.
| .map(Map.Entry::getValue) | ||
| .toList(); | ||
| } catch (SQLException | LiquibaseException e) { | ||
| logger.debug("Unable to check for missing database indexes", e); |
There was a problem hiding this comment.
Should be a warning, as we want to be sure that if no log message is there, that all indexes exist as expected. With a debug log we can't do that.
| Set<String> existingIndexes = new HashSet<>(); | ||
|
|
||
| for (String table : tables) { | ||
| try (ResultSet rs = metaData.getIndexInfo(null, dbSchema, table, false, true)) { |
There was a problem hiding this comment.
It seems that some indexes are reported missing here, but the tables that they connect to are also missing. So with that, please ignore all indexes where the table is missing.
There was a problem hiding this comment.
Instead of where the table is missing, maybe "where the table has been deleted" might also be possible with the data from liquibase.
There was a problem hiding this comment.
I've changed to intercept the dropTable changes, and the logs are clean now.
a80f469 to
f2af3d9
Compare
Closes keycloak#48695 Signed-off-by: Pedro Ruivo <1492066+pruivo@users.noreply.github.com>
f2af3d9 to
228c3bc
Compare
Unreported flaky test detectedIf the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR. org.keycloak.testsuite.adapter.servlet.SAMLServletAdapterTest#testReloginWithInvalidAuthSessionCookieKeycloak CI - Adapter IT Strict Cookies |
…gelog with their cumulated state Signed-off-by: Alexander Schwartz <alexander.schwartz@ibm.com>
09daa46 to
b652e77
Compare
|
@pruivo - I tried to retrieve the indexes from H2, but there are just too many autogenerated ones which is very confusing. I then debugged a startup with PostgreSQL and it expected 106 indexes from the parsed Liquibase files. And then I asked IntelliJ to create a full schema export to SQL and this also showed 106 indexes. So I think this is now good enough. Please let me know your thoughts. |
It looks good to me. I tried last night with MSSQL as well and manually confirmed the This wouldn't have detected the mistake in the Liquibase changelog with the missing index. But I'm ok to merge if you are. |
Closes #48695
dropTablechanges - those remove indexes too.