@@ -10,10 +10,18 @@ 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) {
@@ -26,13 +34,16 @@ class TSchemaObjectsCache {
2634
2735 void RegisterField (const TString& fingerprint, const std::shared_ptr<arrow::Field>& f) {
2836 AFL_TRACE (NKikimrServices::TX_COLUMNSHARD)(" event" , " register_field" )(" fp" , fingerprint)(" f" , f->ToString ());
37+ std::unique_lock lock (FieldsMutex);
2938 AFL_VERIFY (Fields.emplace (fingerprint, f).second );
3039 }
3140 void RegisterColumnFeatures (const TString& fingerprint, const std::shared_ptr<TColumnFeatures>& f) {
3241 AFL_TRACE (NKikimrServices::TX_COLUMNSHARD)(" event" , " register_column_features" )(" fp" , fingerprint)(" info" , f->DebugString ());
42+ std::unique_lock lock (FeaturesMutex);
3343 AFL_VERIFY (ColumnFeatures.emplace (fingerprint, f).second );
3444 }
3545 std::shared_ptr<arrow::Field> GetField (const TString& fingerprint) const {
46+ std::unique_lock lock (FieldsMutex);
3647 auto it = Fields.find (fingerprint);
3748 if (it == Fields.end ()) {
3849 AFL_TRACE (NKikimrServices::TX_COLUMNSHARD)(" event" , " get_field_miss" )(" fp" , fingerprint)(" count" , Fields.size ())(
@@ -47,6 +58,7 @@ class TSchemaObjectsCache {
4758 }
4859 template <class TConstructor >
4960 TConclusion<std::shared_ptr<TColumnFeatures>> GetOrCreateColumnFeatures (const TString& fingerprint, const TConstructor& constructor) {
61+ std::unique_lock lock (FeaturesMutex);
5062 auto it = ColumnFeatures.find (fingerprint);
5163 if (it == ColumnFeatures.end ()) {
5264 AFL_TRACE (NKikimrServices::TX_COLUMNSHARD)(" event" , " get_column_features_miss" )(" fp" , UrlEscapeRet (fingerprint))(
@@ -65,6 +77,25 @@ class TSchemaObjectsCache {
6577 }
6678 return it->second ;
6779 }
80+
81+ std::shared_ptr<const TIndexInfo> GetIndexInfoCache (TIndexInfo&& indexInfo);
82+ };
83+
84+ class TSchemaCachesManager {
85+ private:
86+ THashMap<ui64, std::shared_ptr<TSchemaObjectsCache>> CacheByTableOwner;
87+ TMutex Mutex;
88+
89+ public:
90+ std::shared_ptr<TSchemaObjectsCache> GetCache (const ui64 ownerPathId) {
91+ AFL_VERIFY (ownerPathId);
92+ std::unique_lock lock (Mutex);
93+ auto findCache = CacheByTableOwner.FindPtr (ownerPathId);
94+ if (findCache) {
95+ return *findCache;
96+ }
97+ return CacheByTableOwner.emplace (ownerPathId, std::make_shared<TSchemaObjectsCache>()).first ->second ;
98+ }
6899};
69100
70101} // namespace NKikimr::NOlap
0 commit comments