Skip to content

[io] use UUIDv4 in ROOT files#22035

Open
jblomer wants to merge 6 commits intoroot-project:masterfrom
jblomer:fix-uuid
Open

[io] use UUIDv4 in ROOT files#22035
jblomer wants to merge 6 commits intoroot-project:masterfrom
jblomer:fix-uuid

Conversation

@jblomer
Copy link
Copy Markdown
Contributor

@jblomer jblomer commented Apr 23, 2026

Use UUIDv4 in TDirectory (hence in TDirectoryFile and TFile) and in the RMiniFile. Note that TDirectory is used without gSystem (needed for GetCryptoRandom()) in the context of rootcling. In principle, GetCryptoRandom() should work without a TSystem object. That may be for a later PR.

The UUIDv4, unlike the current UUIDv1, is (with high enough probability) globally unique.

Also fixes a race in TUUID::AsString().

EDIT: The last two commits factor out the GetCryptoRandom() into a free function, so that it can be used unconditionally in the I/O.

Fixes #22015
Replaces #22016

jblomer added 4 commits April 24, 2026 00:14
Use UUIDv4 in TDirectory (hence in TDirectoryFile and TFile) and in the
RMiniFile. Note that TDirectory is used without gSystem (needed for
GetCryptoRandom()) in the context of rootcling.  In principle,
GetCryptoRandom() should work without a TSystem object.  That may be for
a later commit.

The UUIDv4, unlike the current UUIDv1, is (with high enough probability)
globally unique.
@jblomer jblomer requested review from dpiparo, hahnjo, pcanal and silverweed and removed request for ferdymercury and hahnjo April 23, 2026 22:14
Comment thread core/base/src/TDirectory.cxx Outdated
Comment on lines +55 to +56
// In the context of rootcling, we don't have gSystem
if (gSystem)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// In the context of rootcling, we don't have gSystem
if (gSystem)
// Fallback to the default constructed TUUID if we
// get here before gSystem is initialized.
if (gSystem)

@github-actions
Copy link
Copy Markdown

Test Results

    22 files      22 suites   3d 11h 29m 1s ⏱️
 3 851 tests  3 799 ✅  1 💤 51 ❌
76 931 runs  76 862 ✅ 18 💤 51 ❌

For more details on these failures, see this check.

Results for commit f17534b.

@dpiparo
Copy link
Copy Markdown
Member

dpiparo commented Apr 24, 2026

Impressive PR: thanks for it. It should be backported until 6.36.

Comment thread core/base/src/TUUID.cxx
const char *TUUID::AsString() const
{
static char uuid[40];
TTHREAD_TLS(char) uuid[40];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why can't we use thread_local?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's what it resolves to. I can use thread_local but this file uses TTHREAD_TLS in other places so I used this for consistency.

jblomer added 2 commits April 24, 2026 10:31
Factor out calling the OS crypto random number generator into a free
function in the Base package. In turn, TSystem::GetCryptoRandom() can be
static and does not rely in gSystem being initialized.
Copy link
Copy Markdown
Member

@vepadulano vepadulano left a comment

Choose a reason for hiding this comment

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

LGTM, let's wait for the CI. Just a minor consideration.

Comment on lines +30 to +38
#elif defined(R__GETRANDOM_CLIB)
return getrandom(buf, len, GRND_NONBLOCK) == len;
#elif defined(R__USE_URANDOM)
std::ifstream urandom{"/dev/urandom"};
if (!urandom)
return false;
urandom.read(reinterpret_cast<char *>(buf), len);
return true;
#else
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Here GRND_NONBLOCK should be fine since we're only interested in the case where we can immediately fill the buffer with the right lenght I believe. OTOH, are we fine with the possibility of partially filled buffer for lengths greater than 256 bytes https://man7.org/linux/man-pages/man2/getrandom.2.html ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's a good point, this was already present before. Perhaps we restrict the input length to 256. We don't use it for anything longer currently.

Comment thread core/base/src/TSystem.cxx
Error("GetCryptoRandom", "Not implemented");
return -1;
if (len < 0) {
return false;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this be:

Suggested change
return false;
return -1;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Non uniquess of the UUID inside TFile

6 participants