aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Rutkovsky <alexvru@mail.ru>2022-03-15 20:47:34 +0300
committerAlexander Rutkovsky <alexvru@mail.ru>2022-03-15 20:47:34 +0300
commit94dc3af93a40e68dbc0f2f54c00fe3ee87b2ccca (patch)
tree3c49d523792c3aaa839b88e3080f5155aa01cc86
parentcea1fe93d48662f39ad59510fe78c3987019a99e (diff)
downloadydb-94dc3af93a40e68dbc0f2f54c00fe3ee87b2ccca.tar.gz
Support template for cache file path KIKIMR-14384
ref:4969104c274f41126bc92ae351006230e9af31f8
-rw-r--r--ydb/core/blobstorage/nodewarden/node_warden.h2
-rw-r--r--ydb/core/blobstorage/nodewarden/node_warden_cache.cpp22
-rw-r--r--ydb/core/driver_lib/run/kikimr_services_initializers.cpp18
3 files changed, 38 insertions, 4 deletions
diff --git a/ydb/core/blobstorage/nodewarden/node_warden.h b/ydb/core/blobstorage/nodewarden/node_warden.h
index 4d91550869..9ecc35bd3c 100644
--- a/ydb/core/blobstorage/nodewarden/node_warden.h
+++ b/ydb/core/blobstorage/nodewarden/node_warden.h
@@ -64,6 +64,6 @@ namespace NKikimr {
bool ObtainStaticKey(TEncryptionKey *key);
bool ObtainPDiskKey(TEncryptionKey *key, const NKikimrProto::TKeyConfig& keyConfig);
- std::unique_ptr<ICacheAccessor> CreateFileCacheAccessor(const TFsPath& cacheFilePath);
+ std::unique_ptr<ICacheAccessor> CreateFileCacheAccessor(const TString& templ, const std::unordered_map<char, TString>& vars);
} // NKikimr
diff --git a/ydb/core/blobstorage/nodewarden/node_warden_cache.cpp b/ydb/core/blobstorage/nodewarden/node_warden_cache.cpp
index ed9a1cd8f5..59f0324d23 100644
--- a/ydb/core/blobstorage/nodewarden/node_warden_cache.cpp
+++ b/ydb/core/blobstorage/nodewarden/node_warden_cache.cpp
@@ -180,7 +180,7 @@ TNodeWarden::TWrappedCacheOp TNodeWarden::UpdateServiceSet(const NKikimrBlobStor
};
}
-std::unique_ptr<ICacheAccessor> NKikimr::CreateFileCacheAccessor(const TFsPath& cacheFilePath) {
+std::unique_ptr<ICacheAccessor> NKikimr::CreateFileCacheAccessor(const TString& templ, const std::unordered_map<char, TString>& vars) {
class TAccessor : public ICacheAccessor {
TFsPath Path;
@@ -230,5 +230,23 @@ std::unique_ptr<ICacheAccessor> NKikimr::CreateFileCacheAccessor(const TFsPath&
}
};
- return std::make_unique<TAccessor>(cacheFilePath);
+ TStringStream ss;
+ for (size_t i = 0; i < templ.size(); ++i) {
+ if (templ[i] == '%') {
+ ++i;
+ if (i != templ.size()) {
+ if (const auto it = vars.find(templ[i]); it != vars.end()) {
+ ss << it->second;
+ } else {
+ ss << templ[i];
+ }
+ } else {
+ ss << '%';
+ }
+ } else {
+ ss << templ[i];
+ }
+ }
+
+ return std::make_unique<TAccessor>(ss.Str());
}
diff --git a/ydb/core/driver_lib/run/kikimr_services_initializers.cpp b/ydb/core/driver_lib/run/kikimr_services_initializers.cpp
index 001d2159a9..2779210077 100644
--- a/ydb/core/driver_lib/run/kikimr_services_initializers.cpp
+++ b/ydb/core/driver_lib/run/kikimr_services_initializers.cpp
@@ -833,7 +833,23 @@ void TBSNodeWardenInitializer::InitializeServices(NActors::TActorSystemSetup* se
nodeWardenConfig->AllDriveModels->Merge(Config.GetDriveModelConfig());
}
if (bsc.HasCacheFilePath()) {
- nodeWardenConfig->CacheAccessor = CreateFileCacheAccessor(bsc.GetCacheFilePath());
+ std::unordered_map<char, TString> vars{{'n', ToString(NodeId)}};
+ for (const auto& node : Config.GetNameserviceConfig().GetNode()) {
+ if (node.GetNodeId() == NodeId) {
+ vars['h'] = node.GetHost();
+ vars['p'] = ToString(node.GetPort());
+ break;
+ }
+ }
+ if (Config.HasDynamicNodeConfig()) {
+ const auto& dyn = Config.GetDynamicNodeConfig();
+ if (dyn.HasNodeInfo()) {
+ const auto& ni = dyn.GetNodeInfo();
+ vars['h'] = ni.GetHost();
+ vars['p'] = ToString(ni.GetPort());
+ }
+ }
+ nodeWardenConfig->CacheAccessor = CreateFileCacheAccessor(bsc.GetCacheFilePath(), vars);
}
nodeWardenConfig->CachePDisks = bsc.GetCachePDisks();
nodeWardenConfig->CacheVDisks = bsc.GetCacheVDisks();