Skip to content

Commit 368ab20

Browse files
kofemannmksahakyan
authored andcommitted
srm,spacemanager: fix liquibase migration checksum mismatch
Motivation: The since dCache have migrated to liquibase4, some incomatibilies have been observed in srm and spacemanager db schema migrations. - new way of calculating checksums (with vs without spaces) - liqubase uses id+author to identify changesets. In case of collisions the behaviour is unpredictable, in particular, with liquibase 4.xx the wrong changeset is selected for validation. Modification: Add DB specific conditional statement to explicitly handle incompatibility. To ensure unique author+id combination. Add a concept of changeset-pre that will update checksums in databasechangelog to match new calculation rules (whitespace included vs excluded) and match checksums to new ids. `dcache database update` command as well as auto-migrate are updates to apply `pre` changes before the main change set. Result: srm and space manager databases can be migrated without issues Fixes: #7930 Acked-by: Dmitry Litvintsev Target: master, 11.1, 11.0 Require-book: no Require-notes: yes (cherry picked from commit 14a743e) Signed-off-by: Tigran Mkrtchyan <tigran.mkrtchyan@desy.de>
1 parent d0ff55c commit 368ab20

7 files changed

Lines changed: 56 additions & 7 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<databaseChangeLog
3+
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
6+
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.29.xsd">
7+
8+
<!--
9+
IMPORTANT:
10+
This file contains changes that should be applied prior any other schema changes,
11+
typically to fix liquibase or schema issues that prevent other changes from being applied.
12+
-->
13+
14+
<changeSet id="0.2" author="tigran" runOrder="first">
15+
16+
<comment>
17+
Fix liquibase issue with duplicate id and mismatching md5sums in databasechangelog table.
18+
This change set should be applied before any other changes.
19+
</comment>
20+
21+
<sql>
22+
UPDATE databasechangelog SET id='1.1' WHERE md5sum = '7:06282b8a1dd8aaf973cffe417726e36e';
23+
UPDATE databasechangelog SET id='2.1' WHERE md5sum = '7:cacb95e06876aa5ac4bba2288a0ff4a2';
24+
25+
UPDATE databasechangelog SET md5sum = '7:001b41c08a1151cb6c80f613eca8404d' WHERE md5sum = '7:2680461d52281f893a9d9a0fb09e0c3a';
26+
UPDATE databasechangelog SET md5sum = '7:5e691a2d81bcea624c3cee36c8a713a1' WHERE md5sum = '7:74c38b7901e8f9c20ab109c2dce6e1a8';
27+
UPDATE databasechangelog SET md5sum = '7:b39033e0e9d9a9cba9463b3ff51ea506' WHERE md5sum = '7:77c33a2aaa9cf04663eed16b67bec984';
28+
UPDATE databasechangelog SET md5sum = '7:fbe6e97e29f3001817daf4be5daa1079' WHERE md5sum = '7:b93ee356b569a0a28796b3f85dae4f1c';
29+
</sql>
30+
</changeSet>
31+
32+
</databaseChangeLog>

modules/dcache-spacemanager/src/main/resources/diskCacheV111/services/space/db/spacemanager.changelog-2.9.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
</rollback>
106106
</changeSet>
107107

108-
<changeSet id="1" author="behrmann">
108+
<changeSet id="1.1" author="behrmann">
109109
<comment>Replace free space column with available space column</comment>
110110
<renameColumn tableName="srmlinkgroup" oldColumnName="freespaceinbytes" newColumnName="availablespaceinbytes" columnDataType="bigint"/>
111111
<sql>UPDATE srmlinkgroup SET availablespaceinbytes = availablespaceinbytes - reservedspaceinbytes</sql>
@@ -387,7 +387,7 @@
387387
</rollback>
388388
</changeSet>
389389

390-
<changeSet id="2" author="behrmann">
390+
<changeSet id="2.1" author="behrmann">
391391
<comment>Drop pnfspath column</comment>
392392
<dropUniqueConstraint tableName="srmspacefile" constraintName="srmspacefile_pnfspath_unique"/>
393393
<dropColumn tableName="srmspacefile" columnName="pnfspath"/>
@@ -400,6 +400,9 @@
400400
</changeSet>
401401

402402
<changeSet id="4.1" author="behrmann">
403+
<preConditions onFail="MARK_RAN" onFailMessage="Site local srmspacefile_expirationtime_idx index not found (this is not an error)">
404+
<indexExists tableName="srmspacefile" indexName="srmspacefile_expirationtime_idx"/>
405+
</preConditions>
403406
<comment>Drop expirtationtime column</comment>
404407
<dropIndex tableName="srmspacefile" indexName="srmspacefile_expirationtime_idx"/>
405408
<dropColumn tableName="srmspacefile" columnName="expirationtime"/>

modules/dcache-spacemanager/src/main/resources/diskCacheV111/services/space/spacemanager.xml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,21 @@
8383
</constructor-arg>
8484
</bean>
8585

86-
<bean id="liquibase" class="org.dcache.util.SpringLiquibase">
86+
<bean id="liquibase-pre" class="org.dcache.util.SpringLiquibase">
87+
<description>Database schema manager</description>
88+
<property name="dataSource" ref="data-source"/>
89+
<property name="changeLog" value="classpath:${spacemanager.db.schema.changelog-pre}"/>
90+
<property name="shouldUpdate" value="${spacemanager.db.schema.auto}"/>
91+
</bean>
92+
93+
<bean id="liquibase" class="org.dcache.util.SpringLiquibase" depends-on="liquibase-pre">
8794
<description>Database schema manager</description>
8895
<property name="dataSource" ref="data-source"/>
8996
<property name="changeLog" value="classpath:${spacemanager.db.schema.changelog}"/>
9097
<property name="shouldUpdate" value="${spacemanager.db.schema.auto}"/>
9198
</bean>
9299

93-
<bean id="tx-manager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
100+
<bean id="tx-manager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
94101
<description>Database transaction manager</description>
95102
<property name="dataSource" ref="data-source"/>
96103
</bean>

modules/dcache-srm/src/main/resources/diskCacheV111/srm/srmmanager.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,14 @@
662662
</constructor-arg>
663663
</bean>
664664

665-
<bean id="liquibase" class="org.dcache.util.SpringLiquibase">
665+
<bean id="liquibase-pre" class="org.dcache.util.SpringLiquibase">
666+
<description>Database schema manager</description>
667+
<property name="dataSource" ref="data-source"/>
668+
<property name="changeLog" value="${srmmanager.db.schema.changelog-pre}"/>
669+
<property name="shouldUpdate" value="${srmmanager.db.schema.auto}"/>
670+
</bean>
671+
672+
<bean id="liquibase" class="org.dcache.util.SpringLiquibase" depends-on="liquibase-pre">
666673
<description>Database schema manager</description>
667674
<property name="dataSource" ref="data-source"/>
668675
<property name="changeLog" value="classpath:${srmmanager.db.schema.changelog}"/>

modules/srm-server/src/main/resources/org/dcache/srm/request/sql/srm.changelog-master.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
<property name="blob.type" value="bytea" dbms="postgresql"/>
88
<property name="blob.type" value="BLOB" dbms="oracle,h2,hsqldb"/>
99

10-
<include file="org/dcache/srm/request/sql/00-liquibase-fixes.xml"/>
11-
1210
<include file="org/dcache/srm/request/sql/srm.changelog-2.14.xml"/>
1311
<include file="org/dcache/srm/request/sql/srm.changelog-4.0.xml"/>
1412
</databaseChangeLog>

skel/share/defaults/spacemanager.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,5 +160,6 @@ spacemanager.db.schema.auto=${dcache.db.schema.auto}
160160
# Liquibase schema definition
161161
spacemanager.db.schema.changelog=diskCacheV111/services/space/db/spacemanager.changelog-master.xml
162162

163+
spacemanager.db.schema.changelog-pre=diskCacheV111/services/space/db/00-liquibase-fixes.xml
163164

164165
(obsolete)spacemanager.cell.export = See spacemanager.cell.consume

skel/share/defaults/srmmanager.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ srmmanager.db.connections.idle = 1
167167
# Liquibase schema definition
168168
srmmanager.db.schema.changelog=org/dcache/srm/request/sql/srm.changelog-master.xml
169169

170+
srmmanager.db.schema.changelog-pre=org/dcache/srm/request/sql/00-liquibase-fixes.xml
170171

171172
# ---- TCP streams to use for GridFTP transfer
172173
#

0 commit comments

Comments
 (0)