MCPcopy Create free account
hub / github.com/alibaba/zvec / open

Method open

src/core/algorithm/flat_sparse/flat_sparse_streamer.cc:58–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56}
57
58int FlatSparseStreamer::open(IndexStorage::Pointer stg) {
59 LOG_DEBUG("FlatSparseStreamer open");
60
61 if (ailego_unlikely(state_ != STATE_INITED)) {
62 LOG_ERROR("Open storage failed, init streamer first!");
63 return IndexError_NoReady;
64 }
65
66 int ret = entity_.open(std::move(stg), meta_);
67 if (ret != 0) {
68 LOG_ERROR("FlatSparseStreamer entity failed to open storage");
69 return ret;
70 }
71
72 IndexMeta index_meta;
73 ret = entity_.get_index_sparse_meta(&index_meta);
74 if (ret == IndexError_NoExist) {
75 // Set IndexMeta for the new index
76 ret = entity_.set_index_sparse_meta(meta_);
77 if (ret != 0) {
78 LOG_ERROR("Failed to set index meta for %s", IndexError::What(ret));
79 return ret;
80 }
81 } else {
82 if (index_meta.streamer_revision() != meta_.streamer_revision()) {
83 LOG_ERROR("Streamer revision mismatch, expect=%u, actual=%u",
84 meta_.streamer_revision(), index_meta.streamer_revision());
85 return IndexError_Mismatch;
86 }
87 if (index_meta.metric_name() != meta_.metric_name() ||
88 index_meta.data_type() != meta_.data_type()) {
89 LOG_ERROR("IndexMeta mismatch from the previous in index");
90 return IndexError_Mismatch;
91 }
92 // The IndexMeasure Params may be updated like MipsSquaredEuclidean
93 auto metric_params = index_meta.metric_params();
94 metric_params.merge(meta_.metric_params());
95 meta_.set_metric(index_meta.metric_name(), 0, metric_params);
96 }
97
98 state_ = STATE_OPENED;
99 magic_ = IndexContext::GenerateMagic();
100
101 return 0;
102}
103
104int FlatSparseStreamer::close() {
105 if (state_ != STATE_OPENED) {

Callers

nothing calls this directly

Calls 6

get_index_sparse_metaMethod · 0.80
set_index_sparse_metaMethod · 0.80
streamer_revisionMethod · 0.80
data_typeMethod · 0.45
mergeMethod · 0.45
set_metricMethod · 0.45

Tested by

no test coverage detected