Skip to content

RFC: new storage driver "swift-plus" - #2441

Closed
majewsky wants to merge 7 commits into
distribution:mainfrom
sapcc:swift-plus
Closed

majewsky wants to merge 7 commits into
distribution:mainfrom
sapcc:swift-plus

Conversation

@majewsky

@majewsky majewsky commented Nov 6, 2017 •

Copy link
Copy Markdown
Contributor

The Swift storage driver famously has problems with eventual consistency (tracked in issue #1013, see also the heuristics that I added in PRs #1605, #1650 and #1710). In our team, we switched to CoreOS's competing product Quay instead, which works around the eventual consistency problems by storing most metadata in Postgres, putting only long-lived blobs into Swift.

Since we now want to make a new deployment where Quay is not an option, I implemented a new storage driver, currently called "swift-plus", which does the same: Metadata and small files (below 256 bytes) are stored in a Postgres instance, and large files (mostly image layers) go into Swift. I have yet to run any load tests on this, but the design would suggest that there should be no eventual consistency problems with this driver.

This is very WIP at the moment, but I'm putting up the PR now already to get some early feedback. Current status:

  • implementation
    • implement push
    • implement pull
    • implement efficient pull with URLFor
    • automatic first-time setup of DB schema
  • cleanup diff
  • documentation

Some notes on the implementation:

  • The swift-plus driver lives in the same Go package as the existing swift driver because of code sharing (related to config validation and driver initialization). Furthermore, the plus driver uses the original driver for Swift operations (via a private interface), so that the DB-related code (in the plus driver) is separated from the Swift-related code (in the original driver).
  • The configuration for swift-plus is nearly identical to swift, with the only difference being the required postgresuri configuration value that typically looks like postgres://user:password@hostname/databasename (see doc here).
  • There is no upgrade path from the swift driver to swift-plus, other than standing up a new registry instance and mirroring all images into it (i.e. for image; do docker pull && docker tag && docker push; done). I initially considered offering an upgrade path for all those existing users suffering from Swift eventual consistency problems? #1013, but it turned out to constrain the design too much.

@GordonTheTurtle

Copy link
Copy Markdown

Please sign your commits following these rules:
https://github.com/moby/moby/blob/master/CONTRIBUTING.md#sign-your-work
The easiest way to do this is to amend the last commit:

$ git clone -b "swift-plus" [email protected]:sapcc/distribution.git somewhere
$ cd somewhere
$ git rebase -i HEAD~842354442760
editor opens
change each 'pick' to 'edit'
save the file and quit
$ git commit --amend -s --no-edit
$ git rebase --continue # and repeat the amend for each commit
$ git push -f

Amending updates the existing PR. You DO NOT need to open a new one.

@codecov

codecov Bot commented Nov 7, 2017 •

Copy link
Copy Markdown

Codecov Report

Merging #2441 into master will decrease coverage by 1.31%.
The diff coverage is 43.53%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2441      +/-   ##
==========================================
- Coverage   50.52%   49.21%   -1.32%     
==========================================
  Files         125      130       +5     
  Lines       13855    12385    -1470     
==========================================
- Hits         7000     6095     -905     
+ Misses       6157     5528     -629     
- Partials      698      762      +64
Impacted Files Coverage Δ
context/logger.go 93.33% <ø> (-1.67%) ⬇️
configuration/configuration.go 68.33% <ø> (+1.9%) ⬆️
registry/storage/driver/storagedriver.go 33.33% <ø> (ø) ⬆️
registry/handlers/context.go 80.76% <ø> (+2.64%) ⬆️
registry/storage/driver/azure/azure.go 0.7% <0%> (+0.05%) ⬆️
registry/storage/driver/swift/swift-plus.go 0.49% <0%> (ø)
registry/storage/driver/inmemory/driver.go 73.71% <0%> (+0.11%) ⬆️
registry/storage/driver/gcs/gcs.go 0.39% <0%> (+0.07%) ⬆️
...storage/driver/middleware/cloudfront/middleware.go 2% <0%> (ø)
registry/registry.go 3.07% <0%> (+0.58%) ⬆️
... and 148 more

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 71f230d...7e09a80. Read the comment docs.

Signed-off-by: Stefan Majewsky <[email protected]>
The Swift storage driver famously has problems with eventual consistency
(see also the heuristics that I added last year). In our team, we
switched to CoreOS's competing product Quay instead, which works around
the eventual consistency problems by storing most metadata in Postgres,
putting only long-lived blobs into Swift.

Since we now want to make a new deployment where Quay is not an option,
I implemented a new storage driver, currently called "swift-plus", which
does the same: Metadata and small files (below 256 bytes) are stored in
a Postgres instance, and large files (mostly image layers) go into
Swift. I have yet to run any load tests on this, but the design would
suggest that there should be no eventual consistency problems with this
driver.

Some notes on the implementation:

- The `swift-plus` driver lives in the same Go package as the existing
  `swift` driver because of code sharing (related to config validation
  and driver initialization). Furthermore, the plus driver uses the
  original driver for Swift operations (via a private interface), so
  that the DB-related code (in the plus driver) is separated from the
  Swift-related code (in the original driver).

- The configuration for `swift-plus` is nearly identical to `swift`,
  with the only difference being the required `postgresuri`
  configuration value.

- There is *no upgrade path* from the `swift` driver to `swift-plus`,
  other than standing up a new registry instance and mirroring all
  images into it (i.e. `for image; do docker pull && docker tag &&
  docker push; done`). I initially considered offering an upgrade path
  for all those existing users suffering from distribution#1013, but it turned out
  to constrain the design too much.

Signed-off-by: Stefan Majewsky <[email protected]>
@zhouhaibing089

zhouhaibing089 commented Nov 9, 2017 •

Copy link
Copy Markdown
Contributor

it will bring much more complexity to operate registry with a database, storage driver is only about storage, not database.

However, I do agree that this is a place where registry should enhance, but should in a way that would benefit all the use cases no matter which storage driver is in use.

At my first thought, the cache layer is something that should be in, currently, it plays a role where we need to check existence of a certain blob by digest.

Well, what if the cache layer can also serve small blobs directly, actually, I mean the manifests, if this can be served directly without hitting storage, then this is no difference with a database setup probably. And, to complete the idea, we should also know when the manifest is removed from storage, but this should not be a big problem to detect/hook.

This is my naive idea though.

@majewsky

majewsky commented Nov 9, 2017

Copy link
Copy Markdown
Contributor Author

If one result of this discussion is to enhance the caching logic somewhere else in the Registry, and that alleviates the problems in #1013, then I'm all for it. I'm not certain, though. The biggest source of eventual consistency issues was with chunked uploading of layers, which swift-plus fixes by tracking segments in Postgres during upload (and also by using the more reliable SLOs instead of DLOs to merge segments into whole objects on the Swift side).

it will bring much more complexity to operate registry with a database, storage driver is only about storage, not database.

In my experience, a Postgres instance is much easier to operate than a Swift cluster, by multiple orders of magnitude. (Also, this is not about replacing the original swift driver. swift-plus is an option for those who want to invest more for the extra consistency.)

I thought about this some more and came to the conclusion that
implementing deleteUpwards() safely without any race conditions is not
worth the trouble. If there are some more DB entries for now-empty
directories, so what?

Signed-off-by: Stefan Majewsky <[email protected]>
@majewsky

Copy link
Copy Markdown
Contributor Author

I completed a load test with this driver on our infrastructure, using a similar setup with which I investigated the eventual inconsistency problems in the original Swift storage driver:

  • 10 worker processes continuously pounding Swift with PUT and DELETE requests for 1-byte objects, to create pressure on the object-updater and cause temporary inconsistencies
  • 10 worker processes that continuously build small Docker images (a single layer with 4 KiB of random data in it), then push them to the registry and pull them immediately afterwards

This ran for about 6 hours, totalling over 8,000 images pushed and pulled, and while Swift was visibly strained from the load according to our Grafana dashboards, not a single error occurred in the registry's log, and not a single request to Swift resulted in an error response (HTTP status code 400+). For comparison, the old Swift driver would have at least one or two errors per hour, and that's after all the patches that I contributed. And even then, there would be a ton of backoffs and retries because Swift would send 404 responses all the time.

@siju-vasudevan

Copy link
Copy Markdown

@majewsky . Thanks a lot !!!! . Can we use the new swift driver ? If yes what all changes we need to make from the existing setup and Do you have any short document for the new driver setup?

//PostgresURI is only used by the swift-plus driver. The value is a libpq
//connection URI (starting with "postgres://") as described here:
//https://www.postgresql.org/docs/9.6/static/libpq-connect.html#LIBPQ-CONNSTRING
PostgresURI string

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I may be missing something, but I don't see this used anywhere.

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.

Look at the swift-plus.go file. It's collapsed by default by Github's UI because it's fairly large.

@stevvooe

Copy link
Copy Markdown
Collaborator

@majewsky Thanks for the proposal!

I think this is an interesting approach, especially for those that are willing to add postgres to a registry deployment. Addressing this issue at the driver level, rather than the metadata level leaves room for making any driver more consistent (maybe) while avoiding the cost of upgrading. Even though you say there is no upgrade path, I am not so sure its something that couldn't be achieved.

Have you compared this approach to simply adding a store that makes the metadata consistent, avoiding hits to the storage driver? There would be a lot more code, but all drivers would benefit.

The results you got in your tests would make me think that postgres is already in use. However, I don't see any commits that call out to postgres. Am I missing something? Is there some changes we make on the existing driver to address these issues?

Looking forward to hearing your response.

@zhouhaibing089

Copy link
Copy Markdown
Contributor

@stevvooe could you comment on this as well?

what if the cache layer can also serve small blobs directly, actually, I mean the manifests, if this can be served directly without hitting storage, then this is no difference with a database setup probably.

@stevvooe

Copy link
Copy Markdown
Collaborator

@zhouhaibing089

what if the cache layer can also serve small blobs directly?

I have looked into this, both expanding redis' role and employing something like groupcache. That would address performance issues for slow backends (:eyes: s3). I am not sure what effect it would have on consistency, but I can't see addressing the same problems this PR is attempting to address, which is read-after-write consistency.

That said, it would be great to explore complementary patches that address this.

@majewsky

majewsky commented Dec 4, 2017

Copy link
Copy Markdown
Contributor Author

Sorry for not replying earlier. I have been off work for two weeks.

Even though you say there is no upgrade path, I am not so sure its something that couldn't be achieved.

It's difficult. I initially tried to use the same file layout on the Swift side, in order to enable an upgrade path, but gave up when trying to implement Move. I don't have all the details in my head anymore, but I found it more reliable to use randomly-chosen unique identifiers for blobs in Swift, and link these to the actual file paths in the DB only.

Have you compared this approach to simply adding a store that makes the metadata consistent, avoiding hits to the storage driver? There would be a lot more code, but all drivers would benefit.

I have not looked at this level yet. I'm only familiar with the storagedriver interface, and the swift implementation of that interface in particular. I may have a look when time permits. Do you have a particular place where I can start reading?

@Vad1mo

Vad1mo commented Mar 5, 2018 •

Copy link
Copy Markdown
Contributor

TBH I am not a big fan of this solution, It add more complexity, has no migration path.
However the swift problem #1013 is the one most discussed here and is in the top 50 of the oldest issues.
There are a few other related issues and PRs open related to that problem. Even is this is not an the best possible nor elegant solution that we could wish for.

This solution is the only one that works for swift.

I vote to make this driver part of the distribution, until a better solution is provided.

p.s.
I am currently writing a registry migrator tool that allows to move everything from one registry to another. This cli tool might be used to migrate.

Signed-off-by: Stefan Majewsky <[email protected]>
@milosgajdos

Copy link
Copy Markdown
Member

There is no plan to support new storage driver in distribution. In fact, we've just deprecated support for swift and oss drivers. We might reopen distribution to the new drivers but it will likely be done via some pluggable interface whilst the drivers itself would be managed in dedicated repositories. There is no ETA on that

@Jamstah

Jamstah commented Sep 18, 2023

Copy link
Copy Markdown
Collaborator

Currently not accepting new storage drivers. If you are maintaining a fork for swift support, you could consider adding it here: https://github.com/distribution/distribution/blob/main/docs/storage-drivers/index.md#driver-contribution

To join in discussion around storage drivers, see #3988.

@Jamstah Jamstah closed this Sep 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants