railwatch 0.8.5 → 0.8.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +42 -0
- data/db/railwatch_telemetry_migrate/20260919000100_create_export_queue.rb +125 -87
- data/db/railwatch_telemetry_migrate/20260922000000_add_covering_indexes_for_dashboard_aggregates.rb +4 -4
- data/db/railwatch_telemetry_migrate/20260923000000_add_people_index.rb +1 -1
- data/db/railwatch_telemetry_migrate/20260925000000_add_tenant_summary_index.rb +1 -1
- data/lib/railwatch/configuration.rb +8 -1
- data/lib/railwatch/patches/migration_busy_timeout.rb +73 -0
- data/lib/railwatch/patches.rb +11 -0
- data/lib/railwatch/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f9e80ca205e8ad9435148ba6b185c3de1796f8ffe489f1208876f38e21686181
|
|
4
|
+
data.tar.gz: '09028109bb2da10a48db010d19f126a5e406bcbe50d2991ebcc303e4c4d74318'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 75c81cb580e0948629948f8be59ccaf81e175239e2d268ae7b8cf9f5f6a42073e930881fc2ac5fe7700806c925684f9defd297f47673a2b2470754d688858554
|
|
7
|
+
data.tar.gz: 8603393804ca3cdd96c5406fb313b1dca1ff7b378c780b7b42765c14d2b76c4e2d0895f8766c0a50fcbe14e0ea5f9ec1381fb7d330737d4ab50b950c76e84e56
|
data/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,48 @@
|
|
|
6
6
|
filled in by the release commit, which is also the only commit that
|
|
7
7
|
touches lib/railwatch/version.rb and Gemfile.lock. See CONTRIBUTING.md. -->
|
|
8
8
|
|
|
9
|
+
## 0.8.7 (2026-10-06)
|
|
10
|
+
|
|
11
|
+
- A migration of the railwatch databases waits up to 60 s for SQLite's
|
|
12
|
+
write lock instead of the database's own `timeout` (5 s in the generated
|
|
13
|
+
`database.yml`). A deploy migrates while the previous release is still
|
|
14
|
+
serving, and on an embedded install that release's writer keeps
|
|
15
|
+
committing telemetry to the same file: about a second per transaction on
|
|
16
|
+
a warm 15 GB file, several seconds while the deploy's image build has the
|
|
17
|
+
disk. rebulk-system's container entrypoint ran `db:prepare` into that,
|
|
18
|
+
got `SQLite3::BusyException: database is locked` from the first
|
|
19
|
+
migration that needed a write, and crash-looped until the health check
|
|
20
|
+
gave up. Only the connection Active Record migrates with is changed, only
|
|
21
|
+
while it migrates, and only for a database whose `migrations_paths` are
|
|
22
|
+
this gem's; the app's requests keep failing fast. It applies with
|
|
23
|
+
Railwatch disabled, which is how an entrypoint migrates.
|
|
24
|
+
`RAILWATCH_MIGRATION_BUSY_TIMEOUT` (`c.migration_busy_timeout`, seconds)
|
|
25
|
+
sets it; keep it inside the deploy's health-check window.
|
|
26
|
+
|
|
27
|
+
## 0.8.6 (2026-10-06)
|
|
28
|
+
|
|
29
|
+
- An install upgrading from 0.5.0 or older can migrate again. 0.5.1
|
|
30
|
+
renumbered the export queue migration (20260919000000 to
|
|
31
|
+
20260919000100), so a telemetry database that had already run it under
|
|
32
|
+
the old number saw it as pending, and its plain `create_table` raised
|
|
33
|
+
"table export_destinations already exists" -- in `db:prepare`, which a
|
|
34
|
+
deploy runs before the app boots. Every statement in it is now
|
|
35
|
+
`if_not_exists`, so it builds the queue on a new database, completes it
|
|
36
|
+
on one that ran the old number (keeping anything already queued), and
|
|
37
|
+
stays a no-op where the new number has run. Rolling it back on a
|
|
38
|
+
database that came through the old number leaves the queue in place,
|
|
39
|
+
since the old version still owns it; anywhere else it is reversed as
|
|
40
|
+
before.
|
|
41
|
+
- The 0.8.0, 0.8.1 and 0.8.5 index migrations accept an index that is
|
|
42
|
+
already there. Each one reads a whole table, and on a telemetry file
|
|
43
|
+
much larger than memory that is not seconds: about 40 s per table on
|
|
44
|
+
rebulk-system's 14.8 GB file, five builds in all, against a deploy
|
|
45
|
+
that health-checks within 90 s of the container starting -- and runs
|
|
46
|
+
`db:prepare` inside that window. An operator can now build them ahead
|
|
47
|
+
of the deploy, while the old release still serves, with the
|
|
48
|
+
migrations' own `CREATE INDEX` statements; `db:prepare` then records
|
|
49
|
+
them and moves on.
|
|
50
|
+
|
|
9
51
|
## 0.8.5 (2026-09-25)
|
|
10
52
|
|
|
11
53
|
- A new migration adds a partial covering index for the per-tenant sums
|
|
@@ -13,96 +13,134 @@
|
|
|
13
13
|
# is stored.
|
|
14
14
|
#
|
|
15
15
|
# Nothing here is written unless export is explicitly enabled.
|
|
16
|
+
#
|
|
17
|
+
# Every statement is if_not_exists, because this migration has run before
|
|
18
|
+
# under another number. Through 0.5.0 it was 20260919000000; 0.5.1 moved it
|
|
19
|
+
# here so it could not collide with a host's own telemetry migration at that
|
|
20
|
+
# number (Railwatch Cloud has one). An install upgrading from 0.5.0 or older
|
|
21
|
+
# therefore already holds every table, index and column below, recorded
|
|
22
|
+
# under the old version, and sees this one as pending: a plain create_table
|
|
23
|
+
# raised "table export_destinations already exists" in db:prepare, which a
|
|
24
|
+
# deploy runs before the app boots. The old run is detected by what it
|
|
25
|
+
# built, not by its version, because on a host like Railwatch Cloud the old
|
|
26
|
+
# number belongs to a different migration.
|
|
27
|
+
#
|
|
28
|
+
# Rolling back has the mirror problem: on a database that came through the
|
|
29
|
+
# old number, these tables and columns -- and anything queued in them -- are
|
|
30
|
+
# the old version's, which stays recorded as applied. So down leaves them
|
|
31
|
+
# alone there, and reverses the migration everywhere else.
|
|
16
32
|
class CreateExportQueue < ActiveRecord::Migration[8.1]
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
#
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
t.string :state, limit: 16, null: false, default: "ready"
|
|
30
|
-
t.datetime :retry_at, precision: 6
|
|
31
|
-
t.string :reason, limit: 64
|
|
32
|
-
|
|
33
|
-
t.string :lease_owner, limit: 36
|
|
34
|
-
t.bigint :lease_generation, null: false, default: 0
|
|
35
|
-
t.datetime :lease_expires_at, precision: 6
|
|
36
|
-
|
|
37
|
-
# Live totals, maintained in the same transaction as the rows they
|
|
38
|
-
# describe, so admission can be decided without counting the table.
|
|
39
|
-
t.bigint :queued_bytes, null: false, default: 0
|
|
40
|
-
t.bigint :queued_deliveries, null: false, default: 0
|
|
41
|
-
# Lifetime accounting: acked, rejected, expired, discarded, shed.
|
|
42
|
-
t.json :counters, null: false, default: {}
|
|
43
|
-
|
|
44
|
-
t.timestamps
|
|
33
|
+
OLD_VERSION = 20260919000000
|
|
34
|
+
|
|
35
|
+
def up
|
|
36
|
+
build_queue
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def down
|
|
40
|
+
if built_under_old_number?
|
|
41
|
+
say("left in place: #{OLD_VERSION} built this queue under its pre-0.5.1 number and is still recorded as applied")
|
|
42
|
+
else
|
|
43
|
+
revert { build_queue }
|
|
45
44
|
end
|
|
45
|
+
end
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
# delivery cannot be made young again by relabelling it.
|
|
54
|
-
t.string :delivery_id, limit: 36, null: false
|
|
55
|
-
# What this delivery is a delivery OF. One per source batch today; a
|
|
56
|
-
# future policy that selects across batches supplies its own key.
|
|
57
|
-
t.string :selection_key, limit: 160, null: false
|
|
58
|
-
|
|
59
|
-
t.binary :body
|
|
60
|
-
t.string :body_sha256, limit: 64, null: false
|
|
61
|
-
t.string :metadata_sha256, limit: 64, null: false
|
|
62
|
-
t.bigint :body_bytes, null: false
|
|
63
|
-
t.bigint :ndjson_bytes, null: false
|
|
64
|
-
t.integer :record_count, null: false
|
|
65
|
-
# Everything about the delivery that is not its body: version, drop
|
|
66
|
-
# counts, backpressure. Digested into metadata_sha256 so the same id
|
|
67
|
-
# arriving with different counts is a conflict, not an update.
|
|
68
|
-
t.json :wire_metadata, null: false, default: {}
|
|
69
|
-
|
|
70
|
-
t.string :state, limit: 8, null: false, default: "pending"
|
|
71
|
-
# Set only when done: acked, rejected, expired, discarded.
|
|
72
|
-
t.string :disposition, limit: 16
|
|
73
|
-
t.datetime :enqueued_at, null: false, precision: 6
|
|
74
|
-
t.datetime :expires_at, null: false, precision: 6
|
|
75
|
-
t.datetime :next_attempt_at, null: false, precision: 6
|
|
76
|
-
t.bigint :attempts, null: false, default: 0
|
|
77
|
-
|
|
78
|
-
t.string :claim_token, limit: 36
|
|
79
|
-
t.bigint :claim_generation
|
|
80
|
-
t.datetime :claim_expires_at, precision: 6
|
|
81
|
-
|
|
82
|
-
t.integer :last_status
|
|
83
|
-
t.string :last_reason, limit: 64
|
|
84
|
-
t.json :ack
|
|
85
|
-
t.datetime :finished_at, precision: 6
|
|
86
|
-
|
|
87
|
-
t.timestamps
|
|
47
|
+
private
|
|
48
|
+
# The old version is recorded, and no migration file this database knows
|
|
49
|
+
# of claims it: only the gem's own pre-0.5.1 CreateExportQueue did.
|
|
50
|
+
def built_under_old_number?
|
|
51
|
+
context = connection.pool.migration_context
|
|
52
|
+
context.get_all_versions.include?(OLD_VERSION) && context.migrations.none? { |m| m.version == OLD_VERSION }
|
|
88
53
|
end
|
|
89
54
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
55
|
+
def build_queue
|
|
56
|
+
# One row per destination this database has ever been pointed at.
|
|
57
|
+
create_table :export_destinations, if_not_exists: true do |t|
|
|
58
|
+
t.string :url, null: false
|
|
59
|
+
t.string :url_sha256, limit: 64, null: false
|
|
60
|
+
# Permanent for this database's lineage: it is how the receiver tells
|
|
61
|
+
# our deliveries from another installation's.
|
|
62
|
+
t.string :producer_id, limit: 36, null: false
|
|
63
|
+
# A fingerprint, never the token. If the token changes, queued bytes
|
|
64
|
+
# must not follow it to whatever tenant the new one belongs to.
|
|
65
|
+
t.string :credential_sha256, limit: 64, null: false
|
|
66
|
+
|
|
67
|
+
t.string :state, limit: 16, null: false, default: "ready"
|
|
68
|
+
t.datetime :retry_at, precision: 6
|
|
69
|
+
t.string :reason, limit: 64
|
|
70
|
+
|
|
71
|
+
t.string :lease_owner, limit: 36
|
|
72
|
+
t.bigint :lease_generation, null: false, default: 0
|
|
73
|
+
t.datetime :lease_expires_at, precision: 6
|
|
74
|
+
|
|
75
|
+
# Live totals, maintained in the same transaction as the rows they
|
|
76
|
+
# describe, so admission can be decided without counting the table.
|
|
77
|
+
t.bigint :queued_bytes, null: false, default: 0
|
|
78
|
+
t.bigint :queued_deliveries, null: false, default: 0
|
|
79
|
+
# Lifetime accounting: acked, rejected, expired, discarded, shed.
|
|
80
|
+
t.json :counters, null: false, default: {}
|
|
81
|
+
|
|
82
|
+
t.timestamps
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
add_index :export_destinations, :url_sha256, unique: true, if_not_exists: true
|
|
86
|
+
add_index :export_destinations, :producer_id, unique: true, if_not_exists: true
|
|
87
|
+
|
|
88
|
+
create_table :export_deliveries, if_not_exists: true do |t|
|
|
89
|
+
t.references :export_destination, null: false, foreign_key: true
|
|
90
|
+
# A UUIDv7: its embedded time is how the receiver ages it out, so a
|
|
91
|
+
# delivery cannot be made young again by relabelling it.
|
|
92
|
+
t.string :delivery_id, limit: 36, null: false
|
|
93
|
+
# What this delivery is a delivery OF. One per source batch today; a
|
|
94
|
+
# future policy that selects across batches supplies its own key.
|
|
95
|
+
t.string :selection_key, limit: 160, null: false
|
|
96
|
+
|
|
97
|
+
t.binary :body
|
|
98
|
+
t.string :body_sha256, limit: 64, null: false
|
|
99
|
+
t.string :metadata_sha256, limit: 64, null: false
|
|
100
|
+
t.bigint :body_bytes, null: false
|
|
101
|
+
t.bigint :ndjson_bytes, null: false
|
|
102
|
+
t.integer :record_count, null: false
|
|
103
|
+
# Everything about the delivery that is not its body: version, drop
|
|
104
|
+
# counts, backpressure. Digested into metadata_sha256 so the same id
|
|
105
|
+
# arriving with different counts is a conflict, not an update.
|
|
106
|
+
t.json :wire_metadata, null: false, default: {}
|
|
107
|
+
|
|
108
|
+
t.string :state, limit: 8, null: false, default: "pending"
|
|
109
|
+
# Set only when done: acked, rejected, expired, discarded.
|
|
110
|
+
t.string :disposition, limit: 16
|
|
111
|
+
t.datetime :enqueued_at, null: false, precision: 6
|
|
112
|
+
t.datetime :expires_at, null: false, precision: 6
|
|
113
|
+
t.datetime :next_attempt_at, null: false, precision: 6
|
|
114
|
+
t.bigint :attempts, null: false, default: 0
|
|
115
|
+
|
|
116
|
+
t.string :claim_token, limit: 36
|
|
117
|
+
t.bigint :claim_generation
|
|
118
|
+
t.datetime :claim_expires_at, precision: 6
|
|
119
|
+
|
|
120
|
+
t.integer :last_status
|
|
121
|
+
t.string :last_reason, limit: 64
|
|
122
|
+
t.json :ack
|
|
123
|
+
t.datetime :finished_at, precision: 6
|
|
124
|
+
|
|
125
|
+
t.timestamps
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
add_index :export_deliveries, %i[export_destination_id delivery_id], unique: true,
|
|
129
|
+
name: "index_export_deliveries_on_destination_and_delivery", if_not_exists: true
|
|
130
|
+
# One delivery per selection: a batch replayed into the same transaction
|
|
131
|
+
# cannot enqueue itself twice.
|
|
132
|
+
add_index :export_deliveries, %i[export_destination_id selection_key], unique: true,
|
|
133
|
+
name: "index_export_deliveries_on_destination_and_selection", if_not_exists: true
|
|
134
|
+
add_index :export_deliveries, %i[export_destination_id id], where: "state <> 'done'",
|
|
135
|
+
name: "index_export_deliveries_live", if_not_exists: true
|
|
136
|
+
add_index :export_deliveries, :expires_at, where: "body IS NOT NULL",
|
|
137
|
+
name: "index_export_deliveries_expiring", if_not_exists: true
|
|
138
|
+
add_index :export_deliveries, :finished_at, where: "state = 'done'",
|
|
139
|
+
name: "index_export_deliveries_finished", if_not_exists: true
|
|
140
|
+
|
|
141
|
+
# Why a batch did or did not enqueue anything. Null on every row an
|
|
142
|
+
# install without export ever writes.
|
|
143
|
+
add_column :ingest_batches, :export_disposition, :string, limit: 24, if_not_exists: true
|
|
144
|
+
add_column :ingest_batches, :export_record_count, :bigint, if_not_exists: true
|
|
145
|
+
end
|
|
108
146
|
end
|
data/db/railwatch_telemetry_migrate/20260922000000_add_covering_indexes_for_dashboard_aggregates.rb
CHANGED
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
# Execution.named_like seek them instead of reading the window.
|
|
26
26
|
class AddCoveringIndexesForDashboardAggregates < ActiveRecord::Migration[8.1]
|
|
27
27
|
def change
|
|
28
|
-
add_index :executions, [ :kind, :occurred_at, :queue, :outcome, :queue_latency ], name: "idx_executions_queue_stats"
|
|
28
|
+
add_index :executions, [ :kind, :occurred_at, :queue, :outcome, :queue_latency ], name: "idx_executions_queue_stats", if_not_exists: true
|
|
29
29
|
add_index :health_samples, [ :sampled_at, :threads_max, :threads_busy, :backlog, :queue_depth, :queue_latency ],
|
|
30
|
-
name: "idx_health_samples_series"
|
|
31
|
-
add_index :broadcasts, :occurred_at
|
|
32
|
-
add_index :executions, [ :kind, :occurred_at ], name: "idx_executions_with_preview", where: "exception_preview IS NOT NULL"
|
|
30
|
+
name: "idx_health_samples_series", if_not_exists: true
|
|
31
|
+
add_index :broadcasts, :occurred_at, if_not_exists: true
|
|
32
|
+
add_index :executions, [ :kind, :occurred_at ], name: "idx_executions_with_preview", where: "exception_preview IS NOT NULL", if_not_exists: true
|
|
33
33
|
end
|
|
34
34
|
end
|
|
@@ -10,6 +10,6 @@
|
|
|
10
10
|
class AddPeopleIndex < ActiveRecord::Migration[8.1]
|
|
11
11
|
def change
|
|
12
12
|
add_index :executions, [ :user_ref, :kind, :occurred_at, :status ], name: "idx_executions_people",
|
|
13
|
-
where: "user_ref IS NOT NULL"
|
|
13
|
+
where: "user_ref IS NOT NULL", if_not_exists: true
|
|
14
14
|
end
|
|
15
15
|
end
|
|
@@ -12,6 +12,6 @@
|
|
|
12
12
|
class AddTenantSummaryIndex < ActiveRecord::Migration[8.1]
|
|
13
13
|
def change
|
|
14
14
|
add_index :executions, [ :kind, :app_tenant, :occurred_at, :status, :outcome, :duration, :user_ref ],
|
|
15
|
-
name: "idx_executions_tenant_summary", where: "app_tenant IS NOT NULL"
|
|
15
|
+
name: "idx_executions_tenant_summary", where: "app_tenant IS NOT NULL", if_not_exists: true
|
|
16
16
|
end
|
|
17
17
|
end
|
|
@@ -76,7 +76,7 @@ module Railwatch
|
|
|
76
76
|
:buffer_size, :buffer_bytes, :execution_buffer_bytes, :batch_bytes,
|
|
77
77
|
:backpressure,
|
|
78
78
|
:flush_interval, :flush_threshold,
|
|
79
|
-
:connect_timeout, :timeout, :shutdown_timeout,
|
|
79
|
+
:connect_timeout, :timeout, :shutdown_timeout, :migration_busy_timeout,
|
|
80
80
|
:slow_query_threshold_ms, :n_plus_one_threshold,
|
|
81
81
|
:max_view_renders_per_execution, :ignored_cache_key_prefixes,
|
|
82
82
|
:beacon_enabled, :beacon_rate_limit, :beacon_global_rate_limit, :beacon_allowed_origins,
|
|
@@ -187,6 +187,13 @@ module Railwatch
|
|
|
187
187
|
@connect_timeout = env_float("RAILWATCH_CONNECT_TIMEOUT", 1.0)
|
|
188
188
|
@timeout = env_float("RAILWATCH_TIMEOUT", 3.0)
|
|
189
189
|
@shutdown_timeout = env_float("RAILWATCH_SHUTDOWN_TIMEOUT", 2.0)
|
|
190
|
+
# Seconds a migration of the railwatch databases waits for SQLite's
|
|
191
|
+
# write lock (Patches::MigrationBusyTimeout). A deploy migrates while
|
|
192
|
+
# the old release's writer is still committing to the same file; the
|
|
193
|
+
# database's own `timeout` (5 s) is too short to get between its
|
|
194
|
+
# transactions when the disk is busy. Kept under a typical health-check
|
|
195
|
+
# window (Kamal's deploy_timeout defaults to 30 s and is often 90 s).
|
|
196
|
+
@migration_busy_timeout = env_float("RAILWATCH_MIGRATION_BUSY_TIMEOUT", 60.0)
|
|
190
197
|
@slow_query_threshold_ms = env_float("RAILWATCH_SLOW_QUERY_MS", 5.0)
|
|
191
198
|
@n_plus_one_threshold = env_int("RAILWATCH_N_PLUS_ONE_THRESHOLD", 5)
|
|
192
199
|
@max_view_renders_per_execution = 20
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Railwatch
|
|
4
|
+
module Patches
|
|
5
|
+
# Gives the migration connection to a Railwatch database a long SQLite
|
|
6
|
+
# busy timeout, for the migration only.
|
|
7
|
+
#
|
|
8
|
+
# A deploy migrates while the previous release is still serving, and on
|
|
9
|
+
# an embedded install that release's writer process is committing
|
|
10
|
+
# telemetry to the same file the whole time. Each of its transactions
|
|
11
|
+
# takes SQLite's single write lock: about a second on a warm 15 GB file
|
|
12
|
+
# (the export sender's claim scans the destination's whole delivery
|
|
13
|
+
# history), several seconds while a deploy's image build has the disk.
|
|
14
|
+
# The migration connection waited only the database's configured
|
|
15
|
+
# `timeout` -- 5 s in the generated database.yml -- and then raised
|
|
16
|
+
# SQLite3::BusyException, which db:prepare reports as a failed migration
|
|
17
|
+
# and the container entrypoint as a failed boot. That is how a deploy of
|
|
18
|
+
# rebulk-system crash-looped eight times without one migration running.
|
|
19
|
+
#
|
|
20
|
+
# The configured timeout is the right one for the app's own requests,
|
|
21
|
+
# which should fail fast rather than queue behind ingest. A migration is
|
|
22
|
+
# the opposite: it runs once, before the server binds, and waiting is the
|
|
23
|
+
# only way through. So only the connection Active Record migrates with is
|
|
24
|
+
# changed, only while it migrates, and only for a database whose
|
|
25
|
+
# migrations_paths include this gem's. The host's own databases keep
|
|
26
|
+
# their timeouts.
|
|
27
|
+
module MigrationBusyTimeout
|
|
28
|
+
def migrate(*, **)
|
|
29
|
+
pool = migration_connection_pool
|
|
30
|
+
raw = Railwatch::Patches::MigrationBusyTimeout.lengthen(pool)
|
|
31
|
+
super
|
|
32
|
+
ensure
|
|
33
|
+
Railwatch::Patches::MigrationBusyTimeout.restore(pool, raw) if raw
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
class << self
|
|
37
|
+
# The raw SQLite connection whose timeout was lengthened, or nil when
|
|
38
|
+
# this is not a Railwatch database (or not SQLite).
|
|
39
|
+
def lengthen(pool)
|
|
40
|
+
return unless railwatch_database?(pool.db_config)
|
|
41
|
+
|
|
42
|
+
raw = pool.lease_connection.raw_connection
|
|
43
|
+
return unless raw.respond_to?(:busy_handler_timeout=)
|
|
44
|
+
|
|
45
|
+
raw.busy_handler_timeout = (Railwatch.config.migration_busy_timeout.to_f * 1000).to_i
|
|
46
|
+
raw
|
|
47
|
+
rescue StandardError => e
|
|
48
|
+
Railwatch.debug { "migration busy timeout not applied: #{e.class}: #{e.message}" }
|
|
49
|
+
nil
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Back to what database.yml says, so a connection that outlives the
|
|
53
|
+
# migration (db:migrate in a long-lived process, a spec) behaves as
|
|
54
|
+
# configured afterwards.
|
|
55
|
+
def restore(pool, raw)
|
|
56
|
+
timeout = pool.db_config.configuration_hash[:timeout]
|
|
57
|
+
if timeout
|
|
58
|
+
raw.busy_handler_timeout = Integer(timeout)
|
|
59
|
+
else
|
|
60
|
+
raw.busy_handler(nil)
|
|
61
|
+
end
|
|
62
|
+
rescue StandardError => e
|
|
63
|
+
Railwatch.debug { "migration busy timeout not restored: #{e.class}: #{e.message}" }
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def railwatch_database?(db_config)
|
|
67
|
+
ours = %i[railwatch railwatch_telemetry].map { |name| File.expand_path(Railwatch.migrations_path(name)) }
|
|
68
|
+
Array(db_config.migrations_paths).any? { |path| ours.include?(File.expand_path(path.to_s, Rails.root.to_s)) }
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
data/lib/railwatch/patches.rb
CHANGED
|
@@ -4,6 +4,7 @@ require "railwatch/patches/net_http"
|
|
|
4
4
|
require "railwatch/patches/rake_task"
|
|
5
5
|
require "railwatch/patches/runner_command"
|
|
6
6
|
require "railwatch/patches/inertia"
|
|
7
|
+
require "railwatch/patches/migration_busy_timeout"
|
|
7
8
|
|
|
8
9
|
module Railwatch
|
|
9
10
|
module Patches
|
|
@@ -22,6 +23,16 @@ module Railwatch
|
|
|
22
23
|
# From Rails::Engine#load_tasks, which has already required rake.
|
|
23
24
|
def install_rake_task!
|
|
24
25
|
::Rake::Task.prepend(RakeTask) unless ::Rake::Task.ancestors.include?(RakeTask)
|
|
26
|
+
install_migration_busy_timeout!
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# db:prepare and db:migrate run as rake tasks, so this goes in with the
|
|
30
|
+
# rake patch. Unlike it, this one is not gated on Railwatch.enabled?: a
|
|
31
|
+
# container entrypoint migrates with Railwatch switched off, and that is
|
|
32
|
+
# exactly the migration that has to wait out the old release's writer.
|
|
33
|
+
def install_migration_busy_timeout!
|
|
34
|
+
tasks = ::ActiveRecord::Tasks::DatabaseTasks.singleton_class
|
|
35
|
+
tasks.prepend(MigrationBusyTimeout) unless tasks.ancestors.include?(MigrationBusyTimeout)
|
|
25
36
|
end
|
|
26
37
|
|
|
27
38
|
# From Rails::Application#load_runner, which RunnerCommand#perform calls
|
data/lib/railwatch/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: railwatch
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.8.
|
|
4
|
+
version: 0.8.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Cole Robertson
|
|
@@ -453,6 +453,7 @@ files:
|
|
|
453
453
|
- lib/railwatch/minitest.rb
|
|
454
454
|
- lib/railwatch/patches.rb
|
|
455
455
|
- lib/railwatch/patches/inertia.rb
|
|
456
|
+
- lib/railwatch/patches/migration_busy_timeout.rb
|
|
456
457
|
- lib/railwatch/patches/net_http.rb
|
|
457
458
|
- lib/railwatch/patches/rake_task.rb
|
|
458
459
|
- lib/railwatch/patches/runner_command.rb
|