Skip to content

Conversation

stickies-v
Copy link
Contributor

As a follow-up to #25967 (comment), this PR changes the return type of BaseIndex::GetName() to const std::string& instead of const char*. The first commit is not essential for this change, but since the code is touched and index names are commonly used to specify thread names, I've made the same update there.

No behaviour change, just refactoring to further phase out C-style strings.

Note: util::ThreadRename() used to take an rvalue ref, but since it then passes this to SetInternalName() by value, I don't think there's any benefit to having both an rvalue and lvalue ref function so I just changed it into lvalue ref. Not 100% sure I'm missing something?

@stickies-v stickies-v force-pushed the baseindex-getname-string branch from 22eaf5b to 4f7a2b6 Compare September 1, 2022 12:05
@theStack
Copy link
Contributor

theStack commented Sep 1, 2022

Concept ACK

1 similar comment
@brunoerg
Copy link
Contributor

brunoerg commented Sep 1, 2022

Concept ACK

@sipa
Copy link
Member

sipa commented Sep 1, 2022

What about:

  • Adding an const std::string m_name; field to the base class.
  • Require a name to be passed in to the base class constructor (invoked from the child class constructors).
  • Adding a non-virtual accessor const std::string& GetName() const { return m_name; } to return that name.
  • Remove the corresponding m_name / GetName from the BlockFilterIndex class.
  • Make all child classes pass a name to the parent class constructor.

@stickies-v stickies-v force-pushed the baseindex-getname-string branch from 4f7a2b6 to a6927e8 Compare September 1, 2022 16:48
@stickies-v
Copy link
Contributor Author

Force pushed to address review comments about simplifying the GetName() logic and using string_view instead of const std::string&

@DrahtBot
Copy link
Contributor

DrahtBot commented Sep 1, 2022

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #25193 (indexes: Read the locator's top block during init, allow interaction with reindex-chainstate by mzumsande)

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.

@hebasto
Copy link
Member

hebasto commented Sep 2, 2022

Concept ACK.

@stickies-v stickies-v force-pushed the baseindex-getname-string branch from a6927e8 to 4b1a0bb Compare September 2, 2022 13:27
Copy link
Contributor Author

@stickies-v stickies-v left a comment

Choose a reason for hiding this comment

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

Force pushed to address review feedback regarding:

  • util::TraceThread() to take a std::string copy and avoid potential issues with lifetime introduced by the threading, also updated util::ThreadRename() to take a const lvalue ref to avoid copying twice
  • remove unused includes leftover from earlier versions

@bitcoin bitcoin deleted a comment from Ellajoke Sep 2, 2022
@bitcoin bitcoin deleted a comment Sep 2, 2022
@stickies-v stickies-v force-pushed the baseindex-getname-string branch from 4b1a0bb to 296b831 Compare September 2, 2022 16:17
@stickies-v
Copy link
Contributor Author

Force pushed to partly reverse the previous force push based on sipa's suggestion, again using a string_view for util::TraceThread() and undoing the changes to util::ThreadRename() (now no longer in this PR's diff).

My apologies to reviewers for the back and forth.

@stickies-v stickies-v force-pushed the baseindex-getname-string branch from 296b831 to e5d9c6f Compare September 12, 2022 22:17
@stickies-v
Copy link
Contributor Author

Force pushed to rebase on latest master to fix failing CI (wallet_groups.py) - no other changes.

@maflcko
Copy link
Member

maflcko commented Sep 13, 2022

My preference would still be to use std::string in TraceThread (#25971 (comment)) as a belt-and-suspenders, but the current code is not worse than it was previously.

review ACK e5d9c6f 🎯

Show signature

Signature:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

review ACK e5d9c6f0571ee182f34e0d82c20e5ca2da30ad85 🎯
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUgoCQv+P5w/6IGCCYaSa+M7unM9uCN6fxnRgqaJlASlzu/rGzN0VJcdS404NTdL
FpIpXE2j+kwhgAc6eM+87byb2lR7sNgL/CAC7v1M8tXNMpTMJwlwgLsCykFY7iE9
pK6u9BocyloYAcDNw4u7v2Mph7KTxUIXxqZhz9fFR2dPJrxc6eTmP8OXaRiYlbAo
9BxAw79cQY3+2F3V0THByfcgQdyZO7BF2gpZCNgrY84bwIbotsTgtGU9qLpv46V9
2GBgy7v5jUqsFYPVtnM/cs1NVou779N/rCDH2+4uDBiXyYf6VM8d9ZEYIkzayPmC
hclDiXMwfpZ0hVnbdBhpmYGp9Vb4UoMkZiLleJdlJQsp3R1e3RBCDGPDsy1iV8Aw
mQMfOkiDQxC91eyizLv3eJ8RnUc7vwE9W+MW6FKQzw1O8vaFKfGJEoIK/nb2aMXr
Q92DNYhFxzZpQHG5MfoJj20ySJP/woq7xG/7xpH/zW4QuSaxW6OvqZ3GZFUNROGc
zT0TuUiQ
=b37U
-----END PGP SIGNATURE-----

@stickies-v stickies-v force-pushed the baseindex-getname-string branch from e5d9c6f to 200d84d Compare September 13, 2022 18:10
@stickies-v
Copy link
Contributor Author

Force pushed to fix merge conflict from #24513 that renamed CChainstate -> Chainstate - no other changes.

My preference would still be to use std::string in TraceThread (#25971 (comment)) as a belt-and-suspenders, but the current code is not worse than it was previously.

I'm not opposed to it, but as I don't have a strong view on it, we've already had some back-and-forth and the current implementation doesn't introduce new assumptions there I'd prefer to keep that for a follow-up (which I won't do).

@maflcko
Copy link
Member

maflcko commented Sep 13, 2022

re-ACK 200d84d only change is rebase 🚼

Show signature

Signature:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

re-ACK 200d84d5681918523d982b9ddf60d1127edcb448 only change is rebase 🚼
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUgPNQwAw5LrCWUbRWxPIUc1OLrGT75Vv9alSNady748D38GlxcFc3CBahCxmU4Q
sf3vpVbHN0Mo8Y06vNB0mBZ1r4lcL5U73rGzDELCNFEixh08PTELLrcdWCFLk/Dp
ScpDdGRyMx4fRkjwaYFbUZsq4qUpfPjYTQBsHKyOn/J9RR/yzbMZOP0IGtonG10t
jmO52IAPgcD2duZRCY7HZSsJtAmnaFmV0geDH1LdL0j5G2y76Sqxzid/0H6KeoaK
Tp7lPcf77T/o8lNyYllYAYtEIQp7Gg9yvQOYvmkuAKxyx9f5JOEQtw936zCt5BXt
DgHD5uve0WnR0vp1v1sowAPci/l8D9fVh9iiWQG8oqHJ8Iha4YLaXicsBrJsEbav
9BR+bIdvUw99Bg8UK1XQdEwczVFYrExhzbP50W04DM3HpD3kjlwdZhvwON6P5XKt
2O8A7wFT+KO4qjno+8DItg1FKeVh9kRuMZ7ptXq4RJVyob3L/jT8gTvKgVkcxj5L
N0aIxOMu
=fh6y
-----END PGP SIGNATURE-----

Copy link
Contributor

@w0xlt w0xlt left a comment

Choose a reason for hiding this comment

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

ACK 200d84d

Since it is now a string_view instead of a const char*, update the
name to reflect that the variable is no longer a "Pointer to
String, Zero-terminated" (psz).

-BEGIN VERIFY SCRIPT-
sed -i s/pszThread/thread_name/ $(git grep -l pszThread src)
-END VERIFY SCRIPT-
@maflcko
Copy link
Member

maflcko commented Sep 14, 2022

review ACK 26cf9ea only change is new scripted-diff 😀

Show signature

Signature:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

review ACK 26cf9ea8e44d7fd6450336f567afaedd1275baf7 only change is new scripted-diff 😀
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUiQUAwAuj4HULyQMBta0XNIDl0zy4CCXiT1ZBVXSQoMv0mBjQPP7l5m45FhtTQe
ThS7P6W0rwQq2jGwmPjucd29gS5LuTuf5tBIoExY17u/TDgKa53wz37ggP5d574V
PypsOaugnlpipMrlNBiOguxNS9KjE9n4MrXVF67Pnm+SbcqIW9aOlpLODNYO7MHd
/T+0wy03Vtmknsze7e4v9xp8HxQ2kZab11auPKSMVfuACDhJEBul9a/xrlDILjTG
QvfCG2BRdIaUzMLgtLWGTOD8Ilq7h3ObKjnKW4aH42QIRZi/Wfp3tQhvKkOZaW7N
zAISfPqIk1ZelkAcEPjerE62fdPnWRRBHuZGv4+Vrk0eBgnt422PuvohTaUA98r8
mOL9zcXRXT03VNoV2SsHFBcs2tPQ6K74O7CtB5PZWPWJVvb4HcJt0n9PMUuba5HS
fUlnI5OB6PwLgrFiABiR+fmbskUSdcv+CY0ZT4IDYGB2/m2egzo20HKBWYwVBEO3
T5vJv1+V
=hJ1B
-----END PGP SIGNATURE-----

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

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

ACK 26cf9ea, I have reviewed the code and it looks OK.

@@ -10,10 +10,12 @@

#include <exception>
#include <functional>
#include <string>
#include <utility>
Copy link
Member

@hebasto hebasto Sep 15, 2022

Choose a reason for hiding this comment

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

nit: Why #include <utility>?

Copy link
Member

@maflcko maflcko Sep 15, 2022

Choose a reason for hiding this comment

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

std::move (Edit: Oh yeah. That one isn't used.)

Copy link
Member

Choose a reason for hiding this comment

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

$ git grep move -- src//util/thread.cpp | wc -l
0

Copy link
Member

Choose a reason for hiding this comment

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

iwyu:

util/thread.h should add these lines:
#include <string_view>  // for string_view

util/thread.h should remove these lines:
- #include <string>  // lines 9-9

The full include-list for util/thread.h:
#include <functional>   // for function
#include <string_view>  // for string_view
---

util/thread.cpp should add these lines:

util/thread.cpp should remove these lines:
- #include <utility>  // lines 14-14

The full include-list for util/thread.cpp:
#include <util/thread.h>
#include <logging.h>           // for LogPrintf_, LogPrintf
#include <util/system.h>       // for PrintExceptionContinue
#include <util/threadnames.h>  // for ThreadRename
#include <exception>           // for exception
#include <functional>          // for function
#include <string>              // for allocator, string
---

Copy link
Contributor

@w0xlt w0xlt left a comment

Choose a reason for hiding this comment

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

reACK 26cf9ea

@maflcko maflcko merged commit 5eb9781 into bitcoin:master Sep 16, 2022
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Sep 20, 2022
@stickies-v stickies-v deleted the baseindex-getname-string branch September 22, 2022 13:08
@bitcoin bitcoin locked and limited conversation to collaborators Sep 22, 2023
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.