Adam Litke has uploaded a new change for review.

Change subject: storage: Add support for generation id to VolumeMetadata
......................................................................

storage: Add support for generation id to VolumeMetadata

We would like to add support for a new generation id key in the volume
metadata.  GENID is a monotonically increasing integer that can be used
to determine whether certain operations have been completed on a volume
and to prevent two hosts from sequentially performing the same operation
in the event of double scheduling.

The new GENID key is optional.  If we read metadata without this key, a
default value of 0 will be reported.

This patch supports only the manipulation of the generation ID within
the VolumeMetadata class.  The value will be made available via
Volume.getInfo in a follow-up patch and will be changed by verbs in
subsequent patches.

Change-Id: Icb71e1fc78f6c1e411e725b26c48411ffd04d0b6
Signed-off-by: Adam Litke <[email protected]>
---
M lib/vdsm/storage/constants.py
M lib/vdsm/storage/volumemetadata.py
M tests/storage_volume_metadata_test.py
3 files changed, 26 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/84/64484/1

diff --git a/lib/vdsm/storage/constants.py b/lib/vdsm/storage/constants.py
index 4c00a5b..e2f6cea 100644
--- a/lib/vdsm/storage/constants.py
+++ b/lib/vdsm/storage/constants.py
@@ -125,6 +125,7 @@
 DESCRIPTION = "DESCRIPTION"
 LEGALITY = "LEGALITY"
 MTIME = "MTIME"
+GENERATION = "GENID"
 POOL = MDK_POOLS  # Deprecated
 
 # In block storage, metadata size is limited to BLOCK_SIZE (512), to
diff --git a/lib/vdsm/storage/volumemetadata.py 
b/lib/vdsm/storage/volumemetadata.py
index a8d9641..7dc3bc9 100644
--- a/lib/vdsm/storage/volumemetadata.py
+++ b/lib/vdsm/storage/volumemetadata.py
@@ -33,10 +33,12 @@
 
     def __init__(self, domain, image, puuid, size, format,
                  type, voltype, disktype, description="",
-                 legality=constants.ILLEGAL_VOL, ctime=None, mtime=None):
+                 legality=constants.ILLEGAL_VOL, ctime=None, mtime=None,
+                 generation=None):
         assert(isinstance(size, int))
         assert(ctime is None or isinstance(ctime, int))
         assert(mtime is None or isinstance(mtime, int))
+        assert(generation is None or isinstance(generation, int))
 
         # Storage domain UUID
         self.domain = domain
@@ -62,6 +64,8 @@
         self.ctime = int(time.time()) if ctime is None else ctime
         # Volume modification time (unused and should be zero)
         self.mtime = 0 if mtime is None else mtime
+        # Generation ID increments each time certain operations complete
+        self.generation = 0 if generation is None else generation
 
     @classmethod
     def from_lines(cls, lines):
@@ -86,7 +90,8 @@
                        description=md[constants.DESCRIPTION],
                        legality=md[constants.LEGALITY],
                        ctime=int(md[constants.CTIME]),
-                       mtime=int(md[constants.MTIME]))
+                       mtime=int(md[constants.MTIME]),
+                       generation=int(md.get(constants.GENERATION, 0)))
         except KeyError as e:
             raise exception.MetaDataKeyNotFoundError(
                 "Missing metadata key: %s: found: %s" % (e, md))
@@ -144,4 +149,5 @@
             constants.PUUID: self.puuid,
             constants.MTIME: str(self.mtime),
             constants.LEGALITY: self.legality,
+            constants.GENERATION: self.generation,
         }
diff --git a/tests/storage_volume_metadata_test.py 
b/tests/storage_volume_metadata_test.py
index b8f5873..efd64a6 100644
--- a/tests/storage_volume_metadata_test.py
+++ b/tests/storage_volume_metadata_test.py
@@ -44,7 +44,8 @@
         voltype=sc.type2name(sc.LEAF_VOL),
         disktype=image.SYSTEM_DISK_TYPE,
         description="",
-        legality=sc.LEGAL_VOL)
+        legality=sc.LEGAL_VOL,
+        generation=0)
     res.update(kwargs)
     return res
 
@@ -64,6 +65,7 @@
         sc.MTIME: '0',
         sc.CTIME: '0',
         sc.POOL: '',
+        sc.GENERATION: '1',
     }
     res.update(kwargs)
     return res
@@ -96,7 +98,8 @@
             PUUID=params['puuid'],
             SIZE=str(params['size']),
             TYPE=params['type'],
-            VOLTYPE=params['voltype'])
+            VOLTYPE=params['voltype'],
+            GENID=params['generation'])
 
         with MonkeyPatchScope([[time, 'time', lambda: FAKE_TIME]]):
             info = volume.VolumeMetadata(**params).legacy_info()
@@ -110,6 +113,7 @@
             DISKTYPE=%(disktype)s
             DOMAIN=%(domain)s
             FORMAT=%(format)s
+            GENID=%(generation)s
             IMAGE=%(image)s
             LEGALITY=%(legality)s
             MTIME=0
@@ -137,9 +141,10 @@
         params = make_init_params(**{param: 'not_an_int'})
         self.assertRaises(AssertionError, volume.VolumeMetadata, **params)
 
-    @permutations([[key] for key in make_md_dict() if key != sc.POOL])
+    @permutations([[key] for key in make_md_dict()
+                   if key not in (sc.POOL, sc.GENERATION)])
     def test_from_lines_missing_key(self, required_key):
-        data = make_md_dict(CTIME=None, MTIME=None, POOL=None)
+        data = make_md_dict(POOL=None)
         data[required_key] = None
         lines = make_lines(**data)
         self.assertRaises(se.MetaDataKeyNotFoundError,
@@ -179,3 +184,11 @@
         self.assertEqual(int(data[sc.MTIME]), md.mtime)
         self.assertEqual(int(data[sc.CTIME]), md.ctime)
         self.assertEqual(data[sc.LEGALITY], md.legality)
+        self.assertEqual(int(data[sc.GENERATION]), md.generation)
+
+    def test_generation_default(self):
+        data = make_md_dict()
+        lines = make_lines(generation=None, **data)
+        lines.remove("{}={}".format(sc.GENERATION, 1))
+        md = volume.VolumeMetadata.from_lines(lines)
+        self.assertEqual(0, md.generation)


-- 
To view, visit https://gerrit.ovirt.org/64484
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icb71e1fc78f6c1e411e725b26c48411ffd04d0b6
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke <[email protected]>
_______________________________________________
vdsm-patches mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to