Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Instances] Honor reserved instances #3563

Merged
merged 2 commits into from
Aug 21, 2023
Merged

[Instances] Honor reserved instances #3563

merged 2 commits into from
Aug 21, 2023

Conversation

joligario
Copy link
Contributor

Logic to select next available instance id was incorrect. The correct logic selected the max id + 1 or max reserved + 1, but then it would overwrite if we enabled recycling ids. Additionally, it was incrementing the reserved ids and assigning ids to the max reserved id vice the next available. Finally, it was running the logic twice.

Logic to select next available instance id was incorrect.
The correct logic selected the max id + 1 or max reserved + 1, but then it would overwrite if we enabled recycling ids.
Additionally, it was incrementing the reserved ids and assigning ids to the max reserved id vice the next available.
Finally, it was running the logic twice.
@joligario joligario requested a review from Akkadius August 20, 2023 23:02
@joligario
Copy link
Contributor Author

No instances:

MariaDB [eqemu]> select min(i1.id + 1) as next_available from instance_list i1 left join instance_list i2 on i1.id + 1 = i2.id  where i1.id > 30 and i2.id is null;
+----------------+
| next_available |
+----------------+
|           NULL |
+----------------+
1 row in set (0.001 sec)

MariaDB [eqemu]> SELECT IFNULL(MAX(id), 30) + 1 FROM instance_list WHERE id > 30;
+-------------------------+
| IFNULL(MAX(id), 30) + 1 |
+-------------------------+
|                      31 |
+-------------------------+
1 row in set (0.000 sec)

Some reserved instances populated. Should select 31 if not recycling, NULL if we are:

+----+------+---------+-----------+------------+----------+---------------+
| id | zone | version | is_global | start_time | duration | never_expires |
+----+------+---------+-----------+------------+----------+---------------+
|  1 |   25 |       1 |         1 |          0 |        0 |             1 |
|  2 |   25 |       2 |         1 |          0 |        0 |             1 |
|  3 |  151 |       1 |         1 |          0 |        0 |             1 |
|  4 |  114 |       1 |         1 |          0 |        0 |             1 |
|  5 |  344 |       1 |         1 |          0 |        0 |             1 |
|  6 |  202 |       0 |         1 |          0 |        0 |             1 |
+----+------+---------+-----------+------------+----------+---------------+
6 rows in set (0.000 sec)

MariaDB [eqemu]> SELECT IFNULL(MAX(id), 30) + 1 FROM instance_list WHERE id > 30;
+-------------------------+
| IFNULL(MAX(id), 30) + 1 |
+-------------------------+
|                      31 |
+-------------------------+
1 row in set (0.000 sec)

MariaDB [eqemu]> select min(i1.id + 1) as next_available from instance_list i1 left join instance_list i2 on i1.id + 1 = i2.id  where i1.id > 30 and i2.id is null;
+----------------+
| next_available |
+----------------+
|           NULL |
+----------------+
1 row in set (0.001 sec)

Some scattered instances. Should select 38 if not recycling, 34 if we are:

MariaDB [eqemu]> select * from instance_list;
+----+------+---------+-----------+------------+----------+---------------+
| id | zone | version | is_global | start_time | duration | never_expires |
+----+------+---------+-----------+------------+----------+---------------+
|  1 |   25 |       1 |         1 |          0 |        0 |             1 |
|  2 |   25 |       2 |         1 |          0 |        0 |             1 |
|  3 |  151 |       1 |         1 |          0 |        0 |             1 |
|  4 |  114 |       1 |         1 |          0 |        0 |             1 |
|  5 |  344 |       1 |         1 |          0 |        0 |             1 |
|  6 |  202 |       0 |         1 |          0 |        0 |             1 |
| 31 |  100 |       0 |         0 |          0 |        0 |             0 |
| 32 |  101 |       0 |         0 |          0 |        0 |             0 |
| 33 |  102 |       0 |         0 |          0 |        0 |             0 |
| 37 |  103 |       0 |         0 |          0 |        0 |             0 |
+----+------+---------+-----------+------------+----------+---------------+
10 rows in set (0.000 sec)

MariaDB [eqemu]> SELECT IFNULL(MAX(id), 30) + 1 FROM instance_list WHERE id > 30;
+-------------------------+
| IFNULL(MAX(id), 30) + 1 |
+-------------------------+
|                      38 |
+-------------------------+
1 row in set (0.000 sec)

MariaDB [eqemu]> select min(i1.id + 1) as next_available from instance_list i1 left join instance_list i2 on i1.id + 1 = i2.id  where i1.id > 30 and i2.id is null;
+----------------+
| next_available |
+----------------+
|             34 |
+----------------+
1 row in set (0.001 sec)

@Akkadius
Copy link
Member

Instances:RecycleInstanceIds enabled

image

Instances:RecycleInstanceIds disabled

image

@Akkadius Akkadius merged commit c47644e into master Aug 21, 2023
@Akkadius Akkadius deleted the joligario-patch-1 branch August 21, 2023 00:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants