37 instance->
id, pcmk__node_name(node));
43 "%s cannot run on %s: node cannot run resources",
44 instance->
id, pcmk__node_name(node));
49 if (allowed_node == NULL) {
50 crm_warn(
"%s cannot run on %s: node not allowed",
51 instance->
id, pcmk__node_name(node));
55 if (allowed_node->
weight < 0) {
57 "%s cannot run on %s: parent score is %s there",
58 instance->
id, pcmk__node_name(node),
63 if (allowed_node->
count >= max_per_node) {
65 "%s cannot run on %s: node already has %d instance%s",
66 instance->
id, pcmk__node_name(node), max_per_node,
72 instance->
id, pcmk__node_name(node), allowed_node->
count);
84 ban_unavailable_allowed_nodes(
pcmk_resource_t *instance,
int max_per_node)
91 while (g_hash_table_iter_next(&iter, NULL, (
void **) &node)) {
92 if (!can_run_instance(instance, node, max_per_node)) {
94 instance->
id, pcmk__node_name(node));
96 for (GList *child_iter = instance->
children;
97 child_iter != NULL; child_iter = child_iter->next) {
103 if (child_node != NULL) {
105 "Banning %s child %s " 106 "from unavailable node %s",
107 instance->
id, child->
id,
108 pcmk__node_name(node));
133 g_hash_table_insert(table, (gpointer) node->
details->
id, node);
145 apply_parent_colocations(
const pcmk_resource_t *rsc, GHashTable **nodes)
149 for (
const GList *iter = colocations; iter != NULL; iter = iter->next) {
158 g_list_free(colocations);
161 for (
const GList *iter = colocations; iter != NULL; iter = iter->next) {
166 if (!pcmk__colocation_has_influence(colocation, rsc)) {
173 g_list_free(colocations);
198 pcmk_node_t *current_node1 = pcmk__current_node(instance1);
199 pcmk_node_t *current_node2 = pcmk__current_node(instance2);
200 GHashTable *colocated_scores1 = NULL;
201 GHashTable *colocated_scores2 = NULL;
204 && (instance2 != NULL) && (instance2->
parent != NULL)
205 && (current_node1 != NULL) && (current_node2 != NULL));
208 colocated_scores1 = new_node_table(current_node1);
209 colocated_scores2 = new_node_table(current_node2);
212 apply_parent_colocations(instance1, &colocated_scores1);
213 apply_parent_colocations(instance2, &colocated_scores2);
216 node1 = g_hash_table_lookup(colocated_scores1, current_node1->
details->
id);
217 node2 = g_hash_table_lookup(colocated_scores2, current_node2->
details->
id);
221 crm_trace(
"Assign %s (%d on %s) after %s (%d on %s)",
227 crm_trace(
"Assign %s (%d on %s) before %s (%d on %s)",
233 g_hash_table_destroy(colocated_scores1);
234 g_hash_table_destroy(colocated_scores2);
252 for (GList *iter = rsc->
children; iter != NULL; iter = iter->next) {
274 (*node)->details->id);
276 if ((allowed == NULL) || (allowed->
weight < 0)) {
278 rsc->
id, pcmk__node_name(*node));
305 CRM_ASSERT((instance1 != NULL) && (instance2 != NULL));
308 div1 = strrchr(instance1->
id,
':');
310 div1 = strrchr(instance1->
id,
'-');
312 div2 = strrchr(instance2->
id,
':');
314 div2 = strrchr(instance2->
id,
'-');
318 return (gint) (strtol(div1 + 1, NULL, 10) - strtol(div2 + 1, NULL, 10));
352 unsigned int nnodes1 = 0;
353 unsigned int nnodes2 = 0;
361 CRM_ASSERT((instance1 != NULL) && (instance2 != NULL));
369 if ((nnodes1 > 0) && (nnodes2 > 0)) {
370 if (nnodes1 < nnodes2) {
371 crm_trace(
"Assign %s (active on %d) before %s (active on %d): " 372 "less multiply active",
373 instance1->
id, nnodes1, instance2->
id, nnodes2);
376 }
else if (nnodes1 > nnodes2) {
377 crm_trace(
"Assign %s (active on %d) after %s (active on %d): " 378 "more multiply active",
379 instance1->
id, nnodes1, instance2->
id, nnodes2);
387 can1 = node_is_allowed(instance1, &
node1);
388 can2 = node_is_allowed(instance2, &
node2);
390 crm_trace(
"Assign %s before %s: not active on a disallowed node",
391 instance1->
id, instance2->
id);
394 }
else if (!can1 && can2) {
395 crm_trace(
"Assign %s after %s: active on a disallowed node",
396 instance1->
id, instance2->
id);
402 crm_trace(
"Assign %s before %s: priority (%d > %d)",
403 instance1->
id, instance2->
id,
408 crm_trace(
"Assign %s after %s: priority (%d < %d)",
409 instance1->
id, instance2->
id,
416 crm_trace(
"No assignment preference for %s vs. %s: inactive",
417 instance1->
id, instance2->
id);
420 }
else if (
node1 == NULL) {
421 crm_trace(
"Assign %s after %s: active", instance1->
id, instance2->
id);
424 }
else if (
node2 == NULL) {
425 crm_trace(
"Assign %s before %s: active", instance1->
id, instance2->
id);
433 crm_trace(
"Assign %s before %s: current node can run resources",
434 instance1->
id, instance2->
id);
437 }
else if (!can1 && can2) {
438 crm_trace(
"Assign %s after %s: current node can't run resources",
439 instance1->
id, instance2->
id);
447 crm_trace(
"No assignment preference for %s vs. %s: " 448 "parent not allowed on either instance's current node",
449 instance1->
id, instance2->
id);
452 }
else if (
node1 == NULL) {
453 crm_trace(
"Assign %s after %s: parent not allowed on current node",
454 instance1->
id, instance2->
id);
457 }
else if (
node2 == NULL) {
458 crm_trace(
"Assign %s before %s: parent allowed on current node",
459 instance1->
id, instance2->
id);
465 crm_trace(
"Assign %s before %s: fewer active instances on current node",
466 instance1->
id, instance2->
id);
470 crm_trace(
"Assign %s after %s: more active instances on current node",
471 instance1->
id, instance2->
id);
476 can1 = did_fail(instance1);
477 can2 = did_fail(instance2);
479 crm_trace(
"Assign %s before %s: not failed",
480 instance1->
id, instance2->
id);
482 }
else if (can1 && !can2) {
484 instance1->
id, instance2->
id);
489 rc = cmp_instance_by_colocation(instance1, instance2);
497 crm_trace(
"Assign %s before %s: instance number",
498 instance1->
id, instance2->
id);
500 crm_trace(
"Assign %s after %s: instance number",
501 instance1->
id, instance2->
id);
503 crm_trace(
"No assignment preference for %s vs. %s",
504 instance1->
id, instance2->
id);
526 if (assigned_to == NULL) {
531 if (allowed == NULL) {
562 ((prefer == NULL)?
"no node" : prefer->
details->
uname));
566 "Assignment loop detected involving %s colocations",
570 ban_unavailable_allowed_nodes(instance, max_per_node);
573 chosen = instance->
cmds->
assign(instance, prefer, (prefer == NULL));
574 increment_parent_count(instance, chosen);
600 GHashTable *allowed_orig = NULL;
601 GHashTable *allowed_orig_parent =
parent->allowed_nodes;
604 pcmk__rsc_trace(instance,
"Trying to assign %s to its current node %s",
605 instance->
id, pcmk__node_name(current));
611 "Not assigning %s to current node %s: unavailable",
612 instance->
id, pcmk__node_name(current));
639 while (reserved < available) {
640 chosen = assign_instance(instance, current, max_per_node);
642 if (pcmk__same_node(chosen, current)) {
652 if (chosen == NULL) {
655 "Not assigning %s to current node %s: unavailable",
656 instance->
id, pcmk__node_name(current));
663 "Not assigning %s to current node %s: %s is better",
664 instance->
id, pcmk__node_name(current),
665 pcmk__node_name(chosen));
668 if (++reserved >= available) {
670 "Not assigning %s to current node %s: " 671 "other assignments are more important",
672 instance->
id, pcmk__node_name(current));
676 "Reserved an instance of %s for %s. Retrying " 677 "assignment of %s to %s",
678 rsc->
id, pcmk__node_name(chosen), instance->
id,
679 pcmk__node_name(current));
687 g_hash_table_destroy(allowed_orig);
690 g_hash_table_destroy(
parent->allowed_nodes);
691 parent->allowed_nodes = allowed_orig_parent;
693 if (chosen == NULL) {
698 instance->
id, pcmk__node_name(current));
699 increment_parent_count(instance, chosen);
714 unsigned int available_nodes = 0;
719 while (g_hash_table_iter_next(&iter, NULL, (gpointer *) &node)) {
725 return available_nodes;
751 node = pcmk__current_node(instance);
753 pcmk__rsc_trace(instance,
"Not assigning %s to %s early (unavailable)",
754 instance->
id, pcmk__node_name(node));
760 if ((parent_node != NULL) && (parent_node->
count >= optimal_per_node)) {
762 "Not assigning %s to %s early " 763 "(optimal instances already assigned)",
764 instance->
id, pcmk__node_name(node));
782 int max_total,
int max_per_node)
785 unsigned int available_nodes = reset_allowed_node_counts(collective);
787 int optimal_per_node = 0;
793 if (available_nodes > 0) {
794 optimal_per_node = max_total / available_nodes;
796 if (optimal_per_node < 1) {
797 optimal_per_node = 1;
801 "Assigning up to %d %s instance%s to up to %u node%s " 802 "(at most %d per host, %d optimal)",
805 max_per_node, optimal_per_node);
808 for (iter = instances; (iter != NULL) && (assigned < max_total);
810 int available = max_total - assigned;
812 instance = iter->data;
817 current = preferred_node(instance, optimal_per_node);
818 if ((current != NULL)
819 && assign_instance_early(collective, instance, current,
820 max_per_node, available)) {
825 pcmk__rsc_trace(collective,
"Assigned %d of %d instance%s to current node",
828 for (iter = instances; iter != NULL; iter = iter->next) {
836 current = pcmk__current_node(instance);
838 const char *unmanaged =
"";
841 unmanaged =
"Unmanaged resource ";
843 crm_notice(
"%s%s is running on %s which is no longer allowed",
844 unmanaged, instance->
id, pcmk__node_name(current));
848 if (assigned >= max_total) {
850 "Not assigning %s because maximum %d instances " 852 instance->
id, max_total);
854 "collective_limit_reached", collective->
cluster);
856 }
else if (assign_instance(instance, NULL, max_per_node) != NULL) {
861 pcmk__rsc_debug(collective,
"Assigned %d of %d possible instance%s of %s",
893 const GList *iter = NULL;
904 (iter != NULL) && !pcmk_all_flags_set(*state,
instance_all);
937 (optional?
"optional" :
"unrunnable"));
955 (optional?
"optional" :
"unrunnable"));
985 pcmk__rsc_trace(collective,
"Creating collective instance actions for %s",
989 for (GList *iter = instances; iter != NULL; iter = iter->next) {
993 check_instance_state(instance, &state);
1020 if (pcmk__is_clone(collective)) {
1037 static inline GList *
1040 if (pcmk__is_bundle(rsc)) {
1081 CRM_CHECK((instance != NULL) && (node != NULL),
return false);
1084 && (role != instance->
fns->
state(instance, current))) {
1086 "%s is not a compatible instance (role is not %s)",
1093 instance_node = instance->
fns->
location(instance, NULL, current);
1096 if (instance_node == NULL) {
1098 "%s is not a compatible instance " 1099 "(not assigned to a node)",
1104 if (!pcmk__same_node(instance_node, node)) {
1106 "%s is not a compatible instance " 1107 "(assigned to %s not %s)",
1108 instance->
id, pcmk__node_name(instance_node),
1109 pcmk__node_name(node));
1116 #define display_role(r) \ 1117 (((r) == pcmk_role_unknown)? "matching" : pcmk_role_text(r)) 1138 GList *instances = NULL;
1140 instances = get_instance_list(rsc);
1141 for (GList *iter = instances; iter != NULL; iter = iter->next) {
1146 "Found %s %s instance %s compatible with %s on %s",
1148 match_rsc->
id, pcmk__node_name(node));
1149 free_instance_list(rsc, instances);
1153 free_instance_list(rsc, instances);
1156 "No %s %s instance found compatible with %s on %s",
1158 pcmk__node_name(node));
1181 GList *nodes = NULL;
1185 node = match_rsc->
fns->
location(match_rsc, NULL, current);
1187 return find_compatible_instance_on_node(match_rsc, rsc, node, role,
1194 for (GList *iter = nodes; (iter != NULL) && (instance == NULL);
1195 iter = iter->next) {
1196 instance = find_compatible_instance_on_node(match_rsc, rsc,
1201 if (instance == NULL) {
1203 rsc->
id, match_rsc->
id);
1229 "%s has no instance to order before stopping " 1231 first->
rsc->
id, then_instance->
id);
1239 "Inhibiting %s from being active " 1240 "because there is no %s instance to interleave",
1241 then_instance->
id, first->
rsc->
id);
1302 if (matching_action != NULL) {
1303 return matching_action;
1309 crm_trace(
"No %s action found for %s%s",
1314 crm_err(
"No %s action found for %s to interleave (bug?)",
1315 action_name, instance->
id);
1339 char *action_type = NULL;
1340 const char *action_name =
action->task;
1348 action_name = strstr(action_type,
"_notify_");
1351 action_name += strlen(
"_notify_");
1383 GList *instances = NULL;
1385 const char *orig_first_task = orig_action_name(first);
1393 instances = get_instance_list(then->
rsc);
1394 for (GList *iter = instances; iter != NULL; iter = iter->next) {
1407 if (first_instance == NULL) {
1408 if (unassign_if_mandatory(first, then, then_instance,
type,
1415 first_action = find_instance_action(first, first_instance,
1416 orig_first_task, node,
true);
1417 if (first_action == NULL) {
1421 then_action = find_instance_action(then, then_instance, then->
task,
1423 if (then_action == NULL) {
1433 first_action, then_action, node,
1437 free_instance_list(then->
rsc, instances);
1453 bool interleave =
false;
1456 if ((first->
rsc == NULL) || (then->
rsc == NULL)) {
1457 crm_trace(
"Not interleaving %s with %s: not resource actions",
1462 if (first->
rsc == then->
rsc) {
1463 crm_trace(
"Not interleaving %s with %s: same resource",
1470 crm_trace(
"Not interleaving %s with %s: not clones or bundles",
1484 pcmk__rsc_trace(rsc,
"'%s then %s' will %sbe interleaved (based on %s)",
1485 first->
uuid, then->
uuid, (interleave?
"" :
"not "),
1515 uint32_t
flags, uint32_t filter, uint32_t
type)
1518 uint32_t instance_flags = 0;
1524 if (instance_action == NULL) {
1542 after_iter != NULL; after_iter = after_iter->next) {
1578 uint32_t filter, uint32_t
type,
1583 if (then->
rsc == NULL) {
1586 }
else if (can_interleave_actions(first, then)) {
1587 return update_interleaved_actions(first, then, node, filter,
type);
1591 GList *instances = get_instance_list(then->
rsc);
1598 for (GList *iter = instances; iter != NULL; iter = iter->next) {
1601 changed |= update_noninterleaved_actions(instance, first, then,
1604 free_instance_list(then->
rsc, instances);
1609 #define pe__clear_action_summary_flags(flags, action, flag) do { \ 1610 flags = pcmk__clear_flags_as(__func__, __LINE__, LOG_TRACE, \ 1611 "Action summary", action->rsc->id, \ 1612 flags, flag, #flag); \ 1629 bool any_runnable =
false;
1630 const char *action_name = orig_action_name(
action);
1637 for (
const GList *iter = instances; iter != NULL; iter = iter->next) {
1641 uint32_t instance_flags;
1644 if (pcmk__is_primitive(instance)) {
1645 instance_node = node;
1649 action_name, instance_node);
1650 if (instance_action == NULL) {
1652 instance->
id, action_name, pcmk__node_name(node));
1657 instance->
id, instance_action->
uuid, action_name,
1658 pcmk__node_name(node));
1674 any_runnable =
true;
1678 if (!any_runnable) {
1680 "%s is not runnable because no instance can run %s",
1681 action->uuid, action_name);
pcmk_assignment_methods_t * cmds
#define CRM_CHECK(expr, failure_action)
void pe__create_clone_notif_pseudo_ops(pcmk_resource_t *clone, pcmk_action_t *start, pcmk_action_t *started, pcmk_action_t *stop, pcmk_action_t *stopped)
pcmk_node_t * pe__copy_node(const pcmk_node_t *this_node)
void pcmk__create_instance_actions(pcmk_resource_t *collective, GList *instances)
#define crm_notice(fmt, args...)
'then' is runnable (and migratable) only if 'first' is runnable
pcmk_scheduler_t * cluster
const char * pcmk_role_text(enum rsc_role_e role)
Get readable description of a resource role.
pcmk_node_t *(* location)(const pcmk_resource_t *rsc, GList **list, int current)
void(* create_actions)(pcmk_resource_t *rsc)
bool pcmk__strcase_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
const char * pcmk_readable_score(int score)
Return a displayable static string for a score value.
uint32_t(* action_flags)(pcmk_action_t *action, const pcmk_node_t *node)
#define pcmk__rsc_trace(rsc, fmt, args...)
gboolean order_actions(pcmk_action_t *lh_action, pcmk_action_t *rh_action, uint32_t flags)
#define pcmk__rsc_info(rsc, fmt, args...)
enum rsc_role_e(* state)(const pcmk_resource_t *rsc, gboolean current)
void pcmk__assign_instances(pcmk_resource_t *collective, GList *instances, int max_total, int max_per_node)
void(* add_colocated_node_scores)(pcmk_resource_t *source_rsc, const pcmk_resource_t *target_rsc, const char *log_id, GHashTable **nodes, const pcmk__colocation_t *colocation, float factor, uint32_t flags)
#define PCMK_META_INTERLEAVE
#define CRM_LOG_ASSERT(expr)
pcmk_node_t *(* assign)(pcmk_resource_t *rsc, const pcmk_node_t *prefer, bool stop_if_fail)
gint pcmk__cmp_instance(gconstpointer a, gconstpointer b)
G_GNUC_INTERNAL uint32_t pcmk__update_ordered_actions(pcmk_action_t *first, pcmk_action_t *then, const pcmk_node_t *node, uint32_t flags, uint32_t filter, uint32_t type, pcmk_scheduler_t *scheduler)
enum crm_ais_msg_types type
G_GNUC_INTERNAL void pcmk__update_action_for_orderings(pcmk_action_t *action, pcmk_scheduler_t *scheduler)
bool pcmk__ends_with(const char *s, const char *match)
G_GNUC_INTERNAL bool pcmk__node_available(const pcmk_node_t *node, bool consider_score, bool consider_guest)
G_GNUC_INTERNAL bool pcmk__assign_resource(pcmk_resource_t *rsc, pcmk_node_t *node, bool force, bool stop_if_fail)
gint pcmk__cmp_instance_number(gconstpointer a, gconstpointer b)
#define pcmk__rsc_debug(rsc, fmt, args...)
pcmk_action_t * pe__new_rsc_pseudo_action(pcmk_resource_t *rsc, const char *task, bool optional, bool runnable)
#define PCMK_ACTION_DEMOTE
G_GNUC_INTERNAL void pcmk__copy_node_tables(const pcmk_resource_t *rsc, GHashTable **copy)
#define crm_warn(fmt, args...)
const pcmk_resource_t * pe__get_rsc_in_container(const pcmk_resource_t *instance)
#define pcmk__clear_action_flags(action, flags_to_clear)
void resource_location(pcmk_resource_t *rsc, const pcmk_node_t *node, int score, const char *tag, pcmk_scheduler_t *scheduler)
#define pe__clear_action_summary_flags(flags, action, flag)
#define crm_trace(fmt, args...)
#define pcmk_is_set(g, f)
Convenience alias for pcmk_all_flags_set(), to check single flag.
struct pe_node_shared_s * details
#define PCMK_ACTION_START
G_GNUC_INTERNAL void pcmk__unassign_resource(pcmk_resource_t *rsc)
Wrappers for and extensions to libxml2.
#define PCMK_ACTION_NOTIFIED
#define pcmk__set_rsc_flags(resource, flags_to_set)
bool is_set_recursive(const pcmk_resource_t *rsc, long long flag, bool any)
enum pe_obj_types variant
bool pcmk__str_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
uint32_t pcmk__collective_action_flags(pcmk_action_t *action, const GList *instances, const pcmk_node_t *node)
const char * pcmk_action_text(enum action_tasks action)
Get string equivalent of an action type.
G_GNUC_INTERNAL pcmk_node_t * pcmk__top_allowed_node(const pcmk_resource_t *rsc, const pcmk_node_t *node)
pcmk_resource_t * primary
pcmk_resource_t * pcmk__find_compatible_instance(const pcmk_resource_t *match_rsc, const pcmk_resource_t *rsc, enum rsc_role_e role, bool current)
G_GNUC_INTERNAL void pcmk__restore_node_tables(pcmk_resource_t *rsc, GHashTable *backup)
bool pcmk__instance_matches(const pcmk_resource_t *instance, const pcmk_node_t *node, enum rsc_role_e role, bool current)
G_GNUC_INTERNAL GList * pcmk__with_this_colocations(const pcmk_resource_t *rsc)
GHashTable * pcmk__strkey_table(GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func)
G_GNUC_INTERNAL GHashTable * pcmk__copy_node_table(GHashTable *nodes)
pcmk_action_t * find_first_action(const GList *input, const char *uuid, const char *task, const pcmk_node_t *on_node)
#define pcmk__set_updated_flags(au_flags, action, flags_to_set)
#define crm_err(fmt, args...)
pcmk_scheduler_t * scheduler
#define PCMK_ACTION_STOPPED
G_GNUC_INTERNAL GList * pcmk__this_with_colocations(const pcmk_resource_t *rsc)
pcmk_node_t *(* active_node)(const pcmk_resource_t *rsc, unsigned int *count_all, unsigned int *count_clean)
gboolean parse_op_key(const char *key, char **rsc_id, char **op_type, guint *interval_ms)
#define PCMK_ACTION_PROMOTE
pcmk_resource_t * dependent
#define pcmk__plural_s(i)
uint32_t(* update_ordered_actions)(pcmk_action_t *first, pcmk_action_t *then, const pcmk_node_t *node, uint32_t flags, uint32_t filter, uint32_t type, pcmk_scheduler_t *scheduler)
#define pcmk__set_action_flags(action, flags_to_set)
G_GNUC_INTERNAL GList * pcmk__sort_nodes(GList *nodes, pcmk_node_t *active_node)
#define PCMK_ACTION_PROMOTED
gboolean crm_is_true(const char *s)
Resource role is unknown.
#define PCMK_ACTION_RUNNING
#define PCMK_ACTION_DEMOTED
enum action_tasks get_complex_task(const pcmk_resource_t *rsc, const char *name)
GList * pe__bundle_containers(const pcmk_resource_t *bundle)
#define PCMK_ACTION_NOTIFY
#define PCMK_SCORE_INFINITY
Integer score to use to represent "infinity".
GHashTable * allowed_nodes
uint32_t pcmk__instance_update_ordered_actions(pcmk_action_t *first, pcmk_action_t *then, const pcmk_node_t *node, uint32_t flags, uint32_t filter, uint32_t type, pcmk_scheduler_t *scheduler)