8000 [FrameworkBundle][Cache] Allow configuring PDO-based cache pools, with table auto-creation on first use by nicolas-grekas · Pull Request #27694 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[FrameworkBundle][Cache] Allow configuring PDO-based cache pools, with table auto-creation on first use #27694

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
Jul 9, 2018

Conversation

nicolas-grekas
Copy link
Member
Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -
  • Allowed configuring PDO-based cache pools via a new cache.adapter.pdo abstract service
  • added automatic table creation when using Doctrine DBAL with PDO-based backends

@dmaicher
Copy link
Contributor
dmaicher commented Jun 24, 2018

Hmm I can imagine some scenarios where this automatic table creation could have some side-effects.

For example:

  • the caching table does not exist yet
  • I start a transaction somewhere in my user-land code
  • I perform some updates/inserts to the database (other tables, unrelated to cache)
  • during this transaction I perform some cache saves
  • I want to roll-back my transaction ==> this fails because my transaction was committed implicitly because of the table creation query?

Not sure how likely a scenario like this is 😄 But it could happen I guess

@nicolas-grekas
Copy link
Member Author

@dmaicher sure that's possible. Is this any different than the same scenario with the table already created before, and items not saved for the same reason (a rollback?)

@dmaicher
Copy link
Contributor

Is this any different than the same scenario with the table already created before, and items not saved for the same reason (a rollback?)

I added one point above: I perform some updates/inserts to the database (other tables, unrelated to cache) . So then we have a difference, right? Those changes cannot be rolled back anymore.

@nicolas-grekas
Copy link
Member Author
nicolas-grekas commented Ju 8000 n 24, 2018

Oh sorry I missed that part. Here are some docs on the topic:
https://wiki.postgresql.org/wiki/Transactional_DDL_in_PostgreSQL:_A_Competitive_Analysis
https://stackoverflow.com/questions/4692690/is-it-possible-to-roll-back-create-table-and-alter-table-statements-in-major-sql

We may prefer disabling auto-creation when in the middle of a transaction...

Status: needs work

@nicolas-grekas
Copy link
Member Author

@dmaicher fixed.

Copy link
Contributor
@dmaicher dmaicher left a comment

Choose a reason for hiding this comment

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

one comment for the auto-creation. Otherwise looks good to me 👍

try {
$stmt = $conn->prepare($sql);
} catch (TableNotFoundException $e) {
if (!$conn->isTransactionActive() || \in_array($this->driver, array('pgsql', 'sqlite', 'sqlsrv'), true)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok this looks safer now.

I'm just wondering: What exactly is the use-case now for this auto-creation?

I mean we cannot really rely on it anyway on production as this will simply fail if we are in the middle of a transaction. Sure we can assume eventually there will be a request where this condition is true 😄 But as said we cannot rely on it anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ease of use. And pgsql users will love it. Note also that even now, no exceptions are thrown when the table is not found. PSR-6 only allows a log line. This doesn't change it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah true about the muted exceptions. Forgot about that.

Yeah for pgsql indeed nice 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi guys ! seems like issue here...
im using pgsql and TableNotFoundException throwed only when $stmt->execute();
$stmt = $conn->prepare($sql); is not throwing TableNotFoundException when cache_items table does not exists
@nicolas-grekas what do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I will forget about this in one hour :)
Please create an issue if you think there is something to track.

@javiereguiluz
Copy link
Member

I'm all in for easing the usage of features ... but "database table auto-creation when the PDO cache needs it" makes me nervous. Not sure if it's a real scenario, but imagine this: I enable PDO cache in production without preparing the database for it:

  1. Without table auto-creation I see an error and I'm aware that I need to do some things in the database.
  2. With table auto-creation, everything works ... but maybe I'm using a cloud server, the cache grows a lot ... and I end up with a huge bill from my cloud provider because of the database usage.

@nicolas-grekas
Copy link
Member Author

Without table auto-creation I see an error and I'm aware that I need to do some things in the database.

no you don't, as explained in a comment above, PSR-6 allows no error to be reported, so this is silent - or at best logged. That's why this is an improvement over the current situation.

@fabpot
Copy link
Member
fabpot commented Jul 9, 2018

Thank you @nicolas-grekas.

@fabpot fabpot merged commit 1484117 into symfony:master Jul 9, 2018
fabpot added a commit that referenced this pull request Jul 9, 2018
…ache pools, with table auto-creation on first use (nicolas-grekas)

This PR was merged into the 4.2-dev branch.

Discussion
----------

[FrameworkBundle][Cache] Allow configuring PDO-based cache pools, with table auto-creation on first use

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

* Allowed configuring PDO-based cache pools via a new `cache.adapter.pdo` abstract service
* added automatic table creation when using Doctrine DBAL with PDO-based backends

Commits
-------

1484117 [FrameworkBundle][Cache] Allow configuring PDO-based cache pools, with table auto-creation on first use
@weaverryan
Copy link
Member

Do we need a docs issue?

@nicolas-grekas nicolas-grekas deleted the cache-pdo-config branch July 22, 2018 20:25
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull request Jul 23, 2018
…ion (nicolas-grekas)

This PR was merged into the master branch.

Discussion
----------

[Cache] tell about PDO configuration and table autocreation

Doc for symfony/symfony#27694

Commits
-------

187300a [Cache] tell about PDO configuration and table autocreation
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.2 Nov 1, 2018
This was referenced Nov 3, 2018
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.

7 participants
0