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

rpc: make `gettxoutsettinfo` run lock-free #6290

Merged
merged 1 commit into from Jun 19, 2015

Conversation

@laanwj
Copy link
Member

laanwj commented Jun 16, 2015

For leveldb "An iterator operates on a snapshot of the database taken when the iterator is created". This means that it is unnecessary to lock out other threads while computing statistics, and neither to hold cs_main for the whole time. Let the thread run free.

I've been using this patch for about 8 months without issues, including on a node that automatically dumps the information for every N blocks.

For leveldb "An iterator operates on a snapshot of the database taken
when the iterator is created". This means that it is unnecessary to
lock out other threads while computing statistics, and neither to hold
cs_main for the whole time. Let the thread run free.
@laanwj laanwj added the RPC/REST/ZMQ label Jun 16, 2015
@sipa
Copy link
Member

sipa commented Jun 16, 2015

Untested ACK

@jgarzik
Copy link
Contributor

jgarzik commented Jun 16, 2015

ut ACK

@jonasschnelli
Copy link
Member

jonasschnelli commented Jun 17, 2015

This would mean that CoinsViewCache::GetBestBlock() (which accesses mutable uint256 hashBlock in "self" space) get called unlocked (https://github.com/bitcoin/bitcoin/pull/6290/files#diff-81e4f16a1b5d5b7ca25351a63d07cb80R111). But i'm not sure it this is a problem.

But i agree that we should do more of these LOCK space reducing.

@laanwj
Copy link
Member Author

laanwj commented Jun 17, 2015

This would mean that CoinsViewCache::GetBestBlock() (which accesses mutable uint256 hashBlock in "self" space) get called unlocked (https://github.com/bitcoin/bitcoin/pull/6290/files#diff-81e4f16a1b5d5b7ca25351a63d07cb80R111). But i'm not sure it this is a problem.

Whoa. Good catch. I expected that this would invoke CCoinsViewDB::GetBestBlock() which accesses just the db and not any internal fields or global state. But it's a virtual. It shouldn't actually be using the cached value at all but query the db.

@laanwj
Copy link
Member Author

laanwj commented Jun 17, 2015

Correction: CCoinsViewCache does not derive from CCoinsViewDB (or the other way around), it just wraps one. So there is no problem AFAIK.

@jonasschnelli
Copy link
Member

jonasschnelli commented Jun 17, 2015

Right. Was following the wrong path... it calls uint256 CCoinsViewDB::GetBestBlock(). Sorry for the noise.

@laanwj laanwj merged commit 57092ed into bitcoin:master Jun 19, 2015
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
laanwj added a commit that referenced this pull request Jun 19, 2015
57092ed rpc: make `gettxoutsettinfo` run lock-free (Wladimir J. van der Laan)
{
LOCK(cs_main);
stats.nHeight = mapBlockIndex.find(stats.hashBlock)->second->nHeight;
}

This comment has been minimized.

Copy link
@luke-jr

luke-jr Jun 23, 2015

Member

Couldn't nHeight change before we get to this block, after we start getting the other stats?

This comment has been minimized.

Copy link
@sipa

sipa via email Jun 23, 2015

Member

This comment has been minimized.

Copy link
@luke-jr

luke-jr Jun 23, 2015

Member

Ah, right.

random-zebra added a commit to PIVX-Project/PIVX that referenced this pull request May 27, 2020
82f9088 Refactor: Remove using namespace <xxx> from /dbwrapper_tests (random-zebra)
6db0b37 rpc: make `gettxoutsettinfo` run lock-free (random-zebra)
f009cf4 Do not shadow members in dbwrapper (random-zebra)
b7e540c dbwrapper: Move `HandleError` to `dbwrapper_private` (random-zebra)
43004d0 leveldbwrapper file rename to dbwrapper.* (random-zebra)
c882dd9 leveldbwrapper symbol rename: Remove "Level" from class, etc. names (random-zebra)
f6496da leveldbwrapper: Remove unused .Prev(), .SeekToLast() methods (random-zebra)
cacf3c2 Fix chainstate serialized_size computation (random-zebra)
a2a3d33 Add tests for CLevelDBBatch, CLevelDBIterator (random-zebra)
94150ac Encapsulate CLevelDB iterators cleanly (random-zebra)
21df7cc [DB] Refactor leveldbwrapper (random-zebra)
2251db3 change hardcoded character constants to a set of descriptive named co… (random-zebra)

Pull request description:

  This backports a series of updates and cleanups to the LevelDB wrapper from:

  - bitcoin#5707
  - bitcoin#6650 [`*`]
  - bitcoin#6777 [`*`]
  - bitcoin#6865
  - bitcoin#6873
  - bitcoin#7927 [`*`]
  - bitcoin#8467
  - bitcoin#6290
  - bitcoin#9281

  PIVX-specific edits were required to keep the sporks and zerocoin databases in line.

  [`*`] NOTE: excluding the obfuscation of databases by xoring data, as we might not want this feature (e.g. as zcash/zcash#2598). Otherwise it can be discussed, and added, with a separate PR.

ACKs for top commit:
  furszy:
    Re ACK 82f9088 .
  Fuzzbawls:
    ACK 82f9088

Tree-SHA512: 1e4a75621d2ec2eb68e01523d15321d1d2176b81aac0525617852899ab38c9b4980daecb9056d054e7961fc758a22143edf914c40d1819144a394f2869a8ad57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.