From 1f1188c38779cd0701f2725eda2f4c00d74c1fe2 Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Fri, 7 Dec 2012 13:29:49 +0100 Subject: [PATCH] cmdlib: Opportunistic locking on instance creation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds a new parameter to βOpInstanceCreateβ and βOpInstanceMultiAllocβ to use opportunistic locks. Signed-off-by: Michael Hanselmann <hansmi@google.com> Reviewed-by: Guido Trotter <ultrotter@google.com> --- htest/Test/Ganeti/OpCodes.hs | 2 +- htools/Ganeti/OpCodes.hs | 1 + htools/Ganeti/OpParams.hs | 7 +++++++ lib/opcodes.py | 8 ++++++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/htest/Test/Ganeti/OpCodes.hs b/htest/Test/Ganeti/OpCodes.hs index 3251ee228..a1631e58d 100644 --- a/htest/Test/Ganeti/OpCodes.hs +++ b/htest/Test/Ganeti/OpCodes.hs @@ -217,7 +217,7 @@ instance Arbitrary OpCodes.OpCode where genMaybe (pure []) <*> genMaybe genNodeNameNE <*> arbitrary <*> genMaybe genNodeNameNE <*> genMaybe genNodeNameNE <*> genMaybe genNameNE <*> - arbitrary <*> (genTags >>= mapM mkNonEmpty) + arbitrary <*> arbitrary <*> (genTags >>= mapM mkNonEmpty) "OP_INSTANCE_MULTI_ALLOC" -> OpCodes.OpInstanceMultiAlloc <$> genMaybe genNameNE <*> pure [] "OP_INSTANCE_REINSTALL" -> diff --git a/htools/Ganeti/OpCodes.hs b/htools/Ganeti/OpCodes.hs index 6d93286a2..03b606997 100644 --- a/htools/Ganeti/OpCodes.hs +++ b/htools/Ganeti/OpCodes.hs @@ -294,6 +294,7 @@ $(genOpCode "OpCode" , pSrcNode , pSrcPath , pStartInstance + , pOpportunisticLocking , pInstTags ]) , ("OpInstanceMultiAlloc", diff --git a/htools/Ganeti/OpParams.hs b/htools/Ganeti/OpParams.hs index cda751e39..d3eca0e4d 100644 --- a/htools/Ganeti/OpParams.hs +++ b/htools/Ganeti/OpParams.hs @@ -71,6 +71,7 @@ module Ganeti.OpParams , pIgnoreConsistency , pStorageName , pUseLocking + , pOpportunisticLocking , pNameCheck , pNodeGroupAllocPolicy , pGroupNodeParams @@ -607,6 +608,12 @@ pStorageName = pUseLocking :: Field pUseLocking = defaultFalse "use_locking" +-- | Whether to employ opportunistic locking for nodes, meaning nodes already +-- locked by another opcode won't be considered for instance allocation (only +-- when an iallocator is used). +pOpportunisticLocking :: Field +pOpportunisticLocking = defaultFalse "opportunistic_locking" + -- | Whether to check name. pNameCheck :: Field pNameCheck = defaultTrue "name_check" diff --git a/lib/opcodes.py b/lib/opcodes.py index 91818d1c6..47216ccd4 100644 --- a/lib/opcodes.py +++ b/lib/opcodes.py @@ -159,6 +159,12 @@ _PDiskParams = \ _PHvState = ("hv_state", None, ht.TMaybeDict, "Set hypervisor states") _PDiskState = ("disk_state", None, ht.TMaybeDict, "Set disk states") +#: Opportunistic locking +_POpportunisticLocking = \ + ("opportunistic_locking", False, ht.TBool, + ("Whether to employ opportunistic locking for nodes, meaning nodes" + " already locked by another opcode won't be considered for instance" + " allocation (only when an iallocator is used)")) _PIgnoreIpolicy = ("ignore_ipolicy", False, ht.TBool, "Whether to ignore ipolicy violations") @@ -1241,6 +1247,7 @@ class OpInstanceCreate(OpCode): _PWaitForSync, _PNameCheck, _PIgnoreIpolicy, + _POpportunisticLocking, ("beparams", ht.EmptyDict, ht.TDict, "Backend parameters for instance"), ("disks", ht.NoDefault, ht.TListOf(_TDiskParams), "Disk descriptions, for example ``[{\"%s\": 100}, {\"%s\": 5}]``;" @@ -1300,6 +1307,7 @@ class OpInstanceMultiAlloc(OpCode): """ OP_PARAMS = [ + _POpportunisticLocking, _PIAllocFromDesc("Iallocator used to allocate all the instances"), ("instances", ht.EmptyList, ht.TListOf(ht.TInstanceOf(OpInstanceCreate)), "List of instance create opcodes describing the instances to allocate"), -- GitLab