# Verifies sflqUpdateLease4 function
pgsql_sflqUpdateLease4() {
- test_start "pgsql.pgsql_sflQUpdateLease4"
+ test_start "pgsql.pgsql_sflqUpdateLease4"
# Let's wipe the whole database
pgsql_wipe
# Update the lease to declined
sql="select sflqUpdateLease4($bigint_address, NULL, NULL, 3600::bigint, '$future'::timestamp,\
1::bigint, 'f'::boolean, 'f'::boolean, NULL,\
- 1::bigint, NULL, NULL, NULL, 0::bigint)";
+ 1::bigint, NULL, NULL, NULL, 0::bigint,\
+ $bigint_address, '$future'::timestamp)";
run_statement "sflqUpdateLease4 1" "$sql"
# Verify lease is updated lease4 and but not present free_lease4
# Update the lease to be reclaimed.
sql="select sflqUpdateLease4($bigint_address, NULL, NULL, 3600::bigint, '$future'::timestamp,\
1::bigint, 'f'::boolean, 'f'::boolean, NULL,\
- 2::bigint, NULL, NULL, NULL, 0::bigint)";
+ 2::bigint, NULL, NULL, NULL, 0::bigint,\
+ $bigint_address, '$future'::timestamp)";
run_statement "sflqUpdateLease4 2" "$sql"
# Verify lease is updated in lease4 and added to free_lease4
# Update the expired lease.
sql="select sflqUpdateLease4($bigint_address, NULL, NULL, 3600::bigint, '$expired'::timestamp,\
1::bigint, 'f'::boolean, 'f'::boolean, NULL,\
- 0::bigint, NULL, NULL, NULL, 0::bigint)";
- run_statement "sflqUpdateLease4 3" "$sql"
+ 0::bigint, NULL, NULL, NULL, 0::bigint,\
+ $bigint_address, '$expired'::timestamp)";
+ run_statement "sflqUpdateLease4 4" "$sql"
# Verify lease is updated in lease4 and added to free_lease4
sql="select count(address) from lease4 where address = $bigint_address and state = 0;"
$subnet_id::bigint, 3600::bigint, $ltype::smallint, \
$iaid::integer, 128::smallint, 'f'::boolean, 'f'::boolean,\
NULL, NULL, 0::smallint, 0::smallint, $state::bigint, \
- NULL, 0::bigint)"
+ NULL, 0::bigint, $in_address::inet, '$future'::timestamp)"
run_statement "sflqUpdateLease6 $in_address" "$sql"
# Verify lease is updated in lease6 and but not present in free_lease6
$subnet_id::bigint, 3600::bigint, $ltype::smallint, \
$iaid::integer, 128::smallint, 'f'::boolean, 'f'::boolean,\
NULL, NULL, 0::smallint, 0::smallint, $state::bigint, \
- NULL, 0::bigint)"
+ NULL, 0::bigint, $in_address::inet, '$future'::timestamp)"
run_statement "sflqUpdateLease6 $in_address" "$sql"
# Verify lease is updated in lease6 and added to free_lease6
$subnet_id::bigint, 3600::bigint, $ltype::smallint, \
$iaid::integer, 128::smallint, 'f'::boolean, 'f'::boolean,\
NULL, NULL, 0::smallint, 0::smallint, $state::bigint, \
- NULL, 0::bigint)"
+ NULL, 0::bigint, $in_address::inet, '$expired'::timestamp)"
run_statement "sflqUpdateLease6 $in_address" "$sql"
# Verify lease is updated in lease6 and added to free_lease6
"SELECT sflqInsertLease4($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)" },
// SFLQ_UPDATE_LEASE4
- // Code sets all 16 bindinggs, we only need first 14.
{ 16, { OID_INT8, OID_BYTEA, OID_BYTEA, OID_INT8, OID_TIMESTAMP, OID_INT8,
OID_BOOL, OID_BOOL, OID_VARCHAR, OID_INT8, OID_TEXT, OID_BYTEA,
OID_BYTEA, OID_INT8, OID_INT8, OID_TIMESTAMP },
"slfqUpdateLease4",
- "SELECT sflqUpdateLease4($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)" },
+ "SELECT sflqUpdateLease4($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16)" },
// SLQ_DELETE_LEASE4
{ 2, { OID_INT8, OID_TIMESTAMP },
"$10, $11, $12, $13, $14, $15, $16, $17, $18)" },
// SFLQ_UPDATE_LEASE6
- // Code sets all 20 bindinggs, we only need first 18.
{ 20, { OID_VARCHAR, OID_BYTEA, OID_INT8, OID_TIMESTAMP, OID_INT8, OID_INT8,
OID_INT2, OID_INT4, OID_INT2, OID_BOOL, OID_BOOL, OID_VARCHAR,
OID_BYTEA, OID_INT2, OID_INT2,
OID_INT8, OID_TEXT, OID_INT8, OID_TEXT, OID_TIMESTAMP },
"slfqUpdateLease6",
"SELECT sflqUpdateLease6(cast($1 as inet), $2, $3, $4, $5, $6, $7, $8, $9, "
- "$10, $11, $12, $13, $14, $15, $16, $17, $18)" },
+ "$10, $11, $12, $13, $14, $15, $16, $17, $18, "
+ "cast($19 as inet), $20)" },
// SFLQ_DELETE_LEASE6
{ 2, { OID_VARCHAR, OID_TIMESTAMP },
-- Remember the lease affected row count.
SET lease_row_count = row_count();
- -- Update SFLQ data.
- -- If it is expired or expired-reclaimed add it to the free lease queue
- -- otherwise delete it from the free lease queue.
- IF (p_state = 2 OR (p_expire <= now() AND p_valid_lifetime != 0xFFFFFFFF))
+ IF (lease_row_count > 0)
THEN
- -- Insert into free queue. Ignore duplicates.
- INSERT INTO free_lease4 (address) VALUES (p_address)
- ON DUPLICATE KEY UPDATE address = p_address;
- ELSE
- -- Delete it from the free queue. Ignore nothing deleted.
- DELETE FROM free_lease4 WHERE address = p_address;
+ -- Update SFLQ data.
+ -- If it is expired or expired-reclaimed add it to the free lease queue
+ -- otherwise delete it from the free lease queue.
+ IF (p_state = 2 OR (p_expire <= now() AND p_valid_lifetime != 0xFFFFFFFF))
+ THEN
+ -- Insert into free queue. Ignore duplicates.
+ INSERT INTO free_lease4 (address) VALUES (p_address)
+ ON DUPLICATE KEY UPDATE address = p_address;
+ ELSE
+ -- Delete it from the free queue. Ignore nothing deleted.
+ DELETE FROM free_lease4 WHERE address = p_address;
+ END IF;
END IF;
COMMIT;
- -- If lease was updated but SFLQ logic changed no rows
- -- force affected row count back to 1.
+ -- COMMIT resets row count so regardless of what happened
+ -- with SLFQ if the lease was updated force affected row count
+ -- back to 1.
IF (lease_row_count > 0)
THEN
CALL sflqFakeRowCount();
COMMIT;
- -- If the lease was deleted but SFLQ logic changed no rows
- -- force affected row count back to 1.
+ -- COMMIT resets row count so regardless of what happened
+ -- with SLFQ if the lease was deleted force affected row count
+ -- back to 1.
IF (lease_row_count > 0)
THEN
CALL sflqFakeRowCount();
-- Remember the lease affected row count.
SET lease_row_count = row_count();
- -- Update SFLQ data.
- -- If it is expired or expired-reclaimed add it to the free lease queue
- -- otherwise delete it from the free lease queue.
- IF (p_state = 2 OR (p_expire <= now() AND p_valid_lifetime != 0xFFFFFFFF))
+ IF (lease_row_count > 0)
THEN
- -- Insert into free queue. Ignore duplicates.
- INSERT INTO free_lease6 (address, bin_address)
- VALUES (INET6_NTOA(p_address), p_address)
- ON DUPLICATE KEY UPDATE bin_address = p_address;
- ELSE
- -- Delete it from the free queue. Ignore nothing deleted.
- DELETE FROM free_lease6 WHERE bin_address = p_address;
+ -- Update SFLQ data.
+ -- If it is expired or expired-reclaimed add it to the free lease queue
+ -- otherwise delete it from the free lease queue.
+ IF (p_state = 2 OR (p_expire <= now() AND p_valid_lifetime != 0xFFFFFFFF))
+ THEN
+ -- Insert into free queue. Ignore duplicates.
+ INSERT INTO free_lease6 (address, bin_address)
+ VALUES (INET6_NTOA(p_address), p_address)
+ ON DUPLICATE KEY UPDATE bin_address = p_address;
+ ELSE
+ -- Delete it from the free queue. Ignore nothing deleted.
+ DELETE FROM free_lease6 WHERE bin_address = p_address;
+ END IF;
END IF;
COMMIT;
- -- If lease was updated but SFLQ logic changed no rows
- -- force affected row count back to 1.
+ -- COMMIT resets row count so regardless of what happened
+ -- with SLFQ if the lease was updated force affected row count
+ -- back to 1.
IF (lease_row_count > 0)
THEN
CALL sflqFakeRowCount();
COMMIT;
- -- If the lease was deleted but SFLQ logic changed no rows
- -- force affected row count back to 1.
+ -- COMMIT resets row count so regardless of what happened
+ -- with SLFQ if the lease was deleted force affected row count
+ -- back to 1.
IF (lease_row_count > 0)
THEN
CALL sflqFakeRowCount();
DROP FUNCTION IF EXISTS sflqInsertLease6;
DROP FUNCTION IF EXISTS sflqUpdateLease6;
DROP FUNCTION IF EXISTS sflqDeleteLease6;
+DROP PROCEDURE IF EXISTS sflqFakeRowCount;
DROP TABLE IF EXISTS free_lease4;
DROP TABLE IF EXISTS flq_pool4;
DROP TABLE IF EXISTS free_lease6;
-- Remember the lease affected row count.
SET lease_row_count = row_count();
- -- Update SFLQ data.
- -- If it is expired or expired-reclaimed add it to the free lease queue
- -- otherwise delete it from the free lease queue.
- IF (p_state = 2 OR (p_expire <= now() AND p_valid_lifetime != 0xFFFFFFFF))
+ IF (lease_row_count > 0)
THEN
- -- Insert into free queue. Ignore duplicates.
- INSERT INTO free_lease4 (address) VALUES (p_address)
- ON DUPLICATE KEY UPDATE address = p_address;
- ELSE
- -- Delete it from the free queue. Ignore nothing deleted.
- DELETE FROM free_lease4 WHERE address = p_address;
+ -- Update SFLQ data.
+ -- If it is expired or expired-reclaimed add it to the free lease queue
+ -- otherwise delete it from the free lease queue.
+ IF (p_state = 2 OR (p_expire <= now() AND p_valid_lifetime != 0xFFFFFFFF))
+ THEN
+ -- Insert into free queue. Ignore duplicates.
+ INSERT INTO free_lease4 (address) VALUES (p_address)
+ ON DUPLICATE KEY UPDATE address = p_address;
+ ELSE
+ -- Delete it from the free queue. Ignore nothing deleted.
+ DELETE FROM free_lease4 WHERE address = p_address;
+ END IF;
END IF;
COMMIT;
- -- If lease was updated but SFLQ logic changed no rows
- -- force affected row count back to 1.
+ -- COMMIT resets row count so regardless of what happened
+ -- with SLFQ if the lease was updated force affected row count
+ -- back to 1.
IF (lease_row_count > 0)
THEN
CALL sflqFakeRowCount();
COMMIT;
- -- If the lease was deleted but SFLQ logic changed no rows
- -- force affected row count back to 1.
+ -- COMMIT resets row count so regardless of what happened
+ -- with SLFQ if the lease was deleted force affected row count
+ -- back to 1.
IF (lease_row_count > 0)
THEN
CALL sflqFakeRowCount();
-- Remember the lease affected row count.
SET lease_row_count = row_count();
- -- Update SFLQ data.
- -- If it is expired or expired-reclaimed add it to the free lease queue
- -- otherwise delete it from the free lease queue.
- IF (p_state = 2 OR (p_expire <= now() AND p_valid_lifetime != 0xFFFFFFFF))
+ IF (lease_row_count > 0)
THEN
- -- Insert into free queue. Ignore duplicates.
- INSERT INTO free_lease6 (address, bin_address)
- VALUES (INET6_NTOA(p_address), p_address)
- ON DUPLICATE KEY UPDATE bin_address = p_address;
- ELSE
- -- Delete it from the free queue. Ignore nothing deleted.
- DELETE FROM free_lease6 WHERE bin_address = p_address;
+ -- Update SFLQ data.
+ -- If it is expired or expired-reclaimed add it to the free lease queue
+ -- otherwise delete it from the free lease queue.
+ IF (p_state = 2 OR (p_expire <= now() AND p_valid_lifetime != 0xFFFFFFFF))
+ THEN
+ -- Insert into free queue. Ignore duplicates.
+ INSERT INTO free_lease6 (address, bin_address)
+ VALUES (INET6_NTOA(p_address), p_address)
+ ON DUPLICATE KEY UPDATE bin_address = p_address;
+ ELSE
+ -- Delete it from the free queue. Ignore nothing deleted.
+ DELETE FROM free_lease6 WHERE bin_address = p_address;
+ END IF;
END IF;
COMMIT;
- -- If lease was updated but SFLQ logic changed no rows
- -- force affected row count back to 1.
+ -- COMMIT resets row count so regardless of what happened
+ -- with SLFQ if the lease was updated force affected row count
+ -- back to 1.
IF (lease_row_count > 0)
THEN
CALL sflqFakeRowCount();
COMMIT;
- -- If the lease was deleted but SFLQ logic changed no rows
- -- force affected row count back to 1.
+ -- COMMIT resets row count so regardless of what happened
+ -- with SLFQ if the lease was deleted force affected row count
+ -- back to 1.
IF (lease_row_count > 0)
THEN
CALL sflqFakeRowCount();
END;
$$ LANGUAGE plpgsql;
+-- Procedure to create an affected rows count of 1.
+-- Used after udpate and delete lease operations.
+CREATE OR REPLACE FUNCTION sflqFakeRowCount()
+RETURNS VOID
+LANGUAGE plpgsql AS $$
+BEGIN
+ IF (get_session_value('kea.sflq_dummy_row_count_exists') IS NOT NULL)
+ THEN
+ UPDATE sflq_dummy_row_count SET dummy_val = NOT dummy_val;
+ ELSE
+ CREATE TEMPORARY TABLE sflq_dummy_row_count ( dummy_val BOOLEAN );
+ PERFORM set_session_value('kea.sflq_dummy_row_count_exists', true);
+ INSERT INTO sflq_dummy_row_count (dummy_val) VALUES (false);
+ END IF;
+END;
+$$;
+
-- Procedure to insert a v4 lease and update SFLQ data.
CREATE OR REPLACE FUNCTION sflqInsertLease4(p_address BIGINT,
p_hwaddr BYTEA,
p_user_context TEXT,
p_relay_id BYTEA,
p_remote_id BYTEA,
- p_pool_id BIGINT)
+ p_pool_id BIGINT,
+ p_where_address BIGINT,
+ p_where_expire TIMESTAMP WITH TIME ZONE)
RETURNS VOID
LANGUAGE plpgsql AS $$
+DECLARE
+ row_count INTEGER;
BEGIN
UPDATE lease4 SET address = p_address, hwaddr = p_hwaddr, client_id = p_client_id,
valid_lifetime = p_valid_lifetime, expire = p_expire,
fqdn_rev = p_fqdn_rev, hostname = p_hostname, state = p_state,
user_context = p_user_context, relay_id = p_relay_id,
remote_id = p_remote_id, pool_id = p_pool_id
- WHERE (address = p_address and expire = p_expire);
+ WHERE (address = p_where_address and expire = p_where_expire);
- -- Update SFLQ data.
- -- If it is expired or expired-reclaimed delete add it to the
- -- free queue otherwise delete it from the free queue.
- IF (p_state = 2 OR (p_expire <= now() AND p_valid_lifetime != x'FFFFFFFF'::bigint))
+ -- Remember the lease affected row count.
+ GET DIAGNOSTICS row_count = ROW_COUNT;
+
+ IF (row_count > 0)
THEN
- -- Insert into free queue. Ignore duplicates.
- INSERT INTO free_lease4 (address) VALUES (p_address)
- ON CONFLICT DO NOTHING;
- ELSE
- -- Delete it from the free queue. Ignore nothing deleted.
- DELETE FROM free_lease4 WHERE address = p_address;
+ -- Update SFLQ data.
+ -- If it is expired or expired-reclaimed delete add it to the
+ -- free queue otherwise delete it from the free queue.
+ IF (p_state = 2 OR (p_expire <= now() AND p_valid_lifetime != x'FFFFFFFF'::bigint))
+ THEN
+ -- Insert into free queue. Ignore duplicates.
+ INSERT INTO free_lease4 (address) VALUES (p_address)
+ ON CONFLICT DO NOTHING;
+ ELSE
+ -- Delete it from the free queue. Ignore nothing deleted.
+ DELETE FROM free_lease4 WHERE address = p_address;
+ END IF;
+
+ GET DIAGNOSTICS row_count = ROW_COUNT;
+ -- If lease was updated but SFLQ logic changed no rows
+ -- force affected row count back to 1.
+ IF (row_count = 0)
+ THEN
+ PERFORM sflqFakeRowCount();
+ END IF;
END IF;
END;
$$;
BEGIN
-- Delete the lease from lease4.
DELETE FROM lease4 WHERE address = p_address AND expire = p_expire;
+
+ -- Remember the lease affected row count.
GET DIAGNOSTICS row_count = ROW_COUNT;
-- If we didn't delete it either it was already gone or expire
-- Insert into free queue. Ignore duplicates.
INSERT INTO free_lease4 (address) VALUES (p_address)
ON CONFLICT DO NOTHING;
+
+ GET DIAGNOSTICS row_count = ROW_COUNT;
+ IF (row_count = 0)
+ THEN
+ -- If the lease was deleted but SFLQ logic changed no rows
+ -- force affected row count back to 1.
+ PERFORM sflqFakeRowCount();
+ END IF;
END IF;
END;
$$;
p_hwaddr_source SMALLINT,
p_state BIGINT,
p_user_context TEXT,
- p_pool_id BIGINT)
+ p_pool_id BIGINT,
+ p_where_address INET,
+ p_where_expire TIMESTAMP WITH TIME ZONE)
RETURNS VOID
LANGUAGE plpgsql AS $$
+DECLARE
+ row_count INTEGER;
BEGIN
UPDATE lease6
SET address = p_address, duid = p_duid, valid_lifetime = p_valid_lifetime,
fqdn_fwd = p_fqdn_fwd, fqdn_rev = p_fqdn_rev, hostname = p_hostname,
hwaddr = p_hwaddr, hwtype = p_hwtype, hwaddr_source = p_hwaddr_source,
state = p_state, user_context = p_user_context, pool_id = p_pool_id
- WHERE (address = p_address and expire = p_expire);
+ WHERE (address = p_where_address and expire = p_where_expire);
- -- Update SFLQ data.
- -- If it is expired or expired-reclaimed delete add it to the
- -- free queue otherwise delete it from the free queue.
- IF (p_state = 2 OR (p_expire <= now() AND p_valid_lifetime != x'FFFFFFFF'::bigint))
+ -- Remember the lease affected row count.
+ GET DIAGNOSTICS row_count = ROW_COUNT;
+
+ IF (row_count > 0)
THEN
- -- Insert into free queue. Ignore duplicates.
- INSERT INTO free_lease6 (address, bin_address)
- VALUES (p_address, inetToBytea(p_address))
- ON CONFLICT DO NOTHING;
- ELSE
- -- Delete it from the free queue. Ignore nothing deleted.
- DELETE FROM free_lease6 WHERE address = p_address;
+ -- Update SFLQ data.
+ -- If it is expired or expired-reclaimed delete add it to the
+ -- free queue otherwise delete it from the free queue.
+ IF (p_state = 2 OR (p_expire <= now() AND p_valid_lifetime != x'FFFFFFFF'::bigint))
+ THEN
+ -- Insert into free queue. Ignore duplicates.
+ INSERT INTO free_lease6 (address, bin_address)
+ VALUES (p_address, inetToBytea(p_address))
+ ON CONFLICT DO NOTHING;
+ ELSE
+ -- Delete it from the free queue. Ignore nothing deleted.
+ DELETE FROM free_lease6 WHERE address = p_address;
+ END IF;
+
+ GET DIAGNOSTICS row_count = ROW_COUNT;
+ -- If lease was updated but SFLQ logic changed no rows
+ -- force affected row count back to 1.
+ IF (row_count > 0)
+ THEN
+ PERFORM sflqFakeRowCount();
+ END IF;
END IF;
END;
$$;
BEGIN
-- Delete the lease from lease6.
DELETE FROM lease6 WHERE address = p_address AND expire = p_expire;
+
+ -- Remember the lease affected row count.
GET DIAGNOSTICS row_count = ROW_COUNT;
-- If we didn't delete it either it was already gone or expire
INSERT INTO free_lease6 (address, bin_address)
VALUES (p_address, inetToBytea(p_address))
ON CONFLICT DO NOTHING;
+
+ GET DIAGNOSTICS row_count = ROW_COUNT;
+ IF (row_count = 0)
+ THEN
+ -- If the lease was deleted but SFLQ logic changed no rows
+ -- force affected row count back to 1.
+ PERFORM sflqFakeRowCount();
+ END IF;
END IF;
END;
$$;
DROP FUNCTION IF EXISTS sflqInsertLease6;
DROP FUNCTION IF EXISTS sflqUpdateLease6;
DROP FUNCTION IF EXISTS sflqDeleteLease6;
+DROP FUNCTION IF EXISTS sflqFakeRowCount;
DROP TABLE IF EXISTS free_lease4;
DROP TABLE IF EXISTS flq_pool4;
DROP TABLE IF EXISTS free_lease6;
END;
\$\$ LANGUAGE plpgsql;
+-- Procedure to create an affected rows count of 1.
+-- Used after udpate and delete lease operations.
+CREATE OR REPLACE FUNCTION sflqFakeRowCount()
+RETURNS VOID
+LANGUAGE plpgsql AS \$\$
+BEGIN
+ IF (get_session_value('kea.sflq_dummy_row_count_exists') IS NOT NULL)
+ THEN
+ UPDATE sflq_dummy_row_count SET dummy_val = NOT dummy_val;
+ ELSE
+ CREATE TEMPORARY TABLE sflq_dummy_row_count ( dummy_val BOOLEAN );
+ PERFORM set_session_value('kea.sflq_dummy_row_count_exists', true);
+ INSERT INTO sflq_dummy_row_count (dummy_val) VALUES (false);
+ END IF;
+END;
+\$\$;
+
-- Procedure to insert a v4 lease and update SFLQ data.
CREATE OR REPLACE FUNCTION sflqInsertLease4(p_address BIGINT,
p_hwaddr BYTEA,
p_user_context TEXT,
p_relay_id BYTEA,
p_remote_id BYTEA,
- p_pool_id BIGINT)
+ p_pool_id BIGINT,
+ p_where_address BIGINT,
+ p_where_expire TIMESTAMP WITH TIME ZONE)
RETURNS VOID
LANGUAGE plpgsql AS \$\$
+DECLARE
+ row_count INTEGER;
BEGIN
UPDATE lease4 SET address = p_address, hwaddr = p_hwaddr, client_id = p_client_id,
valid_lifetime = p_valid_lifetime, expire = p_expire,
fqdn_rev = p_fqdn_rev, hostname = p_hostname, state = p_state,
user_context = p_user_context, relay_id = p_relay_id,
remote_id = p_remote_id, pool_id = p_pool_id
- WHERE (address = p_address and expire = p_expire);
+ WHERE (address = p_where_address and expire = p_where_expire);
- -- Update SFLQ data.
- -- If it is expired or expired-reclaimed delete add it to the
- -- free queue otherwise delete it from the free queue.
- IF (p_state = 2 OR (p_expire <= now() AND p_valid_lifetime != x'FFFFFFFF'::bigint))
+ -- Remember the lease affected row count.
+ GET DIAGNOSTICS row_count = ROW_COUNT;
+
+ IF (row_count > 0)
THEN
- -- Insert into free queue. Ignore duplicates.
- INSERT INTO free_lease4 (address) VALUES (p_address)
- ON CONFLICT DO NOTHING;
- ELSE
- -- Delete it from the free queue. Ignore nothing deleted.
- DELETE FROM free_lease4 WHERE address = p_address;
+ -- Update SFLQ data.
+ -- If it is expired or expired-reclaimed delete add it to the
+ -- free queue otherwise delete it from the free queue.
+ IF (p_state = 2 OR (p_expire <= now() AND p_valid_lifetime != x'FFFFFFFF'::bigint))
+ THEN
+ -- Insert into free queue. Ignore duplicates.
+ INSERT INTO free_lease4 (address) VALUES (p_address)
+ ON CONFLICT DO NOTHING;
+ ELSE
+ -- Delete it from the free queue. Ignore nothing deleted.
+ DELETE FROM free_lease4 WHERE address = p_address;
+ END IF;
+
+ GET DIAGNOSTICS row_count = ROW_COUNT;
+ -- If lease was updated but SFLQ logic changed no rows
+ -- force affected row count back to 1.
+ IF (row_count = 0)
+ THEN
+ PERFORM sflqFakeRowCount();
+ END IF;
END IF;
END;
\$\$;
BEGIN
-- Delete the lease from lease4.
DELETE FROM lease4 WHERE address = p_address AND expire = p_expire;
+
+ -- Remember the lease affected row count.
GET DIAGNOSTICS row_count = ROW_COUNT;
-- If we didn't delete it either it was already gone or expire
-- Insert into free queue. Ignore duplicates.
INSERT INTO free_lease4 (address) VALUES (p_address)
ON CONFLICT DO NOTHING;
+
+ GET DIAGNOSTICS row_count = ROW_COUNT;
+ IF (row_count = 0)
+ THEN
+ -- If the lease was deleted but SFLQ logic changed no rows
+ -- force affected row count back to 1.
+ PERFORM sflqFakeRowCount();
+ END IF;
END IF;
END;
\$\$;
p_hwaddr_source SMALLINT,
p_state BIGINT,
p_user_context TEXT,
- p_pool_id BIGINT)
+ p_pool_id BIGINT,
+ p_where_address INET,
+ p_where_expire TIMESTAMP WITH TIME ZONE)
RETURNS VOID
LANGUAGE plpgsql AS \$\$
+DECLARE
+ row_count INTEGER;
BEGIN
UPDATE lease6
SET address = p_address, duid = p_duid, valid_lifetime = p_valid_lifetime,
fqdn_fwd = p_fqdn_fwd, fqdn_rev = p_fqdn_rev, hostname = p_hostname,
hwaddr = p_hwaddr, hwtype = p_hwtype, hwaddr_source = p_hwaddr_source,
state = p_state, user_context = p_user_context, pool_id = p_pool_id
- WHERE (address = p_address and expire = p_expire);
+ WHERE (address = p_where_address and expire = p_where_expire);
- -- Update SFLQ data.
- -- If it is expired or expired-reclaimed delete add it to the
- -- free queue otherwise delete it from the free queue.
- IF (p_state = 2 OR (p_expire <= now() AND p_valid_lifetime != x'FFFFFFFF'::bigint))
+ -- Remember the lease affected row count.
+ GET DIAGNOSTICS row_count = ROW_COUNT;
+
+ IF (row_count > 0)
THEN
- -- Insert into free queue. Ignore duplicates.
- INSERT INTO free_lease6 (address, bin_address)
- VALUES (p_address, inetToBytea(p_address))
- ON CONFLICT DO NOTHING;
- ELSE
- -- Delete it from the free queue. Ignore nothing deleted.
- DELETE FROM free_lease6 WHERE address = p_address;
+ -- Update SFLQ data.
+ -- If it is expired or expired-reclaimed delete add it to the
+ -- free queue otherwise delete it from the free queue.
+ IF (p_state = 2 OR (p_expire <= now() AND p_valid_lifetime != x'FFFFFFFF'::bigint))
+ THEN
+ -- Insert into free queue. Ignore duplicates.
+ INSERT INTO free_lease6 (address, bin_address)
+ VALUES (p_address, inetToBytea(p_address))
+ ON CONFLICT DO NOTHING;
+ ELSE
+ -- Delete it from the free queue. Ignore nothing deleted.
+ DELETE FROM free_lease6 WHERE address = p_address;
+ END IF;
+
+ GET DIAGNOSTICS row_count = ROW_COUNT;
+ -- If lease was updated but SFLQ logic changed no rows
+ -- force affected row count back to 1.
+ IF (row_count > 0)
+ THEN
+ PERFORM sflqFakeRowCount();
+ END IF;
END IF;
END;
\$\$;
BEGIN
-- Delete the lease from lease6.
DELETE FROM lease6 WHERE address = p_address AND expire = p_expire;
+
+ -- Remember the lease affected row count.
GET DIAGNOSTICS row_count = ROW_COUNT;
-- If we didn't delete it either it was already gone or expire
INSERT INTO free_lease6 (address, bin_address)
VALUES (p_address, inetToBytea(p_address))
ON CONFLICT DO NOTHING;
+
+ GET DIAGNOSTICS row_count = ROW_COUNT;
+ IF (row_count = 0)
+ THEN
+ -- If the lease was deleted but SFLQ logic changed no rows
+ -- force affected row count back to 1.
+ PERFORM sflqFakeRowCount();
+ END IF;
END IF;
END;
\$\$;