Fix Unit Test failing from uninit values in CompactionServiceInput (#13080)

Summary:
# Summary

There was a [test failure](https://github.com/facebook/rocksdb/actions/runs/11381731053/job/31663774089?fbclid=IwZXh0bgNhZW0CMTEAAR0YJVdnkKUhN15RJQrLsvicxqzReS6y4A14VFQbWu-81XJsSsyNepXAr2c_aem_JyQqNdtpeKFSA6CjlD-pDg) from uninit value in the CompactionServiceInput

```
[ RUN      ] CompactionJobTest.InputSerialization
==79945== Use of uninitialised value of size 8
==79945==    at 0x58EA69B: _itoa_word (_itoa.c:179)
==79945==    by 0x5906574: __vfprintf_internal (vfprintf-internal.c:1687)
==79945==    by 0x591AF99: __vsnprintf_internal (vsnprintf.c:114)
==79945==    by 0x1654AE: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > __gnu_cxx::__to_xstring<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, char>(int (*)(char*, unsigned long, char const*, __va_list_tag*), unsigned long, char const*, ...) (string_conversions.h:111)
==79945==    by 0x5126C65: to_string (basic_string.h:6568)
==79945==    by 0x5126C65: rocksdb::SerializeSingleOptionHelper(void const*, rocksdb::OptionType, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*) (options_helper.cc:541)
==79945==    by 0x512718B: rocksdb::OptionTypeInfo::Serialize(rocksdb::ConfigOptions const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, void const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*) const (options_helper.cc:1084)
```

This was due to `options_file_number` value not set in the unit test. However, this value is guaranteed to be set in the normal path. It was just missing in the test path. Setting the 0 as the default value for uninitialized fields in the `CompactionServiceInput` and `CompactionServiceResult` for now.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/13080

Test Plan: Existing tests should be sufficient

Reviewed By: cbi42

Differential Revision: D64573567

Pulled By: jaykorean

fbshipit-source-id: 7843a951770c74445620623d069a52ba93ad94d5
This commit is contained in:
Jay Huh 2024-10-18 07:31:54 -07:00 committed by Facebook GitHub Bot
parent 58fc9d61b7
commit 0ca691654f
1 changed files with 3 additions and 3 deletions

View File

@ -386,7 +386,7 @@ struct CompactionServiceInput {
// files needed for this compaction, for both input level files and output // files needed for this compaction, for both input level files and output
// level files. // level files.
std::vector<std::string> input_files; std::vector<std::string> input_files;
int output_level; int output_level = 0;
// db_id is used to generate unique id of sst on the remote compactor // db_id is used to generate unique id of sst on the remote compactor
std::string db_id; std::string db_id;
@ -397,7 +397,7 @@ struct CompactionServiceInput {
bool has_end = false; bool has_end = false;
std::string end; std::string end;
uint64_t options_file_number; uint64_t options_file_number = 0;
// serialization interface to read and write the object // serialization interface to read and write the object
static Status Read(const std::string& data_str, CompactionServiceInput* obj); static Status Read(const std::string& data_str, CompactionServiceInput* obj);
@ -454,7 +454,7 @@ struct CompactionServiceOutputFile {
struct CompactionServiceResult { struct CompactionServiceResult {
Status status; Status status;
std::vector<CompactionServiceOutputFile> output_files; std::vector<CompactionServiceOutputFile> output_files;
int output_level; int output_level = 0;
// location of the output files // location of the output files
std::string output_path; std::string output_path;