Skip to content
This repository was archived by the owner on Aug 2, 2021. It is now read-only.

[Store] Allow parameters to be set via cli and env vars#195

Merged
gbalint merged 1 commit into
ethersphere:swarm-network-rewritefrom
async-la:storage-params
Jan 18, 2018
Merged

[Store] Allow parameters to be set via cli and env vars#195
gbalint merged 1 commit into
ethersphere:swarm-network-rewritefrom
async-la:storage-params

Conversation

@christopherdro
Copy link
Copy Markdown

I'm not sure if this is the best branch to PR against but I wanted to avoid future conflicts with #172

Comment thread swarm/storage/netstore.go
self.ChunkDbPath = filepath.Join(path, "chunks")
if self.ChunkDbPath == "" {
self.ChunkDbPath = filepath.Join(path, "chunks")
}
Copy link
Copy Markdown
Author

@christopherdro christopherdro Jan 14, 2018

Choose a reason for hiding this comment

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

Is this the best way to handle this or does it make more sense to add this to NewDefaultStoreParams ? https://github.com/async-la/go-ethereum/blob/872aeef800ee6368704bec7fc8108d4a235b6e19/swarm/storage/netstore.go#L61

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think it is fine here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It needs to be here because the default for a path can be overridden by command line or env var later.

Comment thread cmd/swarm/main.go Outdated
EnvVar: SWARM_ENV_STORE_CACHE_CAPACITY,
}
SwarmStoreRadius = cli.IntFlag{
Name: "radius",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think the flags should be prefixed with store., for example:

--store.path
--store.size
--store.cache.size
--store.radius

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

👍

Comment thread cmd/swarm/config.go Outdated
}

if storeDbCapacity := os.Getenv(SWARM_ENV_STORE_DB_CAPACITY); storeDbCapacity != "" {
if id, _ := strconv.Atoi(storeDbCapacity); id != 0 {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This should return an error rather silently ignoring an incorrectly formatted value.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Strictly for this config or all flags that try and convert string to int?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I mean there should always be a good reason to ignore errors, and I don't feel like there is a good reason to here (e.g. if I put --store.size=1O (i.e. the letter O rather than a zero) then I'd rather get an error than silently ignore).

So I'd recommend all code like this to check the error, but I don't think it is necessary to make that change in this PR.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Agreed. I’ll make the changes here and follow up with another PR addressing the others.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It doesn't look like we need to use os.Getenv at all if we use the EnvVar property when defining our cli flags. https://github.com/ethersphere/go-ethereum/pull/195/files#diff-5be8f583a91eb8ca7024b8af84ef4b28R165 I think this also behaves as intended with the order of precedence being , cli -> env vars -> default.

The most recent changes I see around this was in ethereum/go-ethereum#15548. @holisticode I think we we might be able to get rid of envVarsOverride here as long as the EnvVar property is set when the flags are initially defined.

@lmars By using the correct types for our cli flags, we get syntax checking we want.
Setting --store.size=1O would result in a in the following error.
invalid value "1O" for flag -store.size: strconv.ParseUint: parsing "1O": invalid syntax

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Indeed it seems EnvVar can supply the needs of envVarsOverride - nevertheless before doing so thorough testing is required. I think to remember that EnvVar behavior with default values sometimes interfered with intended behavior, but I don't recall details.

Comment thread swarm/storage/netstore.go
self.ChunkDbPath = filepath.Join(path, "chunks")
if self.ChunkDbPath == "" {
self.ChunkDbPath = filepath.Join(path, "chunks")
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think it is fine here.

@christopherdro christopherdro force-pushed the storage-params branch 3 times, most recently from 04d62f7 to 22c4761 Compare January 14, 2018 22:48
Comment thread cmd/swarm/main.go
SwarmUploadMimeType,
// pss flags
SwarmPssEnabledFlag,
// storage flags
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

rename comment to store

@gbalint gbalint force-pushed the swarm-network-rewrite branch from a9cd26e to ddfc0a2 Compare January 15, 2018 09:27
@christopherdro
Copy link
Copy Markdown
Author

@gbalint Was there a reason you tried to merge network rewrite here?

@christopherdro
Copy link
Copy Markdown
Author

I just rebased and forced push back up. Should be good to go again.

@gbalint gbalint force-pushed the swarm-network-rewrite branch from 70d231b to c38007a Compare January 17, 2018 09:57
@janos janos force-pushed the swarm-network-rewrite branch from c38007a to 70d231b Compare January 17, 2018 10:09
@gbalint gbalint merged commit d15ba94 into ethersphere:swarm-network-rewrite Jan 18, 2018
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.

4 participants