@@ -19,7 +19,8 @@ using namespace std;
19
19
namespace {
20
20
21
21
// Build functor for sending messages to connection
22
- auto BuildSender (string_view channel, facade::ArgRange messages, bool unsubscribe = false ) {
22
+ auto BuildSender (string_view channel, facade::ArgRange messages, bool sharded = false ,
23
+ bool unsubscribe = false ) {
23
24
absl::FixedArray<string_view, 1 > views (messages.Size ());
24
25
size_t messages_size = accumulate (messages.begin (), messages.end (), 0 ,
25
26
[](int sum, string_view str) { return sum + str.size (); });
@@ -36,11 +37,12 @@ auto BuildSender(string_view channel, facade::ArgRange messages, bool unsubscrib
36
37
}
37
38
}
38
39
39
- return [channel, buf = std::move (buf), views = std::move (views), unsubscribe](
40
+ return [channel, buf = std::move (buf), views = std::move (views), sharded, unsubscribe](
40
41
facade::Connection* conn, string pattern) {
41
42
string_view channel_view{buf.get (), channel.size ()};
42
43
for (std::string_view message_view : views) {
43
- conn->SendPubMessageAsync ({std::move (pattern), buf, channel_view, message_view, unsubscribe});
44
+ conn->SendPubMessageAsync (
45
+ {std::move (pattern), buf, channel_view, message_view, sharded, unsubscribe});
44
46
}
45
47
};
46
48
}
@@ -117,7 +119,8 @@ void ChannelStore::Destroy() {
117
119
118
120
ChannelStore::ControlBlock ChannelStore::control_block;
119
121
120
- unsigned ChannelStore::SendMessages (std::string_view channel, facade::ArgRange messages) const {
122
+ unsigned ChannelStore::SendMessages (std::string_view channel, facade::ArgRange messages,
123
+ bool sharded) const {
121
124
vector<Subscriber> subscribers = FetchSubscribers (channel);
122
125
if (subscribers.empty ())
123
126
return 0 ;
@@ -144,7 +147,7 @@ unsigned ChannelStore::SendMessages(std::string_view channel, facade::ArgRange m
144
147
}
145
148
146
149
auto subscribers_ptr = make_shared<decltype (subscribers)>(std::move (subscribers));
147
- auto cb = [subscribers_ptr, send = BuildSender (channel, messages)](unsigned idx, auto *) {
150
+ auto cb = [subscribers_ptr, send = BuildSender (channel, messages, sharded )](unsigned idx, auto *) {
148
151
auto it = lower_bound (subscribers_ptr->begin (), subscribers_ptr->end (), idx,
149
152
ChannelStore::Subscriber::ByThreadId);
150
153
while (it != subscribers_ptr->end () && it->LastKnownThreadId () == idx) {
@@ -217,13 +220,14 @@ void ChannelStore::UnsubscribeAfterClusterSlotMigration(const cluster::SlotSet&
217
220
csu.ApplyAndUnsubscribe ();
218
221
}
219
222
223
+ // TODO: Reuse common code with Send function
224
+ // TODO: Find proper solution to hacky `force_unsubscribe` flag or at least move logic out of io
220
225
void ChannelStore::UnsubscribeConnectionsFromDeletedSlots (const ChannelsSubMap& sub_map,
221
226
uint32_t idx) {
222
- const bool should_unsubscribe = true ;
223
227
for (const auto & [channel, subscribers] : sub_map) {
224
228
// ignored by pub sub handler because should_unsubscribe is true
225
229
std::string msg = " __ignore__" ;
226
- auto send = BuildSender (channel, {facade::ArgSlice{msg}}, should_unsubscribe );
230
+ auto send = BuildSender (channel, {facade::ArgSlice{msg}}, false , true );
227
231
228
232
auto it = lower_bound (subscribers.begin (), subscribers.end (), idx,
229
233
ChannelStore::Subscriber::ByThreadId);
0 commit comments