Skip to content

[storage/mysql] Tolerate gaps in GetLeavesByRange#1061

Merged
pav-kv merged 5 commits intogoogle:masterfrom
pav-kv:get_leaves_by_range
Mar 20, 2018
Merged

[storage/mysql] Tolerate gaps in GetLeavesByRange#1061
pav-kv merged 5 commits intogoogle:masterfrom
pav-kv:get_leaves_by_range

Conversation

@pav-kv
Copy link
Copy Markdown
Contributor

@pav-kv pav-kv commented Mar 19, 2018

PREORDERED_LOG uses GetLeavesByRange to load sequenced entries beyond the tree size. It is a normal situation when those entries are not contiguous (AddSequencedLeaves does not enforce the order). This PR makes GetLeavesByRange return a shorter range in such scenario, instead of an error.

}

func (t *logTreeTX) GetLeavesByRange(ctx context.Context, start, count int64) ([]*trillian.LogLeaf, error) {
// TODO(pavelkalinnikov): Clip `count`, for example to max(count, 64k).
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

nit: min(count, 64k)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@codecov-io
Copy link
Copy Markdown

codecov-io commented Mar 19, 2018

Codecov Report

Merging #1061 into master will decrease coverage by 0.04%.
The diff coverage is 78.94%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1061      +/-   ##
==========================================
- Coverage   62.61%   62.57%   -0.05%     
==========================================
  Files         103      103              
  Lines        8448     8455       +7     
==========================================
+ Hits         5290     5291       +1     
- Misses       2630     2634       +4     
- Partials      528      530       +2
Impacted Files Coverage Δ
storage/mysql/map_storage.go 68.58% <100%> (ø) ⬆️
storage/mysql/tree_storage.go 49.26% <100%> (+0.24%) ⬆️
storage/mysql/log_storage.go 68.38% <73.33%> (-0.48%) ⬇️
util/tracker.go 96.61% <0%> (-3.39%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update aaf80ba...51b85b8. Read the comment docs.


if len(ret) == 0 {
return nil, status.Errorf(codes.InvalidArgument, "no leaves found in range [%d, %d+%d)", start, start, count)
return nil, status.Errorf(codes.InvalidArgument, "no contiguous prefix of leaves found in [%d, %d+%d)", start, start, count)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have an impression this shouldn't be an error. For example, if the request is (start=treeSize, count=100), looks reasonable to return an empty slice?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Also, this it probably not InvalidArgument anymore.

@Martin2112
Copy link
Copy Markdown
Contributor

For safety can we limit this change to PREORDERED_LOG trees? It will probably need a small tweak to retain the tree type in the tx.

@pav-kv
Copy link
Copy Markdown
Contributor Author

pav-kv commented Mar 20, 2018

I am not sure what you mean by safety in this case? I think we should rather make the API consistent regardless of the tree type. How about the following:

  • If some entry within the tree size is missing, this should be an error regardless of the tree type.
  • Any gaps beyond the size are tolerable regardless of the tree type.

Since normally LOG have neither gaps, nor entries beyond the tree size, the above should be equivalent to what we have currently, modulo returning empty slice instead of an error if the range is too far to the right.

@Martin2112
Copy link
Copy Markdown
Contributor

If there are gaps in a LOG tree somehow then it's probably too late to save it but the server should detect it. Alternatively, we could enforce that a log tree can never request a range outside of the tree and the not worry about gaps.

Possibly the CTFE checks on the response are sufficient but we should try to exclude the possibility of bad data propagating if we can.

@pav-kv
Copy link
Copy Markdown
Contributor Author

pav-kv commented Mar 20, 2018

Maybe also cap count to treeSize-start for LOG trees for safety, if that is what you mean. This may, however, involve reading from Trees table just for getting the tree type...

@Martin2112
Copy link
Copy Markdown
Contributor

We should get the tree type via the trillian.Tree when the transaction starts.

@pav-kv
Copy link
Copy Markdown
Contributor Author

pav-kv commented Mar 20, 2018

@Martin2112 Improved safety a bit, PTAL.

func (t *logTreeTX) GetLeavesByRange(ctx context.Context, start, count int64) ([]*trillian.LogLeaf, error) {
if count <= 0 {
return nil, fmt.Errorf("invalid count %d", count)
return nil, fmt.Errorf("count=%d,want>0", count)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure about changing these. I think they might get returned in server responses but not 100% certain.

Copy link
Copy Markdown
Contributor Author

@pav-kv pav-kv Mar 20, 2018

Choose a reason for hiding this comment

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

Yes, it gets returned in server responses. Should I leave it intact? I thought a bit clarified messages would be better.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Made it slightly more human readable.

@Martin2112
Copy link
Copy Markdown
Contributor

Martin2112 commented Mar 20, 2018 via email

@pav-kv pav-kv merged commit d0c1068 into google:master Mar 20, 2018
@pav-kv pav-kv deleted the get_leaves_by_range branch March 20, 2018 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants