Skip to content
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

Rocksdb: create folder if it doesn't exist #245

Closed
wants to merge 10 commits into from

Conversation

faddat
Copy link
Contributor

@faddat faddat commented May 6, 2022

Instead of panicking and crashing, if rocksdb finds that it doesn't have a folder (eg: snapshots.db) it will now make it.

Tested and working here:

evmos/evmos#542

@codecov
Copy link

codecov bot commented May 6, 2022

Codecov Report

Merging #245 (42f39d9) into master (b3c748f) will decrease coverage by 0.06%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #245      +/-   ##
==========================================
- Coverage   68.54%   68.48%   -0.07%     
==========================================
  Files          27       27              
  Lines        2130     2132       +2     
==========================================
  Hits         1460     1460              
- Misses        595      597       +2     
  Partials       75       75              
Impacted Files Coverage Δ
rocksdb.go 71.22% <0.00%> (-1.04%) ⬇️
Impacted Files Coverage Δ
rocksdb.go 71.22% <0.00%> (-1.04%) ⬇️

Copy link
Contributor

@creachadair creachadair left a comment

Choose a reason for hiding this comment

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

The description says rocks, but touches badger also, and a bunch of other unrelated changes. Let's please keep the cleanup changes separate from the changes that do more meaningful stuff.

Note that BadgerDB doesn't require this treatment: It will create the prefix of the path it's given if necessary. (I don't know about Rocks)

@faddat
Copy link
Contributor Author

faddat commented May 6, 2022

oh sure thing!

I have a habit of always fumpting. 1 moment please.

Back down to one file changed now.

@@ -50,7 +51,10 @@ func NewRocksDBWithOptions(name string, dir string, opts *gorocksdb.Options) (*R
dbPath := filepath.Join(dir, name+".db")
db, err := gorocksdb.OpenDb(opts, dbPath)
if err != nil {
return nil, err
err = os.MkdirAll(dbPath, 0755)
Copy link
Contributor

Choose a reason for hiding this comment

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

gorocksdb.OpenDb calls the C library's rocksdb_open which already creates the directory if it doesn't exist (ref). So this is harmless, but should not be necessary for RocksDB.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not for state sync snapshots.

I am not sure why that is the case, but it is the case.

Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose there is no harm in creating the directory. But isn't this backwards? If we don't create the directory till after the OpenDb call has already failed, the code below will fail anyway.

I'm guessing this probably wants to be something like

if err := os.MkdirAll(dbPath, 0700); err != nil {
   return nil, fmt.Errorf("creating database path: %w", err)
}
db, err := gorocksdb.OpenDb(opts, dbPath)
if err != nil {
   return nil, fmt.Errorf("opening database: %w", err)
}

or words to that effect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know why this works. Let me show ya what I have......

@github-actions
Copy link

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the Stale label Jun 25, 2022
@github-actions github-actions bot closed this Jul 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants