MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / wait

Function wait

src/Storages/System/StorageSystemStackTrace.cpp:187–230  ·  view source on GitHub ↗

Wait for data in pipe and read it.

Source from the content-addressed store, hash-verified

185
186/// Wait for data in pipe and read it.
187bool wait(int timeout_ms)
188{
189 while (true)
190 {
191 int fd = notification_pipe.fds_rw[0];
192 pollfd poll_fd{fd, POLLIN, 0};
193
194 int poll_res = poll(&poll_fd, 1, timeout_ms);
195 if (poll_res < 0)
196 {
197 if (errno == EINTR)
198 {
199 --timeout_ms; /// Quite a hacky way to update timeout. Just to make sure we avoid infinite waiting.
200 if (timeout_ms == 0)
201 return false;
202 continue;
203 }
204
205 throw ErrnoException(ErrorCodes::CANNOT_READ_FROM_FILE_DESCRIPTOR, "Cannot poll pipe");
206 }
207 if (poll_res == 0)
208 return false;
209
210 int notification_num = 0;
211 ssize_t read_res = ::read(fd, &notification_num, sizeof(notification_num));
212
213 if (read_res < 0)
214 {
215 if (errno == EINTR)
216 continue;
217
218 throw ErrnoException(ErrorCodes::CANNOT_READ_FROM_FILE_DESCRIPTOR, "Cannot read from pipe");
219 }
220
221 if (read_res == sizeof(notification_num))
222 {
223 if (notification_num == sequence_num.load(std::memory_order_relaxed))
224 return true;
225 continue; /// Drain delayed notifications.
226 }
227
228 throw Exception(ErrorCodes::LOGICAL_ERROR, "Read wrong number of bytes from pipe");
229 }
230}
231
232using ThreadIdToName = std::unordered_map<UInt64, String, DefaultHash<UInt64>>;
233

Callers 10

generateMethod · 0.70
waitMethod · 0.50
removeMethod · 0.50
processMethod · 0.50
~ResourceTestManagerMethod · 0.50
waitAllMethod · 0.50
cancelMethod · 0.50
cancelAllMethod · 0.50
ContextSharedPartClass · 0.50

Calls 4

ErrnoExceptionClass · 0.85
readFunction · 0.50
ExceptionClass · 0.50
loadMethod · 0.45

Tested by 1

~ResourceTestManagerMethod · 0.40