-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds a key_hash column to the solid_cache_entries table. This column is a 64-bit integer that is a truncated SHA256 hash of the key. This allows us to use a smaller index than the 1024 byte key column. The byte_size column is also added to the table. This is the size of the value in bytes. This is for a separate feature but is included in this commit to piggy back on the migrations. The migrations themselves are split into three steps. This allows existing tables to be migrated without downtime. There is a new configuration field `key_hash_stage` that can be set to `:ignored`, `:unindexed` or `:indexed`. This controls how the key_hash column is used and should be set as the migrations are completed. The default is :indexed, which is what is required for fresh installations of solid_cache. In this case you can apply all three migrations at the same time. In the case of an existing setup however, the steps are: 1. Install the new gem, install the migrations and set `config.solid_cache.key_hash_stage = :ignored` 2. Run the first migration, which adds the new columns 3. Update `config.solid_cache.key_hash_stage = :unindexed` 4. Backfill or truncate the table 5. Run the second migration, which adds the indexes and null constraints 6. Update `config.solid_cache.key_hash_stage = :indexed` 7. Run the third migration, which removes the old key index For later versions of the gem we'll assume that the key_hash column exists and the `config.solid_cache.key_hash_stage`. We'll also squash the migrations into a single file.
- Loading branch information
Showing
13 changed files
with
267 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
db/migrate/20240108155507_add_key_hash_and_byte_size_to_solid_cache_entries.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class AddKeyHashAndByteSizeToSolidCacheEntries < ActiveRecord::Migration[7.1] | ||
def change | ||
change_table :solid_cache_entries do |t| | ||
t.column :key_hash, :integer, null: true, limit: 8 | ||
t.column :byte_size, :integer, null: true, limit: 4 | ||
end | ||
end | ||
end |
11 changes: 11 additions & 0 deletions
11
...0111600_add_key_hash_and_byte_size_indexes_and_null_constraints_to_solid_cache_entries.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class AddKeyHashAndByteSizeIndexesAndNullConstraintsToSolidCacheEntries < ActiveRecord::Migration[7.1] | ||
def change | ||
change_table :solid_cache_entries, bulk: true do |t| | ||
t.change_null :key_hash, false | ||
t.change_null :byte_size, false | ||
t.index :key_hash, unique: true | ||
t.index [:key_hash, :byte_size] | ||
t.index :byte_size | ||
end | ||
end | ||
end |
7 changes: 7 additions & 0 deletions
7
db/migrate/20240110111702_remove_key_index_from_solid_cache_entries.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class RemoveKeyIndexFromSolidCacheEntries < ActiveRecord::Migration[7.1] | ||
def change | ||
change_table :solid_cache_entries do |t| | ||
t.remove_index :key | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.