From 2b3e829fc81da2453007d2fb57bbaf4341d5758e Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Sat, 3 Feb 2024 11:47:19 -0500 Subject: [PATCH] Ensure table is created before shutting down --- auto/restore/downloader.go | 52 +++++++++++++++++------------------ system_test/e2e/auto_state.py | 2 ++ 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/auto/restore/downloader.go b/auto/restore/downloader.go index 31fb9088..65e34c37 100644 --- a/auto/restore/downloader.go +++ b/auto/restore/downloader.go @@ -14,6 +14,32 @@ import ( "github.com/rqlite/rqlite/v8/aws" ) +// stats captures stats for the Uploader service. +var stats *expvar.Map + +var ( + gzipMagic = []byte{0x1f, 0x8b, 0x08} +) + +const ( + numDownloadsOK = "num_downloads_ok" + numDownloadsFail = "num_downloads_fail" + numDownloadBytes = "download_bytes" +) + +func init() { + stats = expvar.NewMap("downloader") + ResetStats() +} + +// ResetStats resets the expvar stats for this module. Mostly for test purposes. +func ResetStats() { + stats.Init() + stats.Add(numDownloadsOK, 0) + stats.Add(numDownloadsFail, 0) + stats.Add(numDownloadBytes, 0) +} + // DownloadFile downloads the auto-restore file from the given URL, and returns the path to // the downloaded file. If the download fails, and the config is marked as continue-on-failure, then // the error is returned, but errOK is set to true. If the download fails, and the file is not @@ -64,32 +90,6 @@ type StorageClient interface { fmt.Stringer } -// stats captures stats for the Uploader service. -var stats *expvar.Map - -var ( - gzipMagic = []byte{0x1f, 0x8b, 0x08} -) - -const ( - numDownloadsOK = "num_downloads_ok" - numDownloadsFail = "num_downloads_fail" - numDownloadBytes = "download_bytes" -) - -func init() { - stats = expvar.NewMap("downloader") - ResetStats() -} - -// ResetStats resets the expvar stats for this module. Mostly for test purposes. -func ResetStats() { - stats.Init() - stats.Add(numDownloadsOK, 0) - stats.Add(numDownloadsFail, 0) - stats.Add(numDownloadBytes, 0) -} - type Downloader struct { storageClient StorageClient logger *log.Logger diff --git a/system_test/e2e/auto_state.py b/system_test/e2e/auto_state.py index 7b61542a..2d16a07e 100644 --- a/system_test/e2e/auto_state.py +++ b/system_test/e2e/auto_state.py @@ -150,6 +150,8 @@ class TestAutoRestoreS3(unittest.TestCase): n0.start() n0.wait_for_ready() n0.execute('CREATE TABLE bar (id INTEGER NOT NULL PRIMARY KEY, name TEXT)') + j = n1.query('SELECT * FROM bar', level='strong') + self.assertEqual(j, d_("{'results': [{'types': ['integer', 'text'], 'columns': ['id', 'name']}]}")) n0.stop() # Create a new node, using the directory from the previous node, but check