Skip to content

Refactor storage #643

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

Merged
merged 38 commits into from
May 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
e49396d
storage: move db::file::Blob to storage::Blob
pietroalbini Jan 22, 2020
69b36c4
wip
pietroalbini Jan 23, 2020
fc944a1
Add some impls
jyn514 Mar 15, 2020
b868fc5
Remove unnecessary copy
jyn514 Mar 15, 2020
15ec1c6
Use new Storage backend
jyn514 Mar 15, 2020
75e30f7
[BROKEN] try to add rusoto_mock
jyn514 Mar 15, 2020
7727a98
Get basic tests working
jyn514 Mar 16, 2020
b980ebb
Add 404 test
jyn514 Mar 16, 2020
2cc30a6
Refactor out shared code
jyn514 Mar 16, 2020
8c44199
Split uploading into different functions
jyn514 Mar 17, 2020
42d82c1
Add tests for `store_all`
jyn514 Mar 17, 2020
8bbf8d3
Clean up store_all a little
jyn514 Mar 17, 2020
8d328fa
Fix typo
jyn514 Apr 10, 2020
c4f3ecf
Fix rebase conflicts
jyn514 Apr 11, 2020
6d18790
Run rustfmt
jyn514 Apr 11, 2020
81b7325
Encapsulate the s3_client
jyn514 Apr 11, 2020
abbb3e0
Remove code duplication
jyn514 Apr 13, 2020
c06e21c
Pre-allocate vectors of known size
jyn514 Apr 13, 2020
1341332
Use 2018 idioms
jyn514 Apr 13, 2020
cd99af0
Remove move-to-s3 command
jyn514 Apr 15, 2020
4549ed8
Use `ON CONFLICT` instead of rewriting it manually
jyn514 Apr 15, 2020
9213286
haha rustfmt go brrr
jyn514 Apr 15, 2020
c6b79f3
Only create runtime once, instead of for each batch
jyn514 Apr 20, 2020
a12aef4
Don't poll each future on each wakeup
jyn514 Apr 20, 2020
30ff8ad
Make rustfmt happy
jyn514 Apr 20, 2020
e89dab8
Don't hold all PutObjectOutputs in memory
jyn514 Apr 20, 2020
7251900
Fix test failure
jyn514 Apr 20, 2020
478dcb9
Use min.io to test S3 uploads
jyn514 Apr 25, 2020
df9de24
[BROKEN] start adding more tests
jyn514 Apr 25, 2020
cb9f5fe
Add more tests
jyn514 Apr 26, 2020
4c4c623
rustfmt go brrr
jyn514 Apr 26, 2020
2194aa8
Cleanup
jyn514 Apr 26, 2020
2911c7a
Add instructions to README for running s3 tests
jyn514 Apr 26, 2020
8268445
Move some code around
jyn514 Apr 28, 2020
ec9280e
Don't read all files into memory at once
jyn514 Apr 28, 2020
034b8ca
Add test for uploading more than a single batch of files
jyn514 Apr 28, 2020
e0104d0
Move TestS3 into a submodule
jyn514 Apr 29, 2020
5d982d7
test_s3 -> test
jyn514 May 1, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ CRATESFYI_GITHUB_ACCESSTOKEN=
CRATESFYI_PREFIX=ignored/cratesfyi-prefix
CRATESFYI_DATABASE_URL=postgresql://cratesfyi:password@localhost
RUST_LOG=cratesfyi,rustwide=info
AWS_ACCESS_KEY_ID=cratesfyi
AWS_SECRET_ACCESS_KEY=secret_key
S3_ENDPOINT=http://localhost:9000
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ jobs:
restore-key: |
${{ runner.os }}-cargo-build-target-${{ env.CURRENT_RUSTC_VERSION }}-

- name: Launch the postgres image
- name: Launch the postgres and min.io images
run: |
cp .env.sample .env
. .env
mkdir -p ${CRATESFYI_PREFIX}/public-html
docker-compose up -d db
docker-compose up -d db s3
# Give the database enough time to start up
sleep 5
# Make sure the database is actually working
Expand Down
20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,22 @@ cargo test
```

Some tests require access to the database. To run them, set the
`CRATESFYI_DATABASE_URL` to the url of a PostgreSQL database. If you are using
the `docker-compose` environment to run tests against, see the
[Docker-Compose][docker-compose-section] section for the default PostgreSQL URL.
You don't have to run the migrations on it or ensure it's empty, as all the
tests use temporary tables to prevent conflicts with each other or existing
data. See the [wiki page on developing outside docker-compose][wiki-no-compose]
`CRATESFYI_DATABASE_URL` in `.env` to the url of a PostgreSQL database,
and set the `AWS_ACCESS_KEY_ID`, `S3_ENDPOINT`, and `AWS_SECRET_ACCESS_KEY` variables.
We have some reasonable default parameters in `.env.sample`.

For example, if you are using the `docker-compose` environment to run tests against, you can launch only the database and s3 server like so:

```console
docker-compose up -d db s3
```

If you don't want to use docker-compose, see the
[wiki page on developing outside docker-compose][wiki-no-compose]
for more information on how to setup this environment.
Note that either way, you will need docker installed for sandboxing with Rustwide.

[wiki-no-compose]: https://github.com/rust-lang/docs.rs/wiki/Developing-without-docker-compose
[docker-compose-section]: #Docker-Compose

### Docker-Compose

Expand Down
13 changes: 0 additions & 13 deletions src/bin/cratesfyi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ pub fn main() {
.subcommand(SubCommand::with_name("database")
.about("Database operations")
.setting(AppSettings::ArgRequiredElseHelp)
.subcommand(SubCommand::with_name("move-to-s3"))
.subcommand(SubCommand::with_name("migrate")
.about("Run database migrations")
.arg(Arg::with_name("VERSION")))
Expand Down Expand Up @@ -263,18 +262,6 @@ pub fn main() {
} else if matches.subcommand_matches("update-search-index").is_some() {
let conn = db::connect_db().unwrap();
db::update_search_index(&conn).expect("Failed to update search index");
} else if matches.subcommand_matches("move-to-s3").is_some() {
let conn = db::connect_db().unwrap();
let mut count = 1;
let mut total = 0;
while count != 0 {
count = db::move_to_s3(&conn, 5_000).expect("Failed to upload batch to S3");
total += count;
eprintln!(
"moved {} rows to s3 in this batch, total moved so far: {}",
count, total
);
}
} else if let Some(matches) = matches.subcommand_matches("delete-crate") {
let name = matches.value_of("CRATE_NAME").expect("missing crate name");
let conn = db::connect_db().expect("failed to connect to the database");
Expand Down
2 changes: 1 addition & 1 deletion src/db/delete_crate.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::file::{s3_client, S3_BUCKET_NAME};
use crate::storage::s3::{s3_client, S3_BUCKET_NAME};
use failure::{Error, Fail};
use postgres::Connection;
use rusoto_s3::{DeleteObjectsRequest, ListObjectsV2Request, ObjectIdentifier, S3Client, S3};
Expand Down
Loading