Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mon 14375 queue size limited #342

Merged
merged 14 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix(broker): file size is computed faster
  • Loading branch information
bouda1 committed Aug 3, 2022
commit a763aa89fa23dae3647cc5382672165aa1ddabc7
2 changes: 1 addition & 1 deletion broker/core/inc/com/centreon/broker/file/splitter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class splitter : public fs_file {
std::mutex _mutex1;
std::mutex _mutex2;
std::mutex _id_m;
size_t _size = 0u;
std::atomic<size_t> _size;

void _open_read_file();
void _open_write_file();
Expand Down
2 changes: 1 addition & 1 deletion broker/core/inc/com/centreon/broker/misc/filesystem.hh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ std::list<std::string> dir_content_with_filter(std::string const& path,
bool file_exists(std::string const& path);
bool dir_exists(std::string const& path);
bool mkpath(std::string const& path);
int64_t file_size(std::string const& path);
int64_t file_size(const std::string& path) noexcept;
bool writable(const std::string& name);
bool readable(const std::string& name);
} // namespace filesystem
Expand Down
3 changes: 2 additions & 1 deletion broker/core/src/file/splitter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ splitter::splitter(std::string const& path,
_wfile{},
_wmutex{nullptr},
_wid{0},
_woffset{0} {
_woffset{0},
_size{0u} {
// Get IDs of already existing file parts. File parts are suffixed
// with their order number. A file named /var/lib/foo would have
// parts named /var/lib/foo, /var/lib/foo1, /var/lib/foo2, ...
Expand Down
16 changes: 12 additions & 4 deletions broker/core/src/misc/filesystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,18 @@ bool filesystem::mkpath(std::string const& path) {
}
}

int64_t filesystem::file_size(std::string const& path) {
std::ifstream file{path, std::ios::binary | std::ios::ate};
int64_t size{file.tellg()};
return size;
/**
* @brief Get the file size of the file whose path is given.
*
* @param path The file name.
*
* @return the size in bytes of the file or -1 on error.
*/
int64_t filesystem::file_size(const std::string& path) noexcept {
struct stat file_stat;
if (stat(path.c_str(), &file_stat) == 0)
return file_stat.st_size;
return -1;
}

/**
Expand Down
8 changes: 8 additions & 0 deletions tests/broker-engine/rrd-from-db.robot
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ BRRDDMDB1
Broker Config Log central core error
Broker Config Log rrd rrd debug
Broker Config Log rrd core error
Broker Config Flush Log central 0
Broker Config Flush Log rrd 0
Create Metrics 3
${start}= Get Current Date
Start Broker
Expand Down Expand Up @@ -65,6 +67,8 @@ BRRDDIDDB1
Broker Config Log central sql info
Broker Config Log rrd rrd debug
Broker Config Log rrd core error
Broker Config Flush Log central 0
Broker Config Flush Log rrd 0
Create Metrics 3

${start}= Get Current Date
Expand Down Expand Up @@ -108,6 +112,8 @@ BRRDRBDB1
Config Broker module
Broker Config Log rrd rrd trace
Broker Config Log central sql trace
Broker Config Flush Log central 0
Broker Config Flush Log rrd 0
Create Metrics 3

${start}= Get Current Date
Expand Down Expand Up @@ -155,6 +161,8 @@ BRRDRBUDB1
Config Broker module
Broker Config Log rrd rrd trace
Broker Config Log central sql trace
Broker Config Flush Log central 0
Broker Config Flush Log rrd 0
Broker Config Add Item module0 bbdo_version 3.0.1
Broker Config Add Item rrd bbdo_version 3.0.1
Broker Config Add Item central bbdo_version 3.0.1
Expand Down
7 changes: 3 additions & 4 deletions tests/broker/start-stop.robot
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,15 @@ Start Stop Service
Sleep ${interval}
Send Signal To Process SIGTERM b1
${result}= Wait For Process b1 timeout=60s on_timeout=kill
Should Be True ${result.rc} == -15 or ${result.rc} == 0 msg=Broker service badly stopped
Should Be True ${result.rc} == -15 or ${result.rc} == 0 msg=Broker service badly stopped with code ${result.rc}
Send Signal To Process SIGTERM b2
${result}= Wait For Process b2 timeout=60s on_timeout=kill
Should Be True ${result.rc} == -15 or ${result.rc} == 0 msg=Broker service badly stopped
Should Be True ${result.rc} == -15 or ${result.rc} == 0 msg=Broker service badly stopped with code ${result.rc}

Start Stop Instance
[Arguments] ${interval}
Start Process /usr/sbin/cbd ${EtcRoot}/centreon-broker/central-broker.json alias=b1
Sleep ${interval}
Send Signal To Process SIGTERM b1
${result}= Wait For Process b1 timeout=60s on_timeout=kill
Should Be True ${result.rc} == -15 or ${result.rc} == 0 msg=Broker instance badly stopped

Should Be True ${result.rc} == -15 or ${result.rc} == 0 msg=Broker instance badly stopped with code ${result.rc}