Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Fail upload if it uses more then available space #220

Merged
merged 3 commits into from
Nov 9, 2023

Conversation

gammazero
Copy link
Collaborator

Before upload, check that more then the disk has more than the minimum free space. Upload up to the size limit that would exceed the available space.

Fixes #179

Before upload, check that more then the disk has more than the minimum free space. Upload up to the size limit that would exceed the available space.

Fixes #179
Copy link
Contributor

@elijaharita elijaharita left a comment

Choose a reason for hiding this comment

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

Aside from one non-critical recommendation, looks good to me

}

// NewLocalStore instantiates a new LocalStore and uses the given dir as the place to store blobs.
// Blobs are stored as flat files, named by their ID with .bin extension.
func NewLocalStore(dir string) *LocalStore {
func NewLocalStore(dir string, minFreeSpace uint64) *LocalStore {
Copy link
Contributor

Choose a reason for hiding this comment

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

This new parameter might go better in a new config struct, since it's optional and what it represents is not obvious when reading a function call. Will also set up a better pattern for adding new options if ever needed in the future.

myStore := NewLocalStore("/a/dir", 1024) // what is 1024?

myStore := NewLocalStore("/a/dir", LocalStoreConfig { MinFreeSpace: 1024 }) // better in my opinion

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I would prefer to pass Option parameters instead of a config. If passing a config, we would still want a source of default values, which the option provides. I am implemented the optional parameter in the PR update.

As far as this: myStore := NewLocalStore("/a/dir", 1024)
... no one should ever do that anyway. Code like that should always use a const, never a raw number. For example:

const minFreeSpace = 2 * Gib // 2 Gib must remain free on disk
...
myStore := NewLocalStore("/a/dir", minFreeSpace)

Copy link
Contributor

Choose a reason for hiding this comment

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

nice, option pattern is even better

fair point about minFreeSpace as a param. i guess i can't back it up more than that it feels weird - i like to see fundamental, required fields as direct constructor params and optional peripheral fields to go in a config struct or option pattern.

definitely more philosophical than practical, would never deny a PR on these grounds, i just like discussing style : )

@codecov-commenter
Copy link

Codecov Report

Merging #220 (d72ab67) into main (c504ff1) will increase coverage by 1.85%.
The diff coverage is 70.83%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #220      +/-   ##
==========================================
+ Coverage   38.31%   40.17%   +1.85%     
==========================================
  Files           6        7       +1     
  Lines         903      941      +38     
==========================================
+ Hits          346      378      +32     
- Misses        511      515       +4     
- Partials       46       48       +2     
Files Coverage Δ
blob/blob.go 37.50% <ø> (ø)
integration/singularity/store.go 35.94% <100.00%> (+1.00%) ⬆️
blob/option.go 81.25% <81.25%> (ø)
integration/singularity/options.go 23.46% <0.00%> (-0.68%) ⬇️
blob/local_store.go 45.83% <76.00%> (+11.28%) ⬆️

Copy link
Contributor

@elijaharita elijaharita left a comment

Choose a reason for hiding this comment

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

nice

@gammazero gammazero merged commit f9281a2 into main Nov 9, 2023
7 checks passed
@gammazero gammazero deleted the low-storage-fails-upload branch November 9, 2023 03:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fail fast upload request if running out of disk space
3 participants