Merge lp:~jfb-tempo-consulting/unifield-server/us-1341 into lp:unifield-server

Proposed by jftempo
Status: Merged
Merged at revision: 4485
Proposed branch: lp:~jfb-tempo-consulting/unifield-server/us-1341
Merge into: lp:unifield-server
Diff against target: 136 lines (+66/-26)
3 files modified
bin/addons/msf_profile/i18n/fr_MF.po (+14/-0)
bin/addons/sync_client/orm.py (+4/-8)
bin/addons/sync_client/sync_client.py (+48/-18)
To merge this branch: bzr merge lp:~jfb-tempo-consulting/unifield-server/us-1341
Reviewer Review Type Date Requested Status
UniField Reviewer Team Pending
Review via email: mp+329439@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Jeff Allen (jr.allen) wrote :

UF 6.0 unfortunately needs to tolerate the time when pg 8.4 and pg 9.6 is mixed in the fleet. Until now we didn't notice any use of Postgres where that would make a difference, but I'm afraid this won't work on Pg 8.4.

Your thoughts?

Revision history for this message
jftempo (jfb-tempo-consulting) wrote :

To my knowledge (but I didn't test this code on pg8.4):
   - pg8.4 ISOLATION_LEVEL_REPEATABLE_READ == pg8.4 ISOLATION_LEVEL_SERIALIZABLE
   - pg8.4 ISOLATION_LEVEL_SERIALIZABLE == pg9.6 ISOLATION_LEVEL_REPEATABLE_READ

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/addons/msf_profile/i18n/fr_MF.po'
2--- bin/addons/msf_profile/i18n/fr_MF.po 2017-08-18 15:27:28 +0000
3+++ bin/addons/msf_profile/i18n/fr_MF.po 2017-08-29 09:52:36 +0000
4@@ -98950,3 +98950,17 @@
5 #: field:sync.version.instance.monitor,instance_state:0
6 msgid "Instance State"
7 msgstr "État de l'instance"
8+
9+#. module: sync_client
10+#: code:addons/sync_client/sync_client.py:670
11+#, python-format
12+msgid "Unable to generate updates after %d tries"
13+msgstr "Impossible de générer les data après %d tentatives"
14+
15+#. module: sync_client
16+#: code:addons/sync_client/sync_client.py:677
17+#, python-format
18+msgid "Unable to generate updates, retrying %d/%d"
19+msgstr "Impossible de générer les data, nouvel essai %d/%d"
20+
21+
22
23=== modified file 'bin/addons/sync_client/orm.py'
24--- bin/addons/sync_client/orm.py 2017-02-20 09:08:28 +0000
25+++ bin/addons/sync_client/orm.py 2017-08-29 09:52:36 +0000
26@@ -122,13 +122,9 @@
27 WHERE module = 'sd' AND
28 model = %s AND
29 """+add_sql+"""
30- ("""+field+""" < last_modification OR """+field+""" IS NULL) AND
31- (create_date is NULL or create_date <= NOW())""",
32+ ("""+field+""" < last_modification OR """+field+""" IS NULL)
33+ """,
34 sql_params)
35- # NOW() is the sql transaction begin date
36- # can't use (sync_date IS NULL or last_modification <= NOW()) bc UTP-1201 use case failed
37- # can't use (last_modification <= NOW()) bc a record created before the sync but updated during the sync will not be sent
38- # and if this record is used in a m2o it will be set to false
39 result = [row[0] for row in cr.fetchall()]
40 else:
41 touched_fields = set(touched_fields)
42@@ -138,8 +134,8 @@
43 WHERE module = 'sd' AND
44 model = %s AND
45 """+add_sql+"""
46- ("""+field+""" < last_modification OR """+field+""" IS NULL) AND
47- (create_date is NULL or create_date <= NOW())""",
48+ ("""+field+""" < last_modification OR """+field+""" IS NULL)
49+ """,
50 sql_params)
51 result = [row[0] for row in cr.fetchall()
52 if row[1] is None \
53
54=== modified file 'bin/addons/sync_client/sync_client.py'
55--- bin/addons/sync_client/sync_client.py 2017-08-18 14:46:12 +0000
56+++ bin/addons/sync_client/sync_client.py 2017-08-29 09:52:36 +0000
57@@ -32,6 +32,7 @@
58 import math
59 import hashlib
60 from psycopg2 import OperationalError
61+from psycopg2.extensions import ISOLATION_LEVEL_REPEATABLE_READ, TransactionRollbackError
62
63 import logging
64 from sync_common import get_md5, check_md5
65@@ -637,24 +638,53 @@
66 return True
67
68 @sync_subprocess('data_push_create')
69- def create_update(self, cr, uid, context=None):
70- context = context or {}
71- updates = self.pool.get(context.get('update_to_send_model', 'sync.client.update_to_send'))
72-
73- def prepare_update(session):
74- updates_count = 0
75- for rule_id in self.pool.get('sync.client.rule').search(cr, uid, [('type', '!=', 'USB')], context=context):
76- updates_count += sum(updates.create_update(
77- cr, uid, rule_id, session, context=context))
78- return updates_count
79-
80- entity = self.get_entity(cr, uid, context)
81- session = str(uuid.uuid1())
82- updates_count = prepare_update(session)
83- if updates_count > 0:
84- self.write(cr, uid, [entity.id], {'session_id' : session})
85- return updates_count
86- #state init => update_send
87+ def create_update(self, oldcr, uid, context=None):
88+ cr = pooler.get_db(oldcr.dbname).cursor()
89+ cr._cnx.set_isolation_level(ISOLATION_LEVEL_REPEATABLE_READ)
90+ nb_tries = 1
91+ MAX_TRIES = 10
92+ while True:
93+ try:
94+ context = context or {}
95+ logger = context.get('logger')
96+ updates = self.pool.get(context.get('update_to_send_model', 'sync.client.update_to_send'))
97+
98+ def prepare_update(session):
99+ updates_count = 0
100+ for rule_id in self.pool.get('sync.client.rule').search(cr, uid, [('type', '!=', 'USB')], context=context):
101+ updates_count += sum(updates.create_update(
102+ cr, uid, rule_id, session, context=context))
103+ return updates_count
104+
105+ entity = self.get_entity(cr, uid, context)
106+ session = str(uuid.uuid1())
107+ updates_count = prepare_update(session)
108+ if updates_count > 0:
109+ self.write(cr, uid, [entity.id], {'session_id' : session})
110+ cr.commit()
111+ cr.close(True)
112+ return updates_count
113+ except TransactionRollbackError:
114+ cr.rollback()
115+ if nb_tries == MAX_TRIES:
116+ msg = _("Unable to generate updates after %d tries") % MAX_TRIES
117+ if logger:
118+ logger.append(msg)
119+ logger.write()
120+ self._logger.info(msg)
121+ cr.close(True)
122+ raise
123+ msg = _("Unable to generate updates, retrying %d/%d") % (nb_tries, MAX_TRIES)
124+ if logger:
125+ logger.append(msg)
126+ logger.write()
127+ self._logger.info(msg)
128+ nb_tries += 1
129+ except:
130+ cr.rollback()
131+ cr.close(True)
132+ raise
133+
134
135 @sync_subprocess('data_push_send')
136 def send_update(self, cr, uid, context=None):

Subscribers

People subscribed via source and target branches