1
1

regx: fixed the order of hosts for ranges with different prefixes

Example:
For the list of hosts `a01,b00,a00` a regex is generated:
`a[2:1.0],b[2:0]`, where `a`-hosts prefixes moved to the begining,
it breaks the hosts ordering.
This commit fixes regex for that case to `a[2:1],b[2:0],a[2:0]`

Signed-off-by: Boris Karasev <karasev.b@gmail.com>
Этот коммит содержится в:
Boris Karasev 2019-01-30 09:23:36 +06:00
родитель 1967e41a71
Коммит 46e38b9193
3 изменённых файлов: 64 добавлений и 80 удалений

Просмотреть файл

@ -154,38 +154,25 @@ static int nidmap_create(opal_pointer_array_t *pool, char **regex)
}
/* is this node name already on our list? */
found = false;
for (item = opal_list_get_first(&nodenms);
!found && item != opal_list_get_end(&nodenms);
item = opal_list_get_next(item)) {
ndreg = (orte_regex_node_t*)item;
if (0 < strlen(prefix) && NULL == ndreg->prefix) {
continue;
}
if (0 == strlen(prefix) && NULL != ndreg->prefix) {
continue;
}
if (0 < strlen(prefix) && NULL != ndreg->prefix
&& 0 != strcmp(prefix, ndreg->prefix)) {
continue;
}
if (NULL == suffix && NULL != ndreg->suffix) {
continue;
}
if (NULL != suffix && NULL == ndreg->suffix) {
continue;
}
if (NULL != suffix && NULL != ndreg->suffix &&
0 != strcmp(suffix, ndreg->suffix)) {
continue;
}
if (numdigits != ndreg->num_digits) {
continue;
}
if (0 != opal_list_get_size(&nodenms)) {
ndreg = (orte_regex_node_t*)opal_list_get_last(&nodenms);
if ((0 < strlen(prefix) && NULL == ndreg->prefix) ||
(0 == strlen(prefix) && NULL != ndreg->prefix) ||
(0 < strlen(prefix) && NULL != ndreg->prefix &&
0 != strcmp(prefix, ndreg->prefix)) ||
(NULL == suffix && NULL != ndreg->suffix) ||
(NULL != suffix && NULL == ndreg->suffix) ||
(NULL != suffix && NULL != ndreg->suffix &&
0 != strcmp(suffix, ndreg->suffix)) ||
(numdigits != ndreg->num_digits)) {
found = false;
} else {
/* found a match - flag it */
found = true;
/* get the last range on this nodeid - we do this
* to preserve order
*/
}
}
if (found) {
range = (orte_regex_range_t*)opal_list_get_last(&ndreg->ranges);
if (NULL == range) {
/* first range for this nodeid */
@ -193,22 +180,18 @@ static int nidmap_create(opal_pointer_array_t *pool, char **regex)
range->vpid = nodenum;
range->cnt = 1;
opal_list_append(&ndreg->ranges, &range->super);
break;
}
/* see if the node number is out of sequence */
if (nodenum != (range->vpid + range->cnt)) {
} else if (nodenum != (range->vpid + range->cnt)) {
/* start a new range */
range = OBJ_NEW(orte_regex_range_t);
range->vpid = nodenum;
range->cnt = 1;
opal_list_append(&ndreg->ranges, &range->super);
break;
}
} else {
/* everything matches - just increment the cnt */
range->cnt++;
break;
}
if (!found) {
} else {
/* need to add it */
ndreg = OBJ_NEW(orte_regex_node_t);
if (0 < strlen(prefix)) {

Просмотреть файл

@ -170,35 +170,25 @@ static int nidmap_create(opal_pointer_array_t *pool, char **regex)
}
/* is this node name already on our list? */
found = false;
for (item = opal_list_get_first(&nodenms);
!found && item != opal_list_get_end(&nodenms);
item = opal_list_get_next(item)) {
ndreg = (orte_regex_node_t*)item;
if (0 < strlen(prefix) && NULL == ndreg->prefix) {
continue;
}
if (0 == strlen(prefix) && NULL != ndreg->prefix) {
continue;
}
if (0 < strlen(prefix) && NULL != ndreg->prefix
&& 0 != strcmp(prefix, ndreg->prefix)) {
continue;
}
if (NULL == suffix && NULL != ndreg->suffix) {
continue;
}
if (NULL != suffix && NULL == ndreg->suffix) {
continue;
}
if (NULL != suffix && NULL != ndreg->suffix &&
0 != strcmp(suffix, ndreg->suffix)) {
continue;
}
if (numdigits != ndreg->num_digits) {
continue;
}
if (0 != opal_list_get_size(&nodenms)) {
ndreg = (orte_regex_node_t*)opal_list_get_last(&nodenms);
if ((0 < strlen(prefix) && NULL == ndreg->prefix) ||
(0 == strlen(prefix) && NULL != ndreg->prefix) ||
(0 < strlen(prefix) && NULL != ndreg->prefix &&
0 != strcmp(prefix, ndreg->prefix)) ||
(NULL == suffix && NULL != ndreg->suffix) ||
(NULL != suffix && NULL == ndreg->suffix) ||
(NULL != suffix && NULL != ndreg->suffix &&
0 != strcmp(suffix, ndreg->suffix)) ||
(numdigits != ndreg->num_digits)) {
found = false;
} else {
/* found a match - flag it */
found = true;
}
}
if (found) {
/* get the last range on this nodeid - we do this
* to preserve order
*/
@ -209,22 +199,18 @@ static int nidmap_create(opal_pointer_array_t *pool, char **regex)
range->vpid = nodenum;
range->cnt = 1;
opal_list_append(&ndreg->ranges, &range->super);
break;
}
/* see if the node number is out of sequence */
if (nodenum != (range->vpid + range->cnt)) {
} else if (nodenum != (range->vpid + range->cnt)) {
/* start a new range */
range = OBJ_NEW(orte_regex_range_t);
range->vpid = nodenum;
range->cnt = 1;
opal_list_append(&ndreg->ranges, &range->super);
break;
}
} else {
/* everything matches - just increment the cnt */
range->cnt++;
break;
}
if (!found) {
} else {
/* need to add it */
ndreg = OBJ_NEW(orte_regex_node_t);
if (0 < strlen(prefix)) {

Просмотреть файл

@ -21,7 +21,7 @@
int main(int argc, char **argv)
{
int rc;
char *regex, **nodelist;
char *regex = NULL, **nodelist;
char **nodes=NULL;
int i;
opal_pointer_array_t *node_pool;
@ -71,7 +71,7 @@ int main(int argc, char **argv)
nptr->index = opal_pointer_array_add(node_pool, nptr);
}
opal_argv_free(nodelist);
if (ORTE_SUCCESS != (rc = orte_regx.nidmap_create(node_pool, &regex))) {
@ -85,14 +85,29 @@ int main(int argc, char **argv)
}
free(regex);
regex = opal_argv_join(nodes, ',');
opal_argv_free(nodes);
if (0 == strcmp(regex, argv[1])) {
fprintf(stderr, "EXACT MATCH\n");
} else {
fprintf(stderr, "ERROR: %s\n", regex);
if (opal_argv_count(nodes) != opal_argv_count(nodelist)) {
fprintf(stderr, "ERROR: number of nodes %d, expected %d\n",
opal_argv_count(nodes), opal_argv_count(nodelist));
goto exit;
}
for (i=0; NULL != nodelist[i]; i++) {
if (0 == strcmp(nodelist[i], nodes[i])) {
fprintf(stderr, "%s OK\n", nodelist[i]);
}
fprintf(stderr, "%s ERROR, expect %s\n", nodes[i], nodelist[i]);
}
}
free(regex);
regex = NULL;
}
exit:
opal_argv_free(nodelist);
opal_argv_free(nodes);
for (i=0; (nptr = opal_pointer_array_get_item(node_pool, i)) != NULL; i++) {
free(nptr->name);