Skip to content

Commit 3e76b0c

Browse files
committed
feat(lvmsr): support vdi_revert on lvm
* Support `vdi_revert` * Add journals for rollback in case of failure * Rewrite lvm journal creation with security feature against writing too much inside allocated space * Read more in lvm journal Signed-off-by: Antoine Bartuccio <antoine.bartuccio@vates.tech>
1 parent 2efdee8 commit 3e76b0c

5 files changed

Lines changed: 829 additions & 229 deletions

File tree

drivers/FileSR.py

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@
1717
#
1818
# FileSR: local-file storage repository
1919
from pathlib import Path
20-
import json
2120
import contextlib
2221

23-
from sm_typing import Dict, Optional, List, override, Tuple, Collection, Union, Any, TypeVar, Type
22+
from sm_typing import Dict, Optional, List, override, Tuple, Collection, Union, Any
2423

25-
import abc
2624
import SR
2725
import VDI
2826
import SRCommand
@@ -37,6 +35,7 @@
3735
import time
3836
import glob
3937
import fjournaler
38+
from jutils import BaseLogEntry
4039
from uuid import uuid4
4140
from cowutil import (
4241
getCowUtil,
@@ -122,54 +121,6 @@ def from_file_vdi(cls, vdi: "FileVDI") -> "VDILogEntry":
122121
def __str__(self) -> str:
123122
return str(self.to_dict())
124123

125-
LogEntry = TypeVar("LogEntry", bound="BaseLogEntry")
126-
127-
class BaseLogEntry(abc.ABC):
128-
"""Base class for serializing journal based entries inteded to rollback failed operations"""
129-
130-
@property # type: ignore # Only way to simulate an abstract class variable
131-
@classmethod
132-
@abc.abstractmethod
133-
def CURRENT_VERSION(cls) -> str:
134-
...
135-
136-
@property # type: ignore # Only way to simulate an abstract class variable
137-
@classmethod
138-
@abc.abstractmethod
139-
def JRN_KEY(cls) -> str:
140-
...
141-
142-
@classmethod
143-
@abc.abstractmethod
144-
def from_dict(cls: Type[LogEntry], data: Dict[str, Any]) -> LogEntry:
145-
...
146-
147-
@abc.abstractmethod
148-
def to_dict(self) -> Dict[str, Collection[Any]]:
149-
...
150-
151-
@staticmethod
152-
def _get_version_from_journal_id(journal_id: str) -> str:
153-
_, version = journal_id.split("+")
154-
return version.replace("-", ".")
155-
156-
@classmethod
157-
def from_journal(cls: Type[LogEntry], journal_id: str, value: str) -> LogEntry:
158-
version = cls._get_version_from_journal_id(journal_id)
159-
if version != cls.CURRENT_VERSION:
160-
raise xs_errors.SRException(f"Could not revert operation {journal_id} with mismatched log versions {version} != {cls.CURRENT_VERSION}")
161-
return cls.from_dict(json.loads(value))
162-
163-
def to_journal(self) -> Tuple[str, str]:
164-
# We use + as a version delimiter to not clash with journaler file name parsing
165-
journal_id = f"{util.gen_uuid()}+{self.CURRENT_VERSION.replace('.', '-')}"
166-
value = json.dumps(self.to_dict())
167-
return journal_id, value
168-
169-
@override
170-
def __str__(self) -> str:
171-
return str(self.to_dict())
172-
173124
class RevertLogEntry(BaseLogEntry):
174125
"""Journal entry used to rollback failed revert operations"""
175126

0 commit comments

Comments
 (0)