Skip to content

feat(tdigest): add support of TDIGEST.RESET command#2826

Merged
PragmaTwice merged 11 commits intoapache:unstablefrom
SharonIV0x86:feat/tdigest.reset
Mar 20, 2025
Merged

feat(tdigest): add support of TDIGEST.RESET command#2826
PragmaTwice merged 11 commits intoapache:unstablefrom
SharonIV0x86:feat/tdigest.reset

Conversation

@SharonIV0x86
Copy link
Contributor

@SharonIV0x86 SharonIV0x86 commented Mar 13, 2025

This closes #2804

This PR is a Work In Progress and adds the support for the TDIGEST.RESET command https://redis.io/docs/latest/commands/tdigest.reset/.

I’m currently working on implementing the TDIGEST.RESET command. However, I noticed that there doesn’t seem to be a built-in way to delete centroids from a TDigest. And in order to reset a digest we need to delete the centroids that its containing, correct me if im wrong.
Also, to do this, one way i see is that we can manually delete them by iterating over the stored centroids and removing them one by one.

Additionally there seems to be already a Reset() function defined.

void Reset() {

And i am really confused about the two implementation of the TDigest in kvrocks, one in types/redis_tdigest.cc and one in type/tdigest.cc.
The existing TDigest commands uses the TDigest implementation from types/redis_tdigest.cc and it currently has no Reset() function defined.

So any assistance or reviews on this PR are highly appreciated as i am new to the codebase.

To the best of my knowledge DummyCentroids class is being used as a class to iterate over centroids in Quantile function, maybe if its possible we can add some functionality in this class to delete a centroid.

@PragmaTwice PragmaTwice changed the title feat(tdigest): Added TDIGEST.RESET command. WIP feat(tdigest): add suuport of TDIGEST.RESET command Mar 14, 2025
@PragmaTwice PragmaTwice changed the title feat(tdigest): add suuport of TDIGEST.RESET command feat(tdigest): add support of TDIGEST.RESET command Mar 14, 2025
@SharonIV0x86
Copy link
Contributor Author

@PragmaTwice I updated the Reset function so that it resets the metadata fields and writes the new metadata back.

From what I understand, this should only clear the high-level info, removing references to the centroids without actually deleting them. The centroids should still exist until compaction eventually cleans them up.

But when I run TDIGEST.RESET, it gets stuck in an infinite loop. I’m not sure why any ideas on what might be causing this?

@SharonIV0x86 SharonIV0x86 marked this pull request as ready for review March 14, 2025 08:29
@PragmaTwice
Copy link
Member

@LindaSummer Hi, could you help to review this PR when you have time?

@LindaSummer
Copy link
Member

@LindaSummer Hi, could you help to review this PR when you have time?

Hi @PragmaTwice ,

Of course!
I will take a review today.😊

Best Regards,
Edward

@LindaSummer
Copy link
Member

LindaSummer commented Mar 15, 2025

@PragmaTwice I updated the Reset function so that it resets the metadata fields and writes the new metadata back.

From what I understand, this should only clear the high-level info, removing references to the centroids without actually deleting them. The centroids should still exist until compaction eventually cleans them up.

But when I run TDIGEST.RESET, it gets stuck in an infinite loop. I’m not sure why any ideas on what might be causing this?

Hi @SharonIV0x86 ,

Thanks very much for your effort!😊

If I understand correctly, the compaction is handled by rocksdb and we should delete related keys to free the reference of related keys.

In my subkey design, I use a flag prefix for centroid keys. It could be deleted by some method like deletebyprefix.

I'm now without a computer by my side, I would provide the function link of prefix deletion today after back home.😊

For the infinite loop issue, I will try to find the cause if you don't mind.😊

Best Regards,
Edward

@SharonIV0x86
Copy link
Contributor Author

@LindaSummer The looping issue is fixed and it works as expected.

@SharonIV0x86
Copy link
Contributor Author

@LindaSummer If possible also provide your implementation too, as you mentioned it can be used by some method like deletebyprefix but ig its not added to kvrocks yet. So ill compare yours and mine and whichever is better we'll go with it.

Copy link
Member

@LindaSummer LindaSummer left a comment

Choose a reason for hiding this comment

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

Hi @SharonIV0x86 ,

Thanks very much for your contribution! 😊

Left with some comments.

By the way, could you add some go integration test for this command to cover the new code in this PR if possible?

Best Regards,
Edward

Copy link
Member

@LindaSummer LindaSummer left a comment

Choose a reason for hiding this comment

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

Hi @SharonIV0x86 ,

Reviewed with some comments. 😊

Best Regards,
Edward

Added go integration tests for TDIGEST.RESET

Made requested changes.

Added go test case
@SharonIV0x86
Copy link
Contributor Author

@LindaSummer I cross-checked with the redis-stack and it returns OK for both the cases.

  1. If digest is empty and you execute a reset: returns OK.
  2. If digest is non-empty and you execute a reset: return OK.

Now this aligns with the functionality of redis-stack. Also i added a go test case for this. Please review when you have time 😄

Copy link
Member

@LindaSummer LindaSummer left a comment

Choose a reason for hiding this comment

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

Hi @SharonIV0x86 ,

Thanks for your effort.😊
Generally LGTM.

Leave with some nitpick comments.

Best Regards,
Edward

@SharonIV0x86
Copy link
Contributor Author

@LindaSummer Made the changes, pls check now and lmk so i can proceed with opening a PR for modifying docs.

Copy link
Member

@LindaSummer LindaSummer left a comment

Choose a reason for hiding this comment

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

Hi @SharonIV0x86 ,

Thanks for your contribution!

Left one comment.

Other parts are LGTM.

Best Regards,
Edward

fix(cluster): resolve forbidden slot range cleanup bug during the slot migration (apache#2829)

Made smoll fixes.

Made smoll changes
}
}; // Stop forbidding writing slot to accept write commands
if (slot_range == srv_->slot_migrator->GetForbiddenSlotRange()) srv_->slot_migrator->ReleaseForbiddenSlotRange();
if (slot_range.HasOverlap(srv_->slot_migrator->GetForbiddenSlotRange())) {
Copy link
Member

@LindaSummer LindaSummer Mar 19, 2025

Choose a reason for hiding this comment

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

Hi @SharonIV0x86 ,

It seems that this file change should not be shown in this PR.

Could you take a review on your commit?

Best Regards,
Edward

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This seems like a mistake, maybe merging the base branch with this can fix it?

constexpr auto kInfoObservations = "Observations";
constexpr auto kInfoTotalCompressions = "Total compressions";
} // namespace

Copy link
Member

@LindaSummer LindaSummer Mar 19, 2025

Choose a reason for hiding this comment

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

Hi @SharonIV0x86 ,

Could you help keep this blank line for namespace section if you don't mind? 😊

Best Regards,
Edward

@LindaSummer
Copy link
Member

Hi @SharonIV0x86

LGTM

Thanks very much for your contribution!😊

Best Regards,
Edward

Kept a blank line for namespace.
@SharonIV0x86
Copy link
Contributor Author

Hi @SharonIV0x86

LGTM

Thanks very much for your contribution!😊

Best Regards, Edward

Done.
Also kindly take a look at this, as i want to work on this issue next.

@sonarqubecloud
Copy link

@PragmaTwice PragmaTwice merged commit f025147 into apache:unstable Mar 20, 2025
36 checks passed
@SharonIV0x86 SharonIV0x86 deleted the feat/tdigest.reset branch March 23, 2025 07:13
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.

TDigest: Implement TDIGEST.RESET command Algorithm

4 participants