Skip to content

Commit

Permalink
Merge branch 'sync/upstream-7.1-patched' into total/chewy-v7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
lucanioi authored Nov 27, 2023
2 parents 55f2813 + 662caeb commit 89c7b28
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 11 deletions.
94 changes: 94 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: CI

on: [push]

jobs:
tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ruby: [2.6, 2.7]
gemfile: [rails.5.2.activerecord, rails.6.0.activerecord, rails.6.1.activerecord]
name: ${{ matrix.ruby }}-${{ matrix.gemfile }}

env:
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile

steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run Elasticsearch
uses: elastic/elastic-github-actions/elasticsearch@master
with:
stack-version: 7.10.1
port: 9250
- name: Tests
run: bundle exec rspec

ruby-3-0-activerecord-6-1:
runs-on: ubuntu-latest
env:
BUNDLE_GEMFILE: gemfiles/rails.6.1.activerecord.gemfile
steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0'
bundler-cache: true
- name: Run Elasticsearch
uses: elastic/elastic-github-actions/elasticsearch@master
with:
stack-version: 7.10.1
port: 9250
- name: Tests
run: bundle exec rspec

ruby-3-0-activerecord-6-1-es6:
runs-on: ubuntu-latest
env:
BUNDLE_GEMFILE: gemfiles/rails.6.1.activerecord.gemfile
steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0'
bundler-cache: true
- name: Run Elasticsearch
uses: elastic/elastic-github-actions/elasticsearch@master
with:
stack-version: 6.8.15
port: 9250
- name: Tests
run: bundle exec rspec

ruby-2-7-activerecord-6-1-es6:
runs-on: ubuntu-latest
env:
BUNDLE_GEMFILE: gemfiles/rails.6.1.activerecord.gemfile
steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
bundler-cache: true
- name: Run Elasticsearch
uses: elastic/elastic-github-actions/elasticsearch@master
with:
stack-version: 6.8.15
port: 9250
- name: Tests
run: bundle exec rspec

rubocop:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
bundler-cache: true
- run: bundle exec rubocop --format simple
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@

* [#722](https://github.com/toptal/chewy/issues/722): Remove alias_method_chain, use Module#prepend instead ([@dalthon][])

## 7.0.1 (2021-05-03)

### Changes

* [#792](https://github.com/toptal/chewy/pull/792): Skip ES version memoization for search requests ([@rabotyaga][])
* See the Migration Guide for details

## 7.0.0 (2021-02-22)

### New Features
Expand Down
2 changes: 1 addition & 1 deletion lib/chewy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
require 'active_support/core_ext/object/inclusion'
require 'active_support/core_ext/string/inflections'

require 'i18n/core_ext/hash'
require 'active_support/core_ext/hash'
require 'chewy/backports/deep_dup' unless Object.respond_to?(:deep_dup)
require 'singleton'
require 'base64'
Expand Down
9 changes: 5 additions & 4 deletions lib/chewy/rake_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def reset(only: nil, except: nil, parallel: nil, output: STDOUT)
# @param parallel [true, Integer, Hash] any acceptable parallel options for import
# @param output [IO] output io for logging
# @return [Array<Chewy::Index>] indexes that were actually reset
def upgrade(only: nil, except: nil, parallel: nil, output: STDOUT)
def upgrade(only: nil, except: nil, parallel: nil, output: STDOUT, force_suffix: nil)
subscribed_task_stats(output) do
indexes = indexes_from(only: only, except: except)

Expand All @@ -70,7 +70,7 @@ def upgrade(only: nil, except: nil, parallel: nil, output: STDOUT)
if changed_indexes.present?
indexes.each do |index|
if changed_indexes.include?(index)
reset_one(index, output, parallel: parallel)
reset_one(index, output, parallel: parallel, force_suffix: force_suffix)
else
output.puts "Skipping #{index}, the specification didn't change"
end
Expand Down Expand Up @@ -294,9 +294,10 @@ def human_duration(seconds)
end.compact.reverse.join(' ')
end

def reset_one(index, output, parallel: false)
def reset_one(index, output, parallel: false, force_suffix: nil)
output.puts "Resetting #{index}"
index.reset!((Time.now.to_f * 1000).round, parallel: parallel)
suffix = force_suffix || (Time.now.to_f * 1000).round
index.reset!(suffix, parallel: parallel)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/chewy/rspec/update_index.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'i18n/core_ext/hash'
require 'active_support/core_ext/hash'

# Rspec matcher `update_index`
# To use it - add `require 'chewy/rspec'` to the `spec_helper.rb`
Expand Down
15 changes: 10 additions & 5 deletions lib/tasks/chewy.rake
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ namespace :chewy do

desc 'Resets data for the specified indexes or all of them only if the index specification is changed'
task upgrade: :environment do |_task, args|
Chewy::RakeHelper.upgrade(**parse_classes(args.extras))
force_suffix = args.extras.first
Chewy::RakeHelper.upgrade(force_suffix: force_suffix)
end

desc 'Updates data for the specified indexes/types or all of them'
Expand All @@ -42,8 +43,9 @@ namespace :chewy do
end

desc 'Resets all the indexes with the specification changed and synchronizes the rest of them'
task deploy: :environment do
processed = Chewy::RakeHelper.upgrade
task deploy: :environment do |_task, args|
force_suffix = args.extras.first
processed = Chewy::RakeHelper.upgrade(force_suffix: force_suffix)
Chewy::RakeHelper.sync(except: processed)
end

Expand All @@ -55,7 +57,9 @@ namespace :chewy do

desc 'Parallel version of `rake chewy:upgrade`'
task upgrade: :environment do |_task, args|
Chewy::RakeHelper.upgrade(**parse_parallel_args(args.extras))
parallel = args.extras.first =~ /\A\d+\z/ ? Integer(args.extras.first) : true
force_suffix = args.extras.second
Chewy::RakeHelper.upgrade(parallel: parallel, force_suffix: force_suffix)
end

desc 'Parallel version of `rake chewy:update`'
Expand All @@ -71,7 +75,8 @@ namespace :chewy do
desc 'Parallel version of `rake chewy:deploy`'
task deploy: :environment do |_task, args|
parallel = args.extras.first =~ /\A\d+\z/ ? Integer(args.extras.first) : true
processed = Chewy::RakeHelper.upgrade(parallel: parallel)
force_suffix = args.extras.second
processed = Chewy::RakeHelper.upgrade(parallel: parallel, force_suffix: force_suffix)
Chewy::RakeHelper.sync(except: processed, parallel: parallel)
end
end
Expand Down
19 changes: 19 additions & 0 deletions migration_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,29 @@ In order to upgrade Chewy 6/Elasticsearch 6 to Chewy 7/Elasticsearch 7 in the mo
* Run your test suite on Chewy 7.0 / Elasticsearch 7
* Run manual tests on Chewy 7.0 / Elasticsearch 7
* Upgrade to Chewy 7.0
* The “total hits” counter is an integer for ES versions < 7 and an object (hash) for the versions starting from 7.0.0. Elasticsearch added a special option, `rest_total_hits_as_int`, to ease the upgrade, that could be appended to any request and results in the old “total hits” format. Unfortunately, this option is not recognized by ES versions prior to 7.0.0, which means that we have to check the version to decide if we need this option.
Normally Chewy does memoization of the current ES version, but this might be inappropriate for the upgrade, as the version changes live.
To handle that we have 2 versions of Chewy for this stage of the upgrade: 7.0.0 and 7.0.1. Version 7.0.0 does the memoization and version 7.0.1 requests the current version on every search request.
* You can use the 7.0.0 version if it's fine for you to have an application restart immediately after ES cluster upgrade.
* If you're using the 7.0.1 version you might be interested in keeping the timeframe between this step and the last one as small as possible, as version 7.0.1 skips ES version memoization for search requests to help dynamically detect ES version. This leads to an extra version request on each search request, i.e. could affect the overall performance/latency of the search and a load of ES cluster.
* Perform a [rolling upgrade](https://www.elastic.co/guide/en/elasticsearch/reference//rolling-upgrades.html) of Elasticsearch
* Run your test suite on Chewy 7.1 / Elasticsearch 7
* Run manual tests on Chewy 7.1 / Elasticsearch 7
* Upgrade to Chewy 7.1
* Upgrade to Chewy 7.2:
* Remove all the the `Chewy::Type` class usages, e.g. remove `CitiesIndex::City` / `CitiesIndex.city`
* `CitiesIndex::City.import! ...` becomes `CitiesIndex.import! ...`
* Update indexes with simplified DSL:
* `define_type` block -> `index_scope` clause
* it can be omitted completely, if you don't need to specify the scope or options, e.g. `name`
* Remove type names from string representations:
* in `update_index` ActiveRecord helper and RSpec matcher, e.g.
* `update_index('cities#city')` -> `update_index('cities')`
* `update_index(UsersIndex::User)` -> `update_index(UsersIndex)`
* in rake tasks (e.g. `rake chewy:update[cities#city]` -> `rake chewy:update[cities]`)
* rake tasks output is also changed (e.g. `Imported CitiesIndex::City in 1s, stats: index 3` -> `Imported CitiesIndex in 1s, stats: index 3`)
* Use index name instead of type name in loader additional scope
* e.g. `CitiesIndex.filter(...).load(city: {scope: City.where(...)})` -> `CitiesIndex.filter(...).load(cities: {scope: City.where(...)})`

## Chewy 5/Elasticsearch 5 to Chewy 6/Elasticsearch 6

Expand Down

0 comments on commit 89c7b28

Please sign in to comment.