Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions qa/suites/rgw/notifications/overrides.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ overrides:
setuser: ceph
setgroup: ceph
debug rgw: 20
debug rgw lifecycle: 20
debug rgw notification: 20
rgw crypt s3 kms backend: testing
rgw crypt s3 kms encryption keys: testkey-1=YmluCmJvb3N0CmJvb3N0LWJ1aWxkCmNlcGguY29uZgo= testkey-2=aWIKTWFrZWZpbGUKbWFuCm91dApzcmMKVGVzdGluZwo=
rgw crypt require ssl: false
Expand Down
1 change: 1 addition & 0 deletions qa/suites/rgw/verify/overrides.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ overrides:
setuser: ceph
setgroup: ceph
debug rgw: 20
debug rgw notification: 20
rgw crypt s3 kms backend: testing
rgw crypt s3 kms encryption keys: testkey-1=YmluCmJvb3N0CmJvb3N0LWJ1aWxkCmNlcGguY29uZgo= testkey-2=aWIKTWFrZWZpbGUKbWFuCm91dApzcmMKVGVzdGluZwo=
rgw crypt require ssl: false
Expand Down
136 changes: 93 additions & 43 deletions src/rgw/driver/rados/rgw_notify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ void publish_commit_completion(rados_completion_t completion, void *arg) {
};

class Manager : public DoutPrefixProvider {
bool shutdown = false;
const size_t max_queue_size;
const uint32_t queues_update_period_ms;
const uint32_t queues_update_retry_ms;
Expand Down Expand Up @@ -289,7 +290,7 @@ class Manager : public DoutPrefixProvider {
cct);
ldpp_dout(this, 20) << "INFO: push endpoint created: " << event_entry.push_endpoint <<
" for entry: " << entry.marker << dendl;
const auto ret = push_endpoint->send_to_completion_async(cct, event_entry.event, optional_yield(io_context, yield));
const auto ret = push_endpoint->send(event_entry.event, optional_yield(io_context, yield));
if (ret < 0) {
ldpp_dout(this, 5) << "WARNING: push entry marker: " << entry.marker
<< " failed. error: " << ret
Expand All @@ -311,7 +312,7 @@ class Manager : public DoutPrefixProvider {

// clean stale reservation from queue
void cleanup_queue(const std::string& queue_name, spawn::yield_context yield) {
while (true) {
while (!shutdown) {
ldpp_dout(this, 20) << "INFO: trying to perform stale reservation cleanup for queue: " << queue_name << dendl;
const auto now = ceph::coarse_real_time::clock::now();
const auto stale_time = now - std::chrono::seconds(stale_reservations_period_s);
Expand Down Expand Up @@ -346,6 +347,27 @@ class Manager : public DoutPrefixProvider {
boost::system::error_code ec;
timer.async_wait(yield[ec]);
}
ldpp_dout(this, 5) << "INFO: manager stopped. done cleanup for queue: " << queue_name << dendl;
}

// unlock (lose ownership) queue
int unlock_queue(const std::string& queue_name, spawn::yield_context yield) {
librados::ObjectWriteOperation op;
op.assert_exists();
rados::cls::lock::unlock(&op, queue_name+"_lock", lock_cookie);
auto& rados_ioctx = rados_store.getRados()->get_notif_pool_ctx();
const auto ret = rgw_rados_operate(this, rados_ioctx, queue_name, &op, optional_yield(io_context, yield));
if (ret == -ENOENT) {
ldpp_dout(this, 10) << "INFO: queue: " << queue_name
<< ". was removed. nothing to unlock" << dendl;
return 0;
}
if (ret == -EBUSY) {
ldpp_dout(this, 10) << "INFO: queue: " << queue_name
<< ". already owned by another RGW. no need to unlock" << dendl;
return 0;
}
return ret;
}

// processing of a specific queue
Expand All @@ -361,7 +383,7 @@ class Manager : public DoutPrefixProvider {

CountersManager queue_counters_container(queue_name, this->get_cct());

while (true) {
while (!shutdown) {
// if queue was empty the last time, sleep for idle timeout
if (is_idle) {
Timer timer(io_context);
Expand Down Expand Up @@ -446,7 +468,7 @@ class Manager : public DoutPrefixProvider {
if (result == EntryProcessingResult::Successful || result == EntryProcessingResult::Expired
|| result == EntryProcessingResult::Migrating) {
ldpp_dout(this, 20) << "INFO: processing of entry: " << entry.marker
<< " (" << entry_idx << "/" << total_entries << ") from: " << queue_name
<< " (" << entry_idx << "/" << total_entries << ") from: " << queue_name << " "
<< entryProcessingResultString[static_cast<unsigned int>(result)] << dendl;
remove_entries = true;
needs_migration_vector[entry_idx - 1] = (result == EntryProcessingResult::Migrating);
Expand Down Expand Up @@ -588,6 +610,7 @@ class Manager : public DoutPrefixProvider {
queue_counters_container.set(l_rgw_persistent_topic_size, entries_size);
}
}
ldpp_dout(this, 5) << "INFO: manager stopped. done processing for queue: " << queue_name << dendl;
}

// lits of owned queues
Expand All @@ -598,6 +621,7 @@ class Manager : public DoutPrefixProvider {
void process_queues(spawn::yield_context yield) {
auto has_error = false;
owned_queues_t owned_queues;
size_t processed_queue_count = 0;

// add randomness to the duration between queue checking
// to make sure that different daemons are not synced
Expand All @@ -609,7 +633,8 @@ class Manager : public DoutPrefixProvider {

std::vector<std::string> queue_gc;
std::mutex queue_gc_lock;
while (true) {
auto& rados_ioctx = rados_store.getRados()->get_notif_pool_ctx();
while (!shutdown) {
Timer timer(io_context);
const auto duration = (has_error ?
std::chrono::milliseconds(queues_update_retry_ms) : std::chrono::milliseconds(queues_update_period_ms)) +
Expand Down Expand Up @@ -640,7 +665,7 @@ class Manager : public DoutPrefixProvider {
failover_time,
LOCK_FLAG_MAY_RENEW);

ret = rgw_rados_operate(this, rados_store.getRados()->get_notif_pool_ctx(), queue_name, &op, optional_yield(io_context, yield));
ret = rgw_rados_operate(this, rados_ioctx, queue_name, &op, optional_yield(io_context, yield));
if (ret == -EBUSY) {
// lock is already taken by another RGW
ldpp_dout(this, 20) << "INFO: queue: " << queue_name << " owned (locked) by another daemon" << dendl;
Expand All @@ -662,12 +687,21 @@ class Manager : public DoutPrefixProvider {
if (owned_queues.insert(queue_name).second) {
ldpp_dout(this, 10) << "INFO: queue: " << queue_name << " now owned (locked) by this daemon" << dendl;
// start processing this queue
spawn::spawn(io_context, [this, &queue_gc, &queue_gc_lock, queue_name](spawn::yield_context yield) {
spawn::spawn(io_context, [this, &queue_gc, &queue_gc_lock, queue_name, &processed_queue_count](spawn::yield_context yield) {
++processed_queue_count;
process_queue(queue_name, yield);
// if queue processing ended, it means that the queue was removed or not owned anymore
const auto ret = unlock_queue(queue_name, yield);
if (ret < 0) {
ldpp_dout(this, 5) << "WARNING: failed to unlock queue: " << queue_name << " with error: " <<
ret << " (ownership would still move if not renewed)" << dendl;
} else {
ldpp_dout(this, 10) << "INFO: queue: " << queue_name << " not locked (ownership can move)" << dendl;
}
// mark it for deletion
std::lock_guard lock_guard(queue_gc_lock);
queue_gc.push_back(queue_name);
--processed_queue_count;
ldpp_dout(this, 10) << "INFO: queue: " << queue_name << " marked for removal" << dendl;
}, make_stack_allocator());
} else {
Expand All @@ -680,21 +714,55 @@ class Manager : public DoutPrefixProvider {
std::for_each(queue_gc.begin(), queue_gc.end(), [this, &owned_queues](const std::string& queue_name) {
topics_persistency_tracker.erase(queue_name);
owned_queues.erase(queue_name);
ldpp_dout(this, 20) << "INFO: queue: " << queue_name << " removed" << dendl;
ldpp_dout(this, 10) << "INFO: queue: " << queue_name << " was removed" << dendl;
});
queue_gc.clear();
}
}
Timer timer(io_context);
while (processed_queue_count > 0) {
ldpp_dout(this, 5) << "INFO: manager stopped. " << processed_queue_count << " queues are still being processed" << dendl;
timer.expires_from_now(std::chrono::milliseconds(queues_update_retry_ms));
boost::system::error_code ec;
timer.async_wait(yield[ec]);
}
ldpp_dout(this, 5) << "INFO: manager stopped. done processing all queues" << dendl;
}

public:

~Manager() {
}

void stop() {
shutdown = true;
work_guard.reset();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you want the unlock_queue() cleanup stuff to happen, you should avoid the call to io_context.stop(). that means that any suspended coroutines won't ever resume, so the worker threads would join immediately

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cbodley if i'm not stopping the io_context, i can get a a crash if the async unlock() call completes after the manager already destroyed.
the other option, is to call the sync version of unlock() (as i did before), but if we have many queues, this would be an issue.
so, i guess that i would risk that sometimes the unlock is being called and sometimes it does not (i will eventually get the lock, once the lock timer expires).

@cbodley cbodley Apr 22, 2024 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cbodley if i'm not stopping the io_context, i can get a a crash if the async unlock() call completes after the manager already destroyed.

if you don't call io_context::stop(), then any threads calling io_context.run() would continue to run until all of their coroutines finish. that means the calls to thread::join() just below will block until that happens. so i don't think there's a risk of racing with Manager's destruction

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i tried commenting out this io_context.stop() line and the cleanup/shutdown mostly works:

2024-05-02T15:28:32.534-0400 7f34c54006c0  5 rgw notify: INFO: manager stopped. done processing for queue: RGW11111111111111111:Topic
2024-05-02T15:28:32.534-0400 7f34c54006c0  1 -- 192.168.245.130:0/802693616 --> [v2:192.168.245.130:6800/3518936173,v1:192.168.245.130:6801/3518936173] -- osd_op(unknown.0.0:3088 2.0 2:0e9ddf52:notif::RGW11111111111111111%3aTopic:head [stat,call lock.unlock in=71b] snapc 0=[] ondisk+write+known_if_redirected+supports_pool_eio e13) -- 0x562f2d2eaa80 con 0x562f2ad66480
2024-05-02T15:28:32.536-0400 7f350aa006c0  1 -- 192.168.245.130:0/802693616 <== osd.0 v2:192.168.245.130:6800/3518936173 3090 ==== osd_op_reply(3088 RGW11111111111111111:Topic [stat,call] v13'427 uv427 ondisk = 0) ==== 212+0+0 (crc 0 0 0) 0x562f2ae58d80 con 0x562f2ad66480
2024-05-02T15:28:32.537-0400 7f34c54006c0 10 rgw notify: INFO: queue: RGW11111111111111111:Topic not locked (ownership can move)
2024-05-02T15:28:32.537-0400 7f34c54006c0 10 rgw notify: INFO: queue: RGW11111111111111111:Topic marked for removal
2024-05-02T15:28:33.406-0400 7f34c54006c0  1 -- 192.168.245.130:0/802693616 --> [v2:192.168.245.130:6800/3518936173,v1:192.168.245.130:6801/3518936173] -- osd_op(unknown.0.0:3089 2.0 2:6fe6cc47:notif::queues_list_object:head [omap-get-keys in=12b] snapc 0=[] ondisk+read+known_if_redirected+supports_pool_eio e13) -- 0x562f2d273500 con 0x562f2ad66480
2024-05-02T15:28:33.406-0400 7f350aa006c0  1 -- 192.168.245.130:0/802693616 <== osd.0 v2:192.168.245.130:6800/3518936173 3091 ==== osd_op_reply(3089 queues_list_object [omap-get-keys out=35b] v0'0 uv411 ondisk = 0) ==== 162+0+35 (crc 0 0 0) 0x562f2ae58d80 con 0x562f2ad66480
2024-05-02T15:28:33.406-0400 7f34c54006c0  1 -- 192.168.245.130:0/802693616 --> [v2:192.168.245.130:6800/3518936173,v1:192.168.245.130:6801/3518936173] -- osd_op(unknown.0.0:3090 2.0 2:0e9ddf52:notif::RGW11111111111111111%3aTopic:head [stat,call lock.lock in=87b] snapc 0=[] ondisk+write+known_if_redirected+supports_pool_eio e13) -- 0x562f2d273880 con 0x562f2ad66480
2024-05-02T15:28:33.409-0400 7f350aa006c0  1 -- 192.168.245.130:0/802693616 <== osd.0 v2:192.168.245.130:6800/3518936173 3092 ==== osd_op_reply(3090 RGW11111111111111111:Topic [stat,call] v13'428 uv428 ondisk = 0) ==== 212+0+0 (crc 0 0 0) 0x562f2ae58d80 con 0x562f2ad66480
2024-05-02T15:28:33.409-0400 7f34c54006c0 20 rgw notify: INFO: queue: RGW11111111111111111:Topic ownership (lock) renewed
2024-05-02T15:28:33.409-0400 7f34c54006c0 10 rgw notify: INFO: queue: RGW11111111111111111:Topic was removed
2024-05-02T15:28:33.409-0400 7f34c54006c0  5 rgw notify: INFO: manager stopped. done processing for queues

the only strange part is that process_queues() raced to lock the queue again after process_queue() unlocked/returned

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tried testing locally without io_context.stop() when more than one RGW exists:

RGW_PER_ZONE=2 ../src/test/rgw/test-rgw-multisite.sh 1

but the tests (data_path_v2_test) got stuck in "migrating" state.
with the above call the tests are running fine.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you tell which coroutine gets stuck on shutdown?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trying with these steps:

$ MON=1 OSD=1 RGW=0 MDS=0 MGR=0 RGW_PER_ZONE=2 ../src/test/rgw/test-rgw-multisite.sh 1
$ bin/radosgw-admin -c run/c1/ceph.conf user create --uid testid --access-key 0555b35654ad1656d804 --secret h7GhxuBLTrlhVUyxSPUKUV8r/2EI4ngqJxD7iBdBYLhwluN30JaT3Q== --display-name 'M. Tester' --email [email protected]
$ BNTESTS_CONF=../work/test_bn.conf python -m nose -s ../src/test/rgw/bucket_notification/test_bn.py -v -a data_path_v2_test

i see both rgws crashing on Manager shutdown:

    -5> 2024-05-03T13:55:17.483-0400 7fd99c4006c0  5 rgw notify: INFO: manager stopped. done processing for queue: :vxhzxs-1_topic
    -4> 2024-05-03T13:55:17.483-0400 7fd99c4006c0  1 -- 192.168.245.130:0/2176396696 --> [v2:192.168.245.130:6800/2282501434,v1:192.168.245.130:6801/2282501434] -- osd_op(unknown.0.0:722 2.0 2:071c9d28:notif::%3avxhzxs-1_topic:head [stat,call lock.unlock in=60b] snapc 0=[] ondisk+write+known_if_redirected+supports_pool_eio e19) -- 0x563fe8e8b880 con 0x563fe0b80900
    -3> 2024-05-03T13:55:17.484-0400 7fd99c4006c0  5 rgw notify: INFO: manager stopped. done processing for queues
    -2> 2024-05-03T13:55:17.485-0400 7fdb102006c0  1 -- 192.168.245.130:0/2176396696 <== osd.0 v2:192.168.245.130:6800/2282501434 731 ==== osd_op_reply(722 :vxhzxs-1_topic [stat,call] v19'1633 uv1633 ondisk = 0) ==== 201+0+0 (crc 0 0 0) 0x563fe592ed80 con 0x563fe0b80900
    -1> 2024-05-03T13:55:17.485-0400 7fd99c4006c0 10 rgw notify: INFO: queue: :vxhzxs-1_topic not locked (ownership can move)
     0> 2024-05-03T13:55:17.485-0400 7fd99c4006c0 -1 *** Caught signal (Segmentation fault) **
 in thread 7fd99c4006c0 thread_name:notif-worker0

 ceph version Development (no_version) squid (dev)
 1: /home/cbodley/ceph/build/bin/radosgw(+0x13bf562) [0x563fde456562]
 2: /lib64/libc.so.6(+0x3e9a0) [0x7fdb1905c9a0]
 3: pthread_mutex_lock()
 4: (std::mutex::lock()+0x9) [0x563fddc0eb7d]
 5: (rgw::notify::Manager::process_queues(spawn::basic_yield_context<boost::asio::executor_binder<void (*)(), boost::asio::any_io_executor> >)::{lambda(spawn::basic_yield_context<boost::asio::executor_binder<void (*)(), boost::asio::any_io_executor> >)#1}::operator()(spawn::basic_yield_context<boost::asio::executor_binder<void (*)(), boost::asio::any_io_executor> >) const+0x2ab) [0x563fde03c9fb]
 6: (spawn::detail::spawn_helper<boost::asio::executor_binder<void (*)(), boost::asio::strand<boost::asio::io_context::basic_executor_type<std::allocator<void>, 0ul> > >, rgw::notify::Manager::process_queues(spawn::basic_yield_context<boost::asio::executor_binder<void (*)(), boost::asio::any_io_executor> >)::{lambda(spawn::basic_yield_context<boost::asio::executor_binder<void (*)(), boost::asio::any_io_executor> >)#1}, boost::context::basic_protected_fixedsize_stack<boost::context::stack_traits> >::operator()()::{lambda(boost::context::continuation&&)#1}::operator()(boost::context::continuation&&) const+0xc9) [0x563fde03cd53]  
 7: (boost::context::detail::record<boost::context::continuation, boost::context::basic_protected_fixedsize_stack<boost::context::stack_traits>, spawn::detail::spawn_helper<boost::asio::executor_binder<void (*)(), boost::asio::strand<boost::asio::io_context::basic_executor_type<std::allocator<void>, 0ul> > >, rgw::notify::Manager::process_queues(spawn::basic_yield_context<boost::asio::executor_binder<void (*)(), boost::asio::any_io_executor> >)::{lambda(spawn::basic_yield_context<boost::asio::executor_binder<void (*)(), boost::asio::any_io_executor> >)#6}, boost::context::basic_protected_fixedsize_stack<boost::context::stack_traits> >::operator()()::{lambda(boost::context::continuation&&)#1}>::run(void*)+0x2e) [0x563fde03cef4]
 8: (void boost::context::detail::context_entry<boost::context::detail::record<boost::context::continuation, boost::context::basic_protected_fixedsize_stack<boost::context::stack_traits>, spawn::detail::spawn_helper<boost::asio::executor_binder<void (*)(), boost::asio::strand<boost::asio::io_context::basic_executor_type<std::allocator<void>, 0ul> > >, rgw::notify::Manager::process_queues(spawn::basic_yield_context<boost::asio::executor_binder<void (*)(), boost::asio::any_io_executor> >)::{lambda(spawn::basic_yield_context<boost::asio::executor_binder<void (*)(), boost::asio::any_io_executor> >)#1}, boost::context::basic_protected_fixedsize_stack<boost::context::stack_traits> >::operator()()::{lambda(boost::context::continuation&&)#1}> >(boost::context::detail::transfer_t)+0x68) [0x563fde03cfd8]
 9: make_fcontext()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's because queue_gc_lock (and queue_gc) are variables on the stack of process_queues(), which can return before the process_queue() coroutines return

on shutdown, maybe process_queues() should keep looping until owned_queues is empty?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this gets too complicated, we might just revert the shutdown/unlock changes and leave io_context.stop() there for now

io_context.stop();
std::for_each(workers.begin(), workers.end(), [] (auto& worker) { worker.join(); });
}

void init() {
spawn::spawn(io_context, [this](spawn::yield_context yield) {
process_queues(yield);
}, make_stack_allocator());

// start the worker threads to do the actual queue processing
const std::string WORKER_THREAD_NAME = "notif-worker";
for (auto worker_id = 0U; worker_id < worker_count; ++worker_id) {
workers.emplace_back([this]() {
try {
io_context.run();
} catch (const std::exception& err) {
ldpp_dout(this, 1) << "ERROR: notification worker failed with error: " << err.what() << dendl;
throw err;
}
});
const auto rc = ceph_pthread_setname(workers.back().native_handle(),
(WORKER_THREAD_NAME+std::to_string(worker_id)).c_str());
ceph_assert(rc == 0);
}
ldpp_dout(this, 10) << "INfO: started notification manager with: " << worker_count << " workers" << dendl;
}

// ctor: start all threads
Manager(CephContext* _cct, uint32_t _max_queue_size, uint32_t _queues_update_period_ms,
uint32_t _queues_update_retry_ms, uint32_t _queue_idle_sleep_us, u_int32_t failover_time_ms,
Expand All @@ -714,28 +782,7 @@ class Manager : public DoutPrefixProvider {
reservations_cleanup_period_s(_reservations_cleanup_period_s),
site(site),
rados_store(*store)
{
spawn::spawn(io_context, [this](spawn::yield_context yield) {
process_queues(yield);
}, make_stack_allocator());

// start the worker threads to do the actual queue processing
const std::string WORKER_THREAD_NAME = "notif-worker";
for (auto worker_id = 0U; worker_id < worker_count; ++worker_id) {
workers.emplace_back([this]() {
try {
io_context.run();
} catch (const std::exception& err) {
ldpp_dout(this, 10) << "Notification worker failed with error: " << err.what() << dendl;
throw(err);
}
});
const auto rc = ceph_pthread_setname(workers.back().native_handle(),
(WORKER_THREAD_NAME+std::to_string(worker_id)).c_str());
ceph_assert(rc == 0);
}
ldpp_dout(this, 10) << "Started notification manager with: " << worker_count << " workers" << dendl;
}
{}

int add_persistent_topic(const std::string& topic_queue, optional_yield y) {
if (topic_queue == Q_LIST_OBJECT_NAME) {
Expand Down Expand Up @@ -771,10 +818,7 @@ class Manager : public DoutPrefixProvider {
}
};

// singleton manager
// note that the manager itself is not a singleton, and multiple instances may co-exist
// TODO make the pointer atomic in allocation and deallocation to avoid race conditions
static Manager* s_manager = nullptr;
std::unique_ptr<Manager> s_manager;

constexpr size_t MAX_QUEUE_SIZE = 128*1000*1000; // 128MB
constexpr uint32_t Q_LIST_UPDATE_MSEC = 1000*30; // check queue list every 30seconds
Expand All @@ -785,24 +829,31 @@ constexpr uint32_t WORKER_COUNT = 1; // 1 worker thread
constexpr uint32_t STALE_RESERVATIONS_PERIOD_S = 120; // cleanup reservations that are more than 2 minutes old
constexpr uint32_t RESERVATIONS_CLEANUP_PERIOD_S = 30; // reservation cleanup every 30 seconds

bool init(CephContext* cct, rgw::sal::RadosStore* store,
const SiteConfig& site, const DoutPrefixProvider *dpp) {
bool init(const DoutPrefixProvider* dpp, rgw::sal::RadosStore* store,
const SiteConfig& site) {
if (s_manager) {
ldpp_dout(dpp, 1) << "ERROR: failed to init notification manager: already exists" << dendl;
return false;
}
if (!RGWPubSubEndpoint::init_all(dpp->get_cct())) {
return false;
}
// TODO: take conf from CephContext
s_manager = new Manager(cct, MAX_QUEUE_SIZE,
s_manager = std::make_unique<Manager>(dpp->get_cct(), MAX_QUEUE_SIZE,
Q_LIST_UPDATE_MSEC, Q_LIST_RETRY_MSEC,
IDLE_TIMEOUT_USEC, FAILOVER_TIME_MSEC,
STALE_RESERVATIONS_PERIOD_S, RESERVATIONS_CLEANUP_PERIOD_S,
WORKER_COUNT,
store, site);
s_manager->init();
return true;
}

void shutdown() {
delete s_manager;
s_manager = nullptr;
if (!s_manager) return;
RGWPubSubEndpoint::shutdown_all();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this guaranteed to trigger cancellation of outstanding completions?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the endpoints are all stopped, there is nothing to invoke the callbacks for the completions.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if outstanding completions aren't canceled, i would expect process_entry()'s calls to push_endpoint->send() to hang and prevent the io_context threads from joining

separately, what happens if we call push_endpoint->send() after RGWPubSubEndpoint::shutdown_all()?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if outstanding completions aren't canceled, i would expect process_entry()'s calls to push_endpoint->send() to hang and prevent the io_context threads from joining

separately, what happens if we call push_endpoint->send() after RGWPubSubEndpoint::shutdown_all()?

the "manager" pointers should be deleted and set to null. this should return an "-ESRCH" error.
however, i do see this crash:

     "/lib64/libc.so.6(+0x3e6f0) [0x7fb79c23e6f0]",
        "__pthread_rwlock_wrlock()",
        "(RGWHTTPManager::register_request(rgw_http_req_data*)+0x37) [0x55a1f56c76e7]",
        "(RGWHTTPManager::add_request(RGWHTTPClient*)+0x168) [0x55a1f56c8c48]",
        "radosgw(+0x80ab13) [0x55a1f58b3b13]",
        "radosgw(+0x80f52b) [0x55a1f58b852b]",
        "(void boost::context::detail::context_entry<boost::context::detail::record<boost::context::continuation, boost::context::basic_protected_fixedsize_stack<boost::context::stack_traits>, spawn::detail::spawn_helper<boost::asio::executor_binder<void (*)(), boost::asio::any_io_executor>, rgw::notify::Manager::process_queue(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, spawn::basic_yield_context<boost::asio::executor_binder<void (*)(), boost::asio::any_io_executor> >)::{lambda(spawn::basic_yield_context<boost::asio::executor_binder<void (*)(), boost::asio::any_io_executor> >)#7}, boost::context::basic_protected_fixedsize_stack<boost::context::stack_traits> >::operator()()::{lambda(boost::context::continuation&&)#1}> >(boost::context::detail::transfer_t)+0x55) [0x55a1f58b92f5]",
        "make_fcontext()"

probably a race condition with the deletion of the pointer.
will protect it with a shared mutex, so that the different sender don't block one another, and only the shutdown

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

however, i don't see any code there that calcel any pending work.
@cbodley do you think that calling "RGWHTTPManager::manage_pending_requests()" would fix that?

it looks like RGWHTTPManager::reqs_thread_entry(), below the while (!going_down) loop, does loop over outstanding requests to call _unlink_request() -> _finish_request(req_data, -ECANCELED);

s_manager->stop();
s_manager.reset();
}

int add_persistent_topic(const std::string& topic_name, optional_yield y) {
Expand Down Expand Up @@ -842,7 +893,7 @@ int remove_persistent_topic(const std::string& topic_queue, optional_yield y) {
if (!s_manager) {
return -EAGAIN;
}
return remove_persistent_topic(s_manager, s_manager->rados_store.getRados()->get_notif_pool_ctx(), topic_queue, y);
return remove_persistent_topic(s_manager.get(), s_manager->rados_store.getRados()->get_notif_pool_ctx(), topic_queue, y);
}

rgw::sal::Object* get_object_with_attributes(
Expand Down Expand Up @@ -1203,8 +1254,7 @@ int publish_commit(rgw::sal::Object* obj,
dpp->get_cct());
ldpp_dout(res.dpp, 20) << "INFO: push endpoint created: "
<< topic.cfg.dest.push_endpoint << dendl;
const auto ret = push_endpoint->send_to_completion_async(
dpp->get_cct(), event_entry.event, res.yield);
const auto ret = push_endpoint->send(event_entry.event, res.yield);
if (ret < 0) {
ldpp_dout(dpp, 1)
<< "ERROR: failed to push sync notification event with error: "
Expand Down
4 changes: 2 additions & 2 deletions src/rgw/driver/rados/rgw_notify.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ namespace rgw::notify {
// initialize the notification manager
// notification manager is dequeuing the 2-phase-commit queues
// and send the notifications to the endpoints
bool init(CephContext* cct, rgw::sal::RadosStore* store,
const rgw::SiteConfig& site, const DoutPrefixProvider *dpp);
bool init(const DoutPrefixProvider* dpp, rgw::sal::RadosStore* store,
const rgw::SiteConfig& site);

// shutdown the notification manager
void shutdown();
Expand Down
Loading