Skip to content

Conversation

laanwj
Copy link
Member

@laanwj laanwj commented Oct 9, 2013

This pull may be slightly controversial, but I dare say that GetDataDir() is never used on any performance critical paths (and if it is, it is a bug).
It's not that heavy in the first place.

This change simplifies the code (no more ClearDatadirCache) and removes any pathCached/csPathCached destruction order problems (if they are still around).

@@ -1033,9 +1033,7 @@ void PrintExceptionContinue(std::exception* pex, const char* pszThread)
pathRet = fs::path(pszHome);
#ifdef MAC_OSX
// Mac
pathRet /= "Library/Application Support";
fs::create_directory(pathRet);
Copy link
Member Author

Choose a reason for hiding this comment

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

Removed this fs::create_directory as we do fs::create_directories anyway which creates all parent directories as needed.

Copy link

Choose a reason for hiding this comment

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

You mean in GetDataDir()?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. Or are there any other paths to here?

Copy link

Choose a reason for hiding this comment

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

AFAIK no.

@Diapolo
Copy link

Diapolo commented Oct 10, 2013

I'm fine with that change, I remember it was a pain to see some issues raised, because of wrong data-dir paths because of caching etc.

@BitcoinPullTester
Copy link

Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/23e0d45b79f1885a318f9eed6a7c5ceb6e449206 for binaries and test log.
This test script verifies pulls every time they are updated. It, however, dies sometimes and fails to test properly. If you are waiting on a test, please check timestamps to verify that the test.log is moving at http://jenkins.bluematt.me/pull-tester/current/
Contact BlueMatt on freenode if something looks broken.

static CCriticalSection csPathCached;

const boost::filesystem::path &GetDataDir(bool fNetSpecific)
const boost::filesystem::path GetDataDir(bool fNetSpecific)
Copy link
Member

Choose a reason for hiding this comment

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

Returning a const by value doesn't mean much :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Lol, indeed, I'll remove the const

@sipa
Copy link
Member

sipa commented Oct 13, 2013

OpenDiskFile() calls GetDataDir, so during IBD and initial startup it is called many times. It's unlikely to be a performance burden, but it seems silly to make that many system calls (yes, I realize we call open() and read() and gettimeofdate() much more...) over and over again, trusting that it will never change.

I'd be fine with just storing the block directory once in main, and reusing that, instead of having a cache at the GetDataDir level.

@laanwj
Copy link
Member Author

laanwj commented Oct 15, 2013

I think it's silly to use this kind of caching logic for what is a simple string operation that is only invoked before opening a file.

With the system call you mean the fs::create_directories (as getenv is not a system call)? I agree that's a bit silly to do every time. It would be better to create the directories at some sane point in the initialization process and not every time before returning.

Hmmm maybe the directory could be stored at that point too, avoiding the computation in GetDataDir completely AND any caching logic, and also the dependency on Params().DataDir().

@laanwj
Copy link
Member Author

laanwj commented Oct 19, 2013

I don't care enough about this to keep it open.

@laanwj laanwj closed this Oct 19, 2013
laanwj added a commit that referenced this pull request Nov 18, 2017
c1e5d40 Make debugging test crash easier (MeshCollider)
8263f6a Create walletdir if datadir doesn't exist and fix tests (MeshCollider)
9587a9c Default walletdir is wallets/ if it exists (MeshCollider)
d987889 Add release notes for -walletdir and wallets/ dir (MeshCollider)
80c5cbc Add test for -walletdir (MeshCollider)
0530ba0 Add -walletdir parameter to specify custom wallet dir (MeshCollider)

Pull request description:

  Closes #11348

  Adds a `-walletdir` parameter which specifies a directory to use for wallets, allowing them to be stored separately from the 'main' data directory. Creates a new `wallets/` directory in datadir if this is the first time running, and defaults to using it if it exists.

  Includes tests and release notes. Things which might need to be considered more:
  - there is no 'lock' on the wallets directory, which might be needed?
  - because this uses a new wallets/ directory by default, downgrading to an earlier version won't see the wallets in that directory (not a big deal though, users can just copy them up to the main dir)
  - jnewbery suggested putting each wallet in its own directory, which is a good idea, but out of scope for this PR IMO. EDIT: this is being done in #11687
  - doc/files.md needs updating (will do soon)

  I also considered including  a cleanup by removing caching of data directory paths and instead just initialise them once on startup (c.f. #3073), but decided it wasn't super relevant here will just complicate review.

Tree-SHA512: c8ac04bfe9a810c32055f2c8b8fa0d535e56125ceb8d96f12447dd3538bf3e5ee992b60b1cd2173bf5f3fa023a9feab12c9963593bf27ed419df929bb413398d
Bushstar pushed a commit to Bushstar/omnicore that referenced this pull request Apr 8, 2020
…param

c1e5d40 Make debugging test crash easier (MeshCollider)
8263f6a Create walletdir if datadir doesn't exist and fix tests (MeshCollider)
9587a9c Default walletdir is wallets/ if it exists (MeshCollider)
d987889 Add release notes for -walletdir and wallets/ dir (MeshCollider)
80c5cbc Add test for -walletdir (MeshCollider)
0530ba0 Add -walletdir parameter to specify custom wallet dir (MeshCollider)

Pull request description:

  Closes bitcoin#11348

  Adds a `-walletdir` parameter which specifies a directory to use for wallets, allowing them to be stored separately from the 'main' data directory. Creates a new `wallets/` directory in datadir if this is the first time running, and defaults to using it if it exists.

  Includes tests and release notes. Things which might need to be considered more:
  - there is no 'lock' on the wallets directory, which might be needed?
  - because this uses a new wallets/ directory by default, downgrading to an earlier version won't see the wallets in that directory (not a big deal though, users can just copy them up to the main dir)
  - jnewbery suggested putting each wallet in its own directory, which is a good idea, but out of scope for this PR IMO. EDIT: this is being done in bitcoin#11687
  - doc/files.md needs updating (will do soon)

  I also considered including  a cleanup by removing caching of data directory paths and instead just initialise them once on startup (c.f. bitcoin#3073), but decided it wasn't super relevant here will just complicate review.

Tree-SHA512: c8ac04bfe9a810c32055f2c8b8fa0d535e56125ceb8d96f12447dd3538bf3e5ee992b60b1cd2173bf5f3fa023a9feab12c9963593bf27ed419df929bb413398d
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
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