Skip to content

check duplicate message before enqueue #260

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

Merged
merged 22 commits into from
Jul 22, 2025
Merged

check duplicate message before enqueue #260

merged 22 commits into from
Jul 22, 2025

Conversation

sonus21
Copy link
Owner

@sonus21 sonus21 commented Jul 15, 2025

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes: #259

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Unit Test
  • Integration Test
  • Reactive Integration Test

Test Configuration:

  • Spring Version
  • Spring Boot Version
  • Redis Driver Version

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@hyokwangryu-lunit
Copy link

hyokwangryu-lunit commented Jul 16, 2025

Hello @sonus21,
This PR includes a feature I need urgently—would you be able to review and merge it soon?
And, Would you mind updating enqueueUniqueIn as well?

Comment on lines 63 to 67
if(isMessageAlreadyExist(queueName, messageId)){
log.warn("trying to enqueue duplicate message {}", messageId);
return false;
}
return enqueue(queueName, messageId, message);
Copy link

@Tsar Tsar Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this is not really atomic: if 2 same messageId are enqueued at the same time using this method, then both may pass the check and both will be enqueued.

I have checked how uniqueness is implemented in db-scheduler.
Basically, the logic looks like this:

try {
   if (already queued)
      return false
   insert to queue  // (!!!) id is unique in DB schema, so the query will fail if it tries to insert duplicate
} catch (DB exception) {
   if (already queued)  // second check of "already queued"
      return false
   else
      throw exception
}

Can we do something like this here?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not required here, because redis is a single threaded unlike database.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, but this method does at least 2 separate Redis operations.
If 2 messages are scheduled at the same time, you can't guarantee it will be "isMessageAlreadyExist -> enqueue -> isMessageAlreadyExist -> enqueue", but not "isMessageAlreadyExist -> isMessageAlreadyExist -> enqueue -> enqueue".
Or can you?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

potentially, we can.. i've updated the pr to use setIfAbsent redis command

@sonus21 sonus21 merged commit 9fec46e into master Jul 22, 2025
8 checks passed
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.

When RqueueMessageEnqueuer::enqueueUnique() is going to be properly implemented?
3 participants