Open papertigers opened 2 months ago
Using https://github.com/oxidecomputer/omicron/commit/ce73bc179271eecdb0b048fd5620a748a9f0f952 to grab crdb version 22.2.19 we can see that the database no longer silently truncates the string:
demo@127.0.0.1:26257/movr> insert into inv_nvme_disk_firmware (inv_collection_id, sled_id, slot, number_of_slots, active_slot, next_active_slot, slot1_is_read_only, slot_firmware_versions) values ('C84C2603-D30F-46A3-B696-AE122A825E00', '5DF4FF26-28A7-4961-8B20-45A33358B56C', 1, 1, 1, NULL, true, ARRAY['FIRMWARETOOLONG']);
ERROR: value too long for type STRING(8)
SQLSTATE: 22001
While working on #6275 I was writing a test to verify some of the constraints set by the following table:
In particular I was writing a test that would attempt to input an NVMe firmware version string that was larger than a
STRING(8)
in theslot_firmware_versions
ARRAY with a value ofvec![Some("firmwaretoolarge")]
. What I found however was a little odd as the test was failing onexpect_err('XXX')
as the test was able to insert data just fine. Usingdev-db
I was able to import the state of CRDB from the test and found that CRDB silently truncated the firmware version string to justFIRMWARE
:The CRDB docs state the following about bounding a strings size:
My first thought was that somewhere along the way from rust -> diesel -> crdb we were somehow casting to the string in the array. To investigate this path I used diesel-dtrace and found that we are in fact not using
CAST
anywhere in the raw sql statement.Next I wanted to recreate the issue in the crdb repl on my Mac so I created the table and attempted to run an insert command again:
Oddly enough I received the error I was expecting to see in my unit test. My next thought was that the crdb version I have installed via
brew
on my Mac is newer than what we are using in the control plane, so I fired updev-db
again and attempted the same experiment:It appears upstream has fixed this bug at some point along the way.
control plan crdb version:
macOS crdb version: