activerecord-cockroachdb-adapter 7.0.0 → 7.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8f39021d1353c56c2830adac978ec3336f993bdb46e670f4c975be8d2c307c5
4
- data.tar.gz: 8ea587bc12a5e5bc806901d28c7e67e9f63a0c2f5dfc769f2370ab4dd3f20c65
3
+ metadata.gz: 829d7c6d923f6d2949dfcca1c946be01286b79f643987696b0d271c696e3c55d
4
+ data.tar.gz: 558689db88c43aaa1fe4d10216796ee2754d9b206cc56feb846b0ca2e05e745c
5
5
  SHA512:
6
- metadata.gz: 6c7fca690e7203047ffeac709b9a62165c96f3ccb7ec26f3fe412daffc979f62ec392117912e15af15865aacf9f2b09bf2ff4d2efc155ee1f3dcbef1b2a213bb
7
- data.tar.gz: 55cf42b3a055eabbec2045dac6650d50a96a085794dc2ef6bbb08efb44182daff7664720292f720099c3b08239edafbe1ae668779aa975426d9d8905fe98620b
6
+ metadata.gz: 6b3ad08b9912080c5f324ef1b244e5f9d1ed22cd1e63f3c9ee9623399e5c92e12000681b0988e533a19e4e403325a13a419e534499c2d3fd6316b36525be57d9
7
+ data.tar.gz: c77f0016087842bdcfd7d8cbb0989b687653dcc4e6ce3e5c618b2fe2f1a44e1c995b84836235ba497f7623713987180796c1d07ae639f16dd4be6af747c1e9a4
@@ -0,0 +1,57 @@
1
+ # This workflow is based off of the example at
2
+ # https://github.com/docker/metadata-action
3
+ #
4
+ # Multi-platform configuration from
5
+ # https://github.com/docker/build-push-action/blob/master/docs/advanced/multi-platform.md
6
+ #
7
+ # Caching from
8
+ # https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md
9
+ name: Docker
10
+ permissions:
11
+ contents: read
12
+ on:
13
+ push:
14
+ branches: [ master ]
15
+ paths:
16
+ - 'build/Dockerfile'
17
+ # Only build, but don't push, on a PR if it touches the Dockerfile,
18
+ # since this takes a while to execute.
19
+ pull_request:
20
+ paths:
21
+ - 'build/Dockerfile'
22
+ jobs:
23
+ docker:
24
+ runs-on: ubuntu-latest
25
+ steps:
26
+ - name: Checkout
27
+ uses: actions/checkout@v3
28
+ - name: Set up QEMU
29
+ uses: docker/setup-qemu-action@v2
30
+ - name: Set up Docker Buildx
31
+ uses: docker/setup-buildx-action@v2
32
+ - name: Docker meta
33
+ id: meta
34
+ uses: docker/metadata-action@v4
35
+ with:
36
+ images: cockroachdb/activerecord_test_container
37
+ labels: |
38
+ org.opencontainers.image.title=Active Record CockroachDB Adapter Test Image
39
+ org.opencontainers.image.vendor=Cockroach Labs Inc.
40
+ org.opencontainers.image.description=Environment for running tests
41
+ - name: Login to DockerHub
42
+ if: github.event_name != 'pull_request'
43
+ uses: docker/login-action@v2
44
+ with:
45
+ username: ${{ secrets.DOCKERHUB_USERNAME }}
46
+ password: ${{ secrets.DOCKERHUB_TOKEN }}
47
+ - name: Build and push
48
+ uses: docker/build-push-action@v4
49
+ with:
50
+ context: .
51
+ file: build/Dockerfile
52
+ platforms: linux/amd64,linux/arm64
53
+ push: ${{ github.event_name != 'pull_request' }}
54
+ tags: ${{ steps.meta.outputs.tags }}
55
+ labels: ${{ steps.meta.outputs.labels }}
56
+ cache-from: type=gha
57
+ cache-to: type=gha,mode=max
data/.gitignore CHANGED
@@ -8,3 +8,10 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  *.gem
11
+ /debug.log
12
+ /cockroach-url
13
+ /cockroach-data/
14
+ /cockroach-*.linux-amd64/
15
+ /docker_root/
16
+ /ruby-build/
17
+ /test/db/
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.2.1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 7.0.1 - 2023-03-24
4
+
5
+ - Reconnect on retryable connection errors.
6
+
3
7
  ## 7.0.0 - 2022-06-02
4
8
 
5
9
  - Add support for Active Record 7.0.3
data/CONTRIBUTING.md CHANGED
@@ -25,22 +25,39 @@ CREATE DATABASE activerecord_unittest2;
25
25
  ```
26
26
 
27
27
  It is best to have a Ruby environment manager installed, such as
28
- [rvm](https://rvm.io/), as Rails has varying Ruby version requirements.
29
- If you are using rvm, you then install and use the required Ruby
30
- version. The current tests use Rails 5.2.0 beta and Ruby >= 2.2.2.
28
+ [rbenv](https://github.com/rbenv/rbenv), as Rails has varying Ruby version
29
+ requirements. If you are using rbenv, you then install and use the required
30
+ Ruby version.
31
31
 
32
32
  (Alternatively, one can use `./docker.sh build/teamcity-test.sh` to run
33
- tests similarily to TeamCity. The database is destroyed between each
33
+ tests similarly to TeamCity. The database is destroyed between each
34
34
  test file.)
35
35
 
36
+ Install rbenv with ruby-build on MacOS:
36
37
 
37
38
  ```bash
38
- rvm install 2.2.5
39
- # This only makes Ruby 2.2.5 active for the length of the terminal session.
40
- rvm use 2.2.5
39
+ brew install rbenv ruby-build
40
+ echo 'eval "$(rbenv init - zsh)"' >> ~/.profile
41
41
  ```
42
42
 
43
- Using [bundler](http://bundler.io/), install the dependancies of Rails.
43
+ Install rbenv with ruby-build on Ubuntu:
44
+
45
+ ```bash
46
+ sudo apt-get install rbenv
47
+ echo 'eval "$(rbenv init - zsh)"' >> ~/.profile
48
+
49
+ git clone https://github.com/sstephenson/ruby-build.git ~/ruby-build
50
+ sh ~/ruby-build/install.sh
51
+ ```
52
+
53
+ Use rbenv to install version of Ruby specified by `.ruby-version`.
54
+
55
+ ```bash
56
+ rbenv install
57
+ rbenv rehash
58
+ ```
59
+
60
+ Using [bundler](http://bundler.io/), install the dependencies of Rails.
44
61
 
45
62
  ```bash
46
63
  bundle install
@@ -52,13 +69,13 @@ Then, to run the full test suite with an active CockroachDB instance:
52
69
  bundle exec rake test
53
70
  ```
54
71
 
55
- To run specific ActiveRecord tests, set environemnt variable `TEST_FILES_AR`. For example, to run ActiveRecord tests `test/cases/associations_test.rb` and `test/cases/ar_schema_test.rb.rb`
72
+ To run specific ActiveRecord tests, set environment variable `TEST_FILES_AR`. For example, to run ActiveRecord tests `test/cases/associations_test.rb` and `test/cases/ar_schema_test.rb.rb`
56
73
 
57
74
  ```bash
58
75
  TEST_FILES_AR="test/cases/associations_test.rb,test/cases/ar_schema_test.rb" bundle exec rake test
59
76
  ```
60
77
 
61
- To run specific CockroachDB Adapter tests, set environemnt variable `TEST_FILES`. For example, to run CockroachDB Adpater tests `test/cases/adapter_test.rb` and `test/cases/associations/left_outer_join_association_test.rb`
78
+ To run specific CockroachDB Adapter tests, set environment variable `TEST_FILES`. For example, to run CockroachDB Adpater tests `test/cases/adapter_test.rb` and `test/cases/associations/left_outer_join_association_test.rb`
62
79
 
63
80
  ```bash
64
81
  TEST_FILES="test/cases/adapter_test.rb,test/cases/associations/left_outer_join_association_test.rb" bundle exec rake test
@@ -104,7 +121,7 @@ And the `activerecord_unittest` database will use the `RESTORE` command to load
104
121
  ## Support past Rails versions
105
122
 
106
123
  Currently, only a beta version of Rails is tested. This means that the
107
- adapter has been modified in to accomodate unreleased changes. In order
124
+ adapter has been modified in to accommodate unreleased changes. In order
108
125
  to run the tests for Rails 5.1 or 4.2, the test changes will need to be
109
126
  cherry-picked back. Conflicts are mostly only expected for tests that
110
127
  have not yet been added.
@@ -129,7 +146,7 @@ against different versions of CockroachDB.
129
146
 
130
147
  As CockroachDB improves, so do the features that can be supported in
131
148
  ActiveRecord. Many of them are gated by conditions the
132
- CockroachDBAdapter has overrided. As these features are completed, these
149
+ CockroachDBAdapter has overridden. As these features are completed, these
133
150
  gates should be toggled. Something that would help this process would be
134
151
  linking those issues back to this adapter so that part of the feature
135
152
  completing includes updating the adapter.
@@ -231,10 +248,10 @@ need to be cleaned up.
231
248
  # Notes for the non-Rubyer
232
249
 
233
250
  rvm is an environment manager that lets you manage and swap between
234
- multiple verisons of Ruby and their dependancies.
251
+ multiple versions of Ruby and their dependencies.
235
252
 
236
- bundle is dependancy manager that uses a projects `Gemfile` (and often
237
- `<project>.gemspec`) to manage and load dependancies and their required
253
+ bundle is dependency manager that uses a projects `Gemfile` (and often
254
+ `<project>.gemspec`) to manage and load dependencies and their required
238
255
  versions. When using projects commands are prefixed with
239
- `bundle exec ...`. Bundle will ensure that all depenedncies are fetched
256
+ `bundle exec ...`. Bundle will ensure that all dependencies are fetched
240
257
  and used.
data/Gemfile CHANGED
@@ -47,7 +47,7 @@ else
47
47
  )
48
48
  end
49
49
 
50
- # Get Rails from source beacause the gem doesn't include tests
50
+ # Get Rails from source because the gem doesn't include tests
51
51
  version = ENV['RAILS_VERSION'] || get_version_from_gemspec
52
52
  gem 'rails', git: "https://github.com/rails/rails.git", tag: "v#{version}"
53
53
  end
data/build/Dockerfile CHANGED
@@ -8,10 +8,7 @@ RUN apt-get --allow-releaseinfo-change update -y && apt-get install -y \
8
8
  libxslt-dev \
9
9
  libxml2-dev \
10
10
  libsqlite3-dev \
11
+ rbenv \
11
12
  && rm -rf /var/lib/apt/lists/*
12
13
 
13
- # Ruby testing dependencies.
14
- RUN gem install bundle rake
15
-
16
- # Add global Gem binaries to the path.
17
- ENV PATH /usr/local/lib/ruby/gems/2.4.0::$PATH
14
+ RUN rm -rf ~/ruby-build; git clone https://github.com/sstephenson/ruby-build.git ~/ruby-build; sh ~/ruby-build/install.sh
data/build/local-test.sh CHANGED
@@ -11,7 +11,6 @@ rm -f "$urlfile"
11
11
  # canceled on an agent.
12
12
  rm -rf $HOME/tmp/rails &
13
13
  # Start CockroachDB.
14
- cockroach quit --insecure || true
15
14
  cockroach start --insecure --host=localhost --listening-url-file="$urlfile" --store=path=$HOME/tmp/rails &
16
15
  trap "echo 'Exit routine: Killing CockroachDB.' && kill -9 $! &> /dev/null" EXIT
17
16
  for i in {0..3}
@@ -31,8 +30,3 @@ echo "Rebuilding database"
31
30
  (cd rails/activerecord && bundle exec rake db:cockroachdb:rebuild)
32
31
  echo "Starting tests"
33
32
  (cd rails/activerecord && bundle exec rake test:cockroachdb TESTFILES=$1)
34
-
35
- # Attempt a clean shutdown for good measure. We'll force-kill in the atexit
36
- # handler if this fails.
37
- cockroach quit --insecure
38
- trap - EXIT
@@ -2,9 +2,17 @@
2
2
 
3
3
  set -euox pipefail
4
4
 
5
+ eval "$(rbenv init -)"
6
+
7
+ rbenv install --skip-existing --verbose
8
+
9
+ rbenv rehash
10
+
11
+ ruby -v
12
+
5
13
  # Download CockroachDB
6
- VERSION=v22.1.0
7
- wget -qO- https://binaries.cockroachdb.com/cockroach-$VERSION.linux-amd64.tgz | tar xvz
14
+ VERSION=v22.2.6
15
+ wget -qO- https://binaries.cockroachdb.com/cockroach-$VERSION.linux-amd64.tgz | tar xvz
8
16
  readonly COCKROACH=./cockroach-$VERSION.linux-amd64/cockroach
9
17
 
10
18
  # Make sure cockroach can be found on the path. This is required for the
@@ -16,9 +24,6 @@ run_cockroach() {
16
24
  # Start a CockroachDB server, wait for it to become ready, and arrange
17
25
  # for it to be force-killed when the script exits.
18
26
  rm -f "$urlfile"
19
- # Clean out a past CockroachDB instance. This will clean out leftovers
20
- # from the build agent, and also between CockroachDB runs.
21
- cockroach quit --insecure || true
22
27
  rm -rf cockroach-data
23
28
  # Start CockroachDB.
24
29
  cockroach start-single-node --max-sql-memory=25% --cache=25% --insecure --host=localhost --spatial-libs=./cockroach-$VERSION.linux-amd64/lib --listening-url-file="$urlfile" >/dev/null 2>&1 &
@@ -54,8 +59,11 @@ run_cockroach() {
54
59
  cockroach sql --insecure -e "SET CLUSTER SETTING sql.defaults.experimental_temporary_tables.enabled = 'true';"
55
60
  }
56
61
 
62
+ gem env
63
+
57
64
  # Install ruby dependencies.
58
- gem install bundler:2.3.14
65
+ gem install bundler:2.4.9 rake:13.0.6
66
+
59
67
  bundle install
60
68
 
61
69
  run_cockroach
@@ -68,11 +76,6 @@ else
68
76
  HAS_FAILED=0
69
77
  fi
70
78
 
71
- # Attempt a clean shutdown for good measure. We'll force-kill in the
72
- # exit trap if this script fails.
73
- cockroach quit --insecure
74
- trap - EXIT
75
-
76
79
  if [ $HAS_FAILED -eq 1 ]; then
77
80
  exit 1
78
81
  fi
data/docker.sh CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  set -euox pipefail
6
6
 
7
- DOCKER_IMAGE_TAG=cockroachdb/activerecord_test_container:20210914
7
+ DOCKER_IMAGE_TAG=cockroachdb/activerecord_test_container:master
8
8
 
9
9
  # Absolute path to this repository.
10
10
  repo_root=$(cd "$(dirname "${0}")" && pwd)
@@ -10,21 +10,44 @@ module ActiveRecord
10
10
  # exceeded.
11
11
  def within_new_transaction(isolation: nil, joinable: true, attempts: 0)
12
12
  super(isolation: isolation, joinable: joinable)
13
+ rescue ActiveRecord::ConnectionNotEstablished => error
14
+ raise unless retryable? error
15
+ raise if attempts >= @connection.max_transaction_retries
16
+
17
+ sleep_rand_seconds(attempts)
18
+
19
+ unless @connection.active?
20
+ warn "connection isn't active, reconnecting"
21
+ @connection.reconnect!
22
+ end
23
+
24
+ within_new_transaction(isolation: isolation, joinable: joinable, attempts: attempts + 1) { yield }
13
25
  rescue ActiveRecord::StatementInvalid => error
14
26
  raise unless retryable? error
15
27
  raise if attempts >= @connection.max_transaction_retries
16
28
 
17
- attempts += 1
18
- sleep_seconds = (2 ** attempts + rand) / 10
19
- sleep(sleep_seconds)
20
- within_new_transaction(isolation: isolation, joinable: joinable, attempts: attempts) { yield }
29
+ sleep_rand_seconds(attempts)
30
+
31
+ within_new_transaction(isolation: isolation, joinable: joinable, attempts: attempts + 1) { yield }
21
32
  end
22
33
 
23
34
  def retryable?(error)
35
+ return true if serialization_error?(error)
24
36
  return true if error.is_a? ActiveRecord::SerializationFailure
25
37
  return retryable? error.cause if error.cause
26
38
  false
27
39
  end
40
+
41
+ def serialization_error?(error)
42
+ errors = [error]
43
+ errors << error.cause if error.cause
44
+ errors.any? {|e| e.is_a? PG::TRSerializationFailure }
45
+ end
46
+
47
+ def sleep_rand_seconds(attempts)
48
+ sleep_seconds = (2 ** attempts + rand) / 10
49
+ sleep(sleep_seconds)
50
+ end
28
51
  end
29
52
  end
30
53
 
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecord
4
- COCKROACH_DB_ADAPTER_VERSION = "7.0.0"
4
+ COCKROACH_DB_ADAPTER_VERSION = "7.0.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-cockroachdb-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.0
4
+ version: 7.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cockroach Labs
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-06 00:00:00.000000000 Z
11
+ date: 2023-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -74,8 +74,10 @@ executables: []
74
74
  extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
+ - ".github/workflows/docker.yml"
77
78
  - ".gitignore"
78
79
  - ".gitmodules"
80
+ - ".ruby-version"
79
81
  - CHANGELOG.md
80
82
  - CONTRIBUTING.md
81
83
  - Gemfile
@@ -134,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
136
  - !ruby/object:Gem::Version
135
137
  version: '0'
136
138
  requirements: []
137
- rubygems_version: 3.1.6
139
+ rubygems_version: 3.4.9
138
140
  signing_key:
139
141
  specification_version: 4
140
142
  summary: CockroachDB adapter for ActiveRecord.