Skip to content
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

Added print functionality to iters to allow simpler debugging #51

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

redixhumayun
Copy link
Contributor

@redixhumayun redixhumayun commented Feb 25, 2024

What This PR Does

  • Adds print functionality to all iterators
  • Ensures proper formatting for each iterator

Sample output for a two merge iterator shown below

xxxxxxxxxx    TWO_MERGE_ITERATOR     xxxxxxxxxx
----------        ITERATOR A         ----------
----------      Merge Iterator       ----------

Current Iterator (Index 1):
----------     Memtable Iterator     ----------
Key       : "00"
Value     : "2333"
----------   End Memtable Iterator   ----------

Iterators in Heap: 1
Iterator Index 0: Valid
----------     Memtable Iterator     ----------
Key       : "1"
Value     : ""
----------   End Memtable Iterator   ----------
----------    End Merge Iterator     ----------
----------      END ITERATOR A       ----------

----------        ITERATOR B         ----------
----------      Merge Iterator       ----------

Current Iterator (Index 1):
----------       SST_ITERATOR        ----------
Current Block Index: 0
----------      Block Iterator       ----------
First Key           : "0"
Current Key         : "0"
Current Value       : "2333333"
Key Index           : 0
==========   Block    ==========
Index     : 0
Key       : 0
Value     : 2333333
--------------------
Index     : 1
Key       : 00
Value     : 2333333
--------------------
Index     : 2
Key       : 4
Value     : 23
--------------------
Offsets: [0, 14, 28]
========== End Block  ==========
----------    Block Iterator End     ----------
----------     SST_ITERATOR_END      ----------

Iterators in Heap: 1
Iterator Index 0: Valid
----------       SST_ITERATOR        ----------
Current Block Index: 0
----------      Block Iterator       ----------
First Key           : "4"
Current Key         : "4"
Current Value       : ""
Key Index           : 0
==========   Block    ==========
Index     : 0
Key       : 4
Value     : 
--------------------
Offsets: [0]
========== End Block  ==========
----------    Block Iterator End     ----------
----------     SST_ITERATOR_END      ----------
----------    End Merge Iterator     ----------
----------      END ITERATOR B       ----------
xxxxxxxxxx  END TWO_MERGE_ITERATOR   xxxxxxxxxx

Questions

  • One point to note is that the decoding scheme used for a block is the compressed key format implemented on week 1 day 7. Should that be the decoding scheme while printing?
  • Should this be left as an exercise for the student since they are expected to implement an encoding decoding scheme anyway?

@Adirelle
Copy link

Hello,
Is there any particular reason in choosing to add a new method instead of implementing std::fmt::Debug or std::fmt::Display? These traits seems to be a good fit for this use case.

@redixhumayun
Copy link
Contributor Author

@Adirelle I think the print function has a few advantages

  1. It's easier to control indentation from parent functions so at some point if we want to improve readability with indentation its easier to do so.
  2. It feels natural to put it into the iterator trait because every iterator needs to be able to display itself for debugging

What do you recommend?

@Adirelle
Copy link

@redixhumayun Well, std::fmt::Debug seems the idiomatic way of handling debug printing in rust, quoting the std::fmt page : "The purpose of the Debug trait is to facilitate debugging Rust code".

You can ensure that all StorageIterator implementation also implements the Debug trait by adding it as a requirement :

pub trait StorageIterator: std::fmt::Debug {

Your current implementation of print can be used as a base for implementing std::fmt::Debug::fmt, using writeln!(f, ...) instead of println!(...). And, very optionally, you might provide both terse and verbose output, using the # flag to choose which to use.

Once implemented, you can use println! :

println!("{some_iterator:#?}");

@skyzh
Copy link
Owner

skyzh commented Feb 27, 2024

My personal preference would be having a Debug implementation for storage iterator. I will take over this pull request and work on that later when I have time :)

@redixhumayun
Copy link
Contributor Author

@skyzh hey, sure thing. shall i close the PR in that case?

@skyzh
Copy link
Owner

skyzh commented Jul 3, 2024

I need more time for this pull request :) Thanks anyways and I'll get it merged soon!

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.

3 participants