Merge lp:~jfb-tempo-consulting/unifield-server/US-4350 into lp:unifield-server

Proposed by jftempo
Status: Merged
Merged at revision: 5165
Proposed branch: lp:~jfb-tempo-consulting/unifield-server/US-4350
Merge into: lp:unifield-server
Diff against target: 103 lines (+45/-1)
2 files modified
bin/osv/orm.py (+3/-0)
bin/osv/osv.py (+42/-1)
To merge this branch: bzr merge lp:~jfb-tempo-consulting/unifield-server/US-4350
Reviewer Review Type Date Requested Status
UniField Reviewer Team Pending
Review via email: mp+357936@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/osv/orm.py'
2--- bin/osv/orm.py 2018-08-14 14:10:58 +0000
3+++ bin/osv/orm.py 2018-10-29 09:31:45 +0000
4@@ -1122,6 +1122,9 @@
5 self._parent_store_compute(cr)
6 return (position, 0, 0, 0)
7
8+ def read_web(self, cr, user, ids, fields=None, context=None, load='_classic_read'):
9+ return self.read(cr, user, ids, fields, context=context, load=load)
10+
11 def read(self, cr, user, ids, fields=None, context=None, load='_classic_read'):
12 """
13 Read records with given ids with the given fields
14
15=== modified file 'bin/osv/osv.py'
16--- bin/osv/osv.py 2016-11-04 13:19:03 +0000
17+++ bin/osv/osv.py 2018-10-29 09:31:45 +0000
18@@ -33,11 +33,11 @@
19 from tools.translate import translate
20 import time
21 import random
22+from threading import RLock
23
24 module_list = []
25 module_class_list = {}
26 class_pool = {}
27-
28 PG_CONCURRENCY_ERRORS_TO_RETRY = (errorcodes.LOCK_NOT_AVAILABLE, errorcodes.SERIALIZATION_FAILURE, errorcodes.DEADLOCK_DETECTED)
29 MAX_TRIES_ON_CONCURRENCY_FAILURE = 7
30
31@@ -50,6 +50,32 @@
32 except:
33 pass
34
35+
36+class recorded_psql_pid(object):
37+ _data = {}
38+ _lock = RLock()
39+
40+ def set(self, uuid, value):
41+ with self._lock:
42+ self._data[uuid] = value
43+
44+ def delete(self, uuid):
45+ with self._lock:
46+ try:
47+ del self._data[uuid]
48+ except:
49+ pass
50+
51+ def kill(self, cr, uuid):
52+ with self._lock:
53+ pg_id = self._data.get(uuid)
54+ if pg_id:
55+ cr.execute('select pg_terminate_backend(%s)', (pg_id,))
56+ return True
57+ return False
58+
59+_recorded_psql_pid = recorded_psql_pid()
60+
61 class except_osv(Exception):
62 def __init__(self, name, value, exc_type='warning'):
63 self.name = name
64@@ -62,6 +88,7 @@
65
66
67 class object_proxy(netsvc.Service):
68+ _recorded_psql_pid = {}
69 def __init__(self):
70 self.logger = logging.getLogger('web-services')
71 netsvc.Service.__init__(self, 'object_proxy', audience='')
72@@ -200,10 +227,22 @@
73 def execute(self, db, uid, obj, method, *args, **kw):
74 before = time.time()
75 cr = pooler.get_db(db).cursor()
76+ uuid = False
77 try:
78 try:
79 if method.startswith('_'):
80 raise except_osv('Access Denied', 'Private methods (such as %s) cannot be called remotely.' % (method,))
81+ if method == 'kill_search_filter' and len(args) > 0:
82+ uuid = (uid, obj, int(args[0]))
83+ if _recorded_psql_pid.kill(cr, uuid):
84+ self.logger.info('Sql query on %s killed by %s' % (obj, uid))
85+ return True
86+ if method == 'read_web' and len(args) > 2 and args[2].get('unique_id'):
87+ uuid = (uid, obj, args[2]['unique_id'])
88+ _recorded_psql_pid.set(uuid, cr._cnx.get_backend_pid())
89+ if method == 'search_web' and args[4].get('unique_id'):
90+ uuid = (uid, obj, args[4].get('unique_id'))
91+ _recorded_psql_pid.set(uuid, cr._cnx.get_backend_pid())
92 res = self.execute_cr(cr, uid, obj, method, *args, **kw)
93 if res is None:
94 self.logger.warning('The method %s of the object %s can not return `None` !', method, obj)
95@@ -212,6 +251,8 @@
96 cr.rollback()
97 raise
98 finally:
99+ if uuid:
100+ _recorded_psql_pid.delete(uuid)
101 cr.close()
102 after = time.time()
103 ops_count(db, 'exec', '.'.join([obj, method]), after-before)

Subscribers

People subscribed via source and target branches