Skip to content

Commit

Permalink
Merge pull request #1040
Browse files Browse the repository at this point in the history
dir, stored: start statistics threads only if needed
  • Loading branch information
pstorz committed Feb 24, 2022
2 parents a2cf56b + b84df04 commit 20bf27c
Show file tree
Hide file tree
Showing 31 changed files with 505 additions and 142 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -32,6 +32,7 @@ and since Bareos version 20 this project adheres to [Semantic Versioning](https:
- git: set merge strategy for CHANGELOG.md to union [PR #1062]
- webui: add timeline chart by jobs [PR #1059]
- stored: enable labeling of tapes in drives even if `autoselect=no` [PR #1021]
- dir, stored: start statistics threads only if needed [PR #1040]

### Deprecated

Expand Down
2 changes: 1 addition & 1 deletion core/src/dird/dird_conf.cc
Expand Up @@ -142,7 +142,7 @@ static ResourceItem dir_items[] = {
{ "SdConnectTimeout", CFG_TYPE_TIME, ITEM(res_dir, SDConnectTimeout), 0, CFG_ITEM_DEFAULT, "1800" /* 30 minutes */, NULL, NULL },
{ "HeartbeatInterval", CFG_TYPE_TIME, ITEM(res_dir, heartbeat_interval), 0, CFG_ITEM_DEFAULT, "0", NULL, NULL },
{ "StatisticsRetention", CFG_TYPE_TIME, ITEM(res_dir, stats_retention), 0, CFG_ITEM_DEFAULT, "160704000" /* 5 years */, NULL, NULL },
{ "StatisticsCollectInterval", CFG_TYPE_PINT32, ITEM(res_dir, stats_collect_interval), 0, CFG_ITEM_DEFAULT, "150", "14.2.0-", NULL },
{ "StatisticsCollectInterval", CFG_TYPE_PINT32, ITEM(res_dir, stats_collect_interval), 0, CFG_ITEM_DEFAULT, "0", "14.2.0-", NULL },
{ "VerId", CFG_TYPE_STR, ITEM(res_dir, verid), 0, 0, NULL, NULL, NULL },
{ "OptimizeForSize", CFG_TYPE_BOOL, ITEM(res_dir, optimize_for_size), 0, CFG_ITEM_DEFAULT, "false", NULL, NULL },
{ "OptimizeForSpeed", CFG_TYPE_BOOL, ITEM(res_dir, optimize_for_speed), 0, CFG_ITEM_DEFAULT, "false", NULL, NULL },
Expand Down
28 changes: 23 additions & 5 deletions core/src/dird/stats.cc
Expand Up @@ -2,7 +2,7 @@
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2016-2016 Planets Communications B.V.
Copyright (C) 2014-2019 Bareos GmbH & Co. KG
Copyright (C) 2014-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -37,6 +37,7 @@
#include "lib/bnet.h"
#include "lib/parse_conf.h"
#include "lib/util.h"
#include "lib/berrno.h"

namespace directordaemon {

Expand Down Expand Up @@ -307,22 +308,39 @@ extern "C" void* statistics_thread(void* arg)
return NULL;
}

int StartStatisticsThread(void)
bool StartStatisticsThread(void)
{
StorageResource* storage;
bool collectstatistics = false;
foreach_res (storage, R_STORAGE) {
if (storage->collectstats) {
collectstatistics = true;
break;
}
}
int status;

if (!me->stats_collect_interval) { return 0; }
if (!me->stats_collect_interval || !collectstatistics) {
Emsg1(M_INFO, 0,
_("Director Statistics Thread will not be started. Modify your "
"configuration if you want to activate it.\n"));

return false;
}

quit = false;

if ((status = pthread_create(&statistics_tid, NULL, statistics_thread, NULL))
!= 0) {
return status;
BErrNo be;
Emsg1(M_ERROR_TERM, 0,
_("Director Statistics Thread could not be started. ERR=%s\n"),
be.bstrerror());
}

statistics_initialized = true;

return 0;
return true;
}

void StopStatisticsThread()
Expand Down
4 changes: 2 additions & 2 deletions core/src/dird/stats.h
@@ -1,7 +1,7 @@
/*
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2018-2018 Bareos GmbH & Co. KG
Copyright (C) 2018-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand All @@ -23,7 +23,7 @@

namespace directordaemon {

int StartStatisticsThread(void);
bool StartStatisticsThread(void);
void StopStatisticsThread();
void stats_job_started();

Expand Down
24 changes: 18 additions & 6 deletions core/src/stored/sd_stats.cc
@@ -1,7 +1,7 @@
/*
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2013-2021 Bareos GmbH & Co. KG
Copyright (C) 2013-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -34,6 +34,7 @@
#include "include/jcr.h"
#include "lib/parse_conf.h"
#include "lib/bsock.h"
#include "lib/berrno.h"

namespace storagedaemon {

Expand Down Expand Up @@ -408,14 +409,17 @@ extern "C" void* statistics_thread_runner(void* arg)
return NULL;
}

int StartStatisticsThread(void)
bool StartStatisticsThread(void)
{
int status;

// First see if device and job stats collection is enabled.
if (!me->stats_collect_interval
|| (!me->collect_dev_stats && !me->collect_job_stats)) {
return 0;
Emsg1(M_INFO, 0,
_("Director Statistics Thread was not started. Modify your "
"configuration if you want to activate it.\n"));
return false;
}

/*
Expand All @@ -430,18 +434,26 @@ int StartStatisticsThread(void)
if (device_resource->collectstats) { cnt++; }
}

if (cnt == 0) { return 0; }
if (cnt == 0) {
Emsg1(M_INFO, 0,
_("Director Statistics Thread was not started. Modify your "
"configuration if you want to activate it.\n"));
return false;
}
}

if ((status
= pthread_create(&statistics_tid, NULL, statistics_thread_runner, NULL))
!= 0) {
return status;
BErrNo be;
Emsg1(M_ERROR_TERM, 0,
_("Director Statistics Thread could not be started. ERR=%s\n"),
be.bstrerror());
}

statistics_initialized = true;

return 0;
return true;
}

void StopStatisticsThread()
Expand Down
4 changes: 2 additions & 2 deletions core/src/stored/sd_stats.h
@@ -1,7 +1,7 @@
/*
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2018-2018 Bareos GmbH & Co. KG
Copyright (C) 2018-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand All @@ -23,7 +23,7 @@

namespace storagedaemon {

int StartStatisticsThread(void);
bool StartStatisticsThread(void);
void StopStatisticsThread();
void UpdateDeviceTapealert(const char* devname, uint64_t flags, utime_t now);
void UpdateJobStatistics(JobControlRecord* jcr, utime_t now);
Expand Down
4 changes: 2 additions & 2 deletions core/src/stored/stored_conf.cc
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2000-2009 Free Software Foundation Europe e.V.
Copyright (C) 2011-2012 Planets Communications B.V.
Copyright (C) 2013-2021 Bareos GmbH & Co. KG
Copyright (C) 2013-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -111,7 +111,7 @@ static ResourceItem store_items[] = {
{"AbsoluteJobTimeout", CFG_TYPE_PINT32, ITEM(res_store, jcr_watchdog_time), 0, 0, NULL, NULL, NULL},
{"CollectDeviceStatistics", CFG_TYPE_BOOL, ITEM(res_store, collect_dev_stats), 0, CFG_ITEM_DEFAULT, "false", NULL, NULL},
{"CollectJobStatistics", CFG_TYPE_BOOL, ITEM(res_store, collect_job_stats), 0, CFG_ITEM_DEFAULT, "false", NULL, NULL},
{"StatisticsCollectInterval", CFG_TYPE_PINT32, ITEM(res_store, stats_collect_interval), 0, CFG_ITEM_DEFAULT, "30", NULL, NULL},
{"StatisticsCollectInterval", CFG_TYPE_PINT32, ITEM(res_store, stats_collect_interval), 0, CFG_ITEM_DEFAULT, "0", NULL, NULL},
{"DeviceReserveByMediaType", CFG_TYPE_BOOL, ITEM(res_store, device_reserve_by_mediatype), 0, CFG_ITEM_DEFAULT, "false", NULL, NULL},
{"FileDeviceConcurrentRead", CFG_TYPE_BOOL, ITEM(res_store, filedevice_concurrent_read), 0, CFG_ITEM_DEFAULT, "false", NULL, NULL},
{"SecureEraseCommand", CFG_TYPE_STR, ITEM(res_store, secure_erase_cmdline), 0, 0, NULL, "15.2.1-",
Expand Down
27 changes: 24 additions & 3 deletions core/src/tests/CMakeLists.txt
@@ -1,6 +1,6 @@
# BAREOS® - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2017-2021 Bareos GmbH & Co. KG
# Copyright (C) 2017-2022 Bareos GmbH & Co. KG
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -128,6 +128,12 @@ add_definitions(
-DRELATIVE_PROJECT_SOURCE_DIR=\"${RELATIVE_PROJECT_SOURCE_DIR}\"
)

set(COMMON_SRC testing_dir_common.cc testing_sd_common.cc)

add_library(testing_common STATIC ${COMMON_SRC})

target_link_libraries(testing_common PRIVATE ${LINK_LIBRARIES})

if(NOT client-only)
bareos_add_test(
run_on_incoming_connect_interval
Expand Down Expand Up @@ -343,7 +349,7 @@ if(NOT client-only)
bareos_add_test(
bsock_test_connection_setup
ADDITIONAL_SOURCES ${SSL_UNIT_TEST_FILES}
LINK_LIBRARIES ${LINK_LIBRARIES}
LINK_LIBRARIES testing_common ${LINK_LIBRARIES}
)

bareos_add_test(bool_string LINK_LIBRARIES bareos GTest::gtest_main)
Expand Down Expand Up @@ -413,7 +419,7 @@ endif() # NOT client-only
if(NOT client-only)
bareos_add_test(
addresses_and_ports
LINK_LIBRARIES bareos dird_objects bareosfind bareossql
LINK_LIBRARIES bareos dird_objects bareosfind bareossql testing_common
$<$<BOOL:HAVE_PAM>:${PAM_LIBRARIES}> GTest::gtest_main
)
endif() # NOT client-only
Expand All @@ -428,3 +434,18 @@ endif() # NOT client-only

bareos_add_test(test_poolmem LINK_LIBRARIES bareos GTest::gtest_main)
bareos_add_test(test_bsnprintf LINK_LIBRARIES bareos GTest::gtest_main)

if(NOT client-only)
bareos_add_test(
dir_statistics_thread LINK_LIBRARIES testing_common dird_objects bareos
bareossql bareosfind GTest::gtest_main
)
endif() # NOT client-only

if(NOT client-only)
bareos_add_test(
sd_statistics_thread
LINK_LIBRARIES testing_common dird_objects bareos bareossql bareosfind
Threads::Threads GTest::gtest_main
)
endif() # NOT client-only

0 comments on commit 20bf27c

Please sign in to comment.