This is pretty unusual as per my knowledge and I'm not able to find root cause.
I have a service that I deployed on one of our environments on Kubernetes. It failed to run with the following error:
2020-02-27 11:41:44,178 [instance=] [main] INFO org.flywaydb.core.internal.util.VersionPrinter (Slf4jLog.java:44) - Flyway 3.2.1 by Boxfuse
2020-02-27 11:41:50,665 [instance=] [main] INFO org.flywaydb.core.internal.dbsupport.DbSupportFactory (Slf4jLog.java:44) - Database: jdbc:oracle:thin:@hostname:port/ENVIRONMENT (Oracle 12.2)
2020-02-27 11:41:52,460 [instance=] [main] INFO org.flywaydb.core.internal.command.DbValidate (Slf4jLog.java:44) - Validated 8 migrations (execution time 00:01.063s)
2020-02-27 11:41:53,128 [instance=] [main] WARN org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext (AbstractApplicationContext.java:551) - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.api.FlywayException: Validate failed. Migration Checksum mismatch for migration 2019.4.1.1
-> Applied to database : 1659809745
-> Resolved locally : 1875162162
2020-02-27 11:41:53,129 [instance=] [main] INFO org.apache.catalina.core.StandardService (DirectJDKLog.java:180) - Stopping service [Tomcat]
2020-02-27 11:41:53,153 [instance=] [main] INFO org.springframework.boot.autoconfigure.logging.AutoConfigurationReportLoggingInitializer (AutoConfigurationReportLoggingInitializer.java:101) -
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2020-02-27 11:41:53,160 [instance=] [main] ERROR org.springframework.boot.SpringApplication (SpringApplication.java:771) - Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.api.FlywayException: Validate failed. Migration Checksum mismatch for migration 2019.4.1.1
-> Applied to database : 1659809745
-> Resolved locally : 1875162162
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:296)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1080)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:857)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
at com.domain.app.myapp.MyServiceApplication.main(MyServiceApplication.java:30)
Caused by: org.flywaydb.core.api.FlywayException: Validate failed. Migration Checksum mismatch for migration 2019.4.1.1
-> Applied to database : 1659809745
-> Resolved locally : 1875162162
at org.flywaydb.core.Flyway.doValidate(Flyway.java:1108)
at org.flywaydb.core.Flyway.access$300(Flyway.java:62)
at org.flywaydb.core.Flyway$1.execute(Flyway.java:1012)
at org.flywaydb.core.Flyway$1.execute(Flyway.java:1006)
at org.flywaydb.core.Flyway.execute(Flyway.java:1418)
at org.flywaydb.core.Flyway.migrate(Flyway.java:1006)
at org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:66)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
... 18 more
Process finished with exit code 1
I repaired checksums using mvn flyway:repair
and was able to run service locally. Though K8s was still showing a similar error. This time, I took these checksums manually from the error logs of K8s instance (Resolved Locally
) and put these checksums one by one in flyway schema. This got K8s instance running but now my local instance fails giving checksum error.
Any ideas where I might be taking the wrong approach here? Database host for both local and K8s instances is the same. I'm not sure why only one of these is able to validate Migations at one given scenario.
(I've changed filenames for obvious reasons)