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

Add integrate mix-in #61

Merged
merged 12 commits into from
Jul 16, 2024
Merged

Add integrate mix-in #61

merged 12 commits into from
Jul 16, 2024

Conversation

AlCutter
Copy link
Collaborator

@AlCutter AlCutter commented Jul 12, 2024

This PR adds a storage mix-in for performing the integration of new entries into the log.

Towards #6 & #23

return newTiles
}

// fullTile represents a "fully populated" tile, i.e. it has all non-ephemeral internaly nodes
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// fullTile represents a "fully populated" tile, i.e. it has all non-ephemeral internaly nodes
// fullTile represents a "fully populated" tile, i.e. it has all non-ephemeral internal nodes

storage/integrate.go Show resolved Hide resolved
r.Lock()
defer r.Unlock()
k := layout.TilePath(uint64(tileID.Level), tileID.Index, treeSize)
if e, ok := r.entries[k]; ok && !e.Equals(t) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You should be able to drop this equality check if the read-once semantics for any given tile are fixed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's gone away now

return errors.Join(tc.err...)
}

// Visit should be called once for each newly set non-ephemeral node in the
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: This comment should start with Visitor .... It appears to jump over what this function does and talks about how its return value should be used.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated

//
// Note that by itself, this cache does not update any persisted state.
type tileWriteCache struct {
sync.Mutex
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see where this is used in parallel. Can we remove this mutex to keep it simpler looking?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, it was there from an abundance of caution, but it should never be used in parallel since it's driven by the visitor.

Removed.

Comment on lines 147 to 149
if err := tc.Err(); err != nil {
return 0, nil, nil, err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Worth moving this up a few lines? Maybe even checking it before and after baseRange.AppendRange(newRange, visitor) ? Reasoning being that any errors in here are likely to cause failures in the other operations that depend on the writeTileCache succeeding. It's better to return the root error rather than a symptomatic error.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

//
// The getTile param must know how to fetch the specified tile from storage. It must return an instance of os.ErrNotExist
// (either directly, or wrapped) if the requested tile was not found.
func NewTreeBuilder(getTile func(ctx context.Context, tileID TileID, treeSize uint64) (*api.HashTile, error)) *TreeBuilder {
Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed in person, making this function take all the tiles to look up in batch allows for more flexibility in implementation. And as a side effect, makes it so that we don't end up fetching the same tile multiple times if there are several nodes required from the same tile.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a great observation, thank you!
I've re-worked quite a bit of how this hangs together to support this, PTAL.

storage/integrate.go Show resolved Hide resolved
storage/integrate.go Show resolved Hide resolved
@AlCutter AlCutter merged commit 885ceea into transparency-dev:main Jul 16, 2024
4 checks passed
@AlCutter AlCutter deleted the pr_integrate branch July 16, 2024 11:14
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