MCPcopy Create free account
hub / github.com/apache/cloudberry / constructRandomStr

Method constructRandomStr

gpcontrib/gpcloud/src/gpwriter.cpp:40–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38}
39
40string GPWriter::constructRandomStr() {
41 int randomDevice = ::open("/dev/urandom", O_RDONLY);
42 char randomData[32];
43 size_t randomDataLen = 0;
44
45 S3_CHECK_OR_DIE(randomDevice >= 0, S3RuntimeError, "failed to generate random number");
46
47 while (randomDataLen < sizeof(randomData)) {
48 ssize_t result =
49 ::read(randomDevice, randomData + randomDataLen, sizeof(randomData) - randomDataLen);
50 if (result < 0) {
51 break;
52 }
53 randomDataLen += result;
54 }
55 ::close(randomDevice);
56
57 char out_hash_hex[SHA256_DIGEST_STRING_LENGTH];
58
59 sha256_hex(randomData, 32, out_hash_hex);
60
61 return out_hash_hex + SHA256_DIGEST_STRING_LENGTH - 8 - 1;
62}
63
64// invoked by s3_export(), need to be exception safe
65GPWriter* writer_init(const char* url_with_options, const char* format) {

Callers 1

genUniqueKeyNameMethod · 0.95

Calls 1

sha256_hexFunction · 0.85

Tested by

no test coverage detected