You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using multi-shard databases with the default Rails configuration for sharding, issues arise when attempting to write to the database while in read-only mode. The default configuration is as follows:
The issue occurs because, in read-only mode, the connection attempts to load the following class:
SolidCache::Connections::Unmanaged.new
This leads to a failure since the connection persists in read-only mode, causing the operation to break when a write is attempted.
Solution
To resolve this, I updated the configuration from using database to databases, and enclosed the database name in a single-element array within the solid_cache.yml file. This modification forces the system to load:
SolidCache::Connections::Single.new(names.first)
By doing this, the issue was resolved, as it properly handles the connection in the correct mode.
Before
Here’s the original solid_cache.yml configuration that caused the issue:
When a database is specified, we should always manage connections so
that we can ensure the cache is writable.
But if you just use the default connection for the rest of the app, we
won't attempt to manage that.
Fixes: #214
When using multi-shard databases with the default Rails configuration for sharding, issues arise when attempting to write to the database while in read-only mode. The default configuration is as follows:
The issue occurs because, in read-only mode, the connection attempts to load the following class:
This leads to a failure since the connection persists in read-only mode, causing the operation to break when a write is attempted.
Solution
To resolve this, I updated the configuration from using
database
todatabases
, and enclosed the database name in a single-element array within thesolid_cache.yml
file. This modification forces the system to load:By doing this, the issue was resolved, as it properly handles the connection in the correct mode.
Before
Here’s the original
solid_cache.yml
configuration that caused the issue:After
This is the updated
solid_cache.yml
configuration that resolved the issue:Reference
You can find the specific lines in question that caused the issue here: https://github.com/rails/solid_cache/blob/main/lib/solid_cache/connections.rb#L5
The text was updated successfully, but these errors were encountered: