20
20
#include " cluster/config_frontend.h"
21
21
#include " cluster/controller_snapshot.h"
22
22
#include " cluster/types.h"
23
+ #include " config/configuration.h"
23
24
#include " model/fundamental.h"
24
25
#include " redpanda/application.h"
25
26
#include " redpanda/tests/fixture.h"
26
27
#include " storage/snapshot.h"
27
28
#include " test_utils/async.h"
29
+ #include " test_utils/scoped_config.h"
28
30
29
31
#include < seastar/core/io_priority_class.hh>
30
32
#include < seastar/core/lowres_clock.hh>
@@ -50,9 +52,9 @@ class cluster_metadata_uploader_fixture
50
52
, bucket(cloud_storage_clients::bucket_name(" test-bucket" )) {
51
53
set_expectations_and_listen ({});
52
54
wait_for_controller_leadership ().get ();
53
- tests::cooperative_spin_wait_with_timeout (5s, [this ] {
55
+ RPTEST_REQUIRE_EVENTUALLY (5s, [this ] {
54
56
return app.storage .local ().get_cluster_uuid ().has_value ();
55
- }). get () ;
57
+ });
56
58
cluster_uuid = app.storage .local ().get_cluster_uuid ().value ();
57
59
}
58
60
@@ -66,9 +68,23 @@ class cluster_metadata_uploader_fixture
66
68
auto m_res = co_await download_highest_manifest_for_cluster (
67
69
remote, cluster_uuid, bucket, retry_node);
68
70
if (!m_res.has_value ()) {
71
+ vlog (
72
+ logger.debug ,
73
+ " Current manifest has id {}, waiting for > {}" ,
74
+ -1 ,
75
+ initial_meta_id);
69
76
co_return false ;
70
77
}
71
78
if (m_res.value ().metadata_id <= initial_meta_id) {
79
+ vlog (
80
+ logger.debug ,
81
+ " Current manifest has id {}, waiting for > {}" ,
82
+ m_res.value (),
83
+ initial_meta_id);
84
+ co_return false ;
85
+ }
86
+ if (m_res.value ().controller_snapshot_path .empty ()) {
87
+ vlog (logger.debug , " Missing controller snapshot" );
72
88
co_return false ;
73
89
}
74
90
*downloaded_manifest = std::move (m_res.value ());
@@ -106,6 +122,7 @@ class cluster_metadata_uploader_fixture
106
122
}
107
123
108
124
protected:
125
+ scoped_config test_local_cfg;
109
126
cluster::consensus_ptr raft0;
110
127
cluster::controller_stm& controller_stm;
111
128
cloud_storage::remote& remote;
@@ -115,8 +132,7 @@ class cluster_metadata_uploader_fixture
115
132
116
133
FIXTURE_TEST (
117
134
test_download_highest_manifest, cluster_metadata_uploader_fixture) {
118
- cluster::cloud_metadata::uploader uploader (
119
- cluster_uuid, bucket, remote, raft0);
135
+ auto & uploader = app.controller ->metadata_uploader ();
120
136
retry_chain_node retry_node (
121
137
never_abort, ss::lowres_clock::time_point::max (), 10ms);
122
138
@@ -155,8 +171,7 @@ FIXTURE_TEST(
155
171
156
172
FIXTURE_TEST (
157
173
test_download_highest_manifest_errors, cluster_metadata_uploader_fixture) {
158
- cluster::cloud_metadata::uploader uploader (
159
- cluster_uuid, bucket, remote, raft0);
174
+ auto & uploader = app.controller ->metadata_uploader ();
160
175
retry_chain_node retry_node (
161
176
never_abort, ss::lowres_clock::time_point::min (), 10ms);
162
177
auto down_res
@@ -166,8 +181,7 @@ FIXTURE_TEST(
166
181
}
167
182
168
183
FIXTURE_TEST (test_upload_next_metadata, cluster_metadata_uploader_fixture) {
169
- cluster::cloud_metadata::uploader uploader (
170
- cluster_uuid, bucket, remote, raft0);
184
+ auto & uploader = app.controller ->metadata_uploader ();
171
185
retry_chain_node retry_node (
172
186
never_abort, ss::lowres_clock::time_point::max (), 10ms);
173
187
RPTEST_REQUIRE_EVENTUALLY (5s, [this ] { return raft0->is_leader (); });
@@ -264,10 +278,9 @@ FIXTURE_TEST(test_upload_in_term, cluster_metadata_uploader_fixture) {
264
278
};
265
279
const auto snap_offset = get_local_snap_offset ();
266
280
267
- config::shard_local_cfg ()
268
- .cloud_storage_cluster_metadata_upload_interval_ms .set_value (1000ms);
269
- cluster::cloud_metadata::uploader uploader (
270
- cluster_uuid, bucket, remote, raft0);
281
+ test_local_cfg.get (" cloud_storage_cluster_metadata_upload_interval_ms" )
282
+ .set_value (1000ms);
283
+ auto & uploader = app.controller ->metadata_uploader ();
271
284
cluster::cloud_metadata::cluster_metadata_id highest_meta_id{0 };
272
285
273
286
// Checks that metadata is uploaded a new term, stepping down in between
@@ -280,13 +293,6 @@ FIXTURE_TEST(test_upload_in_term, cluster_metadata_uploader_fixture) {
280
293
281
294
// Start uploading in this term.
282
295
auto upload_in_term = uploader.upload_until_term_change ();
283
- auto defer = ss::defer ([&] {
284
- uploader.stop_and_wait ().get ();
285
- try {
286
- upload_in_term.get ();
287
- } catch (...) {
288
- }
289
- });
290
296
291
297
// Keep checking the latest manifest for whether the metadata ID is
292
298
// some non-zero value (indicating we've uploaded multiple manifests);
@@ -305,7 +311,6 @@ FIXTURE_TEST(test_upload_in_term, cluster_metadata_uploader_fixture) {
305
311
// Stop the upload loop and continue in a new term.
306
312
raft0->step_down (" forced stepdown" ).get ();
307
313
upload_in_term.get ();
308
- defer.cancel ();
309
314
};
310
315
for (int i = 0 ; i < 3 ; ++i) {
311
316
check_uploads_in_term_and_stepdown (snap_offset);
@@ -333,20 +338,12 @@ FIXTURE_TEST(
333
338
// Write a snapshot and begin the upload loop.
334
339
RPTEST_REQUIRE_EVENTUALLY (
335
340
5s, [this ] { return controller_stm.maybe_write_snapshot (); });
336
- config::shard_local_cfg ()
337
- .cloud_storage_cluster_metadata_upload_interval_ms .set_value (1000ms);
338
- cluster::cloud_metadata::uploader uploader (
339
- cluster_uuid, bucket, remote, raft0);
341
+ test_local_cfg.get (" cloud_storage_cluster_metadata_upload_interval_ms" )
342
+ .set_value (1000ms);
343
+ auto & uploader = app.controller ->metadata_uploader ();
340
344
RPTEST_REQUIRE_EVENTUALLY (5s, [this ] { return raft0->is_leader (); });
341
345
342
346
auto upload_in_term = uploader.upload_until_term_change ();
343
- auto defer = ss::defer ([&] {
344
- uploader.stop_and_wait ().get ();
345
- try {
346
- upload_in_term.get ();
347
- } catch (...) {
348
- }
349
- });
350
347
// Wait for some valid metadata to show up.
351
348
cluster::cloud_metadata::cluster_metadata_manifest manifest;
352
349
RPTEST_REQUIRE_EVENTUALLY (5s, [this , &manifest] {
@@ -380,3 +377,27 @@ FIXTURE_TEST(
380
377
return num_deletes >= 2 ;
381
378
});
382
379
}
380
+
381
+ FIXTURE_TEST (test_run_loop, cluster_metadata_uploader_fixture) {
382
+ RPTEST_REQUIRE_EVENTUALLY (
383
+ 5s, [this ] { return controller_stm.maybe_write_snapshot (); });
384
+ test_local_cfg.get (" cloud_storage_cluster_metadata_upload_interval_ms" )
385
+ .set_value (1000ms);
386
+ auto & uploader = app.controller ->metadata_uploader ();
387
+ // Run the upload loop and make sure that new leaders continue to upload.
388
+ uploader.start ();
389
+ cluster::cloud_metadata::cluster_metadata_id highest_meta_id{-1 };
390
+ for (int i = 0 ; i < 3 ; i++) {
391
+ auto initial_meta_id = highest_meta_id;
392
+ cluster::cloud_metadata::cluster_metadata_manifest manifest;
393
+ RPTEST_REQUIRE_EVENTUALLY (10s, [&]() -> ss::future<bool > {
394
+ return downloaded_manifest_has_higher_id (
395
+ initial_meta_id, &manifest);
396
+ });
397
+ BOOST_REQUIRE_GT (manifest.metadata_id , highest_meta_id);
398
+ highest_meta_id = manifest.metadata_id ;
399
+
400
+ // Stop the upload loop and continue in a new term.
401
+ raft0->step_down (" forced stepdown" ).get ();
402
+ }
403
+ }
0 commit comments