summaryrefslogtreecommitdiffstats
path: root/cobbler/serializer.py
diff options
context:
space:
mode:
authorMichael DeHaan <mdehaan@redhat.com>2007-12-12 16:12:02 -0500
committerMichael DeHaan <mdehaan@redhat.com>2007-12-12 16:12:02 -0500
commit67c3916d2993fae45e2d2c0a2de10542883426bc (patch)
treedacf4af843b6299b99001a2d57050c676059d5e1 /cobbler/serializer.py
parentf21d59c43bd9d5101ef1fadd979b85eb63e124b2 (diff)
downloadthird_party-cobbler-67c3916d2993fae45e2d2c0a2de10542883426bc.tar.gz
third_party-cobbler-67c3916d2993fae45e2d2c0a2de10542883426bc.tar.xz
third_party-cobbler-67c3916d2993fae45e2d2c0a2de10542883426bc.zip
Performance tweaking and benchmarks.
Diffstat (limited to 'cobbler/serializer.py')
-rw-r--r--cobbler/serializer.py47
1 files changed, 40 insertions, 7 deletions
diff --git a/cobbler/serializer.py b/cobbler/serializer.py
index 8593aad..ae9f18c 100644
--- a/cobbler/serializer.py
+++ b/cobbler/serializer.py
@@ -16,52 +16,82 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
import errno
import os
from rhpl.translate import _, N_, textdomain, utf8
+import fcntl
from cexceptions import *
import utils
import api as cobbler_api
+LOCK_ENABLED = True
+LOCK_HANDLE = None
+
+def __grab_lock():
+ if not LOCK_ENABLED:
+ return
+ if not os.path.exists("/var/lib/cobbler/lock"):
+ fd = open("/var/lib/cobbler/lock","w+")
+ fd.close()
+ LOCK_HANDLE = open("/var/lib/cobbler/lock","r")
+ fcntl.flock(LOCK_HANDLE.fileno(), fcntl.LOCK_EX)
+
+def __release_lock():
+ if not LOCK_ENABLED:
+ return
+ LOCK_HANDLE = open("/var/lib/cobbler/lock","r")
+ fcntl.flock(LOCK_HANDLE.fileno(), fcntl.LOCK_UN)
+ LOCK_HANDLE.close()
+
def serialize(obj):
"""
Save a collection to disk or other storage.
"""
+ __grab_lock()
storage_module = __get_storage_module(obj.collection_type())
storage_module.serialize(obj)
+ __release_lock()
return True
def serialize_item(collection, item):
"""
Save an item.
"""
+ __grab_lock()
storage_module = __get_storage_module(collection.collection_type())
save_fn = getattr(storage_module, "serialize_item", None)
if save_fn is None:
# print "DEBUG: WARNING: full serializer"
- return storage_module.serialize(collection)
+ rc = storage_module.serialize(collection)
else:
# print "DEBUG: partial serializer"
- return save_fn(collection,item)
+ rc = save_fn(collection,item)
+ __release_lock()
+ return rc
def serialize_delete(collection, item):
"""
Delete an object from a saved state.
"""
+ __grab_lock()
storage_module = __get_storage_module(collection.collection_type())
delete_fn = getattr(storage_module, "serialize_delete", None)
if delete_fn is None:
# print "DEBUG: full delete"
- return storage_module.serialize(collection)
+ rc = storage_module.serialize(collection)
else:
# print "DEBUG: partial delete"
- return delete_fn(collection,item)
-
+ rc = delete_fn(collection,item)
+ __release_lock()
+ return rc
def deserialize(obj,topological=False):
"""
Fill in an empty collection from disk or other storage
"""
+ __grab_lock()
storage_module = __get_storage_module(obj.collection_type())
- return storage_module.deserialize(obj,topological)
+ rc = storage_module.deserialize(obj,topological)
+ __release_lock()
+ return rc
def deserialize_raw(collection_type):
"""
@@ -69,8 +99,11 @@ def deserialize_raw(collection_type):
disk state, without going through the Cobbler object system.
Much faster, when you don't need the objects.
"""
+ __grab_lock()
storage_module = __get_storage_module(collection_type)
- return storage_module.deserialize_raw(collection_type)
+ rc = storage_module.deserialize_raw(collection_type)
+ __release_lock()
+ return rc
def __get_storage_module(collection_type):
"""