Skip to content

Commit d4b55b5

Browse files
committed
Move json serialization under condition in all insertRowToLogTable calls
1 parent 8ec2285 commit d4b55b5

File tree

7 files changed

+41
-56
lines changed

7 files changed

+41
-56
lines changed

src/Disks/ObjectStorages/AzureBlobStorage/AzureObjectStorage.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,12 @@ void AzureObjectStorage::listObjects(const std::string & path, RelativePathsWith
185185
ProfileEvents::increment(ProfileEvents::AzureListObjects);
186186
if (client_ptr->IsClientForDisk())
187187
ProfileEvents::increment(ProfileEvents::DiskAzureListObjects);
188-
ProfileEventTimeIncrement<Microseconds> watch(ProfileEvents::AzureListObjectsMicroseconds);
189188

190-
blob_list_response = client_ptr->ListBlobs(options);
189+
{
190+
ProfileEventTimeIncrement<Microseconds> watch(ProfileEvents::AzureListObjectsMicroseconds);
191+
blob_list_response = client_ptr->ListBlobs(options);
192+
}
193+
191194
const auto & blobs_list = blob_list_response.Blobs;
192195

193196
for (const auto & blob : blobs_list)

src/Disks/ObjectStorages/S3/S3ObjectStorage.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,13 @@ class S3IteratorAsync final : public IObjectStorageIteratorAsync
138138
{
139139
ProfileEvents::increment(ProfileEvents::S3ListObjects);
140140
ProfileEvents::increment(ProfileEvents::DiskS3ListObjects);
141-
ProfileEventTimeIncrement<Microseconds> watch(ProfileEvents::S3ListObjectsMicroseconds);
142141

143-
auto outcome = client->ListObjectsV2(*request);
142+
Aws::S3::Model::ListObjectsV2Outcome outcome;
143+
144+
{
145+
ProfileEventTimeIncrement<Microseconds> watch(ProfileEvents::S3ListObjectsMicroseconds);
146+
outcome = client->ListObjectsV2(*request);
147+
}
144148

145149
/// Outcome failure will be handled on the caller side.
146150
if (outcome.IsSuccess())
@@ -266,9 +270,12 @@ void S3ObjectStorage::listObjects(const std::string & path, RelativePathsWithMet
266270
{
267271
ProfileEvents::increment(ProfileEvents::S3ListObjects);
268272
ProfileEvents::increment(ProfileEvents::DiskS3ListObjects);
269-
ProfileEventTimeIncrement<Microseconds> watch(ProfileEvents::S3ListObjectsMicroseconds);
270273

271-
outcome = client.get()->ListObjectsV2(request);
274+
{
275+
ProfileEventTimeIncrement<Microseconds> watch(ProfileEvents::S3ListObjectsMicroseconds);
276+
outcome = client.get()->ListObjectsV2(request);
277+
}
278+
272279
throwIfError(outcome);
273280

274281
auto result = outcome.GetResult();

src/Interpreters/IcebergMetadataLog.cpp

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void IcebergMetadataLogElement::appendToBlock(MutableColumns & columns) const
8484

8585
void insertRowToLogTable(
8686
const ContextPtr & local_context,
87-
String row,
87+
std::function<String()> get_row,
8888
IcebergMetadataLogLevel row_log_level,
8989
const String & table_path,
9090
const String & file_path,
@@ -104,40 +104,7 @@ void insertRowToLogTable(
104104
.content_type = row_log_level,
105105
.table_path = table_path,
106106
.file_path = file_path,
107-
.metadata_content = row,
108-
.row_in_file = row_in_file});
109-
}
110-
111-
String dumpMetadataObjectToString(const Poco::JSON::Object::Ptr & metadata_object)
112-
{
113-
std::ostringstream oss; // STYLE_CHECK_ALLOW_STD_STRING_STREAM
114-
Poco::JSON::Stringifier::stringify(metadata_object, oss);
115-
return removeEscapedSlashes(oss.str());
116-
}
117-
118-
void insertRowToLogTable(
119-
const ContextPtr & local_context,
120-
const Poco::JSON::Object::Ptr metadata_object,
121-
IcebergMetadataLogLevel row_log_level,
122-
const String & table_path,
123-
const String & file_path,
124-
std::optional<UInt64> row_in_file)
125-
{
126-
IcebergMetadataLogLevel set_log_level = local_context->getSettingsRef()[Setting::iceberg_metadata_log_level].value;
127-
if (set_log_level < row_log_level)
128-
return;
129-
timespec spec{};
130-
if (clock_gettime(CLOCK_REALTIME, &spec))
131-
throw ErrnoException(ErrorCodes::CANNOT_CLOCK_GETTIME, "Cannot clock_gettime");
132-
133-
Context::getGlobalContextInstance()->getIcebergMetadataLog()->add(
134-
DB::IcebergMetadataLogElement{
135-
.current_time = spec.tv_sec,
136-
.query_id = local_context->getCurrentQueryId(),
137-
.content_type = row_log_level,
138-
.table_path = table_path,
139-
.file_path = file_path,
140-
.metadata_content = dumpMetadataObjectToString(metadata_object),
107+
.metadata_content = get_row(),
141108
.row_in_file = row_in_file});
142109
}
143110
}

src/Interpreters/IcebergMetadataLog.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,7 @@ struct IcebergMetadataLogElement
2626

2727
void insertRowToLogTable(
2828
const ContextPtr & local_context,
29-
String row,
30-
IcebergMetadataLogLevel row_log_level,
31-
const String & table_path,
32-
const String & file_path,
33-
std::optional<UInt64> row_in_file);
34-
35-
void insertRowToLogTable(
36-
const ContextPtr & local_context,
37-
const Poco::JSON::Object::Ptr metadata_object,
29+
std::function<String()> get_row,
3830
IcebergMetadataLogLevel row_log_level,
3931
const String & table_path,
4032
const String & file_path,

src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergMetadata.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,16 @@ extern const SettingsBool allow_experimental_insert_into_iceberg;
110110
extern const SettingsBool allow_experimental_iceberg_compaction;
111111
}
112112

113+
namespace
114+
{
115+
String dumpMetadataObjectToString(const Poco::JSON::Object::Ptr & metadata_object)
116+
{
117+
std::ostringstream oss; // STYLE_CHECK_ALLOW_STD_STRING_STREAM
118+
Poco::JSON::Stringifier::stringify(metadata_object, oss);
119+
return removeEscapedSlashes(oss.str());
120+
}
121+
}
122+
113123

114124
using namespace Iceberg;
115125

@@ -233,9 +243,10 @@ bool IcebergMetadata::update(const ContextPtr & local_context)
233243

234244
updateState(local_context, metadata_object);
235245

246+
auto dump_metadata = [&]()->String { return dumpMetadataObjectToString(metadata_object); };
236247
insertRowToLogTable(
237248
local_context,
238-
metadata_object,
249+
dump_metadata,
239250
DB::IcebergMetadataLogLevel::Metadata,
240251
configuration_ptr->getRawPath().path,
241252
metadata_file_path,
@@ -763,9 +774,10 @@ DataLakeMetadataPtr IcebergMetadata::create(
763774

764775
auto format_version = object->getValue<int>(f_format_version);
765776

777+
auto dump_metadata = [&]()->String { return dumpMetadataObjectToString(object); };
766778
insertRowToLogTable(
767779
local_context,
768-
object,
780+
dump_metadata,
769781
DB::IcebergMetadataLogLevel::Metadata,
770782
configuration_ptr->getRawPath().path,
771783
metadata_file_path,

src/Storages/ObjectStorage/DataLakes/Iceberg/ManifestFile.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,10 @@ ManifestFileContent::ManifestFileContent(
155155
const String & path_to_manifest_file_)
156156
: path_to_manifest_file(path_to_manifest_file_)
157157
{
158+
auto dump_metadata = [&]()->String { return manifest_file_deserializer.getMetadataContent(); };
158159
insertRowToLogTable(
159160
context,
160-
manifest_file_deserializer.getMetadataContent(),
161+
dump_metadata,
161162
DB::IcebergMetadataLogLevel::ManifestFileMetadata,
162163
common_path,
163164
path_to_manifest_file,
@@ -230,9 +231,10 @@ ManifestFileContent::ManifestFileContent(
230231

231232
for (size_t i = 0; i < manifest_file_deserializer.rows(); ++i)
232233
{
234+
auto dump_row_metadata = [&]()->String { return manifest_file_deserializer.getContent(i); };
233235
insertRowToLogTable(
234236
context,
235-
manifest_file_deserializer.getContent(i),
237+
dump_row_metadata,
236238
DB::IcebergMetadataLogLevel::ManifestFileEntry,
237239
common_path,
238240
path_to_manifest_file,

src/Storages/ObjectStorage/DataLakes/Iceberg/StatelessMetadataFileGetter.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,10 @@ ManifestFileCacheKeys getManifestList(
148148

149149
ManifestFileCacheKeys manifest_file_cache_keys;
150150

151+
auto dump_metadata = [&]()->String { return manifest_list_deserializer.getMetadataContent(); };
151152
insertRowToLogTable(
152153
local_context,
153-
manifest_list_deserializer.getMetadataContent(),
154+
dump_metadata,
154155
DB::IcebergMetadataLogLevel::ManifestListMetadata,
155156
configuration_ptr->getRawPath().path,
156157
filename,
@@ -185,9 +186,10 @@ ManifestFileCacheKeys getManifestList(
185186
manifest_file_cache_keys.emplace_back(
186187
manifest_file_name, added_sequence_number, added_snapshot_id.safeGet<Int64>(), content_type);
187188

189+
auto dump_row_metadata = [&]()->String { return manifest_list_deserializer.getContent(i); };
188190
insertRowToLogTable(
189191
local_context,
190-
manifest_list_deserializer.getContent(i),
192+
dump_row_metadata,
191193
DB::IcebergMetadataLogLevel::ManifestListEntry,
192194
configuration_ptr->getRawPath().path,
193195
filename,

0 commit comments

Comments
 (0)