[massive store] master_init should commit by default
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Thu, 13 Oct 2016 15:16:38 +0200
changeset 11791 20555214576b
parent 11790 04607da552ac
child 11792 f1911a4638af
[massive store] master_init should commit by default Default client usage is to create a master store to control slave ones. They need to access cwmassive_initialized from another transaction
cubicweb/dataimport/massive_store.py
--- a/cubicweb/dataimport/massive_store.py	Thu Oct 13 15:12:33 2016 +0200
+++ b/cubicweb/dataimport/massive_store.py	Thu Oct 13 15:16:38 2016 +0200
@@ -108,7 +108,7 @@
 
     # master/slaves specific API
 
-    def master_init(self):
+    def master_init(self, commit=True):
         """Initialize database for massive insertion.
 
         This is expected to be called once, by the master store in master/slaves configuration.
@@ -118,6 +118,8 @@
             self.sql('CREATE TABLE cwmassive_initialized'
                      '(retype text, type varchar(128), uuid varchar(32))')
             self._initialized[self] = None
+            if commit:
+                self.commit()
 
     # SQL utilities #########################################################
 
@@ -149,7 +151,7 @@
         """
         if etype not in self._initialized:
             if not self.slave_mode:
-                self.master_init()
+                self.master_init(commit=False)
             tablename = 'cw_%s' % etype.lower()
             tmp_tablename = '%s_%s' % (tablename, self.uuid)
             self.sql("INSERT INTO cwmassive_initialized VALUES (%(e)s, 'etype', %(uuid)s)",
@@ -175,7 +177,7 @@
         """
         if rtype not in self._initialized:
             if not self.slave_mode:
-                self.master_init()
+                self.master_init(commit=False)
             assert not self._cnx.vreg.schema.rschema(rtype).inlined
             self._initialized[rtype] = None
             tablename = '%s_relation' % rtype.lower()