mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-03 15:35:17 +00:00
[#2438] prevent MySQL lease counters from going negative
This commit is contained in:
@@ -618,12 +618,59 @@ mysql_upgrade_13_to_14_test() {
|
|||||||
assert_str_eq '' "${OUTPUT}" "${query}: expected output %s, returned %s"
|
assert_str_eq '' "${OUTPUT}" "${query}: expected output %s, returned %s"
|
||||||
done
|
done
|
||||||
|
|
||||||
# Clean up.
|
# Check that leases counters cannot go negative.
|
||||||
query='DELETE FROM lease4; DELETE FROM lease6;'
|
for v in 4 6; do
|
||||||
run_command \
|
query="SELECT leases FROM lease${v}_stat WHERE subnet_id = 1 AND state = 0 LIMIT 1"
|
||||||
mysql_execute "${query}"
|
run_command \
|
||||||
assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d"
|
mysql_execute "${query}"
|
||||||
assert_str_eq "" "${OUTPUT}" "${query}: expected output %s, returned %s"
|
assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d"
|
||||||
|
assert_str_eq '2' "${OUTPUT}" "${query}: expected output %s, returned %s"
|
||||||
|
|
||||||
|
# Artifically change the subnet counter from 2 down to 1.
|
||||||
|
query="UPDATE lease${v}_stat SET leases = 1 WHERE subnet_id = 1 AND state = 0"
|
||||||
|
run_command \
|
||||||
|
mysql_execute "${query}"
|
||||||
|
assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d"
|
||||||
|
assert_str_eq '' "${OUTPUT}" "${query}: expected output %s, returned %s"
|
||||||
|
|
||||||
|
if test "${json_supported}" = 1; then
|
||||||
|
query="SELECT leases FROM lease${v}_stat_by_client_class WHERE client_class = 'foo' LIMIT 1"
|
||||||
|
run_command \
|
||||||
|
mysql_execute "${query}"
|
||||||
|
assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d"
|
||||||
|
assert_str_eq '2' "${OUTPUT}" "${query}: expected output %s, returned %s"
|
||||||
|
|
||||||
|
# Artifically change the client class counter from 2 down to 1.
|
||||||
|
query="UPDATE lease${v}_stat SET leases = 1 WHERE client_class = 'foo'"
|
||||||
|
run_command \
|
||||||
|
mysql_execute "${query}"
|
||||||
|
assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d"
|
||||||
|
assert_str_eq '' "${OUTPUT}" "${query}: expected output %s, returned %s"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Clean up.
|
||||||
|
query="DELETE FROM lease${v}"
|
||||||
|
run_command \
|
||||||
|
mysql_execute "${query}"
|
||||||
|
assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d"
|
||||||
|
assert_str_eq '' "${OUTPUT}" "${query}: expected output %s, returned %s"
|
||||||
|
|
||||||
|
# SELECT should finish succesfully and the subnet counter should be 0.
|
||||||
|
query="SELECT leases FROM lease${v}_stat WHERE subnet_id = 1 AND state = 0 LIMIT 1"
|
||||||
|
run_command \
|
||||||
|
mysql_execute "${query}"
|
||||||
|
assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d"
|
||||||
|
assert_str_eq '0' "${OUTPUT}" "${query}: expected output %s, returned %s"
|
||||||
|
|
||||||
|
if test "${json_supported}" = 1; then
|
||||||
|
# SELECT should finish succesfully and the client class counter should be 0.
|
||||||
|
query="SELECT leases FROM lease${v}_stat_by_client_class WHERE client_class = 'foo' LIMIT 1"
|
||||||
|
run_command \
|
||||||
|
mysql_execute "${query}"
|
||||||
|
assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d"
|
||||||
|
assert_str_eq '0' "${OUTPUT}" "${query}: expected output %s, returned %s"
|
||||||
|
fi
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
mysql_upgrade_test() {
|
mysql_upgrade_test() {
|
||||||
|
@@ -4521,7 +4521,8 @@ BEGIN
|
|||||||
DECLARE length INT;
|
DECLARE length INT;
|
||||||
DECLARE i INT;
|
DECLARE i INT;
|
||||||
|
|
||||||
-- Ignore ERROR 3141 (22032) at line 1: Invalid JSON text in argument 1 to function json_extract: "The document is empty." at position 0.
|
-- Ignore ERROR 3141 (22032) at line 1: Invalid JSON text in argument 1 to
|
||||||
|
-- function json_extract: "The document is empty." at position 0.
|
||||||
-- Ignore ERROR 4037 (HY000): Unexpected end of JSON text in argument 1 to function 'json_extract'
|
-- Ignore ERROR 4037 (HY000): Unexpected end of JSON text in argument 1 to function 'json_extract'
|
||||||
-- These situations are handled with a propagating NULL result from JSON_EXTRACT.
|
-- These situations are handled with a propagating NULL result from JSON_EXTRACT.
|
||||||
DECLARE CONTINUE HANDLER FOR 3141 BEGIN END;
|
DECLARE CONTINUE HANDLER FOR 3141 BEGIN END;
|
||||||
@@ -4578,7 +4579,7 @@ BEGIN
|
|||||||
SET class = JSON_UNQUOTE(JSON_EXTRACT(old_client_classes, CONCAT('\$[', i, ']')));
|
SET class = JSON_UNQUOTE(JSON_EXTRACT(old_client_classes, CONCAT('\$[', i, ']')));
|
||||||
|
|
||||||
-- Decrement the lease count if the record exists.
|
-- Decrement the lease count if the record exists.
|
||||||
UPDATE lease4_stat_by_client_class SET leases = leases - 1
|
UPDATE lease4_stat_by_client_class SET leases = IF(leases > 0, leases - 1, 0)
|
||||||
WHERE client_class = class;
|
WHERE client_class = class;
|
||||||
|
|
||||||
SET i = i + 1;
|
SET i = i + 1;
|
||||||
@@ -4618,7 +4619,8 @@ BEGIN
|
|||||||
DECLARE length INT;
|
DECLARE length INT;
|
||||||
DECLARE i INT;
|
DECLARE i INT;
|
||||||
|
|
||||||
-- Ignore ERROR 3141 (22032) at line 1: Invalid JSON text in argument 1 to function json_extract: "The document is empty." at position 0.
|
-- Ignore ERROR 3141 (22032) at line 1: Invalid JSON text in argument 1 to
|
||||||
|
-- function json_extract: "The document is empty." at position 0.
|
||||||
-- Ignore ERROR 4037 (HY000): Unexpected end of JSON text in argument 1 to function 'json_extract'
|
-- Ignore ERROR 4037 (HY000): Unexpected end of JSON text in argument 1 to function 'json_extract'
|
||||||
-- These situations are handled with a propagating NULL result from JSON_EXTRACT.
|
-- These situations are handled with a propagating NULL result from JSON_EXTRACT.
|
||||||
DECLARE CONTINUE HANDLER FOR 3141 BEGIN END;
|
DECLARE CONTINUE HANDLER FOR 3141 BEGIN END;
|
||||||
@@ -4635,7 +4637,7 @@ BEGIN
|
|||||||
SET class = JSON_UNQUOTE(JSON_EXTRACT(client_classes, CONCAT('\$[', i, ']')));
|
SET class = JSON_UNQUOTE(JSON_EXTRACT(client_classes, CONCAT('\$[', i, ']')));
|
||||||
|
|
||||||
-- Decrement the lease count if the record exists.
|
-- Decrement the lease count if the record exists.
|
||||||
UPDATE lease4_stat_by_client_class SET leases = leases - 1
|
UPDATE lease4_stat_by_client_class SET leases = IF(leases > 0, leases - 1, 0)
|
||||||
WHERE client_class = class;
|
WHERE client_class = class;
|
||||||
|
|
||||||
SET i = i + 1;
|
SET i = i + 1;
|
||||||
@@ -4656,7 +4658,8 @@ BEGIN
|
|||||||
DECLARE length INT;
|
DECLARE length INT;
|
||||||
DECLARE i INT;
|
DECLARE i INT;
|
||||||
|
|
||||||
-- Ignore ERROR 3141 (22032) at line 1: Invalid JSON text in argument 1 to function json_extract: "The document is empty." at position 0.
|
-- Ignore ERROR 3141 (22032) at line 1: Invalid JSON text in argument 1 to
|
||||||
|
-- function json_extract: "The document is empty." at position 0.
|
||||||
-- Ignore ERROR 4037 (HY000): Unexpected end of JSON text in argument 1 to function 'json_extract'
|
-- Ignore ERROR 4037 (HY000): Unexpected end of JSON text in argument 1 to function 'json_extract'
|
||||||
-- These situations are handled with a propagating NULL result from JSON_EXTRACT.
|
-- These situations are handled with a propagating NULL result from JSON_EXTRACT.
|
||||||
DECLARE CONTINUE HANDLER FOR 3141 BEGIN END;
|
DECLARE CONTINUE HANDLER FOR 3141 BEGIN END;
|
||||||
@@ -4714,7 +4717,7 @@ BEGIN
|
|||||||
SET class = JSON_UNQUOTE(JSON_EXTRACT(old_client_classes, CONCAT('\$[', i, ']')));
|
SET class = JSON_UNQUOTE(JSON_EXTRACT(old_client_classes, CONCAT('\$[', i, ']')));
|
||||||
|
|
||||||
-- Decrement the lease count if the record exists.
|
-- Decrement the lease count if the record exists.
|
||||||
UPDATE lease6_stat_by_client_class SET leases = leases - 1
|
UPDATE lease6_stat_by_client_class SET leases = IF(leases > 0, leases - 1, 0)
|
||||||
WHERE client_class = class AND lease_type = old_lease_type;
|
WHERE client_class = class AND lease_type = old_lease_type;
|
||||||
|
|
||||||
SET i = i + 1;
|
SET i = i + 1;
|
||||||
@@ -4755,7 +4758,8 @@ BEGIN
|
|||||||
DECLARE length INT;
|
DECLARE length INT;
|
||||||
DECLARE i INT;
|
DECLARE i INT;
|
||||||
|
|
||||||
-- Ignore ERROR 3141 (22032) at line 1: Invalid JSON text in argument 1 to function json_extract: "The document is empty." at position 0.
|
-- Ignore ERROR 3141 (22032) at line 1: Invalid JSON text in argument 1 to
|
||||||
|
-- function json_extract: "The document is empty." at position 0.
|
||||||
-- Ignore ERROR 4037 (HY000): Unexpected end of JSON text in argument 1 to function 'json_extract'
|
-- Ignore ERROR 4037 (HY000): Unexpected end of JSON text in argument 1 to function 'json_extract'
|
||||||
-- These situations are handled with a propagating NULL result from JSON_EXTRACT.
|
-- These situations are handled with a propagating NULL result from JSON_EXTRACT.
|
||||||
DECLARE CONTINUE HANDLER FOR 3141 BEGIN END;
|
DECLARE CONTINUE HANDLER FOR 3141 BEGIN END;
|
||||||
@@ -4772,7 +4776,7 @@ BEGIN
|
|||||||
SET class = JSON_UNQUOTE(JSON_EXTRACT(client_classes, CONCAT('\$[', i, ']')));
|
SET class = JSON_UNQUOTE(JSON_EXTRACT(client_classes, CONCAT('\$[', i, ']')));
|
||||||
|
|
||||||
-- Decrement the lease count if the record exists.
|
-- Decrement the lease count if the record exists.
|
||||||
UPDATE lease6_stat_by_client_class SET leases = leases - 1
|
UPDATE lease6_stat_by_client_class SET leases = IF(leases > 0, leases - 1, 0)
|
||||||
WHERE client_class = class AND lease_type = old_lease_type;
|
WHERE client_class = class AND lease_type = old_lease_type;
|
||||||
|
|
||||||
SET i = i + 1;
|
SET i = i + 1;
|
||||||
|
@@ -283,7 +283,8 @@ BEGIN
|
|||||||
DECLARE length INT;
|
DECLARE length INT;
|
||||||
DECLARE i INT;
|
DECLARE i INT;
|
||||||
|
|
||||||
-- Ignore ERROR 3141 (22032) at line 1: Invalid JSON text in argument 1 to function json_extract: "The document is empty." at position 0.
|
-- Ignore ERROR 3141 (22032) at line 1: Invalid JSON text in argument 1 to
|
||||||
|
-- function json_extract: "The document is empty." at position 0.
|
||||||
-- Ignore ERROR 4037 (HY000): Unexpected end of JSON text in argument 1 to function 'json_extract'
|
-- Ignore ERROR 4037 (HY000): Unexpected end of JSON text in argument 1 to function 'json_extract'
|
||||||
-- These situations are handled with a propagating NULL result from JSON_EXTRACT.
|
-- These situations are handled with a propagating NULL result from JSON_EXTRACT.
|
||||||
DECLARE CONTINUE HANDLER FOR 3141 BEGIN END;
|
DECLARE CONTINUE HANDLER FOR 3141 BEGIN END;
|
||||||
@@ -340,7 +341,7 @@ BEGIN
|
|||||||
SET class = JSON_UNQUOTE(JSON_EXTRACT(old_client_classes, CONCAT('\$[', i, ']')));
|
SET class = JSON_UNQUOTE(JSON_EXTRACT(old_client_classes, CONCAT('\$[', i, ']')));
|
||||||
|
|
||||||
-- Decrement the lease count if the record exists.
|
-- Decrement the lease count if the record exists.
|
||||||
UPDATE lease4_stat_by_client_class SET leases = leases - 1
|
UPDATE lease4_stat_by_client_class SET leases = IF(leases > 0, leases - 1, 0)
|
||||||
WHERE client_class = class;
|
WHERE client_class = class;
|
||||||
|
|
||||||
SET i = i + 1;
|
SET i = i + 1;
|
||||||
@@ -380,7 +381,8 @@ BEGIN
|
|||||||
DECLARE length INT;
|
DECLARE length INT;
|
||||||
DECLARE i INT;
|
DECLARE i INT;
|
||||||
|
|
||||||
-- Ignore ERROR 3141 (22032) at line 1: Invalid JSON text in argument 1 to function json_extract: "The document is empty." at position 0.
|
-- Ignore ERROR 3141 (22032) at line 1: Invalid JSON text in argument 1 to
|
||||||
|
-- function json_extract: "The document is empty." at position 0.
|
||||||
-- Ignore ERROR 4037 (HY000): Unexpected end of JSON text in argument 1 to function 'json_extract'
|
-- Ignore ERROR 4037 (HY000): Unexpected end of JSON text in argument 1 to function 'json_extract'
|
||||||
-- These situations are handled with a propagating NULL result from JSON_EXTRACT.
|
-- These situations are handled with a propagating NULL result from JSON_EXTRACT.
|
||||||
DECLARE CONTINUE HANDLER FOR 3141 BEGIN END;
|
DECLARE CONTINUE HANDLER FOR 3141 BEGIN END;
|
||||||
@@ -397,7 +399,7 @@ BEGIN
|
|||||||
SET class = JSON_UNQUOTE(JSON_EXTRACT(client_classes, CONCAT('\$[', i, ']')));
|
SET class = JSON_UNQUOTE(JSON_EXTRACT(client_classes, CONCAT('\$[', i, ']')));
|
||||||
|
|
||||||
-- Decrement the lease count if the record exists.
|
-- Decrement the lease count if the record exists.
|
||||||
UPDATE lease4_stat_by_client_class SET leases = leases - 1
|
UPDATE lease4_stat_by_client_class SET leases = IF(leases > 0, leases - 1, 0)
|
||||||
WHERE client_class = class;
|
WHERE client_class = class;
|
||||||
|
|
||||||
SET i = i + 1;
|
SET i = i + 1;
|
||||||
@@ -418,7 +420,8 @@ BEGIN
|
|||||||
DECLARE length INT;
|
DECLARE length INT;
|
||||||
DECLARE i INT;
|
DECLARE i INT;
|
||||||
|
|
||||||
-- Ignore ERROR 3141 (22032) at line 1: Invalid JSON text in argument 1 to function json_extract: "The document is empty." at position 0.
|
-- Ignore ERROR 3141 (22032) at line 1: Invalid JSON text in argument 1 to
|
||||||
|
-- function json_extract: "The document is empty." at position 0.
|
||||||
-- Ignore ERROR 4037 (HY000): Unexpected end of JSON text in argument 1 to function 'json_extract'
|
-- Ignore ERROR 4037 (HY000): Unexpected end of JSON text in argument 1 to function 'json_extract'
|
||||||
-- These situations are handled with a propagating NULL result from JSON_EXTRACT.
|
-- These situations are handled with a propagating NULL result from JSON_EXTRACT.
|
||||||
DECLARE CONTINUE HANDLER FOR 3141 BEGIN END;
|
DECLARE CONTINUE HANDLER FOR 3141 BEGIN END;
|
||||||
@@ -476,7 +479,7 @@ BEGIN
|
|||||||
SET class = JSON_UNQUOTE(JSON_EXTRACT(old_client_classes, CONCAT('\$[', i, ']')));
|
SET class = JSON_UNQUOTE(JSON_EXTRACT(old_client_classes, CONCAT('\$[', i, ']')));
|
||||||
|
|
||||||
-- Decrement the lease count if the record exists.
|
-- Decrement the lease count if the record exists.
|
||||||
UPDATE lease6_stat_by_client_class SET leases = leases - 1
|
UPDATE lease6_stat_by_client_class SET leases = IF(leases > 0, leases - 1, 0)
|
||||||
WHERE client_class = class AND lease_type = old_lease_type;
|
WHERE client_class = class AND lease_type = old_lease_type;
|
||||||
|
|
||||||
SET i = i + 1;
|
SET i = i + 1;
|
||||||
@@ -517,7 +520,8 @@ BEGIN
|
|||||||
DECLARE length INT;
|
DECLARE length INT;
|
||||||
DECLARE i INT;
|
DECLARE i INT;
|
||||||
|
|
||||||
-- Ignore ERROR 3141 (22032) at line 1: Invalid JSON text in argument 1 to function json_extract: "The document is empty." at position 0.
|
-- Ignore ERROR 3141 (22032) at line 1: Invalid JSON text in argument 1 to
|
||||||
|
-- function json_extract: "The document is empty." at position 0.
|
||||||
-- Ignore ERROR 4037 (HY000): Unexpected end of JSON text in argument 1 to function 'json_extract'
|
-- Ignore ERROR 4037 (HY000): Unexpected end of JSON text in argument 1 to function 'json_extract'
|
||||||
-- These situations are handled with a propagating NULL result from JSON_EXTRACT.
|
-- These situations are handled with a propagating NULL result from JSON_EXTRACT.
|
||||||
DECLARE CONTINUE HANDLER FOR 3141 BEGIN END;
|
DECLARE CONTINUE HANDLER FOR 3141 BEGIN END;
|
||||||
@@ -534,7 +538,7 @@ BEGIN
|
|||||||
SET class = JSON_UNQUOTE(JSON_EXTRACT(client_classes, CONCAT('\$[', i, ']')));
|
SET class = JSON_UNQUOTE(JSON_EXTRACT(client_classes, CONCAT('\$[', i, ']')));
|
||||||
|
|
||||||
-- Decrement the lease count if the record exists.
|
-- Decrement the lease count if the record exists.
|
||||||
UPDATE lease6_stat_by_client_class SET leases = leases - 1
|
UPDATE lease6_stat_by_client_class SET leases = IF(leases > 0, leases - 1, 0)
|
||||||
WHERE client_class = class AND lease_type = old_lease_type;
|
WHERE client_class = class AND lease_type = old_lease_type;
|
||||||
|
|
||||||
SET i = i + 1;
|
SET i = i + 1;
|
||||||
|
Reference in New Issue
Block a user