Skip to content

[HttpKernel][FrameworkBundle] Add RebootableInterface, fix and un-deprecate cache:clear with warmup #23792

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 18, 2017

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Aug 4, 2017

Q A
Branch? 3.4
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? yes
Tests pass? yes
Fixed tickets #23592, #8500
License MIT
Doc PR -

This PR fixes the reasons why we deprecated cache:clear without --no-warmup.

Internally, it requires some cooperation from the Kernel, so that a deprecation is needed.
This allows the same kernel instance to be rebooted under a new cache directory, used during the warmup.
It leverages the new capability to create two independent non colliding containers.

} else {
$realKernel->reboot($warmupDir);

if (!$isRebootable = $realKernel->getCacheDir() === $realCacheDir) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be:

- if (!$isRebootable = $realKernel->getCacheDir() === $realCacheDir) {
+ if (!$isRebootable = $realKernel->getCacheDir() !== $realCacheDir) {

right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comments addressed thanks

@symfony symfony deleted a comment from ogizanagi Aug 5, 2017
@nicolas-grekas nicolas-grekas force-pushed the cache-clear branch 4 times, most recently from 81671eb to f8adb38 Compare August 7, 2017 18:35
@nicolas-grekas
Copy link
Member Author

rebased and ready

@javiereguiluz
Copy link
Member

It's hard to review PRs without description (even if the long title explains a bit what this PR does).

For this and every other PR I'd like to have two brief descriptions:

  1. how does this improves end-user life;
  2. what internal changes will this introduce for Symfony (so we can update Symfony Docs if needed).

Thanks!

@nicolas-grekas nicolas-grekas changed the title [FrameworkBundle][HttpKernel] Fix and un-deprecate cache:clear[ --no-warmup] with new RebootableInterface [HttpKernel][FrameworkBundle] Add RebootableInterface, fix and un-deprecate cache:clear with warmup Aug 7, 2017
@nicolas-grekas nicolas-grekas force-pushed the cache-clear branch 2 times, most recently from 9ec551a to a600b3d Compare August 8, 2017 06:34
@Koc
Copy link
Contributor

Koc commented Aug 8, 2017

@nicolas-grekas does it fixes #8500 also?

@nicolas-grekas
Copy link
Member Author

@Koc looks like so, but only you can confirm :)

@Koc
Copy link
Contributor

Koc commented Aug 8, 2017

does no new instance of AppKernel creates on cache clear?

@nicolas-grekas
Copy link
Member Author

That's correct, it reuses (reboots) the same instance.

Copy link
Member

@chalasr chalasr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should removals in UPGRADE and CHANGELOG files be reverted (already removed in #23825)?

*
* @author Nicolas Grekas <p@tchwork.com>
*/
interface RebootableInterface
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this interface be merged into HttpKernel for 4.0? It seems a lot of stuff will rely on the reboot() method with this PR, maybe there's no sense to keep it in a separate interface and still require kernels to implement it?

(note that my comment would apply specifically for 4.0, not 3.x)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearly not in HttpKernel, as only Kernel implements it, not HttpKernel.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep my bad, Kernel!

Copy link
Member Author

@nicolas-grekas nicolas-grekas Aug 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the method is used only in the cache:clear command, not sure that accounts for "a lot" :)

UPGRADE-3.4.md Outdated
{
public function getCacheDir()
{
return $this->getWarmupDir() ?: 'my-cache-dir';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the fact that an implementation detail leaks (getWarmupDir() is really an internal detail). I would prefer to not change this method at all. getCacheDir() is public because it's part of HttpKernelInterface to provide an easy way to override the cache dir in the project's kernel. It was never meant to be called directly, and most devs probably use kernel.cache_dir anyway.

Instead, we could add a phpdoc warning explaining what I've just written :)

fabpot added a commit that referenced this pull request Aug 18, 2017
…clear with warmup (fabpot)" (nicolas-grekas)

This PR was merged into the 3.3 branch.

Discussion
----------

Revert "feature #21038 [FrameworkBundle] deprecated cache:clear with warmup (fabpot)"

This reverts commit 3495b35, reversing
changes made to 7f7b897.

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #21038
| License       | MIT
| Doc PR        | -

Sibling to #23792: there is no need to trigger the deprecation in 3.3 if we un-deprecate in 3.4.

Commits
-------

9009970 Revert "feature #21038 [FrameworkBundle] deprecated cache:clear with warmup (fabpot)"
@nicolas-grekas nicolas-grekas force-pushed the cache-clear branch 3 times, most recently from 22c419d to 1f08478 Compare August 18, 2017 10:01
@nicolas-grekas
Copy link
Member Author

getWarmupDir is now gone, comments updated
should be ready

@nicolas-grekas nicolas-grekas force-pushed the cache-clear branch 2 times, most recently from 3ae675f to 14b08ec Compare August 18, 2017 10:49
@@ -786,9 +799,6 @@ protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container
@chmod($dir.$file, 0666 & ~umask());
}

// track changes made to the container directory
$container->fileExists(dirname($dir.$file));
Copy link
Member Author

@nicolas-grekas nicolas-grekas Aug 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removes a transient test (CacheClearCommandTest::testCacheIsFreshAfterCacheClearedWithWarmup: Meta file "FixtureTestDebugProjectContainer.php.meta" is not fresh)
and allows debugging the container by patching its generated files when needed (I added this code in 3.4. A bad idea.)
If you mess up with the container files, that's your problem :)

namespace Symfony\Component\HttpKernel;

/**
* Rebotable extends the Kernel to allow it to reboot using a temporary cache directory.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo Rebootable. Anway, I would say Allows the Kernel to be rebooted using ...

*
* @param string|null $warmupDir
*/
public function reboot($warmupDir);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the use case for passing null?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • * @param string|null $warmupDir pass `null` to reboot to the regular cache dir
    

@nicolas-grekas nicolas-grekas force-pushed the cache-clear branch 2 times, most recently from 302592c to 03e6ef6 Compare August 18, 2017 11:49
* The getCacheDir() method of a rebootable kernel should not be called
* while building the container. Use the %kernel.cache_dir% parameter instead.
*
* @param string|null $warmupDir pass `null` to reboot to the regular cache dir
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null without ```

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to reboot in the regular cache dir?

@fabpot
Copy link
Member

fabpot commented Aug 18, 2017

Thank you @nicolas-grekas.

@fabpot fabpot merged commit a4fc492 into symfony:3.4 Aug 18, 2017
fabpot added a commit that referenced this pull request Aug 18, 2017
… fix and un-deprecate cache:clear with warmup (nicolas-grekas)

This PR was merged into the 3.4 branch.

Discussion
----------

[HttpKernel][FrameworkBundle] Add RebootableInterface, fix and un-deprecate cache:clear with warmup

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | #23592, #8500
| License       | MIT
| Doc PR        | -

This PR fixes the reasons why we deprecated cache:clear without --no-warmup.

Internally, it requires some cooperation from the Kernel, so that a deprecation is needed.
This allows the same kernel instance to be rebooted under a new cache directory, used during the warmup.
It leverages the new capability to create two independent non colliding containers.

Commits
-------

a4fc492 [HttpKernel][FrameworkBundle] Add RebootableInterface, fix and un-deprecate cache:clear with warmup
@nicolas-grekas nicolas-grekas deleted the cache-clear branch August 18, 2017 15:11
This was referenced Oct 18, 2017
@hkdobrev
Copy link
Contributor

hkdobrev commented Nov 21, 2017

Thank you for this @nicolas-grekas! I think this blog post could be updated mentioning cache:clear with warmup would not be deprecated in 4.0 if you use RebootableInterface. https://symfony.com/blog/new-in-symfony-3-3-deprecated-cache-clear-with-warmup It's coming as a first result in various cache warmup queries on Google search.

@nicolas-grekas
Copy link
Member Author

Good idea, ping @javiereguiluz

@amici
Copy link

amici commented Nov 2, 2018

The original (and outdated) 3.3 news is still the first to see on google - and kind of very easy to miss the very important notice about the un-deprecation. Could it be a bit more visible? I'd write there, but comments are closed.

@javiereguiluz
Copy link
Member

@amici I agree with you. Instead of making the warning more visible ... we've decided to remove the original blog post content. See https://symfony.com/blog/new-in-symfony-3-3-deprecated-cache-clear-with-warmup Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.