Skip to content

Commit a16614d

Browse files
committed
Supported static storage
1 parent 7f2a682 commit a16614d

File tree

11 files changed

+93
-15
lines changed

11 files changed

+93
-15
lines changed

ydb/core/testlib/basics/helpers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ namespace NFake {
1818
ui64 SectorSize = 0;
1919
ui64 ChunkSize = 0;
2020
ui64 DiskSize = 0;
21+
bool FormatDisk = true;
22+
TString DiskPath;
2123
};
2224

2325
struct INode {

ydb/core/testlib/basics/storage.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ namespace NKikimr {
5454

5555
static ui64 keySalt = 0;
5656
ui64 salt = ++keySalt;
57-
TString baseDir = Runtime.GetTempDir();
57+
TString baseDir = conf.DiskPath ? conf.DiskPath : Runtime.GetTempDir();
5858

5959
if (Conf.UseDisk) {
6060
MakeDirIfNotExist(baseDir.c_str());
6161
}
6262

6363
PDiskPath = TStringBuilder() << baseDir << "pdisk_1.dat";
6464

65-
if (!Mock) {
65+
if (!Mock && conf.FormatDisk) {
6666
FormatPDisk(PDiskPath,
6767
Conf.DiskSize, Conf.SectorSize, Conf.ChunkSize, PDiskGuid,
6868
0x123 + salt, 0x456 + salt, 0x789 + salt, mainKey,

ydb/core/testlib/test_client.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,18 +614,21 @@ namespace Tests {
614614

615615
NKikimrBlobStorage::TDefineBox boxConfig;
616616
boxConfig.SetBoxId(Settings->BOX_ID);
617+
boxConfig.SetItemConfigGeneration(Settings->StorageGeneration);
617618

618619
ui32 nodeId = Runtime->GetNodeId(0);
619620
Y_ABORT_UNLESS(nodesInfo->Nodes[0].NodeId == nodeId);
620621
auto& nodeInfo = nodesInfo->Nodes[0];
621622

622623
NKikimrBlobStorage::TDefineHostConfig hostConfig;
623624
hostConfig.SetHostConfigId(nodeId);
625+
hostConfig.SetItemConfigGeneration(Settings->StorageGeneration);
624626
TString path;
625627
if (Settings->UseSectorMap) {
626628
path ="SectorMap:test-client[:2000]";
627629
} else {
628-
path = TStringBuilder() << Runtime->GetTempDir() << "pdisk_1.dat";
630+
TString diskPath = Settings->CustomDiskParams.DiskPath;
631+
path = TStringBuilder() << (diskPath ? diskPath : Runtime->GetTempDir()) << "pdisk_1.dat";
629632
}
630633
hostConfig.AddDrive()->SetPath(path);
631634
if (Settings->Verbose) {
@@ -641,7 +644,9 @@ namespace Tests {
641644

642645
for (const auto& [poolKind, storagePool] : Settings->StoragePoolTypes) {
643646
if (storagePool.GetNumGroups() > 0) {
644-
bsConfigureRequest->Record.MutableRequest()->AddCommand()->MutableDefineStoragePool()->CopyFrom(storagePool);
647+
auto* command = bsConfigureRequest->Record.MutableRequest()->AddCommand()->MutableDefineStoragePool();
648+
command->CopyFrom(storagePool);
649+
command->SetItemConfigGeneration(Settings->StorageGeneration);
645650
}
646651
}
647652

ydb/core/testlib/test_client.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ namespace Tests {
124124
TString DomainName = TestDomainName;
125125
ui32 NodeCount = 1;
126126
ui32 DynamicNodeCount = 0;
127+
ui64 StorageGeneration = 0;
127128
NFake::TStorage CustomDiskParams;
128129
TControls Controls;
129130
TAppPrepare::TFnReg FrFactory = &DefaultFrFactory;
@@ -179,6 +180,7 @@ namespace Tests {
179180
TServerSettings& SetDomainName(const TString& value);
180181
TServerSettings& SetNodeCount(ui32 value) { NodeCount = value; return *this; }
181182
TServerSettings& SetDynamicNodeCount(ui32 value) { DynamicNodeCount = value; return *this; }
183+
TServerSettings& SetStorageGeneration(ui64 value) { StorageGeneration = value; return *this; }
182184
TServerSettings& SetCustomDiskParams(const NFake::TStorage& value) { CustomDiskParams = value; return *this; }
183185
TServerSettings& SetControls(const TControls& value) { Controls = value; return *this; }
184186
TServerSettings& SetFrFactory(const TAppPrepare::TFnReg& value) { FrFactory = value; return *this; }

ydb/tests/tools/kqprun/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
storage
12
sync_dir
23
example
34
udfs
5+
46
*.log
57
*.json
68
*.sql

ydb/tests/tools/kqprun/kqprun.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ struct TExecutionOptions {
134134
ValidateScriptExecutionOptions(runnerOptions);
135135
ValidateAsyncOptions(runnerOptions.YdbSettings.AsyncQueriesSettings);
136136
ValidateTraceOpt(runnerOptions);
137+
ValidateStorageSettings(runnerOptions.YdbSettings);
137138
}
138139

139140
private:
@@ -258,6 +259,19 @@ struct TExecutionOptions {
258259
}
259260
}
260261

262+
static void ValidateStorageSettings(const TYdbSetupSettings& ydbSettings) {
263+
if (ydbSettings.DisableDiskMock) {
264+
if (ydbSettings.NodeCount + ydbSettings.SharedTenants.size() + ydbSettings.DedicatedTenants.size() > 1) {
265+
ythrow yexception() << "Disable disk mock cannot be used for multi node clusters (already disabled)";
266+
} else if (ydbSettings.PDisksPath) {
267+
ythrow yexception() << "Disable disk mock cannot be used with real PDisks (already disabled)";
268+
}
269+
}
270+
if (ydbSettings.FormatStorage && !ydbSettings.PDisksPath) {
271+
ythrow yexception() << "Cannot format storage without real PDisks, please use --storage-path";
272+
}
273+
}
274+
261275
private:
262276
static void ReplaceYqlTokenTemplate(TString& sql) {
263277
const TString variableName = TStringBuilder() << "${" << YQL_TOKEN_VARIABLE << "}";
@@ -857,9 +871,13 @@ class TMain : public TMainClassArgs {
857871
return static_cast<ui64>(diskSize) << 30;
858872
});
859873

860-
options.AddLongOption("real-pdisks", "Use real PDisks instead of in memory PDisks (also disable disk mock)")
874+
options.AddLongOption("storage-path", "Use real PDisks by specified path instead of in memory PDisks (also disable disk mock), use '-' to use temp directory")
875+
.RequiredArgument("directory")
876+
.StoreResult(&RunnerOptions.YdbSettings.PDisksPath);
877+
878+
options.AddLongOption("format-storage", "Clear storage if it exists on --storage-path")
861879
.NoArgument()
862-
.SetFlag(&RunnerOptions.YdbSettings.UseRealPDisks);
880+
.SetFlag(&RunnerOptions.YdbSettings.FormatStorage);
863881

864882
options.AddLongOption("disable-disk-mock", "Disable disk mock on single node cluster")
865883
.NoArgument()
@@ -882,10 +900,6 @@ class TMain : public TMainClassArgs {
882900
int DoRun(NLastGetopt::TOptsParseResult&&) override {
883901
ExecutionOptions.Validate(RunnerOptions);
884902

885-
if (RunnerOptions.YdbSettings.DisableDiskMock && RunnerOptions.YdbSettings.NodeCount + RunnerOptions.YdbSettings.SharedTenants.size() + RunnerOptions.YdbSettings.DedicatedTenants.size() > 1) {
886-
ythrow yexception() << "Disable disk mock cannot be used for multi node clusters";
887-
}
888-
889903
RunnerOptions.YdbSettings.YqlToken = YqlToken;
890904
RunnerOptions.YdbSettings.FunctionRegistry = CreateFunctionRegistry(UdfsDirectory, UdfsPaths, ExcludeLinkedUdfs).Get();
891905

ydb/tests/tools/kqprun/src/common.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ struct TYdbSetupSettings {
3939
bool SameSession = false;
4040

4141
bool DisableDiskMock = false;
42-
bool UseRealPDisks = false;
42+
bool FormatStorage = false;
43+
std::optional<TString> PDisksPath;
4344
ui64 DiskSize = 32_GB;
4445

4546
bool MonitoringEnabled = false;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
syntax = "proto3";
2+
3+
package NKqpRun;
4+
5+
message TStorageMeta {
6+
uint64 StorageGeneration = 1;
7+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
PROTO_LIBRARY()
2+
3+
ONLY_TAGS(CPP_PROTO)
4+
5+
SRCS(
6+
storage_meta.proto
7+
)
8+
9+
END()

ydb/tests/tools/kqprun/src/ya.make

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ SRCS(
99

1010
PEERDIR(
1111
ydb/core/testlib
12+
13+
ydb/tests/tools/kqprun/src/proto
1214
)
1315

1416
GENERATE_ENUM_SERIALIZATION(common.h)

ydb/tests/tools/kqprun/src/ydb_setup.cpp

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#include <ydb/core/testlib/test_client.h>
1010

1111
#include <ydb/library/yql/providers/s3/actors/yql_s3_actors_factory_impl.h>
12+
13+
#include <ydb/tests/tools/kqprun/src/proto/storage_meta.pb.h>
14+
1215
#include <yql/essentials/utils/log/log.h>
1316

1417

@@ -173,15 +176,46 @@ class TYdbSetup::TImpl {
173176
}
174177

175178
void SetStorageSettings(NKikimr::Tests::TServerSettings& serverSettings) const {
179+
TString diskPath;
180+
if (Settings_.PDisksPath && *Settings_.PDisksPath != "-") {
181+
diskPath = TStringBuilder() << *Settings_.PDisksPath << "/";
182+
}
183+
184+
bool formatDisk = true;
185+
NKqpRun::TStorageMeta storageMeta;
186+
if (diskPath) {
187+
TFsPath storageMetaPath(diskPath);
188+
storageMetaPath.MkDirs();
189+
190+
storageMetaPath = storageMetaPath.Child("kqprun_storage_meta.conf");
191+
if (storageMetaPath.Exists() && !Settings_.FormatStorage) {
192+
if (!google::protobuf::TextFormat::ParseFromString(TFileInput(storageMetaPath.GetPath()).ReadAll(), &storageMeta)) {
193+
ythrow yexception() << "Storage meta is corrupted, please use --format-storage";
194+
}
195+
storageMeta.SetStorageGeneration(storageMeta.GetStorageGeneration() + 1);
196+
formatDisk = false;
197+
}
198+
199+
TString storageMetaStr;
200+
google::protobuf::TextFormat::PrintToString(storageMeta, &storageMetaStr);
201+
202+
TFileOutput storageMetaOutput(storageMetaPath.GetPath());
203+
storageMetaOutput.Write(storageMetaStr);
204+
storageMetaOutput.Finish();
205+
}
206+
176207
const NKikimr::NFake::TStorage storage = {
177-
.UseDisk = Settings_.UseRealPDisks,
208+
.UseDisk = !!Settings_.PDisksPath,
178209
.SectorSize = NKikimr::TTestStorageFactory::SECTOR_SIZE,
179-
.ChunkSize = Settings_.UseRealPDisks ? NKikimr::TTestStorageFactory::CHUNK_SIZE : NKikimr::TTestStorageFactory::MEM_CHUNK_SIZE,
180-
.DiskSize = Settings_.DiskSize
210+
.ChunkSize = Settings_.PDisksPath ? NKikimr::TTestStorageFactory::CHUNK_SIZE : NKikimr::TTestStorageFactory::MEM_CHUNK_SIZE,
211+
.DiskSize = Settings_.DiskSize,
212+
.FormatDisk = formatDisk,
213+
.DiskPath = diskPath
181214
};
182215

183-
serverSettings.SetEnableMockOnSingleNode(!Settings_.DisableDiskMock && !Settings_.UseRealPDisks);
216+
serverSettings.SetEnableMockOnSingleNode(!Settings_.DisableDiskMock && !Settings_.PDisksPath);
184217
serverSettings.SetCustomDiskParams(storage);
218+
serverSettings.SetStorageGeneration(storageMeta.GetStorageGeneration());
185219
}
186220

187221
NKikimr::Tests::TServerSettings GetServerSettings(ui32 grpcPort) {

0 commit comments

Comments
 (0)