Repository navigation
Add SQLite copy and Elasticsearch reindex tasks for the move - #1617
Draft
benrfairless wants to merge 5 commits into
Draft
benrfairless wants to merge 5 commits into
benrfairless wants to merge 5 commits into
Conversation
Copies db/scrapers from the old server to the new one with rsync: a resumable bulk copy days ahead and a final delta pass inside the cutover window. Records elapsed time and transfer speed, takes source and destination from the environment, and refuses a location with a password in it. The delta deletes only with an explicit limit. Adds a file listing (path and size) that the old server can also make with find, and a comparison that prints a report for the dry run record. Part of #1589. Assisted-by: Claude Code:claude-sonnet-5-5 Signed-off-by: Ben Fairless <ben@oaf.org.au>
Rebuilds the Scraper and Owner indexes from the database with Searchkick's reindex, prints progress and the server version, and compares document counts with the database and, optionally, with counts taken from the old server. Nothing from the old index is carried over. Part of #1589. Assisted-by: Claude Code:claude-sonnet-5-5 Signed-off-by: Ben Fairless <ben@oaf.org.au>
Runbook for the new tasks, including the shell commands the old server uses for its file listing, the note that Redis is not carried over, and the manual checks for the rehearsal server in TESTING.md. Part of #1589. Assisted-by: Claude Code:claude-sonnet-5-5 Signed-off-by: Ben Fairless <ben@oaf.org.au>
Comment on lines
+151
to
+161
| total_file_bytes: stat(text, /Total file size: ([\d,.]+)/), | ||
| sent: stat(text, /Total bytes sent: ([\d,.]+)/), | ||
| received: stat(text, /Total bytes received: ([\d,.]+)/) | ||
| }.compact | ||
| end | ||
|
|
||
| sig { params(text: String, pattern: Regexp).returns(T.nilable(Integer)) } | ||
| def self.stat(text, pattern) | ||
| match = text.match(pattern) | ||
| match && match[1]&.delete(",.")&.to_i | ||
| end |
There was a problem hiding this comment.
Bug: Rsync output with invalid UTF-8 byte sequences can raise an ArgumentError during regex parsing in parse_stats.
Severity: LOW
Suggested Fix
Call .scrub on the concatenated output string before performing regex matching, or configure process stream encodings to handle non-UTF-8 bytes cleanly.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: app/lib/morph/sqlite_migration/sync.rb#L146-L161
Potential issue: In `Sync#run`, output lines from `Open3.popen2e` are gathered and
passed directly to `parse_stats` via `output.join`. If `rsync` encounters and prints
filenames containing invalid UTF-8 byte sequences (e.g., in warning or vanished-file
messages), matching regexes against the resulting string in `parse_stats` raises an
`ArgumentError: invalid byte sequence in UTF-8`. Because only `Sync::Error` is rescued
in the task, this unhandled exception crashes the task before metrics can be recorded.
Did we get this right? 👍 / 👎 to inform future reviews.
- Follow a symlinked db/scrapers root, which is a Capistrano linked_dir - Skip files that vanish during a scan, and keep tabs in file names - Reject a non-numeric MAX_DELETE or BWLIMIT_KBPS instead of reading it as 0 - Mark dry runs in the log record, explain rsync exit 23 and 25, and report a missing rsync as a tidy error Part of #1589. Assisted-by: Claude Code:claude-sonnet-5-5
The SQLite scraper data lives in a single directory outside both stages (for example /srv/www/data/scrapers), linked into each stage's shared/db/scrapers. The rehearsal stage is retired at cutover but its data is not copied twice. Replaces the stage directory rename from #1595 in the runbook, the manual tests and the spec examples. The code still has no default source or destination. Part of #1589. Assisted-by: Claude Code:claude-sonnet-5-5
Comment on lines
+35
to
+41
| def self.positive_integer(name, value) | ||
| return nil if value.nil? || value.strip.empty? | ||
|
|
||
| number = T.let(Integer(value, exception: false), T.nilable(Integer)) | ||
| raise Error, "#{name} must be a whole number above 0" if number.nil? || number < 1 | ||
|
|
||
| number |
There was a problem hiding this comment.
Bug: positive_integer calls Integer(value, exception: false) without a base, causing inputs with leading zeroes to be parsed as octal or rejected.
Severity: LOW
Suggested Fix
Specify base 10 by calling Integer(value, 10, exception: false) or validate against \A\d+\z before converting to an integer.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: app/lib/morph/sqlite_migration/sync.rb#L35-L41
Potential issue: In `positive_integer`, calling `Integer(value, exception: false)`
without specifying a base defaults to Ruby literal parsing rules. Inputs with a leading
zero (such as `010`) are interpreted as octal numbers instead of decimal, or rejected as
invalid when containing non-octal digits like `08` or `09`. As a result, values passed
into `--max-delete` or `--bwlimit` can misrepresent the operator's intended base-10
configuration.
benrfairless
marked this pull request as draft
November 27, 2026 13:01
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
db/scrapers, a reindex of Elasticsearch from the database, and verification tasks for both. Runbook indocs/sqlite_and_search_migration.md. Part of Spec: move morph.io to a new Ubuntu 26.04 server #1579.app:sqlite_migration:bulkand:deltatake source and destination fromSQLITE_SOURCEandSQLITE_DESTINATION, authenticate through ssh only (a location with a password in it is refused), and print and optionally log (LOG_FILE) elapsed time and transfer speed. The delta deletes only withDELETE=1and aMAX_DELETElimit, and fails on vanished files, because nothing should change after the freeze.app:sqlite_migration:manifestand:verifycompare file counts and sizes, withdata/andrepos/subtotals. The listing is plainpath<TAB>size, so the old server (Ruby 3.0.7, cannot run this branch) can make it withfind db/scrapers -type f -printf '%P\t%s\n' | sort.app:search_migration:reindexrebuilds theScraperandOwnerindexes with Searchkick'sreindex(fresh index, then alias swap, nothing carried over) and prints the Elasticsearch version, progress, time and document counts, exiting 1 if they differ.:verifyis counts only and can takeSOURCE_COUNTS=Scraper=N,Owner=Nfrom the old server for the record. Counts use the count API becauseIndex#total_docsstops at 10,000, and production has about 11,127 scrapers (checked on a scratch index of 10,001 documents).feature/1579-new-server, notmain. Could it go tomaininstead? Possibly, all of it: it avoids Ruby 3.1+ syntax and uses only public Searchkick 5.0.5 calls. I did not run it on Ruby 3.0.7 or Rails 6.1, and it is only used from the new server, so I left it here. That call is Ben's.app:sqlite_migrationandapp:search_migration(separate files, so Migrate MySQL with a filtered dump and S3 archive #1588 does not conflict); sizes compared, not checksums;rsync --inplaceso a 16 GB file can resume and update in place; no default source or destination (in rehearsal the destination is the app's ownshared/db/scrapers); the delta failing on rsync exit 24 while the bulk copy only warns.Content-Typeoverride) andELASTIC_CLIENT_APIVERSIONING=truein the server's environment. Neither is in this branch yet, so this was only run against 7.17.7.TESTING.mdwill probably conflict with the Migrate MySQL with a filtered dump and S3 archive #1588 branch: both append a section at the end of the file.Type of change
How this was checked
In a private
docker-compose.ruby34.ymlstack (Ruby 3.4.12, Elasticsearch 7.17.7, MySQL 5.7.33, rsync added to a local image), not against production or any real server. The quick profile gave 977 examples, 0 failures at 80.16% against 76.67. The CI profile (docker and GitHub specs excluded, slow specs on) gave 989 examples, 0 failures at 82.46% against 80.05, so no threshold changed.rubocopreported no offences andhaml-lint0 lints, andsrb tcreports nothing in the new files. Specs use tmp directories only and never touchdb/scrapers. By hand I ran the bulk and delta copies with real rsync between temporary directories, the manifest and verify tasks, and a real reindex, verify and progress poll on 7.17.7./code-review(or equivalent): fixed any concerns (and rechecked), linked follow-up issues above, or noted why they are not important aboveAcceptance criteria that need the rehearsal server, not proved here:
/srv/www/rehearsal/shared/db/scrapersruns, with elapsed time and transfer speed recordedAssisted-by: Claude Code:claude-sonnet-5-5