1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/*
* Ceph - scalable distributed file system
*
* Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software
* Foundation. See file COPYING.
*
*/
#include "msg/Message.h"
#include "DispatchQueue.h"
#include "SimpleMessenger.h"
#include "common/ceph_context.h"
#define dout_subsys ceph_subsys_ms
#include "common/debug.h"
/*******************
* DispatchQueue
*/
#undef dout_prefix
#define dout_prefix *_dout << "-- " << msgr->get_myaddr() << " "
void DispatchQueue::enqueue(Message *m, int priority, uint64_t id)
{
Mutex::Locker l(lock);
ldout(cct,20) << "queue " << m << " prio " << priority << dendl;
if (priority >= CEPH_MSG_PRIO_LOW) {
mqueue.enqueue_strict(
id, priority, QueueItem(m));
} else {
mqueue.enqueue(
id, priority, m->get_data().length(), QueueItem(m));
}
cond.Signal();
}
void DispatchQueue::local_delivery(Message *m, int priority)
{
Mutex::Locker l(lock);
m->set_connection(msgr->local_connection->get());
if (priority >= CEPH_MSG_PRIO_LOW) {
mqueue.enqueue_strict(
0, priority, QueueItem(m));
} else {
mqueue.enqueue(
0, priority, m->get_data().length(), QueueItem(m));
}
cond.Signal();
}
/*
* This function delivers incoming messages to the Messenger.
* Pipes with messages are kept in queues; when beginning a message
* delivery the highest-priority queue is selected, the pipe from the
* front of the queue is removed, and its message read. If the pipe
* has remaining messages at that priority level, it is re-placed on to the
* end of the queue. If the queue is empty; it's removed.
* The message is then delivered and the process starts again.
*/
void DispatchQueue::entry()
{
lock.Lock();
while (!stop) {
while (!mqueue.empty() && !stop) {
QueueItem qitem = mqueue.dequeue();
lock.Unlock();
if (qitem.is_code()) {
switch (qitem.get_code()) {
case D_BAD_REMOTE_RESET:
msgr->ms_deliver_handle_remote_reset(qitem.get_connection());
break;
case D_CONNECT:
msgr->ms_deliver_handle_connect(qitem.get_connection());
break;
case D_ACCEPT:
msgr->ms_deliver_handle_accept(qitem.get_connection());
break;
case D_BAD_RESET:
msgr->ms_deliver_handle_reset(qitem.get_connection());
break;
default:
assert(0);
}
} else {
Message *m = qitem.get_message();
uint64_t msize = m->get_dispatch_throttle_size();
m->set_dispatch_throttle_size(0); // clear it out, in case we requeue this message.
ldout(cct,1) << "<== " << m->get_source_inst()
<< " " << m->get_seq()
<< " ==== " << *m
<< " ==== " << m->get_payload().length() << "+" << m->get_middle().length()
<< "+" << m->get_data().length()
<< " (" << m->get_footer().front_crc << " " << m->get_footer().middle_crc
<< " " << m->get_footer().data_crc << ")"
<< " " << m << " con " << m->get_connection()
<< dendl;
msgr->ms_deliver_dispatch(m);
msgr->dispatch_throttle_release(msize);
ldout(cct,20) << "done calling dispatch on " << m << dendl;
}
lock.Lock();
}
if (!stop)
cond.Wait(lock); //wait for something to be put on queue
}
lock.Unlock();
}
void DispatchQueue::discard_queue(uint64_t id) {
Mutex::Locker l(lock);
list<QueueItem> removed;
mqueue.remove_by_class(id, &removed);
for (list<QueueItem>::iterator i = removed.begin();
i != removed.end();
++i) {
assert(!(i->is_code())); // We don't discard id 0, ever!
Message *m = i->get_message();
msgr->dispatch_throttle_release(m->get_dispatch_throttle_size());
m->put();
}
}
void DispatchQueue::start()
{
assert(!stop);
assert(!dispatch_thread.is_started());
dispatch_thread.create();
}
void DispatchQueue::wait()
{
dispatch_thread.join();
}
void DispatchQueue::shutdown()
{
// stop my dispatch thread
lock.Lock();
stop = true;
cond.Signal();
lock.Unlock();
}
|