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

Best practices for a few scheduler functions #3779

Merged
merged 20 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
d236a95
Refactor: libcrmcommon,libpe_status: best practices for get_effective…
kgaillot Nov 8, 2024
1d02191
Refactor: scheduler: add pcmk__set_scheduler_defaults()
kgaillot Nov 11, 2024
8ce7a55
Refactor: libcrmcommon,libpe_status: move deferred parameter check APIs
kgaillot Nov 12, 2024
b239fd2
Refactor: scheduler: add pcmk__free_resource()
kgaillot Nov 12, 2024
1c4baa8
Refactor: scheduler: replace pe_free_nodes()
kgaillot Nov 12, 2024
b428a36
Refactor: scheduler: replace pe__free_ordering()
kgaillot Nov 12, 2024
7140050
Refactor: scheduler: replace pe__free_location()
kgaillot Nov 12, 2024
430d020
Refactor: scheduler: replace pe_free_action()
kgaillot Nov 12, 2024
812e9c1
API: libcrmcommon: add pcmk_reset_scheduler()
kgaillot Nov 11, 2024
c519ace
API: libpe_status: deprecate pe_reset_working_set()
kgaillot Nov 12, 2024
a54f162
API: libpe_status: deprecate cleanup_calculations()
kgaillot Nov 12, 2024
c24e732
API: libpe_status: deprecate set_working_set_defaults()
kgaillot Nov 12, 2024
60d2282
API: libcrmcommon: add pcmk_new_scheduler()
kgaillot Nov 12, 2024
197fefa
API: libpe_status: deprecate pe_new_working_set()
kgaillot Nov 12, 2024
dfcc541
API: libcrmcommon: add pcmk_free_scheduler()
kgaillot Nov 12, 2024
0b83908
API: libpe_status: deprecate pe_free_working_set()
kgaillot Nov 12, 2024
6afa00c
Refactor: scheduler: replace last usage of "working set" terminology
kgaillot Nov 12, 2024
fd14083
Refactor: libpe_status: move pe__update_recheck_time() to libcrmcommon
kgaillot Nov 12, 2024
30bc4f7
Test: libcrmcommon: add unit tests for pcmk__update_recheck_time()
kgaillot Nov 11, 2024
57accaa
Refactor: scheduler: drop redundant argument from pcmk__add_param_che…
kgaillot Jan 2, 2025
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
1 change: 1 addition & 0 deletions include/crm/common/scheduler_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ extern uint32_t pcmk__warnings;
(scheduler)->flags, (flags_to_clear), #flags_to_clear); \
} while (0)

void pcmk__set_scheduler_defaults(pcmk_scheduler_t *scheduler);
time_t pcmk__scheduler_epoch_time(pcmk_scheduler_t *scheduler);

#ifdef __cplusplus
Expand Down
30 changes: 30 additions & 0 deletions lib/common/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,36 @@

uint32_t pcmk__warnings = 0;

/*!
* \internal
* \brief Set non-zero default values in scheduler data
*
* \param[in,out] scheduler Scheduler data to modify
*
* \note Values that default to NULL or 0 will remain unchanged
*/
void
pcmk__set_scheduler_defaults(pcmk_scheduler_t *scheduler)
{
pcmk__assert(scheduler != NULL);
scheduler->flags = 0U;
#if PCMK__CONCURRENT_FENCING_DEFAULT_TRUE
pcmk__set_scheduler_flags(scheduler,
pcmk__sched_symmetric_cluster
|pcmk__sched_concurrent_fencing
kgaillot marked this conversation as resolved.
Show resolved Hide resolved
|pcmk__sched_stop_removed_resources
|pcmk__sched_cancel_removed_actions);
#else
pcmk__set_scheduler_flags(scheduler,
pcmk__sched_symmetric_cluster
|pcmk__sched_stop_removed_resources
|pcmk__sched_cancel_removed_actions);
#endif
scheduler->no_quorum_policy = pcmk_no_quorum_stop;
scheduler->priv->next_action_id = 1;
scheduler->priv->next_ordering_id = 1;
}

/*!
* \internal
* \brief Get the Designated Controller node from scheduler data
Expand Down
3 changes: 2 additions & 1 deletion lib/common/tests/scheduler/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ include $(top_srcdir)/mk/tap.mk
include $(top_srcdir)/mk/unittest.mk

# Add "_test" to the end of all test program names to simplify .gitignore.
check_PROGRAMS = pcmk_get_dc_test \
check_PROGRAMS = pcmk__set_scheduler_defaults_test \
pcmk_get_dc_test \
pcmk_get_no_quorum_policy_test \
pcmk_has_quorum_test \
pcmk_set_scheduler_cib_test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@
#include "mock_private.h"

static void
check_defaults(void **state) {
uint32_t flags;
pcmk_scheduler_t *scheduler = pcmk__assert_alloc(1,
sizeof(pcmk_scheduler_t));
null_scheduler(void **state)
{
pcmk__assert_asserts(pcmk__set_scheduler_defaults(NULL));
}

static void
check_defaults(void **state)
{
uint32_t flags = 0U;
pcmk_scheduler_t *scheduler = NULL;

scheduler = pcmk__assert_alloc(1, sizeof(pcmk_scheduler_t));
scheduler->priv = pcmk__assert_alloc(1, sizeof(pcmk__scheduler_private_t));
set_working_set_defaults(scheduler);
pcmk__set_scheduler_defaults(scheduler);

flags = pcmk__sched_symmetric_cluster
#if PCMK__CONCURRENT_FENCING_DEFAULT_TRUE
Expand All @@ -39,12 +46,10 @@ check_defaults(void **state) {
assert_int_equal(scheduler->no_quorum_policy, pcmk_no_quorum_stop);
assert_int_equal(scheduler->flags, flags);

/* Avoid calling pe_free_working_set here so we don't artificially
* inflate the coverage numbers.
*/
free(scheduler->priv);
free(scheduler);
}

PCMK__UNIT_TEST(NULL, NULL,
cmocka_unit_test(null_scheduler),
cmocka_unit_test(check_defaults))
18 changes: 2 additions & 16 deletions lib/pengine/status.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pe_new_working_set(void)
free(scheduler);
return NULL;
}
set_working_set_defaults(scheduler);
pcmk__set_scheduler_defaults(scheduler);
return scheduler;
}

Expand Down Expand Up @@ -432,21 +432,7 @@ set_working_set_defaults(pcmk_scheduler_t *scheduler)
scheduler->priv->local_node_name = local_node_name;

// Set defaults for everything else
scheduler->priv->next_ordering_id = 1;
scheduler->priv->next_action_id = 1;
scheduler->no_quorum_policy = pcmk_no_quorum_stop;
#if PCMK__CONCURRENT_FENCING_DEFAULT_TRUE
pcmk__set_scheduler_flags(scheduler,
pcmk__sched_symmetric_cluster
|pcmk__sched_concurrent_fencing
|pcmk__sched_stop_removed_resources
|pcmk__sched_cancel_removed_actions);
#else
pcmk__set_scheduler_flags(scheduler,
pcmk__sched_symmetric_cluster
|pcmk__sched_stop_removed_resources
|pcmk__sched_cancel_removed_actions);
#endif
pcmk__set_scheduler_defaults(scheduler);
}

pcmk_resource_t *
Expand Down
3 changes: 1 addition & 2 deletions lib/pengine/tests/status/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ LDADD += $(top_builddir)/lib/pengine/libpe_status_test.la
# Add "_test" to the end of all test program names to simplify .gitignore.
check_PROGRAMS = pe_find_node_any_test \
pe_find_node_id_test \
pe_new_working_set_test \
set_working_set_defaults_test
pe_new_working_set_test

TESTS = $(check_PROGRAMS)
9 changes: 5 additions & 4 deletions lib/pengine/tests/status/pe_new_working_set_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ calloc_fails(void **state) {
}

static void
calloc_succeeds(void **state) {
calloc_succeeds(void **state)
{
pcmk_scheduler_t *scheduler = pe_new_working_set();

/* Nothing else to test about this function, as all it does is call
* set_working_set_defaults which is also a public function and should
* get its own unit test.
/* We only need to test that the return value is non-NULL, as all the
* function does is call pcmk__set_scheduler_defaults(), which should have
* its own unit test.
*/
assert_non_null(scheduler);

Expand Down