Skip to content

Conversation

@maflcko
Copy link
Member

@maflcko maflcko commented Jun 20, 2019

The rationale for caching the datadir is given as

    // This can be called during exceptions by LogPrintf(), so we cache the
    // value so we don't have to do memory allocations after that.

However, since 8c2d695, the debug log location is actually cached itself in m_file_path.

So remove the now-useless caching.

@maflcko
Copy link
Member Author

maflcko commented Jun 20, 2019

Will reopen after #16252

@maflcko maflcko closed this Jun 20, 2019
@laanwj
Copy link
Member

laanwj commented Jun 25, 2019

Concept ACK

Copy link
Member

Choose a reason for hiding this comment

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

happy to see this code simplified, it has been a frequent source of errors in the past

@fanquake fanquake reopened this Jun 25, 2019
@maflcko maflcko force-pushed the 1906-utilNoPath branch 4 times, most recently from fa1c363 to aaaa660 Compare June 25, 2019 14:55
@DrahtBot
Copy link
Contributor

DrahtBot commented Jun 25, 2019

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #16273 (refactor: Remove unused includes by practicalswift)
  • #15871 (Handle exception when creating default -datadir by promag)
  • #15864 (Fix datadir handling by hebasto)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@laanwj
Copy link
Member

laanwj commented Jun 27, 2019

A side-effect of caching was that this code was only run the first call to GetDataDir. Right now, it will try to create the data directory every time:

    if (fs::create_directories(path)) {
        // This is the first run, create wallets subdirectory too
        fs::create_directories(path / "wallets");
    }

(this not only results in system call spam, but also a change in behavior if, for some reason, the datadir disappears)
A simple solution to avoid this would be to add a static bool flag for this.

@promag
Copy link
Contributor

promag commented Jun 27, 2019

but also a change in behavior if, for some reason, the datadir disappears

that's good?

@laanwj wouldn't it be better to just call create_directories as soon as possible, like it should belong to the startup? Currently is kind of hard to know when directories are actually created.

@laanwj
Copy link
Member

laanwj commented Jun 27, 2019

that's good?

That definitely isn't good, if the datadir disappears while running you want the process to die as soon as possible and not mess with creating directories.

@laanwj wouldn't it be better to just call create_directories as soon as possible, like it should belong to the startup? Currently is kind of hard to know when directories are actually created.

Yes that would be better, however this is very hard to reason about, and review, with the complexity of our startup sequence. Maybe better to leave for a future PR, which is why I suggested the most straightforward solution.

@maflcko maflcko force-pushed the 1906-utilNoPath branch 2 times, most recently from 75d7c6c to facf965 Compare June 27, 2019 16:09
@maflcko
Copy link
Member Author

maflcko commented Jun 27, 2019

It is indeed weird to write to disk in a method, whose name implies it is a simple getter.

Added a guard to the disk access for now, but this should be improved in the future. (See also "Fix datadir handling" #15864)

@maflcko
Copy link
Member Author

maflcko commented Jun 27, 2019

I think this is not worth it, so giving up on this for now. Someone should move out the fs::create_directories first.

@maflcko maflcko closed this Jun 27, 2019
@maflcko maflcko deleted the 1906-utilNoPath branch June 27, 2019 18:15
laanwj added a commit that referenced this pull request Jun 28, 2019
fa69c3e util: Explain why the path is cached (MarcoFalke)

Pull request description:

  The rationale for caching the datadir is given as

  ```
      // This can be called during exceptions by LogPrintf(), so we cache the
      // value so we don't have to do memory allocations after that.
  ```

  Since 8c2d695, the debug log location is actually cached itself in `m_file_path`.

  So explain that the caching is now only used to guard against disk access on each call. (See also #16255)

ACKs for top commit:
  promag:
    ACK fa69c3e.
  laanwj:
    ACK fa69c3e
  ryanofsky:
    utACK fa69c3e. Good cleanup. Previous comment was confusing, and definitely not helpful if outdated.

Tree-SHA512: 02108c90026d6d7c02843aaf59a06b4e1fa63d5d4378bb7760f50767efc340dc94c259bf7afb32fa4d47952b48a4e91798d1e0ddc1b051d770405e078636793a
Munkybooty pushed a commit to Munkybooty/dash that referenced this pull request Nov 18, 2021
fa69c3e util: Explain why the path is cached (MarcoFalke)

Pull request description:

  The rationale for caching the datadir is given as

  ```
      // This can be called during exceptions by LogPrintf(), so we cache the
      // value so we don't have to do memory allocations after that.
  ```

  Since 8c2d695, the debug log location is actually cached itself in `m_file_path`.

  So explain that the caching is now only used to guard against disk access on each call. (See also bitcoin#16255)

ACKs for top commit:
  promag:
    ACK fa69c3e.
  laanwj:
    ACK fa69c3e
  ryanofsky:
    utACK fa69c3e. Good cleanup. Previous comment was confusing, and definitely not helpful if outdated.

Tree-SHA512: 02108c90026d6d7c02843aaf59a06b4e1fa63d5d4378bb7760f50767efc340dc94c259bf7afb32fa4d47952b48a4e91798d1e0ddc1b051d770405e078636793a
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants