Skip to content

Commit 4e56d1c

Browse files
authored
Refactoring after PR #16320: Move TS3Export::CreateBuffer() implementation to cpp (#18030)
1 parent 4c15602 commit 4e56d1c

File tree

2 files changed

+51
-51
lines changed

2 files changed

+51
-51
lines changed

ydb/core/tx/datashard/export_s3.h

+1-51
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@
22

33
#ifndef KIKIMR_DISABLE_S3_OPS
44

5-
#include "defs.h"
6-
#include "backup_restore_traits.h"
75
#include "export_iface.h"
8-
#include "export_s3_buffer.h"
9-
10-
#include <ydb/public/api/protos/ydb_export.pb.h>
11-
#include <ydb/core/protos/s3_settings.pb.h>
126

137
namespace NKikimr {
148
namespace NDataShard {
@@ -24,51 +18,7 @@ class TS3Export: public IExport {
2418

2519
IActor* CreateUploader(const TActorId& dataShard, ui64 txId) const override;
2620

27-
IBuffer* CreateBuffer() const override {
28-
using namespace NBackupRestoreTraits;
29-
30-
const auto& scanSettings = Task.GetScanSettings();
31-
const ui64 maxRows = scanSettings.GetRowsBatchSize() ? scanSettings.GetRowsBatchSize() : Max<ui64>();
32-
const ui64 maxBytes = scanSettings.GetBytesBatchSize();
33-
const ui64 minBytes = Task.GetS3Settings().GetLimits().GetMinWriteBatchSize();
34-
35-
TS3ExportBufferSettings bufferSettings;
36-
bufferSettings
37-
.WithColumns(Columns)
38-
.WithMaxRows(maxRows)
39-
.WithMaxBytes(maxBytes)
40-
.WithMinBytes(minBytes); // S3 API returns EntityTooSmall error if file part is smaller that 5MB: https://docs.aws.amazon.com/AmazonS3/latest/API/API_CompleteMultipartUpload.html
41-
if (Task.GetEnableChecksums()) {
42-
bufferSettings.WithChecksum(TS3ExportBufferSettings::Sha256Checksum());
43-
}
44-
45-
switch (CodecFromTask(Task)) {
46-
case ECompressionCodec::None:
47-
break;
48-
case ECompressionCodec::Zstd:
49-
bufferSettings
50-
.WithCompression(TS3ExportBufferSettings::ZstdCompression(Task.GetCompression().GetLevel()));
51-
break;
52-
case ECompressionCodec::Invalid:
53-
Y_ENSURE(false, "unreachable");
54-
}
55-
56-
if (Task.HasEncryptionSettings()) {
57-
NBackup::TEncryptionIV iv = NBackup::TEncryptionIV::Combine(
58-
NBackup::TEncryptionIV::FromBinaryString(Task.GetEncryptionSettings().GetIV()),
59-
NBackup::EBackupFileType::TableData,
60-
0, // already combined
61-
Task.GetShardNum());
62-
bufferSettings.WithEncryption(
63-
TS3ExportBufferSettings::TEncryptionSettings()
64-
.WithAlgorithm(Task.GetEncryptionSettings().GetEncryptionAlgorithm())
65-
.WithKey(NBackup::TEncryptionKey(Task.GetEncryptionSettings().GetSymmetricKey().key()))
66-
.WithIV(iv)
67-
);
68-
}
69-
70-
return CreateS3ExportBuffer(std::move(bufferSettings));
71-
}
21+
IBuffer* CreateBuffer() const override;
7222

7323
void Shutdown() const override {}
7424

ydb/core/tx/datashard/export_s3_buffer.cpp

+50
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
#ifndef KIKIMR_DISABLE_S3_OPS
22

33
#include "export_s3_buffer.h"
4+
#include "backup_restore_traits.h"
5+
#include "export_s3.h"
46
#include "type_serialization.h"
57

68
#include <ydb/core/backup/common/checksum.h>
9+
#include <ydb/core/protos/s3_settings.pb.h>
710
#include <ydb/core/tablet_flat/flat_row_state.h>
811
#include <yql/essentials/types/binary_json/read.h>
12+
#include <ydb/public/api/protos/ydb_export.pb.h>
913
#include <ydb/public/lib/scheme_types/scheme_type_id.h>
1014

1115
#include <library/cpp/string_utils/quote/quote.h>
@@ -430,6 +434,52 @@ void TZStdCompressionProcessor::Reset() {
430434

431435
} // anonymous
432436

437+
IExport::IBuffer* TS3Export::CreateBuffer() const {
438+
using namespace NBackupRestoreTraits;
439+
440+
const auto& scanSettings = Task.GetScanSettings();
441+
const ui64 maxRows = scanSettings.GetRowsBatchSize() ? scanSettings.GetRowsBatchSize() : Max<ui64>();
442+
const ui64 maxBytes = scanSettings.GetBytesBatchSize();
443+
const ui64 minBytes = Task.GetS3Settings().GetLimits().GetMinWriteBatchSize();
444+
445+
TS3ExportBufferSettings bufferSettings;
446+
bufferSettings
447+
.WithColumns(Columns)
448+
.WithMaxRows(maxRows)
449+
.WithMaxBytes(maxBytes)
450+
.WithMinBytes(minBytes); // S3 API returns EntityTooSmall error if file part is smaller that 5MB: https://docs.aws.amazon.com/AmazonS3/latest/API/API_CompleteMultipartUpload.html
451+
if (Task.GetEnableChecksums()) {
452+
bufferSettings.WithChecksum(TS3ExportBufferSettings::Sha256Checksum());
453+
}
454+
455+
switch (CodecFromTask(Task)) {
456+
case ECompressionCodec::None:
457+
break;
458+
case ECompressionCodec::Zstd:
459+
bufferSettings
460+
.WithCompression(TS3ExportBufferSettings::ZstdCompression(Task.GetCompression().GetLevel()));
461+
break;
462+
case ECompressionCodec::Invalid:
463+
Y_ENSURE(false, "unreachable");
464+
}
465+
466+
if (Task.HasEncryptionSettings()) {
467+
NBackup::TEncryptionIV iv = NBackup::TEncryptionIV::Combine(
468+
NBackup::TEncryptionIV::FromBinaryString(Task.GetEncryptionSettings().GetIV()),
469+
NBackup::EBackupFileType::TableData,
470+
0, // already combined
471+
Task.GetShardNum());
472+
bufferSettings.WithEncryption(
473+
TS3ExportBufferSettings::TEncryptionSettings()
474+
.WithAlgorithm(Task.GetEncryptionSettings().GetEncryptionAlgorithm())
475+
.WithKey(NBackup::TEncryptionKey(Task.GetEncryptionSettings().GetSymmetricKey().key()))
476+
.WithIV(iv)
477+
);
478+
}
479+
480+
return CreateS3ExportBuffer(std::move(bufferSettings));
481+
}
482+
433483
NExportScan::IBuffer* CreateS3ExportBuffer(TS3ExportBufferSettings&& settings) {
434484
return new TS3Buffer(std::move(settings));
435485
}

0 commit comments

Comments
 (0)