Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion internal/core/src/common/Schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#pragma once

#include <atomic>
#include <cstdint>
#include <memory>
#include <optional>
Expand Down Expand Up @@ -358,5 +359,5 @@ class Schema {
};

using SchemaPtr = std::shared_ptr<Schema>;

using SafeSchemaPtr = std::atomic<SchemaPtr*>;
} // namespace milvus
13 changes: 4 additions & 9 deletions internal/core/src/segcore/Collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Collection::parse_schema(const void* schema_proto_blob,
const uint64_t version) {
Assert(schema_proto_blob != nullptr);

if (version <= schema_->get_schema_version()) {
if (version <= get_schema_version()) {
return;
}

Expand All @@ -79,14 +79,9 @@ Collection::parse_schema(const void* schema_proto_blob,

AssertInfo(suc, "parse schema proto failed");

auto old_schema = schema_;

schema_ = Schema::ParseFrom(collection_schema);
schema_->set_schema_version(version);

if (old_schema) {
schema_->UpdateLoadFields(old_schema->load_fields());
}
auto new_schema = Schema::ParseFrom(collection_schema);
new_schema->set_schema_version(version);
set_schema(new_schema);
}

} // namespace milvus::segcore
22 changes: 22 additions & 0 deletions internal/core/src/segcore/Collection.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#pragma once

#include <memory>
#include <shared_mutex>
#include <string>

#include "common/Schema.h"
Expand All @@ -36,9 +37,29 @@ class Collection {
public:
SchemaPtr
get_schema() {
std::shared_lock lock(schema_mutex_);
return schema_;
}

uint64_t
get_schema_version() {
std::shared_lock lock(schema_mutex_);
return schema_->get_schema_version();
}

void
set_schema(SchemaPtr& new_schema) {
std::unique_lock lock(schema_mutex_);
auto old_schema = schema_;
if (new_schema->get_schema_version() > schema_->get_schema_version()) {
schema_ = new_schema;
}

if (old_schema) {
schema_->UpdateLoadFields(old_schema->load_fields());
}
}

IndexMetaPtr&
get_index_meta() {
return index_meta_;
Expand All @@ -57,6 +78,7 @@ class Collection {
private:
std::string collection_name_;
SchemaPtr schema_;
std::shared_mutex schema_mutex_;
IndexMetaPtr index_meta_;
};

Expand Down
Loading