Jira (PUP-10952) Changing a Puppet setting in a catalog invalidates the env cache in multithreaded mode

0 views
Skip to first unread message

Maggie Dreyer (Jira)

unread,
Mar 4, 2021, 7:42:01 PM3/4/21
to puppe...@googlegroups.com
Maggie Dreyer moved an issue
 
Puppet / Bug PUP-10952
Changing a Puppet setting in a catalog invalidates the env cache in multithreaded mode
Change By: Maggie Dreyer
Key: SERVER PUP - 2980 10952
Project: Puppet Server
Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.5.2#805002-sha1:a66f935)
Atlassian logo

Maggie Dreyer (Jira)

unread,
Mar 5, 2021, 11:21:01 AM3/5/21
to puppe...@googlegroups.com

Maggie Dreyer (Jira)

unread,
Mar 5, 2021, 11:22:01 AM3/5/21
to puppe...@googlegroups.com

Maggie Dreyer (Jira)

unread,
Mar 5, 2021, 11:22:01 AM3/5/21
to puppe...@googlegroups.com

Maggie Dreyer (Jira)

unread,
Mar 5, 2021, 11:22:01 AM3/5/21
to puppe...@googlegroups.com

Maggie Dreyer (Jira)

unread,
Mar 9, 2021, 3:16:02 PM3/9/21
to puppe...@googlegroups.com
Maggie Dreyer commented on Bug PUP-10952
 
Re: Changing a Puppet setting in a catalog invalidates the env cache in multithreaded mode

On further investigation, it seems like it might be a bug that the rich_data hook is getting called in this context at all. It is not called when the server starts and initializes settings normally, but is called, from here when we create the threadlocal settings object when a setting is updated during a compile. Dunno why yet, but that seems like something we'd rather didn't happen, and fixing that seems better than removing the hook.

Maggie Dreyer (Jira)

unread,
Mar 9, 2021, 3:17:01 PM3/9/21
to puppe...@googlegroups.com
Maggie Dreyer updated an issue
Change By: Maggie Dreyer
While doing research on new loader architectures for SERVER-2860, I discovered the following:

In {{multithreaded}} mode in Puppetserver, we create a new settings object whenever a Puppet setting changes while a JRuby request is being processed. One example is if a Puppet function in a module calls {{Puppet[]=}}. In the process of initializing the new settings object with overrides (for thread safety), we resolve all settings. The {{rich_data}} setting [clears out the environment cache|https://github.com/puppetlabs/puppet/blob/main/lib/puppet/defaults.rb#L2162] when resolved.

This means if you are changing any Puppet settings in your catalog, in multithreaded mode environment caching is effectively disabled, because the cache will be invalidated on every compile of the offending environment.

The most straightforward fix would be to stop clearing all envs on settings initialization. But we'd need to make sure that won't cause other problems for the {{rich_data}} setting.
But a better solution would be to find out why the hook is being called in the first place (we're not altering that setting, and the default hook mode is "on_write_only"), and see if we can avoid it.

Maggie Dreyer (Jira)

unread,
Mar 9, 2021, 3:18:03 PM3/9/21
to puppe...@googlegroups.com
Maggie Dreyer updated an issue
While doing research on new loader architectures for SERVER-2860, I discovered the following:

In {{multithreaded}} mode in Puppetserver, we create a new settings object whenever a Puppet setting changes while a JRuby request is being processed. One example is if a Puppet function in a module calls {{Puppet[]=}}. In the process of initializing the new settings object with overrides (for thread safety), we resolve all settings. The {{rich_data}} setting [clears out the environment cache|https://github.com/puppetlabs/puppet/blob/main/lib/puppet/defaults.rb#L2162] when resolved.

This means if you are changing any Puppet settings in your catalog, in multithreaded mode environment caching is effectively disabled, because the cache will be invalidated on every compile of the offending environment.

The most straightforward fix would be to stop clearing all envs on settings initialization. But we'd need to make sure that won't cause other problems for the {{rich_data}} setting. But a better solution would be to find out why the hook is being called in the first place when [initializing|https://github.com/puppetlabs/puppetserver/blob/9ecd7fb18cd8e02edcfa9e2130c0b2053e0a3209/src/ruby/puppetserver-lib/puppet/server/settings.rb#L25-L31] the threadlocal settings object (we're not altering that setting, and the default hook mode is "on_write_only"), and see if we can avoid it.

Cas Donoghue (Jira)

unread,
Mar 10, 2021, 4:06:03 PM3/10/21
to puppe...@googlegroups.com
Cas Donoghue updated an issue
Change By: Cas Donoghue
Sprint: Froyo - 03/10/2021 , Froyo - 03/24/2021

Maggie Dreyer (Jira)

unread,
Mar 10, 2021, 4:42:01 PM3/10/21
to puppe...@googlegroups.com

Maggie Dreyer (Jira)

unread,
Mar 10, 2021, 4:44:03 PM3/10/21
to puppe...@googlegroups.com
Maggie Dreyer updated an issue
While doing research on new loader architectures for SERVER-2860, I discovered the following:

In {{multithreaded}} mode in Puppetserver, we create a new settings object whenever a Puppet setting changes while a JRuby request is being processed. One example is if a Puppet function in a module calls {{Puppet[]=}}. In the process of initializing the new settings object with overrides (for thread safety), we resolve all settings. The {{rich_data}} setting [clears out the environment cache|https://github.com/puppetlabs/puppet/blob/main/lib/puppet/defaults.rb#L2162] when resolved.

This means if you are changing any Puppet settings in your catalog, in multithreaded mode environment caching is effectively disabled, because the cache will be invalidated on every compile of the offending environment.

The most straightforward fix would be to stop clearing all envs on settings initialization. But we'd need to make sure that won't cause other problems for the {{rich_data}} setting. But a better solution would be to We should find out why the hook is being called in the first place when [initializing|https://github.com/puppetlabs/puppetserver/blob/9ecd7fb18cd8e02edcfa9e2130c0b2053e0a3209/src/ruby/puppetserver-lib/puppet/server/settings.rb#L25-L31] the threadlocal settings object (we're not altering that setting, and the default hook mode is "on_write_only"), and see if we can avoid it.

Maggie Dreyer (Jira)

unread,
Mar 18, 2021, 10:50:04 AM3/18/21
to puppe...@googlegroups.com

Maggie Dreyer (Jira)

unread,
Mar 18, 2021, 6:34:03 PM3/18/21
to puppe...@googlegroups.com
 
Re: Changing a Puppet setting in a catalog invalidates the env cache in multithreaded mode

So I was wrong: we do call that hook when initializing the settings on server start too, we just don't have logging set up yet when that happens. Apparently "on_write_only" hooks are also called when settings are parsed. It does not appear to be possible to avoid that.

Cas Donoghue (Jira)

unread,
Mar 24, 2021, 4:07:03 PM3/24/21
to puppe...@googlegroups.com
Cas Donoghue updated an issue
Change By: Cas Donoghue
Sprint: Froyo - 03/10/2021, Froyo - 03/24/2021 , Froyo - 04/7/2021

Maggie Dreyer (Jira)

unread,
Mar 29, 2021, 6:02:02 PM3/29/21
to puppe...@googlegroups.com

Maggie Dreyer (Jira)

unread,
Mar 29, 2021, 6:02:02 PM3/29/21
to puppe...@googlegroups.com

Maggie Dreyer (Jira)

unread,
Mar 29, 2021, 6:07:03 PM3/29/21
to puppe...@googlegroups.com
Maggie Dreyer updated an issue
Change By: Maggie Dreyer
Release Notes Summary: Fixed an issue in multithreaded mode where changing a Puppet setting while processing a request would cause the environment cache to be invalidated, due to a hook on the `rich_data` setting. The hook has been removed, and environments will now respect changes to the `rich_data` setting without needing to be recreated.

Maggie Dreyer (Jira)

unread,
Mar 29, 2021, 6:09:04 PM3/29/21
to puppe...@googlegroups.com
Maggie Dreyer updated an issue
Change By: Maggie Dreyer
Release Notes Summary: Fixed an issue in multithreaded mode where changing a Puppet setting while processing a request would cause Changing the environment cache to be invalidated, due to a hook on the value of Puppet's `rich_data` setting . The hook has been removed, and environments at runtime will now respect changes to no longer invalidate the `rich_data` setting without needing to be recreated environment cache .

Claire Cadman (Jira)

unread,
Apr 13, 2021, 8:33:02 AM4/13/21
to puppe...@googlegroups.com
Claire Cadman updated an issue
Change By: Claire Cadman
Labels: doc_reviewed
This message was sent by Atlassian Jira (v8.13.2#813002-sha1:c495a97)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages