forked from ydb-platform/ydb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
share schemas between CS on same node (ydb-platform#12673)
- Loading branch information
1 parent
235ed6b
commit c3f10e1
Showing
30 changed files
with
276 additions
and
82 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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
3 changes: 3 additions & 0 deletions
3
ydb/core/tx/columnshard/engines/scheme/abstract/schema_version.cpp
This file contains 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,3 @@ | ||
#include "schema_version.h" | ||
|
||
namespace NKikimr::NOlap {} |
32 changes: 32 additions & 0 deletions
32
ydb/core/tx/columnshard/engines/scheme/abstract/schema_version.h
This file contains 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,32 @@ | ||
#pragma once | ||
|
||
#include <ydb/library/accessor/accessor.h> | ||
|
||
#include <util/digest/numeric.h> | ||
|
||
namespace NKikimr::NOlap { | ||
|
||
class TSchemaVersionId { | ||
private: | ||
YDB_READONLY_DEF(ui64, PresetId); | ||
YDB_READONLY_DEF(ui64, Version); | ||
|
||
public: | ||
bool operator==(const TSchemaVersionId& other) const { | ||
return std::tie(PresetId, Version) == std::tie(other.PresetId, other.Version); | ||
} | ||
|
||
TSchemaVersionId(const ui64 presetId, const ui64 version) | ||
: PresetId(presetId) | ||
, Version(version) { | ||
} | ||
}; | ||
|
||
} | ||
|
||
template <> | ||
struct THash<NKikimr::NOlap::TSchemaVersionId> { | ||
inline size_t operator()(const NKikimr::NOlap::TSchemaVersionId& key) const { | ||
return CombineHashes(key.GetPresetId(), key.GetVersion()); | ||
} | ||
}; |
This file contains 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 |
---|---|---|
|
@@ -3,6 +3,7 @@ LIBRARY() | |
SRCS( | ||
index_info.cpp | ||
column_ids.cpp | ||
schema_version.cpp | ||
) | ||
|
||
PEERDIR( | ||
|
This file contains 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,3 @@ | ||
#include "cache.h" | ||
|
||
namespace NKikimr::NOlap {} |
This file contains 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,72 @@ | ||
#pragma once | ||
|
||
#include <util/generic/hash.h> | ||
#include <util/system/guard.h> | ||
#include <util/system/mutex.h> | ||
|
||
#include <memory> | ||
|
||
namespace NKikimr::NOlap { | ||
|
||
template <typename TKey, typename TObject> | ||
class TObjectCache : std::enable_shared_from_this<TObjectCache<TKey, TObject>> { | ||
private: | ||
THashMap<TKey, std::weak_ptr<const TObject>> Objects; | ||
mutable TMutex Mutex; | ||
|
||
public: | ||
class TEntryGuard { | ||
private: | ||
TKey Key; | ||
std::shared_ptr<const TObject> Object; | ||
std::weak_ptr<TObjectCache> Cache; | ||
|
||
public: | ||
TEntryGuard(TKey key, const std::shared_ptr<const TObject> object, TObjectCache* cache) | ||
: Key(key) | ||
, Object(object) | ||
, Cache(cache->weak_from_this()) { | ||
} | ||
|
||
const TObject* operator->() const { | ||
return Object.get(); | ||
} | ||
const TObject& operator*() const { | ||
return *Object; | ||
} | ||
|
||
~TEntryGuard() { | ||
Object.reset(); | ||
if (auto cache = Cache.lock()) { | ||
cache->TryFree(Key); | ||
} | ||
} | ||
}; | ||
|
||
public: | ||
TEntryGuard Upsert(TKey key, TObject&& object) { | ||
TGuard lock(Mutex); | ||
auto* findSchema = Objects.FindPtr(key); | ||
std::shared_ptr<const TObject> cachedObject; | ||
if (findSchema) { | ||
cachedObject = findSchema->lock(); | ||
} | ||
if (!cachedObject) { | ||
cachedObject = std::make_shared<const TObject>(std::move(object)); | ||
Objects[key] = cachedObject; | ||
} | ||
return TEntryGuard(std::move(key), cachedObject, this); | ||
} | ||
|
||
void TryFree(const TKey& key) { | ||
TGuard lock(Mutex); | ||
auto findObject = Objects.FindPtr(key); | ||
if (findObject) { | ||
if (findObject->expired()) { | ||
Objects.erase(key); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
} // namespace NKikimr::NOlap |
This file contains 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 @@ | ||
LIBRARY() | ||
|
||
SRCS( | ||
cache.cpp | ||
) | ||
|
||
PEERDIR( | ||
ydb/library/actors/core | ||
) | ||
|
||
YQL_LAST_ABI_VERSION() | ||
|
||
END() |
This file contains 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 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 |
---|---|---|
@@ -1,5 +1,12 @@ | ||
#include "objects_cache.h" | ||
|
||
#include <ydb/core/tx/columnshard/engines/scheme/index_info.h> | ||
|
||
namespace NKikimr::NOlap { | ||
|
||
TSchemaObjectsCache::TSchemasCache::TEntryGuard TSchemaObjectsCache::UpsertIndexInfo(const ui64 presetId, TIndexInfo&& indexInfo) { | ||
const TSchemaVersionId versionId(presetId, indexInfo.GetVersion()); | ||
return SchemasByVersion.Upsert(versionId, std::move(indexInfo)); | ||
} | ||
|
||
} // namespace NKikimr::NOlap |
Oops, something went wrong.