Add tracker interface and tests #3

Merged
roysc merged 7 commits from tracker-interface into main 2023-09-26 11:34:42 +00:00
Owner

Refactors the tracker to expose an interface and an implementation type. Decoupling these will let us inject new state/functionality transparently to the client function (like the iterator metrics for cerc-io/ipld-eth-state-snapshot#1).

Refactors the tracker to expose an interface and an implementation type. Decoupling these will let us inject new state/functionality transparently to the client function (like the iterator metrics for https://git.vdb.to/cerc-io/ipld-eth-state-snapshot/pulls/1).
telackey was assigned by roysc 2023-09-25 18:45:36 +00:00
roysc added 3 commits 2023-09-25 18:45:38 +00:00
roysc added 1 commit 2023-09-25 18:46:06 +00:00
telackey approved these changes 2023-09-25 22:48:48 +00:00
@ -145,1 +181,3 @@
func (tr *Tracker) HaltAndDump() error {
// CloseAndSave stops all tracked iterators and dumps their state to a file.
// This closes the tracker, so adding a new iterator will fail.
func (tr *TrackerImpl) CloseAndSave() error {
Member

Is it explicit anywhere that you must call CloseAndSave in order to close the channel, set running to false, etc?

What happens if you don't call that, but the iterator completes?

If we need to call it, I think the pattern:

      tr := tracker.New(recoveryFile, NumIters)
      defer tr.CloseAndSave()  // <--- You must do this!

Needs to be documented explicitly somewhere (unless I am just missing something).

Is it explicit anywhere that you *must* call CloseAndSave in order to close the channel, set running to false, etc? What happens if you don't call that, but the iterator completes? If we need to call it, I think the pattern: ``` tr := tracker.New(recoveryFile, NumIters) defer tr.CloseAndSave() // <--- You must do this! ``` Needs to be documented explicitly somewhere (unless I am just missing something).
Author
Owner

If it's not called, it should just be sort of a leak. The channels won't be flushed or saved, but once all its iterators die, the tracker will still be gc'd. No critical consequences that I foresee, but I will document it.

If it's not called, it should just be sort of a leak. The channels won't be flushed or saved, but once all its iterators die, the tracker will still be gc'd. No critical consequences that I foresee, but I will document it.
roysc marked this conversation as resolved
@ -175,3 +206,4 @@
ret := it.NodeIterator.Next(descend)
if !ret {
it.tracker.RLock()
Member

Why not call it.StopIterator()? I am always nervous about code that requires a precise locking scheme being duplicated multiple places.

Why not call `it.StopIterator()`? I am always nervous about code that requires a precise locking scheme being duplicated multiple places.
Author
Owner

That's fair - I don't think we actually need StopIterator any more, so I will just delete it for now.

That's fair - I don't think we actually need StopIterator any more, so I will just delete it for now.
roysc marked this conversation as resolved
roysc was assigned by telackey 2023-09-25 22:49:52 +00:00
telackey removed their assignment 2023-09-25 22:49:59 +00:00
roysc added 1 commit 2023-09-26 06:01:40 +00:00
roysc added 1 commit 2023-09-26 10:09:42 +00:00
roysc added 1 commit 2023-09-26 11:33:22 +00:00
roysc merged commit 7703ac8ea4 into main 2023-09-26 11:34:42 +00:00
roysc deleted branch tracker-interface 2023-09-26 11:34:42 +00:00
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: cerc-io/eth-iterator-utils#3
No description provided.