accelerate lookup in non-concatenated pools

This commit is contained in:
Andreas Steffen
2009-07-17 13:58:29 +02:00
parent dfd8ddfb33
commit 848133ff1c
+40 -22
View File
@@ -224,41 +224,59 @@ static host_t* acquire_address(private_sql_attribute_t *this,
identity = get_identity(this, id); identity = get_identity(this, id);
if (identity) if (identity)
{ {
char *name; /* check for a single pool first (no concatenation and enumeration) */
enumerator_t *enumerator; if (strchr(names, ',') == NULL)
/* in a first step check for an existing lease over all pools */
enumerator = enumerator_create_token(names, ",", " ");
while (enumerator->enumerate(enumerator, &name))
{ {
pool = get_pool(this, name, &timeout); pool = get_pool(this, names, &timeout);
if (pool) if (pool)
{ {
address = check_lease(this, name, pool, identity); /* check for an existing lease */
if (address) address = check_lease(this, names, pool, identity);
if (address == NULL)
{ {
enumerator->destroy(enumerator); /* get an unallocated address or expired lease */
return address; address = get_lease(this, names, pool, timeout, identity);
} }
} }
} }
enumerator->destroy(enumerator); else
/* in a second step get an unallocated address or expired lease */
enumerator = enumerator_create_token(names, ",", " ");
while (enumerator->enumerate(enumerator, &name))
{ {
pool = get_pool(this, name, &timeout); enumerator_t *enumerator;
if (pool) char *name;
/* in a first step check for an existing lease over all pools */
enumerator = enumerator_create_token(names, ",", " ");
while (enumerator->enumerate(enumerator, &name))
{ {
address = get_lease(this, name, pool, timeout, identity); pool = get_pool(this, name, &timeout);
if (address) if (pool)
{ {
break; address = check_lease(this, name, pool, identity);
if (address)
{
enumerator->destroy(enumerator);
return address;
}
} }
} }
enumerator->destroy(enumerator);
/* in a second step get an unallocated address or expired lease */
enumerator = enumerator_create_token(names, ",", " ");
while (enumerator->enumerate(enumerator, &name))
{
pool = get_pool(this, name, &timeout);
if (pool)
{
address = get_lease(this, name, pool, timeout, identity);
if (address)
{
break;
}
}
}
enumerator->destroy(enumerator);
} }
enumerator->destroy(enumerator);
} }
return address; return address;
} }