Skip to content

Added UNIQUE constraint on auditdb actor_name as suggested in issue.#24

Merged
m-atlantis merged 1 commit intomasterfrom
BITMAG-1083-auditdb-multiple-same-actor
Jun 20, 2022
Merged

Added UNIQUE constraint on auditdb actor_name as suggested in issue.#24
m-atlantis merged 1 commit intomasterfrom
BITMAG-1083-auditdb-multiple-same-actor

Conversation

@Bohlski
Copy link
Copy Markdown
Contributor

@Bohlski Bohlski commented Jun 17, 2022

So the issue description suggests that this synchronized method snippet for extracting actor_guid from the db gets called twice for the same actor with the second run starting before the first has finished inserting the actor into the table. This results in two actor entries with the same actor_name but different actor_guid...

Long guid = DatabaseUtils.selectLongValue(dbConnector, sqlRetrieve, actorName);
if (guid == null) {
    log.debug("Inserting actor '" + actorName + "' into the actor table.");
    String sqlInsert = "INSERT INTO " + ACTOR_TABLE + " ( " + ACTOR_NAME + " ) VALUES ( ? )";
    DatabaseUtils.executeStatement(dbConnector, sqlInsert, actorName);

    guid = DatabaseUtils.selectLongValue(dbConnector, sqlRetrieve, actorName);
}
return guid;

I don't understand why this would be specific to only checksum-pillars, but this might've just been a coincidental observation.

I made the suggested solution of just adding a unique constraint on actor_name, which I guess would have the db throw an error on second insertion if it were to happen again, but at least that would be a more meaningful place to throw an error instead of on retrieval.

Unless I'm misunderstanding what is actually happening, we should at some point look into how this synchronized block could even be executed like that to fix the actual problem.

@m-atlantis m-atlantis merged commit 329fe30 into master Jun 20, 2022
@m-atlantis m-atlantis deleted the BITMAG-1083-auditdb-multiple-same-actor branch June 20, 2022 08:57
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