Commit Graph

82 Commits

Author SHA1 Message Date
Raphael Collet 3e497ea35f [FIX] registry: recompute `pure_function_fields` after every setup
The lazy property `pure_function_fields` was not invalidated upon every setup
of models, and hence could contain old instances of fields.  As every model
setup re-creates instances of fields, the property has to be recomputed.
2015-05-06 09:11:53 +02:00
Christophe Simonis 14fd77c132 [FIX] core: ormcache is now per regisry.
A cross-registry cache was introduced by e2ea691ce.
The initial idea was praiseworthy but sub-optimal for servers with a
lot of registries.
When there is lot of registry loaded, the cache size was huge and
clearing some entries took a lot of CPU time, increasing the chances
of timeout.

Also, the cache was not cleaned when a registry is removed from
registry LRU (this operation would also consume time).
2015-04-03 16:11:57 +02:00
Raphael Collet b156c2e27e [IMP] registry: adapt LRU sizes for registries and ormcache
The registry size is now assumed to be around 10Mb, and ormcache size is
proportional to the maximum number of registries.  Statistics about ormcache
usage is shown to the log when receiving signal SIGUSR1.
2015-03-23 14:36:15 +01:00
Raphael Collet e2ea691cef [IMP] ormcache: turn it into a global LRU cache shared among registries
The ormcache is now shared among registries.  The cached methods use keys like
(DBNAME, MODELNAME, METHOD, args...).  This allows registries with high load to
use more cache than other registries.
2015-03-23 14:36:14 +01:00
Raphael Collet cf26f7ed80 [IMP] models, registry: let the registry retrieve manual fields from database 2015-01-21 11:26:23 +01:00
Raphael Collet 5fee95ca63 [FIX] models, fields: reorganize model setup to retrieve all inherited fields
The model setup sometimes misses entries in _inherit_fields and _all_columns.
This is because those dictionaries are computed from parent models which are
not guaranteed to be completely set up: sometimes a parent field is only
partially set up, and columns are missing (they are generated from fields after
their setup).

To avoid this bug, the setup has been split in three phases:
(1) determine all inherited and custom fields on models;
(2) setup fields, except for recomputation triggers, and generate columns;
(3) add recomputation triggers and complete the setup of the model.

Making these three phases explicit brings good invariants:
- when setting up a field, all models know all their fields;
- when adding recomputation triggers, you know that fields have been set up.
2015-01-21 11:26:23 +01:00
Raphael Collet 8f38a7806a [IMP] enable loading custom models/fields and views from module data files
Loading views for custom models from module data files was not possible because
custom models and fields were introduced into the registry after all modules
were loaded.  As a consequence, the view architecture did not pass the checks.

This patch takes a different approach: custom models and fields are loaded
early on in the registry, so that views can be validated.  The trick is to take
special care of relational custom fields: we skip them if their comodel does
not appear in the registry.  This allows to install and upgrade modules that
create/modify custom models, fields and views for them.
2014-12-19 13:57:08 +01:00
Olivier Dony c87b9c6539 [FIX] decimal_precision: avoid refreshing float precisions at each cache invalidation
Changing the decimal precision of float fields is a rare
operation, while cache clearing occurs fairly frequently.
Signaling a full registry change when the decimal precision
is changed (instead of a mere cache change) is therefore
a better trade-off, and more semantically correct as well.
This way we avoid the decimal precision refresh for each
invalidation.

Registry invalidation implies cache invalidation.
2014-11-19 12:53:58 +01:00
Raphael Collet e038fec696 [IMP] models: improve performance of _setup_fields()
There was an issue in _setup_fields(): the method invokes _inherits_reload(),
which recomputes inherited fields, and invokes itself recursively on children
models.  This may be problematic if the children models have already been set
up.

This optimization avoids recursive calls of method _inherits_reload().  In
_setup_fields(), first all parent models are set up, then their fields are
inspected to determine inherited fields, and their setup is done.  This scheme
guarantees that inherited fields are computed once per model.
2014-11-13 14:54:04 +01:00
Christophe Simonis cc4fba6089 [IMP] core: manage registries via an LRU.
When working with a large number of databases, the memory allocated to
registries wasn't limited, resulting to waste memory (especially in the
longpolling worker, which is not recycled).
The size of the LRU is depending on the soft limit configured for
workers.
2014-10-29 18:28:07 +01:00
Raphael Collet 764c5acd81 [IMP] fields: reset decimal precision on new-style fields
When a decimal_precision record is created/modified, the float fields of the
models in the registry must be reset.  This was done on old-API columns only.
It is now handled by the new-API fields.
2014-09-18 11:11:19 +02:00
Raphael Collet 2d2274aeed [FIX] module loading: manual x2x fields can now refer to manual models
The fix consists in this: when setting up models, ignore manual fields that
refer to unknown models if all models have not been loaded yet.
2014-08-04 15:10:12 +02:00
Raphael Collet cbe2dbb672 [MERGE] new v8 api by rco
A squashed merge is required as the conversion of the apiculture branch from
bzr to git was not correctly done. The git history contains irrelevant blobs
and commits. This branch brings a lot of changes and fixes, too many to list
exhaustively.

- New orm api, objects are now used instead of ids
- Environements to encapsulates cr uid context while maintaining backward compatibility
- Field compute attribute is a new object oriented way to define function fields
- Shared browse record cache
- New onchange protocol
- Optional copy flag on fields
- Documentation update
- Dead code cleanup
- Lots of fixes
2014-07-06 17:05:41 +02:00
Raphael Collet ea167ad7ab [IMP] test cursor: code cleanup to make it more robust to concurrent accesses
bzr revid: rco@openerp.com-20140414075906-2d0i4qhe4x7czsao
2014-04-14 09:59:06 +02:00
Raphael Collet be0096c4a7 [FIX] registry: stupid typo
bzr revid: rco@openerp.com-20140409135225-6ks1kbuchba7u4li
2014-04-09 15:52:25 +02:00
Raphael Collet 980f6fc4b1 [IMP] registry: avoid every direct access registry.db, and rename attribute as registry._db
bzr revid: rco@openerp.com-20140409133515-x2ywcm0d2qkdq3hq
2014-04-09 15:35:15 +02:00
Raphael Collet e5e00e4c0a [IMP] registry: now cursor() simply returns a cursor, which may itself be used as a context manager
bzr revid: rco@openerp.com-20140409095604-joh9dt0qkma12ykm
2014-04-09 11:56:04 +02:00
Raphael Collet f0fd48c44a [IMP] http tests: implement a test cursor that keeps a transaction open accross requests
- TestCursor subclasses Cursor, and simulates commit and rollback with savepoints
 - the registry manages a test mode, in which it only uses the test cursor
 - a reentrant lock forces the serialization of parallel requests

bzr revid: rco@openerp.com-20140408151736-j0guy68i2wjexy3d
2014-04-08 17:17:36 +02:00
Raphael Collet 6bc60505f4 [IMP] registry: add method get_cursor() to simply retrieve a new cursor, and refactor code to use it
bzr revid: rco@openerp.com-20140408125122-ki0zmin3m21k2itd
2014-04-08 14:51:22 +02:00
Raphael Collet b49f536baf [IMP] tests.common: turn class methods into instance methods (this will ease some future refactoring)
bzr revid: rco@openerp.com-20140408114936-jfagg4qvft8bk3ms
2014-04-08 13:49:36 +02:00
Raphael Collet 81b84c62b1 [IMP] registry: switch for a dummy lock only during the execution of http tests
bzr revid: rco@openerp.com-20140408094513-ahtwod1q17ijohbg
2014-04-08 11:45:13 +02:00
Antony Lesuisse c8324bafcc [IMP] phantomjs testing
- avoid dbmanager by presetting db in the test session
- correctly handle login option
- serialize test cursor access

bzr revid: al@openerp.com-20140216212222-4o6x9uljyua3g1og
2014-02-16 22:22:22 +01:00
Antony Lesuisse 278ed718e9 new test execution engine
remove deprecated zipfile support
add preload_registry option when server is running
allow registries to be used in contruction in test mode
add a rollback test case for http tests
add a phantomjs helper

bzr revid: al@openerp.com-20140209004005-p5pwym4sqc23vw5b
2014-02-09 01:40:05 +01:00
Christophe Simonis a69f789b41 [MERGE] forward port of branch 7.0 up to revid 5224 chs@openerp.com-20140206105141-7e8bv8ordqqsswh7
bzr revid: dle@openerp.com-20140205105045-j95kduyjiq83e57z
bzr revid: dle@openerp.com-20140114173613-ruxye1m7fxtcjfim
bzr revid: dle@openerp.com-20140116161158-u95vcs3os4tk2zob
bzr revid: dle@openerp.com-20140121172737-gzawfi3ssg7xifef
bzr revid: chs@openerp.com-20140129094554-c3abc8x3qz9mpszr
bzr revid: chs@openerp.com-20140129140159-9vwkpr078shoonum
bzr revid: chs@openerp.com-20140206110220-myn57cryam1y4k9v
2014-02-06 12:02:20 +01:00
Denis Ledoux 4aeba0c12e [FIX] modules: multi worker signaling initialize variables before loading registry
bzr revid: dle@openerp.com-20140121171836-dxs7cvqcd9nxytu1
2014-01-21 18:18:36 +01:00
Olivier Dony 212b6bc480 [FIX] modules: set initial values for multi-process signaling to None to avoid missing events
For fresh databases, the signaling sequences in the
database stays at 1 until the installation of the
first module. If several workers are hit for this
database before the first module is installed,
this database registry will be loaded with a signaling
sequence of 1. Since  was the default value, any
signal received by workers in this state was ignored 
because they thought the registry was previously
not loaded.
Using None to indicate an  sequence value
is more accurate and avoids this error

bzr revid: dle@openerp.com-20140116151157-3zlyrg48xqn2lkd0
2014-01-16 16:11:57 +01:00
Denis Ledoux 6fd552c3ce [MERGE] Forward-port of latest 7.0 bugfixes, up to rev. 5139 rev-id: dle@openerp.com-20131121132305-qjlclgz5v9tze1fr
bzr revid: odo@openerp.com-20131120102545-2tlp031yib6viz35
bzr revid: chs@openerp.com-20131120161708-c8sbom592moukwxw
bzr revid: dle@openerp.com-20131121155457-lh7fzouk2upeiu16
2013-11-21 16:54:57 +01:00
Martin Trigaux 7ae9e1c86d [FIX] registry: missing a threading.RLock in RegistryManager.get():
if no registry exists and several calls to RegistryManager.get() are called at the same time
by several threads, several registries will be created one after the other and only the last
one will be kept in cls.registries (courtesy of Guewen Baconnier (Camptocamp)

Invert behaviour of commit 3685 because, at that time, the new trigger the schedule_cron_jobs method which ran another lock and called get on the registry. We had a deadlock with the cron. This is no longer the case as we don't call the same method at the end of the creation of the registry and it does not trigger a lock

bzr revid: mat@openerp.com-20131114144401-k00podawlem7cjd1
2013-11-14 15:44:01 +01:00
Olivier Dony 54f740960e [MERGE] Forward-port of latest saas-1 bugfixes, up to rev. 4912 rev-id: odo@openerp.com-20131016110621-36vvlpn8dgsabyt1
bzr revid: odo@openerp.com-20131016111800-jjybreg62bwz61zn
2013-10-16 13:18:00 +02:00
Olivier Dony 8ac110c4dd [MERGE] Forward-port of latest 7.0 bugfixes, up to rev. 5098 rev-id: odo@openerp.com-20131011123914-7zuvd9mch21yxgj8
bzr revid: dle@openerp.com-20131009131902-a93nsbou4w8y0vlx
bzr revid: chs@openerp.com-20131009175454-j06y1ngylfbqyrpj
bzr revid: dle@openerp.com-20130918160049-fo88fl7uyhfoofkv
bzr revid: dle@openerp.com-20130924130544-kmkyr0d73cusvdav
bzr revid: odo@openerp.com-20131011134433-nyfjipvlql4xu127
2013-10-11 15:44:33 +02:00
Olivier Dony 088cb0255d [FIX] registry: restore `elif` changed to `if` in previous commit, for better readability (no effect)
This should have no effect because when the first `if`
is entered a new registry is instantiated with
the default value for base_cache_signaling_sequence
set to 1, preventing entering the next `if` even
without `elif`.

bzr revid: odo@openerp.com-20131011123914-7zuvd9mch21yxgj8
2013-10-11 14:39:14 +02:00
Olivier Dony 78579d289b [FIX] registry: avoid discarding registry or cache when the registry is fresh
When the sequence value is 1 it means that either:
 - the registry was just instantiated, so there is no
   reason to reload it immediately, the real checks will
   start at next request
 - the db was just created with new sequences set to 1,
   so there has been no change to reload

In both cases there is no good reason to reload the
registry, and it is actually a performance killer,
especially for cron workers that keep iterating on
the list of databases.

bzr revid: odo@openerp.com-20131011100313-4bud8e9xq2afp9z7
2013-10-11 12:03:13 +02:00
Guewen Baconnier 9c769c9a99 [FIX] missing a threading.RLock in RegistryManager.get():
if no registry exists and several calls to RegistryManager.get() are called at the same time
by several threads, several registries will be created one after the other and only the last
one will be kept in cls.registries

lp bug: https://launchpad.net/bugs/1238560 fixed

bzr revid: guewen.baconnier@camptocamp.com-20131011092632-b267vhdadh7q9som
2013-10-11 11:26:32 +02:00
niv-openerp ac1d0742a0 [IMP] minor improvement in RegistryManager, useful for web client
bzr revid: nicolas.vanhoren@openerp.com-20130619105335-w3xftm6g0llh1ade
2013-06-19 12:53:35 +02:00
Raphael Collet 05851d21ba [MERGE] from trunk
bzr revid: rco@openerp.com-20130411073017-x6e4h8xbvmy3ofdw
2013-04-11 09:30:17 +02:00
Vo Minh Thu 307ca374d6 [MERGE] forward merge 7.0 until revision 4919.
bzr revid: vmt@openerp.com-20130404130704-24vsmczw34cssytd
2013-04-04 15:07:04 +02:00
Raphael Collet b99398fa29 [IMP] registry: make class Registry inherit from abstract class collections.Mapping
bzr revid: rco@openerp.com-20130404102524-innz9qu824yfds4b
2013-04-04 12:25:24 +02:00
Raphael Collet d3657d858f [IMP] registry: add convenience operators ('in' and 'iter') on registry objects
bzr revid: rco@openerp.com-20130329135853-woi26cl2yiofv7h2
2013-03-29 14:58:53 +01:00
Vo Minh Thu b08d7ef6bd [REF] ir.actions.report.xml: register_all do not make sense any more:
auto=True reports are looked up in the database for each rendering, so they do
no have to be in the report registry any longer.
auto=False reports will register themselves but at this point
they can be updated to use the new `parser` XML attribute.

bzr revid: vmt@openerp.com-20130322153955-s6nyux2pyez6c01w
2013-03-22 16:39:55 +01:00
Vo Minh Thu e746cb1654 [FIX] registry: fix a bug where RegistryManager.new() could return an out-of-date registry.
bzr revid: vmt@openerp.com-20130212085311-o53wv7yful39kktd
2013-02-12 09:53:11 +01:00
Olivier Dony 4fd1bc7b3c [IMP] cron: remove useless pooljobs and schedule_cron_jobs methods
The pooljobs and scheduled_cron_jobs stuff was only used to
delay the processing of cron jobs until after the registry
was fully loaded. However this is already the case because
RegistryManager.new() only sets the flag at the end of the
init step.
The flag was named `registry.cron` but simply meant that the
registry was fully loaded and ready, so it is simpler to
rename it to `registry.ready`.

In multiprocess mode this flag is enterily irrelevant
so there is no need to selectively set it to True or
False. `registry.ready` is simpler.

bzr revid: odo@openerp.com-20121221133751-h4x670vblfr3d09e
2012-12-21 14:37:51 +01:00
Olivier Dony e373ac5aeb [MERGE] *: fix/rationalize db logging to avoid incorrect values during logging
The setting/clearing of the tracking were not done
consistently, causing log messages that appeared
to come from one database while coming from another
one or none at all.

The tracker is now set at the earliest points
of request handling as possible:
- in web, when creating WebRequests (dbname, uid)
- at RPC dispatching in server (uid)
- at cron job acquisition in CronWorker (dbname)
- at Registry acquisition in RegistryManager (dbname)


The tracker is cleared at the very entrance of
the request in the WSGI `application`, ensuring
that no logging is produced with an obsolete
db name. (It cannot be cleared at the end of
the request handling because the werkzeug
wrapper outputs more logging afterwards)

bzr revid: odo@openerp.com-20130301182510-1fqo9o8di0jw95b5
2013-03-01 19:25:10 +01:00
Olivier Dony 9770caedf3 [FIX] registry: another pass of cleanup for registry signaling
Some important points to consider:
 - signaling should be done after any schema alteration (including module [un]installation),
   service registration (e.g. reports)
 - the changes need to be committed to the database *before* signaling, otherwise an
   obvious race condition occurs during reload by other workers
 - any call to restart_pool() must be considered a possible candidate for
   signaling, and the 2 above conditions must be checked

The number of explicit calls was reduced by forcing the signaling at the end of
Registry.new() in case `update_module` was passed as True. In that situation
we always want to signal the changes - so all the redundant signaling calls
can be centralized. We can also assume that the relevant changes have already
been committed at that point, otherwise the registry update would not
have worked in the first place.
This means that there is no need for explicit signaling anymore everytime
`restart_pool` is called with `update_module=True`.

Some missing cr.commit() and explicit signaling calls were added or
moved to the right place. As a reminder: signaling must be done
*after* committing the changes, and usually *after* reloading the
registry on the current worker.

bzr revid: odo@openerp.com-20130301143203-e2csf5pkllwhmwqs
2013-03-01 15:32:03 +01:00
Olivier Dony db81edc287 [FIX] *: fix/rationalize db logging to avoid incorrect values during logging
The setting/clearing of the tracking were not done
consistently, causing log messages that appeared
to come from one database while coming from another
one or none at all.

The tracker is now set at the earliest points
of request handling where we can:
- in web client, when creating WebRequests (dbname, uid)
- at RPC dispatching in server (uid)
- at cron job acquisition in CronWorker (dbname)
- at Registry acquisition in RegistryManager (dbname)


The tracker is cleared at the very entrance of
the request in the WSGI `application`, ensuring
that no logging is produced with an obsolete
db name. (It cannot be cleared at the end of
the request handling because the werkzeug
wrapper outputs more logging afterwards)

bzr revid: odo@openerp.com-20130301120744-jfitcmze2jldecod
2013-03-01 13:07:44 +01:00
Olivier Dony 9f77d2e2f4 [FIX] orm,registry: properly check m2o FKs during model update + fix some models `auto_init`ed multiple times
The case where no constraint existed at all was not working,
and after fixing it, the ORM started to re-create the same
constraints multiple times for some modules. This was for
models that are split within a module (such as res.users in
base, which is made of several small classes): all the
partial models were going through _auto_init instead
of only the final one - doing useless extra work.
      
Unfortunately establishing the FK happens before the
XML data files are loaded, so a number of FK and
NOT NULL constraints failed to apply due to missing
tables/records. base.sql had to be extended a bit
to cover these cases in a minimalist fashion

bzr revid: odo@openerp.com-20121217214645-av9n003yzterhujw
2012-12-17 22:46:45 +01:00
Vo Minh Thu 08a082f63f [FIX] registry: Set the fields_by_model attribute in __init__(), use None to flag non-existing fields-per-model cache.
bzr revid: vmt@openerp.com-20121214141114-em9r66e3sfy21t2r
2012-12-14 15:11:14 +01:00
Antony Lesuisse ae45df93a4 misc
bzr revid: al@openerp.com-20121209190543-83hmvyfcu1af7wiv
2012-12-09 20:05:43 +01:00
Antony Lesuisse f4977b1f44 cron registrymanager removal
bzr revid: al@openerp.com-20121209175300-rhwf9n0y29o7ct19
2012-12-09 18:53:00 +01:00
Antony Lesuisse 42f292af93 cron cleanup, back to the Kernighan KISS roots 1min poll time, rely only on database, multiprocess/multiserver ready.
Nota: If we replace sequence signaling for cache invalidation with pg
listen/notify in the future, we will use the same mechanism for more accurate
cron timing.

bzr revid: al@openerp.com-20121209170447-zs0k3jazokylwvar
2012-12-09 18:04:47 +01:00
Antony Lesuisse 3d2a09a973 multiprocessing signaling manually backported from 6.1
bzr revid: al@openerp.com-20121208181151-lfy956ysnok5b5hf
2012-12-08 19:11:51 +01:00