Skip to content

Commit

Permalink
High: pengine: cl#5070 - Improvements to Master and Clone resource co…
Browse files Browse the repository at this point in the history
…location rules
  • Loading branch information
davidvossel committed Jun 27, 2012
1 parent 6afb2d5 commit 0062eab
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 39 deletions.
4 changes: 2 additions & 2 deletions pengine/allocate.c
Expand Up @@ -69,7 +69,7 @@ resource_alloc_functions_t resource_class_alloc_functions[] = {
group_append_meta,
},
{
native_merge_weights,
clone_merge_weights,
clone_color,
clone_create_actions,
clone_create_probe,
Expand All @@ -83,7 +83,7 @@ resource_alloc_functions_t resource_class_alloc_functions[] = {
clone_append_meta,
},
{
native_merge_weights,
master_merge_weights,
master_color,
master_create_actions,
clone_create_probe,
Expand Down
17 changes: 10 additions & 7 deletions pengine/allocate.h
Expand Up @@ -30,8 +30,7 @@ typedef struct notify_entry_s {
} notify_entry_t;

struct resource_alloc_functions_s {
GHashTable *(*merge_weights) (resource_t *, const char *, GHashTable *, const char *, int,
gboolean, gboolean);
GHashTable *(*merge_weights) (resource_t *, const char *, GHashTable *, const char *, float, enum pe_weights);
node_t *(*allocate) (resource_t *, node_t *, pe_working_set_t *);
void (*create_actions) (resource_t *, pe_working_set_t *);
gboolean(*create_probe) (resource_t *, node_t *, action_t *, gboolean, pe_working_set_t *);
Expand All @@ -51,15 +50,19 @@ struct resource_alloc_functions_s {
};

extern GHashTable *rsc_merge_weights(resource_t * rsc, const char *rhs, GHashTable * nodes,
const char *attr, int factor, enum pe_weights flags);
const char *attr, float factor, enum pe_weights flags);

extern GHashTable *clone_merge_weights(resource_t * rsc, const char *rhs, GHashTable * nodes,
const char *attr, float factor, enum pe_weights flags);

extern GHashTable *master_merge_weights(resource_t * rsc, const char *rhs, GHashTable * nodes,
const char *attr, float factor, enum pe_weights flags);

extern GHashTable *native_merge_weights(resource_t * rsc, const char *rhs, GHashTable * nodes,
const char *attr, int factor, gboolean allow_rollback,
gboolean only_positive);
const char *attr, float factor, enum pe_weights flags);

extern GHashTable *group_merge_weights(resource_t * rsc, const char *rhs, GHashTable * nodes,
const char *attr, int factor, gboolean allow_rollback,
gboolean only_positive);
const char *attr, float factor, enum pe_weights flags);

extern node_t *native_color(resource_t * rsc, node_t * preferred, pe_working_set_t * data_set);
extern void native_create_actions(resource_t * rsc, pe_working_set_t * data_set);
Expand Down
66 changes: 61 additions & 5 deletions pengine/clone.c
Expand Up @@ -227,7 +227,7 @@ sort_clone_instance(gconstpointer a, gconstpointer b, gpointer data_set)

hash1 = native_merge_weights(constraint->rsc_rh, resource1->id, hash1,
constraint->node_attribute,
constraint->score / INFINITY, FALSE, FALSE);
(float) constraint->score / INFINITY, 0);
}

for (gIter = resource1->parent->rsc_cons_lhs; gIter; gIter = gIter->next) {
Expand All @@ -237,7 +237,7 @@ sort_clone_instance(gconstpointer a, gconstpointer b, gpointer data_set)

hash1 = native_merge_weights(constraint->rsc_lh, resource1->id, hash1,
constraint->node_attribute,
constraint->score / INFINITY, FALSE, TRUE);
(float) constraint->score / INFINITY, pe_weights_positive);
}

for (gIter = resource2->parent->rsc_cons; gIter; gIter = gIter->next) {
Expand All @@ -247,7 +247,7 @@ sort_clone_instance(gconstpointer a, gconstpointer b, gpointer data_set)

hash2 = native_merge_weights(constraint->rsc_rh, resource2->id, hash2,
constraint->node_attribute,
constraint->score / INFINITY, FALSE, FALSE);
(float) constraint->score / INFINITY, 0);
}

for (gIter = resource2->parent->rsc_cons_lhs; gIter; gIter = gIter->next) {
Expand All @@ -257,7 +257,7 @@ sort_clone_instance(gconstpointer a, gconstpointer b, gpointer data_set)

hash2 = native_merge_weights(constraint->rsc_lh, resource2->id, hash2,
constraint->node_attribute,
constraint->score / INFINITY, FALSE, TRUE);
(float) constraint->score / INFINITY, pe_weights_positive);
}

/* Current location score */
Expand Down Expand Up @@ -514,7 +514,8 @@ clone_color(resource_t * rsc, node_t * prefer, pe_working_set_t * data_set)
rsc->allowed_nodes =
constraint->rsc_lh->cmds->merge_weights(constraint->rsc_lh, rsc->id, rsc->allowed_nodes,
constraint->node_attribute,
constraint->score / INFINITY, TRUE, TRUE);
(float) constraint->score / INFINITY,
(pe_weights_rollback | pe_weights_positive));
}

gIter = rsc->rsc_tickets;
Expand Down Expand Up @@ -1566,3 +1567,58 @@ clone_append_meta(resource_t * rsc, xmlNode * xml)
crm_xml_add_int(xml, name, clone_data->clone_node_max);
free(name);
}

GHashTable *
clone_merge_weights(resource_t * rsc, const char *rhs, GHashTable * nodes, const char *attr,
float factor, enum pe_weights flags)
{
node_t *node = NULL;
GHashTable *allowed = NULL;
GListPtr gIter = NULL;
GHashTableIter iter;

nodes = rsc_merge_weights(rsc, rhs, nodes, attr, factor, flags);

if (flags & pe_weights_positive) {
return nodes;
}

allowed = g_hash_table_new_full(crm_str_hash, g_str_equal, NULL, NULL);

/* Check to see if there are any nodes in the allowed_nodes
* list that none of the children are capable of running on */
gIter = rsc->children;
for (; gIter != NULL; gIter = gIter->next) {
resource_t *child = (resource_t *) gIter->data;

g_hash_table_iter_init(&iter, child->allowed_nodes);
while (g_hash_table_iter_next(&iter, NULL, (void **) &node)) {
gpointer p = g_hash_table_lookup(allowed, node->details->id);
int prev_score = p ? GPOINTER_TO_INT(p) : -INFINITY;
int new_score = node->weight > prev_score ? node->weight : prev_score;

g_hash_table_replace(allowed, (gpointer) (node->details->id), GINT_TO_POINTER(new_score));
}

}

g_hash_table_iter_init(&iter, nodes);
while (g_hash_table_iter_next(&iter, NULL, (void **) &node)) {
gpointer p = g_hash_table_lookup(allowed, node->details->id);

if (!p) {
continue;
}

/* This basically says, if there are nodes none
* of the clones will run on, factor that into the colocation
* rule. Otherwise ignore the native clone instances. */
if (GPOINTER_TO_INT(p) == -INFINITY) {
node->weight = merge_weights(-INFINITY * factor, node->weight);
}
}

g_hash_table_destroy(allowed);

return nodes;
}
6 changes: 3 additions & 3 deletions pengine/group.c
Expand Up @@ -479,7 +479,7 @@ group_expand(resource_t * rsc, pe_working_set_t * data_set)

GHashTable *
group_merge_weights(resource_t * rsc, const char *rhs, GHashTable * nodes, const char *attr,
int factor, gboolean allow_rollback, gboolean only_positive)
float factor, enum pe_weights flags)
{
GListPtr gIter = rsc->rsc_cons_lhs;
group_variant_data_t *group_data = NULL;
Expand All @@ -495,14 +495,14 @@ group_merge_weights(resource_t * rsc, const char *rhs, GHashTable * nodes, const

nodes =
group_data->first_child->cmds->merge_weights(group_data->first_child, rhs, nodes, attr,
factor, allow_rollback, only_positive);
factor, flags);

for (; gIter != NULL; gIter = gIter->next) {
rsc_colocation_t *constraint = (rsc_colocation_t *) gIter->data;

nodes = native_merge_weights(constraint->rsc_lh, rsc->id, nodes,
constraint->node_attribute,
constraint->score / INFINITY, allow_rollback, only_positive);
(float) constraint->score / INFINITY, flags);
}

clear_bit(rsc->flags, pe_rsc_merging);
Expand Down
38 changes: 34 additions & 4 deletions pengine/master.c
Expand Up @@ -30,6 +30,9 @@ extern gint sort_clone_instance(gconstpointer a, gconstpointer b, gpointer data_

extern int master_score(resource_t * rsc, node_t * node, int not_set_value);

static void
apply_master_prefs(resource_t * rsc);

static void
child_promoting_constraints(clone_variant_data_t * clone_data, enum pe_ordering type,
resource_t * rsc, resource_t * child, resource_t * last,
Expand Down Expand Up @@ -265,6 +268,29 @@ sort_master_instance(gconstpointer a, gconstpointer b, gpointer data_set)
return sort_clone_instance(a, b, data_set);
}

GHashTable *
master_merge_weights(resource_t * rsc, const char *rhs, GHashTable * nodes, const char *attr,
float factor, enum pe_weights flags)
{
GListPtr gIter = NULL;

/* We need to know preference scores before merging weights, make
* sure this has happened */
apply_master_prefs(rsc);
nodes = rsc_merge_weights(rsc, rhs, nodes, attr, factor, flags);

gIter = rsc->children;

for (; gIter != NULL; gIter = gIter->next) {
resource_t *child = (resource_t *) gIter->data;

nodes = child->cmds->merge_weights(child, rhs, nodes, attr, factor, flags | pe_weights_positive);
}

return nodes;
}


static void
master_promotion_order(resource_t * rsc, pe_working_set_t * data_set)
{
Expand Down Expand Up @@ -318,15 +344,18 @@ master_promotion_order(resource_t * rsc, pe_working_set_t * data_set)
* master instance should/must be colocated with
*/
if (constraint->role_lh == RSC_ROLE_MASTER) {
enum pe_weights flags = constraint->score == INFINITY ? 0 : pe_weights_rollback;

/* make sure we have allocated before merging weights */
constraint->rsc_rh->cmds->allocate(constraint->rsc_rh, NULL, data_set);
crm_trace("RHS: %s with %s: %d", constraint->rsc_lh->id, constraint->rsc_rh->id,
constraint->score);
rsc->allowed_nodes =
constraint->rsc_rh->cmds->merge_weights(constraint->rsc_rh, rsc->id,
rsc->allowed_nodes,
constraint->node_attribute,
constraint->score / INFINITY,
constraint->score ==
INFINITY ? FALSE : TRUE, FALSE);
(float) constraint->score / INFINITY,
flags);
}
}

Expand All @@ -344,7 +373,8 @@ master_promotion_order(resource_t * rsc, pe_working_set_t * data_set)
constraint->rsc_lh->cmds->merge_weights(constraint->rsc_lh, rsc->id,
rsc->allowed_nodes,
constraint->node_attribute,
constraint->score / INFINITY, TRUE, TRUE);
(float) constraint->score / INFINITY,
(pe_weights_rollback | pe_weights_positive));
}
}

Expand Down
29 changes: 11 additions & 18 deletions pengine/native.c
Expand Up @@ -259,7 +259,7 @@ node_list_attr_score(GHashTable * list, const char *attr, const char *value)
}

static void
node_hash_update(GHashTable * list1, GHashTable * list2, const char *attr, int factor,
node_hash_update(GHashTable * list1, GHashTable * list2, const char *attr, float factor,
gboolean only_positive)
{
int score = 0;
Expand All @@ -284,24 +284,24 @@ node_hash_update(GHashTable * list1, GHashTable * list2, const char *attr, int f
* TODO: Decide if we want to filter only if weight == -INFINITY
*
*/
crm_trace("%s: Filtering %d + %d*%d (factor * score)",
crm_trace("%s: Filtering %d + %f*%d (factor * score)",
node->details->uname, node->weight, factor, score);

} else if (node->weight == INFINITY_HACK) {
crm_trace("%s: Filtering %d + %d*%d (node < 0)",
crm_trace("%s: Filtering %d + %f*%d (node < 0)",
node->details->uname, node->weight, factor, score);

} else if (only_positive && new_score < 0 && node->weight > 0) {
node->weight = INFINITY_HACK;
crm_trace("%s: Filtering %d + %d*%d (score > 0)",
crm_trace("%s: Filtering %d + %f*%d (score > 0)",
node->details->uname, node->weight, factor, score);

} else if (only_positive && new_score < 0 && node->weight == 0) {
crm_trace("%s: Filtering %d + %d*%d (score == 0)",
crm_trace("%s: Filtering %d + %f*%d (score == 0)",
node->details->uname, node->weight, factor, score);

} else {
crm_trace("%s: %d + %d*%d", node->details->uname, node->weight, factor, score);
crm_trace("%s: %d + %f*%d", node->details->uname, node->weight, factor, score);
node->weight = new_score;
}
}
Expand All @@ -320,22 +320,14 @@ node_hash_dup(GHashTable * hash)

GHashTable *
native_merge_weights(resource_t * rsc, const char *rhs, GHashTable * nodes, const char *attr,
int factor, gboolean allow_rollback, gboolean only_positive)
float factor, enum pe_weights flags)
{
enum pe_weights flags = pe_weights_none;

if (only_positive) {
set_bit_inplace(flags, pe_weights_positive);
}
if (allow_rollback) {
set_bit_inplace(flags, pe_weights_rollback);
}
return rsc_merge_weights(rsc, rhs, nodes, attr, factor, flags);
}

GHashTable *
rsc_merge_weights(resource_t * rsc, const char *rhs, GHashTable * nodes, const char *attr,
int factor, enum pe_weights flags)
float factor, enum pe_weights flags)
{
GHashTable *work = NULL;
int multiplier = 1;
Expand Down Expand Up @@ -402,7 +394,7 @@ rsc_merge_weights(resource_t * rsc, const char *rhs, GHashTable * nodes, const c

crm_trace("Applying %s (%s)", constraint->id, other->id);
work = rsc_merge_weights(other, rhs, work, constraint->node_attribute,
multiplier * constraint->score / INFINITY, flags);
multiplier * (float) constraint->score / INFINITY, flags);
dump_node_scores(LOG_TRACE, NULL, rhs, work);
}

Expand Down Expand Up @@ -487,7 +479,8 @@ native_color(resource_t * rsc, node_t * prefer, pe_working_set_t * data_set)
rsc->allowed_nodes =
constraint->rsc_lh->cmds->merge_weights(constraint->rsc_lh, rsc->id, rsc->allowed_nodes,
constraint->node_attribute,
constraint->score / INFINITY, TRUE, FALSE);
(float) constraint->score / INFINITY,
pe_weights_rollback);
}

for (gIter = rsc->rsc_tickets; gIter != NULL; gIter = gIter->next) {
Expand Down

0 comments on commit 0062eab

Please sign in to comment.