@@ -10,13 +10,22 @@ namespace NKikimr::NOlap {
1010class TSchemaObjectsCache {
1111private:
1212 THashMap<TString, std::shared_ptr<arrow::Field>> Fields;
13- THashMap<TString, std::shared_ptr<TColumnFeatures>> ColumnFeatures;
14- THashSet<TString> StringsCache;
1513 mutable ui64 AcceptionFieldsCount = 0 ;
14+ mutable TMutex FieldsMutex;
15+
16+ THashMap<TString, std::shared_ptr<TColumnFeatures>> ColumnFeatures;
1617 mutable ui64 AcceptionFeaturesCount = 0 ;
18+ mutable TMutex FeaturesMutex;
19+
20+ THashMap<ui64, std::weak_ptr<const TIndexInfo>> SchemasByVersion;
21+ mutable TMutex SchemasMutex;
22+
23+ THashSet<TString> StringsCache;
24+ mutable TMutex StringsMutex;
1725
1826public:
1927 const TString& GetStringCache (const TString& original) {
28+ std::unique_lock lock (StringsMutex);
2029 auto it = StringsCache.find (original);
2130 if (it == StringsCache.end ()) {
2231 it = StringsCache.emplace (original).first ;
@@ -26,13 +35,16 @@ class TSchemaObjectsCache {
2635
2736 void RegisterField (const TString& fingerprint, const std::shared_ptr<arrow::Field>& f) {
2837 AFL_TRACE (NKikimrServices::TX_COLUMNSHARD)(" event" , " register_field" )(" fp" , fingerprint)(" f" , f->ToString ());
38+ std::unique_lock lock (FieldsMutex);
2939 AFL_VERIFY (Fields.emplace (fingerprint, f).second );
3040 }
3141 void RegisterColumnFeatures (const TString& fingerprint, const std::shared_ptr<TColumnFeatures>& f) {
3242 AFL_TRACE (NKikimrServices::TX_COLUMNSHARD)(" event" , " register_column_features" )(" fp" , fingerprint)(" info" , f->DebugString ());
43+ std::unique_lock lock (FeaturesMutex);
3344 AFL_VERIFY (ColumnFeatures.emplace (fingerprint, f).second );
3445 }
3546 std::shared_ptr<arrow::Field> GetField (const TString& fingerprint) const {
47+ std::unique_lock lock (FieldsMutex);
3648 auto it = Fields.find (fingerprint);
3749 if (it == Fields.end ()) {
3850 AFL_TRACE (NKikimrServices::TX_COLUMNSHARD)(" event" , " get_field_miss" )(" fp" , fingerprint)(" count" , Fields.size ())(
@@ -47,6 +59,7 @@ class TSchemaObjectsCache {
4759 }
4860 template <class TConstructor >
4961 TConclusion<std::shared_ptr<TColumnFeatures>> GetOrCreateColumnFeatures (const TString& fingerprint, const TConstructor& constructor) {
62+ std::unique_lock lock (FeaturesMutex);
5063 auto it = ColumnFeatures.find (fingerprint);
5164 if (it == ColumnFeatures.end ()) {
5265 AFL_TRACE (NKikimrServices::TX_COLUMNSHARD)(" event" , " get_column_features_miss" )(" fp" , UrlEscapeRet (fingerprint))(
@@ -65,6 +78,27 @@ class TSchemaObjectsCache {
6578 }
6679 return it->second ;
6780 }
81+
82+ std::shared_ptr<const TIndexInfo> GetIndexInfoCache (TIndexInfo&& indexInfo);
83+ };
84+
85+ class TSchemaCachesManager {
86+ private:
87+ THashMap<ui64, std::shared_ptr<TSchemaObjectsCache>> CacheByTableOwner;
88+ TMutex Mutex;
89+
90+ public:
91+ std::shared_ptr<TSchemaObjectsCache> GetCache (const ui64 ownerPathId) {
92+ if (!ownerPathId) {
93+ return std::make_shared<TSchemaObjectsCache>();
94+ }
95+ std::unique_lock lock (Mutex);
96+ auto findCache = CacheByTableOwner.FindPtr (ownerPathId);
97+ if (findCache) {
98+ return *findCache;
99+ }
100+ return CacheByTableOwner.emplace (ownerPathId, std::make_shared<TSchemaObjectsCache>()).first ->second ;
101+ }
68102};
69103
70104} // namespace NKikimr::NOlap
0 commit comments