mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-26 16:30:56 +00:00
Improve performance when loading BackupMeta.
* Use strtoul() and strtoull() instead of sscanf(). glibc's sscanf() will do a implicit strlen(). * Move implicit construction of Slice("crc32 ") out of loop.
This commit is contained in:
parent
e9ca358157
commit
caa1fd0e0e
|
@ -20,6 +20,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
@ -1163,16 +1164,18 @@ Status BackupEngineImpl::BackupMeta::LoadFromFile(
|
||||||
buf[data.size()] = 0;
|
buf[data.size()] = 0;
|
||||||
|
|
||||||
uint32_t num_files = 0;
|
uint32_t num_files = 0;
|
||||||
int bytes_read = 0;
|
char *next;
|
||||||
sscanf(data.data(), "%" PRId64 "%n", ×tamp_, &bytes_read);
|
timestamp_ = strtoull(data.data(), &next, 10);
|
||||||
data.remove_prefix(bytes_read + 1); // +1 for '\n'
|
data.remove_prefix(next - data.data() + 1); // +1 for '\n'
|
||||||
sscanf(data.data(), "%" PRIu64 "%n", &sequence_number_, &bytes_read);
|
sequence_number_ = strtoull(data.data(), &next, 10);
|
||||||
data.remove_prefix(bytes_read + 1); // +1 for '\n'
|
data.remove_prefix(next - data.data() + 1); // +1 for '\n'
|
||||||
sscanf(data.data(), "%u%n", &num_files, &bytes_read);
|
num_files = strtoul(data.data(), &next, 10);
|
||||||
data.remove_prefix(bytes_read + 1); // +1 for '\n'
|
data.remove_prefix(next - data.data() + 1); // +1 for '\n'
|
||||||
|
|
||||||
std::vector<FileInfo> files;
|
std::vector<FileInfo> files;
|
||||||
|
|
||||||
|
Slice checksum_prefix("crc32 ");
|
||||||
|
|
||||||
for (uint32_t i = 0; s.ok() && i < num_files; ++i) {
|
for (uint32_t i = 0; s.ok() && i < num_files; ++i) {
|
||||||
auto line = GetSliceUntil(&data, '\n');
|
auto line = GetSliceUntil(&data, '\n');
|
||||||
std::string filename = GetSliceUntil(&line, ' ').ToString();
|
std::string filename = GetSliceUntil(&line, ' ').ToString();
|
||||||
|
@ -1188,9 +1191,9 @@ Status BackupEngineImpl::BackupMeta::LoadFromFile(
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t checksum_value = 0;
|
uint32_t checksum_value = 0;
|
||||||
if (line.starts_with("crc32 ")) {
|
if (line.starts_with(checksum_prefix)) {
|
||||||
line.remove_prefix(6);
|
line.remove_prefix(checksum_prefix.size());
|
||||||
sscanf(line.data(), "%u", &checksum_value);
|
checksum_value = strtoul(line.data(), nullptr, 10);
|
||||||
if (memcmp(line.data(), std::to_string(checksum_value).c_str(),
|
if (memcmp(line.data(), std::to_string(checksum_value).c_str(),
|
||||||
line.size() - 1) != 0) {
|
line.size() - 1) != 0) {
|
||||||
return Status::Corruption("Invalid checksum value");
|
return Status::Corruption("Invalid checksum value");
|
||||||
|
|
Loading…
Reference in a new issue