diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 42b8de852..b72318f32 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -7,7 +7,7 @@ name: Execute code coverage jobs: nightly-coverage: - runs-on: ubuntu-latest + runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 diff --git a/.github/workflows/publish-binaries.yml b/.github/workflows/publish-binaries.yml index 944932b4c..601a8dbf4 100644 --- a/.github/workflows/publish-binaries.yml +++ b/.github/workflows/publish-binaries.yml @@ -10,9 +10,9 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, macos-latest, windows-latest] + os: [ubuntu-18.04, macos-latest, windows-latest] include: - - os: ubuntu-latest + - os: ubuntu-18.04 artifact_name: meilisearch asset_name: meilisearch-linux-amd64 - os: macos-latest diff --git a/.github/workflows/publish-deb-brew-pkg.yml b/.github/workflows/publish-deb-brew-pkg.yml index adc785743..163b16573 100644 --- a/.github/workflows/publish-deb-brew-pkg.yml +++ b/.github/workflows/publish-deb-brew-pkg.yml @@ -7,7 +7,7 @@ on: jobs: debian: name: Publish debian packagge - runs-on: ubuntu-latest + runs-on: ubuntu-18.04 steps: - uses: hecrj/setup-rust-action@master with: @@ -29,7 +29,7 @@ jobs: homebrew: name: Bump Homebrew formula - runs-on: ubuntu-latest + runs-on: ubuntu-18.04 steps: - name: Create PR to Homebrew uses: mislav/bump-homebrew-formula-action@v1 diff --git a/.github/workflows/publish-docker-latest.yml b/.github/workflows/publish-docker-latest.yml index 186a635c1..967248a07 100644 --- a/.github/workflows/publish-docker-latest.yml +++ b/.github/workflows/publish-docker-latest.yml @@ -7,7 +7,7 @@ name: Publish latest image to Docker Hub jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v2 - name: Check if current release is latest diff --git a/.github/workflows/publish-docker-tag.yml b/.github/workflows/publish-docker-tag.yml index 852797832..d607d4286 100644 --- a/.github/workflows/publish-docker-tag.yml +++ b/.github/workflows/publish-docker-tag.yml @@ -8,7 +8,7 @@ name: Publish tagged image to Docker Hub jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v1 - name: Publish to Registry diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ddc8150b6..bdb20fc70 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,7 +16,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, macos-latest] + os: [ubuntu-18.04, macos-latest] steps: - uses: actions/checkout@v1 - uses: actions-rs/toolchain@v1 @@ -34,11 +34,11 @@ jobs: uses: actions-rs/cargo@v1 with: command: clippy - args: --all-targets -- --deny warnings + args: --all-targets build-image: name: Test the build of Docker image - runs-on: ubuntu-latest + runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v1 - run: docker build . --file Dockerfile -t meilisearch @@ -49,7 +49,7 @@ jobs: name: create prerelease needs: [check, build-image] if: ${{ contains(github.ref, 'release-') && github.event_name == 'push' }} - runs-on: ubuntu-latest + runs-on: ubuntu-18.04 steps: - name: Checkout code uses: actions/checkout@v2 @@ -76,13 +76,13 @@ jobs: name: create release needs: [check, build-image] if: ${{ contains(github.ref, 'tags/v') }} - runs-on: ubuntu-latest + runs-on: ubuntu-18.04 steps: - name: Checkout code uses: actions/checkout@v2 - name: Get version number id: version-number - run: echo "##[set-output name=number;]$(echo ${{ github.ref }} | sed 's/.*\(v.*\)/\1/')" + run: echo "##[set-output name=number;]$(echo ${{ github.ref }} | sed 's/.*\(v.*\)/\1/')" - name: Create Release id: create_release uses: actions/create-release@v1 diff --git a/bors.toml b/bors.toml index 35b5c4a9f..4a3bf8c38 100644 --- a/bors.toml +++ b/bors.toml @@ -1,3 +1,3 @@ -status = ["Test on macos-latest", "Test on ubuntu-latest"] +status = ["Test on macos-latest", "Test on ubuntu-18.04"] # 4 hours timeout timeout-sec = 14400 diff --git a/meilisearch-core/src/store/facets.rs b/meilisearch-core/src/store/facets.rs index 1a7579099..6766a8a01 100644 --- a/meilisearch-core/src/store/facets.rs +++ b/meilisearch-core/src/store/facets.rs @@ -48,10 +48,10 @@ impl<'a> BytesDecode<'a> for FacetData { let mut size_buf = [0; LEN]; size_buf.copy_from_slice(bytes.get(0..LEN)?); // decode size of the first item from the bytes - let first_size = usize::from_be_bytes(size_buf); + let first_size = u64::from_be_bytes(size_buf); // decode first and second items - let first_item = Str::bytes_decode(bytes.get(LEN..(LEN + first_size))?)?; - let second_item = CowSet::bytes_decode(bytes.get((LEN + first_size)..)?)?; + let first_item = Str::bytes_decode(bytes.get(LEN..(LEN + first_size as usize))?)?; + let second_item = CowSet::bytes_decode(bytes.get((LEN + first_size as usize)..)?)?; Some((first_item, second_item)) } } diff --git a/meilisearch-http/src/main.rs b/meilisearch-http/src/main.rs index 8a4cd620b..0fd84fac1 100644 --- a/meilisearch-http/src/main.rs +++ b/meilisearch-http/src/main.rs @@ -123,7 +123,7 @@ pub fn print_launch_resume(opt: &Opt, data: &Data) { eprintln!("{}", ascii_name); eprintln!("Database path:\t\t{:?}", opt.db_path); - eprintln!("Server listening on: http://\t{:?}", opt.http_addr); + eprintln!("Server listening on:\t\"http://{}\"", opt.http_addr); eprintln!("Environment:\t\t{:?}", opt.env); eprintln!("Commit SHA:\t\t{:?}", env!("VERGEN_SHA").to_string()); eprintln!( diff --git a/meilisearch-http/src/snapshot.rs b/meilisearch-http/src/snapshot.rs index 505ddd269..90db8460a 100644 --- a/meilisearch-http/src/snapshot.rs +++ b/meilisearch-http/src/snapshot.rs @@ -7,7 +7,6 @@ use std::fs::create_dir_all; use std::path::Path; use std::thread; use std::time::Duration; -use tempfile::TempDir; pub fn load_snapshot( db_path: &str, @@ -28,12 +27,22 @@ pub fn load_snapshot( } } -pub fn create_snapshot(data: &Data, snapshot_path: &Path) -> Result<(), Error> { - let tmp_dir = TempDir::new_in(snapshot_path)?; +pub fn create_snapshot(data: &Data, snapshot_dir: impl AsRef, snapshot_name: impl AsRef) -> Result<(), Error> { + create_dir_all(&snapshot_dir)?; + let tmp_dir = tempfile::tempdir_in(&snapshot_dir)?; data.db.copy_and_compact_to_path(tmp_dir.path())?; - compression::to_tar_gz(tmp_dir.path(), snapshot_path).map_err(|e| Error::Internal(format!("something went wrong during snapshot compression: {}", e))) + let temp_snapshot_file = tempfile::NamedTempFile::new_in(&snapshot_dir)?; + + compression::to_tar_gz(tmp_dir.path(), temp_snapshot_file.path()) + .map_err(|e| Error::Internal(format!("something went wrong during snapshot compression: {}", e)))?; + + let snapshot_path = snapshot_dir.as_ref().join(snapshot_name.as_ref()); + + temp_snapshot_file.persist(snapshot_path).map_err(|e| Error::Internal(e.to_string()))?; + + Ok(()) } pub fn schedule_snapshot(data: Data, snapshot_dir: &Path, time_gap_s: u64) -> Result<(), Error> { @@ -42,10 +51,11 @@ pub fn schedule_snapshot(data: Data, snapshot_dir: &Path, time_gap_s: u64) -> Re } let db_name = Path::new(&data.db_path).file_name().ok_or_else(|| Error::Internal("invalid database name".to_string()))?; create_dir_all(snapshot_dir)?; - let snapshot_path = snapshot_dir.join(format!("{}.snapshot", db_name.to_str().unwrap_or("data.ms"))); + let snapshot_name = format!("{}.snapshot", db_name.to_str().unwrap_or("data.ms")); + let snapshot_dir = snapshot_dir.to_owned(); thread::spawn(move || loop { - if let Err(e) = create_snapshot(&data, &snapshot_path) { + if let Err(e) = create_snapshot(&data, &snapshot_dir, &snapshot_name) { error!("Unsuccessful snapshot creation: {}", e); } thread::sleep(Duration::from_secs(time_gap_s)); @@ -62,7 +72,7 @@ mod tests { #[test] fn test_pack_unpack() { - let tempdir = TempDir::new().unwrap(); + let tempdir = tempfile::tempdir().unwrap(); let test_dir = tempdir.path(); let src_dir = test_dir.join("src");