mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-26 01:22:04 +00:00
Print log in case of exception in PollingQueue
This commit is contained in:
parent
1d6bfe8ad7
commit
c61e9a655a
@ -59,9 +59,11 @@ void PollingQueue::addTask(size_t thread_number, void * data, int fd)
|
||||
|
||||
if (-1 == epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fd, &socket_event))
|
||||
throwFromErrno("Cannot add socket descriptor to epoll", ErrorCodes::CANNOT_OPEN_FILE);
|
||||
|
||||
log.emplace_back(Log{.add = true, .key = key, .ptr = data});
|
||||
}
|
||||
|
||||
std::string dumpTasks(const std::unordered_map<std::uintptr_t, PollingQueue::TaskData> & tasks)
|
||||
static std::string dumpTasks(const std::unordered_map<std::uintptr_t, PollingQueue::TaskData> & tasks)
|
||||
{
|
||||
WriteBufferFromOwnString res;
|
||||
res << "Tasks = [";
|
||||
@ -77,6 +79,19 @@ std::string dumpTasks(const std::unordered_map<std::uintptr_t, PollingQueue::Tas
|
||||
return res.str();
|
||||
}
|
||||
|
||||
static std::string dumpLog(const std::vector<PollingQueue::Log> & log)
|
||||
{
|
||||
WriteBufferFromOwnString res;
|
||||
for (const auto & item : log)
|
||||
{
|
||||
res << (item.add ? '+' : '-') << ' ' << item.key << ' ';
|
||||
writePointerHex(item.ptr, res);
|
||||
res << '\n';
|
||||
}
|
||||
|
||||
return res.str();
|
||||
}
|
||||
|
||||
PollingQueue::TaskData PollingQueue::wait(std::unique_lock<std::mutex> & lock)
|
||||
{
|
||||
if (is_finished)
|
||||
@ -105,8 +120,8 @@ PollingQueue::TaskData PollingQueue::wait(std::unique_lock<std::mutex> & lock)
|
||||
auto it = tasks.find(key);
|
||||
if (it == tasks.end())
|
||||
{
|
||||
throw Exception(ErrorCodes::LOGICAL_ERROR, "Task {} ({}) was not found in task queue: {}",
|
||||
key, ptr, dumpTasks(tasks));
|
||||
throw Exception(ErrorCodes::LOGICAL_ERROR, "Task {} ({}) was not found in task queue: {}\n {}",
|
||||
key, ptr, dumpTasks(tasks), dumpLog(log));
|
||||
}
|
||||
|
||||
auto res = it->second;
|
||||
@ -115,6 +130,8 @@ PollingQueue::TaskData PollingQueue::wait(std::unique_lock<std::mutex> & lock)
|
||||
if (-1 == epoll_ctl(epoll_fd, EPOLL_CTL_DEL, res.fd, &event))
|
||||
throwFromErrno("Cannot remove socket descriptor to epoll", ErrorCodes::CANNOT_OPEN_FILE);
|
||||
|
||||
log.emplace_back(Log{.add = true, .key = key, .ptr = ptr});
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <mutex>
|
||||
#include <atomic>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
@ -24,11 +25,19 @@ public:
|
||||
explicit operator bool() const { return data; }
|
||||
};
|
||||
|
||||
struct Log
|
||||
{
|
||||
bool add;
|
||||
std::uintptr_t key;
|
||||
const void * ptr;
|
||||
};
|
||||
|
||||
private:
|
||||
int epoll_fd;
|
||||
int pipe_fd[2];
|
||||
std::atomic_bool is_finished = false;
|
||||
std::unordered_map<std::uintptr_t, TaskData> tasks;
|
||||
std::vector<Log> log;
|
||||
|
||||
public:
|
||||
PollingQueue();
|
||||
|
Loading…
Reference in New Issue
Block a user