Skip to content

Commit 615eacc

Browse files
committed
usage: widen usage_volume unique key to include vm_id
Backport of #13909 to 4.22, targeting 4.22.2. This also creates the 4.22.1.0 to 4.22.2.0 upgrade path, which didn't exist yet: schema-42210to42220.sql, its cleanup companion, the Upgrade42210to42220 class, and the registration in DatabaseUpgradeChecker. The CALLs can't go into schema-42200to42210.sql instead, because every 4.22.1.0 install has already run that file and those are the affected clusters.
1 parent 85bcdb1 commit 615eacc

4 files changed

Lines changed: 77 additions & 0 deletions

File tree

engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
import com.cloud.upgrade.dao.Upgrade42040to42100;
9595
import com.cloud.upgrade.dao.Upgrade42100to42200;
9696
import com.cloud.upgrade.dao.Upgrade42200to42210;
97+
import com.cloud.upgrade.dao.Upgrade42210to42220;
9798
import com.cloud.upgrade.dao.Upgrade420to421;
9899
import com.cloud.upgrade.dao.Upgrade421to430;
99100
import com.cloud.upgrade.dao.Upgrade430to440;
@@ -246,6 +247,7 @@ public DatabaseUpgradeChecker() {
246247
.next("4.20.4.0", new Upgrade42040to42100())
247248
.next("4.21.0.0", new Upgrade42100to42200())
248249
.next("4.22.0.0", new Upgrade42200to42210())
250+
.next("4.22.1.0", new Upgrade42210to42220())
249251
.build();
250252
}
251253

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.upgrade.dao;
18+
19+
public class Upgrade42210to42220 extends DbUpgradeAbstractImpl implements DbUpgrade {
20+
21+
@Override
22+
public String[] getUpgradableVersionRange() {
23+
return new String[] {"4.22.1.0", "4.22.2.0"};
24+
}
25+
26+
@Override
27+
public String getUpgradedVersion() {
28+
return "4.22.2.0";
29+
}
30+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- Licensed to the Apache Software Foundation (ASF) under one
2+
-- or more contributor license agreements. See the NOTICE file
3+
-- distributed with this work for additional information
4+
-- regarding copyright ownership. The ASF licenses this file
5+
-- to you under the Apache License, Version 2.0 (the
6+
-- "License"); you may not use this file except in compliance
7+
-- with the License. You may obtain a copy of the License at
8+
--
9+
-- http://www.apache.org/licenses/LICENSE-2.0
10+
--
11+
-- Unless required by applicable law or agreed to in writing,
12+
-- software distributed under the License is distributed on an
13+
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
-- KIND, either express or implied. See the License for the
15+
-- specific language governing permissions and limitations
16+
-- under the License.
17+
18+
--;
19+
-- Schema upgrade cleanup from 4.22.1.0 to 4.22.2.0
20+
--;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
-- Licensed to the Apache Software Foundation (ASF) under one
2+
-- or more contributor license agreements. See the NOTICE file
3+
-- distributed with this work for additional information
4+
-- regarding copyright ownership. The ASF licenses this file
5+
-- to you under the Apache License, Version 2.0 (the
6+
-- "License"); you may not use this file except in compliance
7+
-- with the License. You may obtain a copy of the License at
8+
--
9+
-- http://www.apache.org/licenses/LICENSE-2.0
10+
--
11+
-- Unless required by applicable law or agreed to in writing,
12+
-- software distributed under the License is distributed on an
13+
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
-- KIND, either express or implied. See the License for the
15+
-- specific language governing permissions and limitations
16+
-- under the License.
17+
18+
--;
19+
-- Schema upgrade from 4.22.1.0 to 4.22.2.0
20+
--;
21+
22+
-- Widen the unique key on cloud_usage.usage_volume to include vm_id, so the cumulative and
23+
-- per-VM volume usage records introduced in 4.22.1 can coexist. See #13399.
24+
CALL `cloud_usage`.`IDEMPOTENT_DROP_INDEX`('id', 'cloud_usage.usage_volume');
25+
CALL `cloud_usage`.`IDEMPOTENT_ADD_UNIQUE_INDEX`('cloud_usage.usage_volume', 'id', '(volume_id ASC, created ASC, vm_id ASC)');

0 commit comments

Comments
 (0)