-
Notifications
You must be signed in to change notification settings - Fork 638
Refactor config transformations #1787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Enjection
merged 9 commits into
ydb-platform:main
from
Enjection:feature/KIKIMR-21043/refactor-yaml-config-parser
Feb 14, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d297edd
implement new yaml config parser
Enjection 9ca3c63
fix incls
Enjection 290d8f9
extract constants
Enjection 42d8130
fix
Enjection f880a4c
replace diff tool to json_diff
Enjection f0a0b11
replace file extensions
Enjection d763498
fix diff tool
Enjection 68b0cf0
fix non-deterministic containers
Enjection 67d75e1
fix non-deterministic iteration in test
Enjection File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#pragma once | ||
|
||
#include <util/generic/string.h> | ||
|
||
#include <utility> | ||
#include <array> | ||
#include <map> | ||
|
||
namespace NKikimr::NYaml { | ||
|
||
constexpr ui32 DEFAULT_INTERCONNECT_PORT = 19001; | ||
|
||
constexpr inline TStringBuf DEFAULT_ROOT_USERNAME = "root"; | ||
|
||
constexpr inline TStringBuf COMBINED_DISK_INFO_PATH = "/blob_storage_config/service_set/groups/*/rings/*/fail_domains/*/vdisk_locations/*"; | ||
constexpr inline TStringBuf GROUP_PATH = "/blob_storage_config/service_set/groups/*"; | ||
constexpr inline TStringBuf DISABLE_BUILTIN_SECURITY_PATH = "/domains_config/disable_builtin_security"; | ||
constexpr inline TStringBuf DEFAULT_GROUPS_PATH = "/domains_config/default_groups"; | ||
constexpr inline TStringBuf DEFAULT_ACCESS_PATH = "/domains_config/default_access"; | ||
|
||
constexpr inline TStringBuf ERASURE_SPECIES_FIELD = "erasure_species"; | ||
|
||
const inline std::array<std::pair<TString, ui32>, 10> DEFAULT_TABLETS{ | ||
std::pair{TString{"FlatHive"}, 1}, | ||
std::pair{TString{"FlatBsController"}, 1}, | ||
std::pair{TString{"FlatSchemeshard"}, 1}, | ||
std::pair{TString{"FlatTxCoordinator"}, 3}, | ||
std::pair{TString{"TxMediator"}, 3}, | ||
std::pair{TString{"TxAllocator"}, 3}, | ||
std::pair{TString{"Cms"}, 1}, | ||
std::pair{TString{"NodeBroker"}, 1}, | ||
std::pair{TString{"TenantSlotBroker"}, 1}, | ||
std::pair{TString{"Console"}, 1}, | ||
}; | ||
|
||
const inline std::map<TString, ui64> GetTablets(ui64 idx) { | ||
return { | ||
{TString{"FlatHive"}, 72057594037968897}, | ||
{TString{"FlatBsController"}, 72057594037932033}, | ||
{TString{"FlatSchemeshard"}, 72057594046678944}, | ||
{TString{"Cms"}, 72057594037936128}, | ||
{TString{"NodeBroker"}, 72057594037936129}, | ||
{TString{"TenantSlotBroker"}, 72057594037936130}, | ||
{TString{"Console"}, 72057594037936131}, | ||
{TString{"TxAllocator"}, TDomainsInfo::MakeTxAllocatorIDFixed(1, idx)}, | ||
{TString{"FlatTxCoordinator"}, TDomainsInfo::MakeTxCoordinatorIDFixed(1, idx)}, | ||
{TString{"TxMediator"}, TDomainsInfo::MakeTxMediatorIDFixed(1, idx)}, | ||
}; | ||
} | ||
|
||
const inline std::array<std::pair<TString, TString>, 4> DEFAULT_EXECUTORS{ | ||
std::pair{TString{"IoExecutor"}, TString{"IO"}}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Можно явно не специфицировать |
||
std::pair{TString{"SysExecutor"}, TString{"SYSTEM"}}, | ||
std::pair{TString{"UserExecutor"}, TString{"USER"}}, | ||
std::pair{TString{"BatchExecutor"}, TString{"BATCH"}}, | ||
}; | ||
|
||
|
||
const inline std::array<std::pair<TString, TString>, 3> EXPLICIT_TABLETS{ | ||
std::pair{TString{"ExplicitCoordinators"}, TString{"FlatTxCoordinator"}}, | ||
std::pair{TString{"ExplicitAllocators"}, TString{"TxAllocator"}}, | ||
std::pair{TString{"ExplicitMediators"}, TString{"TxMediator"}}, | ||
}; | ||
|
||
|
||
} // namespace NKikimr::NYaml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
syntax = "proto2"; | ||
|
||
import "ydb/core/config/protos/marker.proto"; | ||
import "ydb/core/protos/blobstorage.proto"; | ||
import "ydb/core/protos/blobstorage_config.proto"; | ||
import "ydb/core/protos/blobstorage_disk.proto"; | ||
import "ydb/core/protos/blobstorage_disk_color.proto"; | ||
import "ydb/core/protos/blobstorage_pdisk_config.proto"; | ||
import "ydb/core/protos/blobstorage_vdisk_config.proto"; | ||
import "ydb/core/protos/bootstrap.proto"; | ||
import "ydb/core/protos/config.proto"; | ||
import "ydb/library/actors/protos/interconnect.proto"; | ||
|
||
package NKikimrConfig; | ||
option java_package = "ru.yandex.kikimr.proto"; | ||
|
||
// message below used to parse part of yaml by following path | ||
// /blob_storage_config/service_set/groups/*/rings/*/fail_domains/*/vdisk_locations/* | ||
// later this part is transformed and copied to corresponding config parts | ||
message TCombinedDiskInfo { | ||
option (NMarkers.CombinedType) = true; | ||
optional string NodeID = 1; // +allow string // have to copy manually | ||
optional uint32 PDiskID = 2 [(NMarkers.CopyTo) = "TVDiskLocation", (NMarkers.CopyTo) = "TPDisk"]; | ||
optional uint32 VDiskSlotID = 3 [(NMarkers.CopyTo) = "TVDiskLocation"]; | ||
optional uint64 PDiskGuid = 4 [(NMarkers.CopyTo) = "TVDiskLocation", (NMarkers.CopyTo) = "TPDisk"]; | ||
|
||
optional NKikimrBlobStorage.TVDiskID VDiskID = 101 [(NMarkers.CopyTo) = "TVDisk"]; | ||
optional NKikimrBlobStorage.TVDiskLocation VDiskLocation = 102 [(NMarkers.CopyTo) = "TVDisk"]; | ||
optional NKikimrBlobStorage.TVDiskKind.EVDiskKind VDiskKind = 103 [(NMarkers.CopyTo) = "TVDisk"]; | ||
optional bool DoDestroy = 104 [default = false, (NMarkers.CopyTo) = "TVDisk"]; | ||
optional bool DoWipe = 105 [default = false, (NMarkers.CopyTo) = "TVDisk"]; | ||
optional NKikimrBlobStorage.EEntityStatus EntityStatus = 106 [(NMarkers.CopyTo) = "TVDisk", (NMarkers.CopyTo) = "TPDisk"]; | ||
optional string StoragePoolName = 108 [(NMarkers.CopyTo) = "TVDisk"]; | ||
optional NKikimrBlobStorage.TNodeWardenServiceSet.TVDisk.TDonorMode DonorMode = 109 [(NMarkers.CopyTo) = "TVDisk"]; | ||
repeated NKikimrBlobStorage.TNodeWardenServiceSet.TVDisk.TDonor Donors = 110 [(NMarkers.CopyTo) = "TVDisk"]; | ||
optional bool ReadOnly = 111 [(NMarkers.CopyTo) = "TVDisk"]; | ||
|
||
optional string Path = 203 [(NMarkers.CopyTo) = "TPDisk"]; | ||
optional string PDiskCategory = 206; // +allow string // have to copy manually | ||
optional NKikimrBlobStorage.TPDiskConfig PDiskConfig = 207 [(NMarkers.CopyTo) = "TPDisk"]; | ||
optional uint64 InMemoryForTestsBufferBytes = 210 [default = 0, (NMarkers.CopyTo) = "TPDisk"]; | ||
optional string ExpectedSerial = 211 [(NMarkers.CopyTo) = "TPDisk"]; | ||
optional NKikimrBlobStorage.TSerialManagementStage.E ManagementStage = 212 [(NMarkers.CopyTo) = "TPDisk"]; | ||
optional NKikimrBlobStorage.TPDiskSpaceColor.E SpaceColorBorder = 213 [(NMarkers.CopyTo) = "TPDisk"]; | ||
} | ||
|
||
message TSystemTablets { | ||
option (NMarkers.WithMapType) = true; | ||
repeated uint64 DefaultNode = 1; | ||
repeated NKikimrConfig.TBootstrap.TTablet FlatHive = 2 [(NMarkers.AsMap) = "Tablets"]; | ||
repeated NKikimrConfig.TBootstrap.TTablet FlatBsController = 3 [(NMarkers.AsMap) = "Tablets"]; | ||
repeated NKikimrConfig.TBootstrap.TTablet FlatSchemeshard = 4 [(NMarkers.AsMap) = "Tablets"]; | ||
repeated NKikimrConfig.TBootstrap.TTablet Cms = 5 [(NMarkers.AsMap) = "Tablets"]; | ||
repeated NKikimrConfig.TBootstrap.TTablet NodeBroker = 6 [(NMarkers.AsMap) = "Tablets"]; | ||
repeated NKikimrConfig.TBootstrap.TTablet TenantSlotBroker = 7 [(NMarkers.AsMap) = "Tablets"]; | ||
repeated NKikimrConfig.TBootstrap.TTablet Console = 8 [(NMarkers.AsMap) = "Tablets"]; | ||
repeated NKikimrConfig.TBootstrap.TTablet FlatTxCoordinator = 9 [(NMarkers.AsMap) = "Tablets"]; | ||
repeated NKikimrConfig.TBootstrap.TTablet TxAllocator = 10 [(NMarkers.AsMap) = "Tablets"]; | ||
repeated NKikimrConfig.TBootstrap.TTablet TxMediator = 11 [(NMarkers.AsMap) = "Tablets"]; | ||
} | ||
|
||
message THosts { | ||
optional uint32 NodeId = 1; | ||
optional uint32 Port = 2; | ||
optional uint64 HostConfigId = 3; | ||
optional string Host = 4; | ||
optional string InterconnectHost = 5; | ||
optional NActorsInterconnect.TNodeLocation Location = 6; | ||
repeated TStaticNameserviceConfig.TEndpoint Endpoint = 7; | ||
optional NActorsInterconnect.TNodeLocation WalleLocation = 8 [deprecated=true]; | ||
optional string Address = 9; | ||
optional string Name = 10; | ||
} | ||
|
||
// these are additional fields used only before transformations | ||
// after all transformations they shouldnt be used | ||
// but probably will be saved for debugging purposes | ||
message TEphemeralInputFields { | ||
optional TSystemTablets SystemTablets = 1; | ||
optional string StaticErasure = 2; | ||
repeated THosts Hosts = 3; | ||
repeated NKikimrBlobStorage.TDefineHostConfig HostConfigs = 4; | ||
optional uint32 StorageConfigGeneration = 5; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
PROTO_LIBRARY(yaml-config-protos) | ||
|
||
SRCS( | ||
config.proto | ||
) | ||
|
||
PEERDIR( | ||
ydb/core/protos | ||
ydb/core/config/protos | ||
) | ||
|
||
CPP_PROTO_PLUGIN0(config_proto_plugin ydb/core/config/tools/protobuf_plugin) | ||
|
||
EXCLUDE_TAGS(GO_PROTO JAVA_PROTO) | ||
|
||
END() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <ydb/library/yaml_config/yaml_config_parser.h> | ||
|
||
#include <ydb/core/protos/bootstrap.pb.h> | ||
|
||
#include <google/protobuf/descriptor.h> | ||
|
||
#include <util/generic/string.h> | ||
#include <util/string/cast.h> | ||
|
||
Y_DECLARE_OUT_SPEC(, NKikimr::NYaml::TCombinedDiskInfoKey, stream, value) { | ||
stream << "{" << value.Group << "," << value.Ring << "," << value.FailDomain << "," << value.VDiskLocation << "}"; | ||
} | ||
|
||
template <> | ||
bool TryFromStringImpl<::NKikimrConfig::TBootstrap_ETabletType, char>(const char* value, unsigned long size, NKikimrConfig::TBootstrap_ETabletType& res) { | ||
const google::protobuf::EnumDescriptor *descriptor = ::NKikimrConfig::TBootstrap_ETabletType_descriptor(); | ||
const auto* valueDescriptor = descriptor->FindValueByName(TString(value, size)); | ||
if (valueDescriptor) { | ||
res = static_cast<NKikimrConfig::TBootstrap_ETabletType>(valueDescriptor->number()); | ||
return true; | ||
} | ||
return false; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <ydb/library/yaml_config/deprecated/yaml_config_parser.h> | ||
#include <ydb/library/yaml_config/tools/util/defaults.h> | ||
#include <ydb/library/yaml_config/yaml_config_parser.h> | ||
|
||
#include <util/generic/string.h> | ||
#include <util/stream/input.h> | ||
|
||
auto main(int argc, char* argv[]) -> int { | ||
const TString yaml = Cin.ReadAll(); | ||
if (argc == 2 && TString("--deprecated") == argv[1]) { | ||
NKikimrConfig::TAppConfig config; | ||
NKikimr::NYaml::NDeprecated::Parse(yaml, config); | ||
Cout << NKikimr::NYaml::NInternal::ProtoToJson(config); | ||
return 0; | ||
} | ||
Cout << NKikimr::NYaml::NInternal::ProtoToJson(NKikimr::NYaml::Parse(yaml)); | ||
return 0; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
PROGRAM(yaml-to-proto-dump) | ||
|
||
SRCS( | ||
main.cpp | ||
) | ||
|
||
PEERDIR( | ||
ydb/library/yaml_config | ||
ydb/library/yaml_config/deprecated | ||
ydb/library/yaml_config/tools/util | ||
) | ||
|
||
END() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <ydb/library/yaml_config/deprecated/yaml_config_parser.h> | ||
#include <ydb/library/yaml_config/yaml_config_parser.h> | ||
#include <ydb/library/yaml_config/tools/util/defaults.h> | ||
|
||
#include <util/generic/string.h> | ||
#include <util/stream/input.h> | ||
|
||
auto main(int argc, char* argv[]) -> int { | ||
const TString yaml = Cin.ReadAll(); | ||
NKikimrBlobStorage::TConfigRequest config; | ||
if (argc == 2 && TString("--deprecated") == argv[1]) { | ||
Enjection marked this conversation as resolved.
Show resolved
Hide resolved
|
||
config = NKikimr::NYaml::NDeprecated::BuildInitDistributedStorageCommand(yaml); | ||
} else { | ||
config = NKikimr::NYaml::BuildInitDistributedStorageCommand(yaml); | ||
} | ||
Cout << NKikimr::NYaml::NInternal::ProtoToJson(config); | ||
return 0; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
PROGRAM(yaml-to-proto-dump-ds-init) | ||
|
||
SRCS( | ||
main.cpp | ||
) | ||
|
||
PEERDIR( | ||
ydb/library/yaml_config | ||
ydb/library/yaml_config/deprecated | ||
ydb/library/yaml_config/tools/util | ||
) | ||
|
||
END() |
19 changes: 19 additions & 0 deletions
19
ydb/library/yaml_config/tools/simple_json_diff/__main__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import json | ||
import sys | ||
|
||
|
||
def main(): | ||
with open(sys.argv[1], "r") as fh1: | ||
control_data = json.load(fh1) | ||
|
||
with open(sys.argv[2], "r") as fh2: | ||
test_data = json.load(fh2) | ||
|
||
a, b = json.dumps(control_data, sort_keys=True), json.dumps(test_data, sort_keys=True) | ||
|
||
return 0 if a == b else 1 | ||
return 1 | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(main()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
PY3_PROGRAM(simple_json_diff) | ||
|
||
PY_SRCS( | ||
__main__.py | ||
) | ||
|
||
END() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#pragma once | ||
|
||
#include <library/cpp/protobuf/json/proto2json.h> | ||
|
||
#include <google/protobuf/message.h> | ||
|
||
#include <util/generic/string.h> | ||
|
||
namespace NKikimr::NYaml::NInternal { | ||
|
||
inline TString ProtoToJson(const google::protobuf::Message &resp) { | ||
auto config = NProtobufJson::TProto2JsonConfig() | ||
.SetFormatOutput(true) | ||
.SetEnumMode(NProtobufJson::TProto2JsonConfig::EnumName); | ||
return NProtobufJson::Proto2Json(resp, config); | ||
} | ||
|
||
} // namespace NKikimr::NYaml::NInternal |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
LIBRARY() | ||
|
||
SRCS( | ||
defaults.h | ||
) | ||
|
||
PEERDIR( | ||
library/cpp/protobuf/json | ||
) | ||
|
||
END() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
RECURSE( | ||
dump | ||
dump_ds_init | ||
simple_json_diff | ||
util | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inline-константы... ну, такое.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
constexpr же implicitly inline, разве нет?