Skip to content

Commit

Permalink
wckeys: fix initial insertion on empty SQL table
Browse files Browse the repository at this point in the history
The INSERT SQL request did not work when the SlurmDBD MySQL wckey table
is empty because the subrequest in the NOT IN test did not return any
result and this produced an error eventually. The INSERT request has
been reworked using NOT EXISTS test that handles empty tables properly.

Unfortunately, more native solutions such as REPLACE and INSERT IGNORE
cannot be adopted as the wckey_name is not a primary key on the table.

The script is now able to insert wckeys in empty SlurmDBD database
cluster wckeys table.

Fix #8
  • Loading branch information
rezib committed Jan 5, 2023
1 parent 7df7786 commit f5f8d7e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

## Unreleased

### Fixed
- wckeys: fix insertion on empty SlurmDBD wckey table (#8)

## [1.2.13] - 2022-05-18
### Fixed
- epilog: remove TaskEpilog kerberos_lustre.sh messages on stderr
Expand Down
8 changes: 4 additions & 4 deletions wckeys-setup/slurm-wckeys-setup
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,13 @@ INSERT INTO ${DB_NAME}.${CLUSTERNAME}_wckey_table
(creation_time, mod_time, wckey_name, user)
SELECT
'${DATE}','${DATE}','${key}','root'
FROM ${DB_NAME}.${CLUSTERNAME}_wckey_table
WHERE '${key}' NOT IN
WHERE NOT EXISTS
(
SELECT wckey_name
SELECT id_wckey
FROM ${DB_NAME}.${CLUSTERNAME}_wckey_table
WHERE wckey_name = '${key}'
)
LIMIT 1
LIMIT 1;
EOF
print_msg "Adding new wckey= ${key}"
mysql --host=${StorageHost} --user=${StorageUser} --password=${StoragePass} < ${TMP_FILE_MYSQL}
Expand Down

0 comments on commit f5f8d7e

Please sign in to comment.