759 |
759 |
self.__lock.release()
|
760 |
760 |
return set(result)
|
761 |
761 |
|
762 |
|
def acquire(self, names, blocking=1, shared=0):
|
|
762 |
def acquire(self, names, timeout=None, shared=0):
|
763 |
763 |
"""Acquire a set of resource locks.
|
764 |
764 |
|
765 |
765 |
@param names: the names of the locks which shall be acquired
|
766 |
766 |
(special lock names, or instance/node names)
|
767 |
767 |
@param shared: whether to acquire in shared mode; by default an
|
768 |
768 |
exclusive lock will be acquired
|
769 |
|
@param blocking: whether to block while trying to acquire or to
|
770 |
|
operate in try-lock mode (this locking mode is not supported yet)
|
|
769 |
@type timeout: float
|
|
770 |
@param timeout: Maximum time to acquire all locks
|
771 |
771 |
|
772 |
772 |
@return: True when all the locks are successfully acquired
|
773 |
773 |
|
... | ... | |
776 |
776 |
locks requested will be acquired.
|
777 |
777 |
|
778 |
778 |
"""
|
779 |
|
if not blocking:
|
780 |
|
# We don't have non-blocking mode for now
|
|
779 |
if timeout is not None:
|
781 |
780 |
raise NotImplementedError
|
782 |
781 |
|
783 |
782 |
# Check we don't already own locks at this level
|
... | ... | |
961 |
960 |
|
962 |
961 |
return True
|
963 |
962 |
|
964 |
|
def remove(self, names, blocking=1):
|
|
963 |
def remove(self, names):
|
965 |
964 |
"""Remove elements from the lock set.
|
966 |
965 |
|
967 |
966 |
You can either not hold anything in the lockset or already hold a superset
|
968 |
967 |
of the elements you want to delete, exclusively.
|
969 |
968 |
|
970 |
969 |
@param names: names of the resource to remove.
|
971 |
|
@param blocking: whether to block while trying to acquire or to
|
972 |
|
operate in try-lock mode (this locking mode is not supported
|
973 |
|
yet unless you are already holding exclusively the locks)
|
974 |
970 |
|
975 |
971 |
@return:: a list of locks which we removed; the list is always
|
976 |
972 |
equal to the names list if we were holding all the locks
|
977 |
973 |
exclusively
|
978 |
974 |
|
979 |
975 |
"""
|
980 |
|
if not blocking and not self._is_owned():
|
981 |
|
# We don't have non-blocking mode for now
|
982 |
|
raise NotImplementedError
|
983 |
|
|
984 |
976 |
# Support passing in a single resource to remove rather than many
|
985 |
977 |
if isinstance(names, basestring):
|
986 |
978 |
names = [names]
|
... | ... | |
1135 |
1127 |
"""
|
1136 |
1128 |
return level == LEVEL_CLUSTER and (names is None or BGL in names)
|
1137 |
1129 |
|
1138 |
|
def acquire(self, level, names, blocking=1, shared=0):
|
|
1130 |
def acquire(self, level, names, timeout=None, shared=0):
|
1139 |
1131 |
"""Acquire a set of resource locks, at the same level.
|
1140 |
1132 |
|
1141 |
1133 |
@param level: the level at which the locks shall be acquired;
|
... | ... | |
1144 |
1136 |
(special lock names, or instance/node names)
|
1145 |
1137 |
@param shared: whether to acquire in shared mode; by default
|
1146 |
1138 |
an exclusive lock will be acquired
|
1147 |
|
@param blocking: whether to block while trying to acquire or to
|
1148 |
|
operate in try-lock mode (this locking mode is not supported yet)
|
|
1139 |
@type timeout: float
|
|
1140 |
@param timeout: Maximum time to acquire all locks
|
1149 |
1141 |
|
1150 |
1142 |
"""
|
1151 |
1143 |
assert level in LEVELS, "Invalid locking level %s" % level
|
... | ... | |
1164 |
1156 |
" while owning some at a greater one")
|
1165 |
1157 |
|
1166 |
1158 |
# Acquire the locks in the set.
|
1167 |
|
return self.__keyring[level].acquire(names, shared=shared,
|
1168 |
|
blocking=blocking)
|
|
1159 |
return self.__keyring[level].acquire(names, shared=shared, timeout=timeout)
|
1169 |
1160 |
|
1170 |
1161 |
def release(self, level, names=None):
|
1171 |
1162 |
"""Release a set of resource locks, at the same level.
|
... | ... | |
1205 |
1196 |
" while owning some at a greater one")
|
1206 |
1197 |
return self.__keyring[level].add(names, acquired=acquired, shared=shared)
|
1207 |
1198 |
|
1208 |
|
def remove(self, level, names, blocking=1):
|
|
1199 |
def remove(self, level, names):
|
1209 |
1200 |
"""Remove locks from the specified level.
|
1210 |
1201 |
|
1211 |
1202 |
You must either already own the locks you are trying to remove
|
... | ... | |
1215 |
1206 |
it must be a member of LEVELS_MOD
|
1216 |
1207 |
@param names: the names of the locks which shall be removed
|
1217 |
1208 |
(special lock names, or instance/node names)
|
1218 |
|
@param blocking: whether to block while trying to operate in
|
1219 |
|
try-lock mode (this locking mode is not supported yet)
|
1220 |
1209 |
|
1221 |
1210 |
"""
|
1222 |
1211 |
assert level in LEVELS_MOD, "Invalid or immutable level %s" % level
|
... | ... | |
1228 |
1217 |
assert self._is_owned(level) or not self._upper_owned(level), (
|
1229 |
1218 |
"Cannot remove locks at a level while not owning it or"
|
1230 |
1219 |
" owning some at a greater one")
|
1231 |
|
return self.__keyring[level].remove(names, blocking=blocking)
|
|
1220 |
return self.__keyring[level].remove(names)
|