[dataimport] remove eids_seq_start attribute from massive store
authorJulien Cristau <julien.cristau@logilab.fr>
Wed, 02 Dec 2015 15:19:24 +0100
changeset 11026 ce9b3886955d
parent 11025 5413ab08617d
child 11027 ec5eeb08f2e8
[dataimport] remove eids_seq_start attribute from massive store Instead provide a utility function to reset the eid sequence.
dataimport/massive_store.py
dataimport/test/test_massive_store.py
--- a/dataimport/massive_store.py	Wed Dec 02 14:57:03 2015 +0100
+++ b/dataimport/massive_store.py	Wed Dec 02 15:19:24 2015 +0100
@@ -84,8 +84,6 @@
     """
     # size of eid range reserved by the store for each batch
     eids_seq_range = 10000
-    # initial eid (None means use the value in the db)
-    eids_seq_start = None
     # max size of the iid, used to create the iid_eid conversion table
     iid_maxsize = 1024
 
@@ -127,11 +125,6 @@
         self.on_rollback_callback = on_rollback_callback
         # Do our meta tables already exist?
         self._init_massive_metatables()
-        # Internal markers of initialization
-        if self.eids_seq_start is not None and not self.slave_mode:
-            self._cnx.system_sql(self._cnx.repo.system_source.dbhelper.sql_restart_numrange(
-                'entities_id_seq', initial_value=self.eids_seq_start + 1))
-            cnx.commit()
         self.get_next_eid = lambda g=self._get_eid_gen(): next(g)
         # recreate then when self.finish() is called
 
@@ -407,6 +400,10 @@
             # Mark etype as "initialized" for faster check
             self._entities.add(etype)
 
+    def restart_eid_sequence(self, start_eid):
+        self._cnx.system_sql(self._cnx.repo.system_source.dbhelper.sql_restart_numrange(
+            'entities_id_seq', initial_value=start_eid))
+        self._cnx.commit()
 
     ### ENTITIES CREATION #####################################################
 
--- a/dataimport/test/test_massive_store.py	Wed Dec 02 14:57:03 2015 +0100
+++ b/dataimport/test/test_massive_store.py	Wed Dec 02 15:19:24 2015 +0100
@@ -132,10 +132,10 @@
     def test_eids_seq_range(self):
         class MyMassiveObjectStore(MassiveObjectStore):
             eids_seq_range = 1000
-            eids_seq_start = 50000
 
         with self.admin_access.repo_cnx() as cnx:
             store = MyMassiveObjectStore(cnx)
+            store.restart_eid_sequence(50000)
             store.prepare_insert_entity('Location', name=u'toto')
             store.flush()
             cnx.commit()
@@ -146,21 +146,18 @@
     def test_eid_entity(self):
         class MyMassiveObjectStore(MassiveObjectStore):
             eids_seq_range = 1000
-            eids_seq_start = 50000
 
         with self.admin_access.repo_cnx() as cnx:
             store = MyMassiveObjectStore(cnx)
+            store.restart_eid_sequence(50000)
             eid = store.prepare_insert_entity('Location', name=u'toto')
             store.flush()
             self.assertGreater(eid, 50000)
 
     def test_eid_entity_2(self):
-        class MyMassiveObjectStore(MassiveObjectStore):
-            eids_seq_range = 1000
-            eids_seq_start = 50000
-
         with self.admin_access.repo_cnx() as cnx:
-            store = MyMassiveObjectStore(cnx)
+            store = MassiveObjectStore(cnx)
+            store.restart_eid_sequence(50000)
             eid = store.prepare_insert_entity('Location', name=u'toto', eid=10000)
             store.flush()
         self.assertEqual(eid, 10000)