Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

add mirror service #1070

Merged
merged 6 commits into from
Oct 13, 2020
Merged

add mirror service #1070

merged 6 commits into from
Oct 13, 2020

Conversation

mikehelmick
Copy link
Contributor

Towards #928

Proposed Changes

  • Add mirror service that can mirror an index.txt / export archive structure from a CDN to the configured cloud storage. For use in key server migrations.

Release Note

New: Mirror service `cmd/mirror` for mirroring an export directory from one key server to another.

@google-oss-robot google-oss-robot added the approved Auto: added by prow when enough reviewers approve. label Oct 10, 2020
@google-cla google-cla bot added the cla: yes Auto: added by CLA bot when all committers have signed a CLA. label Oct 10, 2020
@google-oss-robot google-oss-robot added the size/XL Auto: extra large number of changes. label Oct 10, 2020
Copy link
Member

@sethvargo sethvargo left a comment

Choose a reason for hiding this comment

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

I think the mirror algorithm is fine, but the implementation has a few flaws. Since everything is a giant loop, none of the defers are running until the very end. Furthermore, for a very large N, we'll hit unnecessary timeouts due to lack of parallelization.

I'd like to suggest we:

  1. Break apart the main HTTP handler into (at least) one testable function.

  2. Leverage some parallelization (either primitively with goroutines or using a library like https://github.com/gammazero/workerpool) with a configurable max.

  3. Add tests for internal/mirror/mirror.go. The blobstore should be stubbable to the in-memory implementation.

internal/mirror/database/mirror.go Show resolved Hide resolved
internal/mirror/database/mirror.go Show resolved Hide resolved
internal/mirror/database/mirror.go Show resolved Hide resolved
internal/mirror/mirror.go Show resolved Hide resolved
internal/mirror/mirror.go Outdated Show resolved Hide resolved
internal/mirror/mirror.go Outdated Show resolved Hide resolved
internal/mirror/mirror.go Outdated Show resolved Hide resolved
internal/mirror/mirror.go Outdated Show resolved Hide resolved
internal/mirror/mirror.go Outdated Show resolved Hide resolved

func deadlinePassed(deadline time.Time) bool {
return time.Now().After(deadline)
}
Copy link
Member

Choose a reason for hiding this comment

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

I'd really like to see this broken down into smaller functions that are easily tested. The current HTTP handler is very long and very nested.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can do as a follow up if that's OK

Copy link
Member

Choose a reason for hiding this comment

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

yup

@mikehelmick
Copy link
Contributor Author

I think the mirror algorithm is fine, but the implementation has a few flaws. Since everything is a giant loop, none of the defers are running until the very end. Furthermore, for a very large N, we'll hit unnecessary timeouts due to lack of parallelization.

Parallelization is achieved at the HTTP layer - will have a cron to active this service every 60 seconds. if one mirror is locked and taking a while, the next invocation will move onto the next one.

State is saved on an http request timeout and processing will continue on next invoke.

I'd like to suggest we:

  1. Break apart the main HTTP handler into (at least) one testable function.

will do in follow up.

  1. Leverage some parallelization (either primitively with goroutines or using a library like https://github.com/gammazero/workerpool) with a configurable max.

we can add additional parallelism, but doesn't seem to be necessary in the testing i've done.

  1. Add tests for internal/mirror/mirror.go. The blobstore should be stubbable to the in-memory implementation.

would like to do in follow up

Copy link
Member

@sethvargo sethvargo left a comment

Choose a reason for hiding this comment

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

/lgtm
/hold

in case someone else wants to give it a once-over. Feel free to unhold.


func deadlinePassed(deadline time.Time) bool {
return time.Now().After(deadline)
}
Copy link
Member

Choose a reason for hiding this comment

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

yup

@google-oss-robot google-oss-robot added do-not-merge/hold Do not merge: held by author or reviewer. lgtm Auto: added by prown with a reviewer LGTMs labels Oct 13, 2020
@google-oss-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mikehelmick, sethvargo

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [mikehelmick,sethvargo]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@mikehelmick
Copy link
Contributor Author

/cancel hold

@mikehelmick
Copy link
Contributor Author

/unhold

@google-oss-robot google-oss-robot removed the do-not-merge/hold Do not merge: held by author or reviewer. label Oct 13, 2020
@google-oss-robot google-oss-robot merged commit 3df5bf7 into google:main Oct 13, 2020
@mikehelmick mikehelmick deleted the mirror branch October 13, 2020 17:07
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Auto: added by prow when enough reviewers approve. cla: yes Auto: added by CLA bot when all committers have signed a CLA. lgtm Auto: added by prown with a reviewer LGTMs size/XL Auto: extra large number of changes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants