-
Notifications
You must be signed in to change notification settings - Fork 1.4k
linstor: incremental snapshots on secondary storage #13746
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
base: 4.22
Are you sure you want to change the base?
Changes from 5 commits
8643df8
a11de68
2bb786e
26f95a8
22c192d
9f97aee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
| package org.apache.cloudstack.storage.snapshot; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; | ||
| import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory; | ||
| import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo; | ||
| import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao; | ||
| import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO; | ||
| import org.junit.Assert; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.mockito.Mock; | ||
| import org.mockito.Mockito; | ||
| import org.mockito.junit.MockitoJUnitRunner; | ||
|
|
||
| import com.cloud.storage.DataStoreRole; | ||
| import com.cloud.storage.SnapshotVO; | ||
|
|
||
| @RunWith(MockitoJUnitRunner.class) | ||
| public class SnapshotObjectTest { | ||
|
|
||
| private static final long PARENT_SNAPSHOT_ID = 2L; | ||
|
|
||
| @Mock | ||
| SnapshotDataStoreDao snapshotStoreDao; | ||
|
|
||
| @Mock | ||
| SnapshotDataFactory snapshotFactory; | ||
|
|
||
| @Mock | ||
| DataStore store; | ||
|
|
||
| @Mock | ||
| SnapshotVO snapshotVO; | ||
|
|
||
| SnapshotObject snapshotObject; | ||
|
|
||
| @Before | ||
| public void setUp() { | ||
| snapshotObject = new SnapshotObject(); | ||
| snapshotObject.configure(snapshotVO, store); | ||
| snapshotObject.snapshotStoreDao = snapshotStoreDao; | ||
| snapshotObject.snapshotFactory = snapshotFactory; | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetCorrectIncrementalParentNoRefsReturnsNull() { | ||
| Mockito.when(snapshotStoreDao.findBySnapshotId(PARENT_SNAPSHOT_ID)).thenReturn(Collections.emptyList()); | ||
|
|
||
| Assert.assertNull(snapshotObject.getCorrectIncrementalParent(PARENT_SNAPSHOT_ID)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetCorrectIncrementalParentPrefersCheckpointBearingRef() { | ||
| SnapshotDataStoreVO refWithoutCheckpoint = Mockito.mock(SnapshotDataStoreVO.class); | ||
| Mockito.when(refWithoutCheckpoint.getKvmCheckpointPath()).thenReturn(null); | ||
| SnapshotDataStoreVO refWithCheckpoint = Mockito.mock(SnapshotDataStoreVO.class); | ||
| Mockito.when(refWithCheckpoint.getKvmCheckpointPath()).thenReturn("checkpoints/2/5/uuid"); | ||
| Mockito.when(refWithCheckpoint.getDataStoreId()).thenReturn(5L); | ||
| Mockito.when(refWithCheckpoint.getRole()).thenReturn(DataStoreRole.Image); | ||
| Mockito.when(snapshotStoreDao.findBySnapshotId(PARENT_SNAPSHOT_ID)).thenReturn(List.of(refWithoutCheckpoint, refWithCheckpoint)); | ||
|
|
||
| SnapshotInfo parentInfo = Mockito.mock(SnapshotInfo.class); | ||
| Mockito.when(snapshotFactory.getSnapshot(PARENT_SNAPSHOT_ID, 5L, DataStoreRole.Image)).thenReturn(parentInfo); | ||
|
|
||
| Assert.assertEquals(parentInfo, snapshotObject.getCorrectIncrementalParent(PARENT_SNAPSHOT_ID)); | ||
| Mockito.verify(parentInfo).setKvmIncrementalSnapshot(true); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetCorrectIncrementalParentFallsBackToPlainParentWithoutCheckpointRefs() { | ||
| SnapshotDataStoreVO refWithoutCheckpoint = Mockito.mock(SnapshotDataStoreVO.class); | ||
| Mockito.when(refWithoutCheckpoint.getKvmCheckpointPath()).thenReturn(null); | ||
| Mockito.when(snapshotStoreDao.findBySnapshotId(PARENT_SNAPSHOT_ID)).thenReturn(List.of(refWithoutCheckpoint)); | ||
|
|
||
| SnapshotInfo parentInfo = Mockito.mock(SnapshotInfo.class); | ||
| Mockito.when(snapshotFactory.getSnapshot(PARENT_SNAPSHOT_ID, store)).thenReturn(parentInfo); | ||
|
|
||
| Assert.assertEquals(parentInfo, snapshotObject.getCorrectIncrementalParent(PARENT_SNAPSHOT_ID)); | ||
| Mockito.verify(parentInfo, Mockito.never()).setKvmIncrementalSnapshot(Mockito.anyBoolean()); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -252,14 +252,12 @@ public void create(final QemuImgFile file, final QemuImgFile backingFile, final | |
| Shouldn't this be -o backing_file=filename instead? | ||
| */ | ||
| s.add("-f"); | ||
| s.add(file.getFormat().toString()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we sure that the format is passed every time for the file if it has a backing file? If so, I think this change is good.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, all current callers pass |
||
| if (backingFile != null) { | ||
| s.add(backingFile.getFormat().toString()); | ||
| s.add("-F"); | ||
| s.add(backingFile.getFormat().toString()); | ||
| s.add("-b"); | ||
| s.add(backingFile.getFileName()); | ||
| } else { | ||
| s.add(file.getFormat().toString()); | ||
| } | ||
|
|
||
| s.add(file.getFileName()); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use a join here instead of Cartesian product, I have no idea why I did not do it with a join originally. Could you refactor this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done