| 33 | : stats_(stats) {} |
| 34 | |
| 35 | int FlatSparseStreamerEntity::open(IndexStorage::Pointer storage, |
| 36 | const IndexMeta &meta) { |
| 37 | if (storage_) { |
| 38 | LOG_ERROR("An storage instance is already opened"); |
| 39 | return IndexError_Duplicate; |
| 40 | } |
| 41 | |
| 42 | keys_map_lock_ = std::make_shared<ailego::SharedMutex>(); |
| 43 | if (!keys_map_lock_) { |
| 44 | LOG_ERROR("FlatSparseStreamerEntity new object failed"); |
| 45 | return IndexError_NoMemory; |
| 46 | } |
| 47 | keys_map_ = std::make_shared<std::map<uint64_t, node_id_t>>(); |
| 48 | |
| 49 | if (storage->get(PARAM_FLAT_SPARSE_META_SEG_ID) || |
| 50 | storage->get(PARAM_FLAT_SPARSE_STREAMER_META_SEG_ID)) { |
| 51 | int ret = this->load_storage(storage, meta); |
| 52 | if (ailego_unlikely(ret != 0)) { |
| 53 | LOG_ERROR("Failed to load storage index"); |
| 54 | return ret; |
| 55 | } |
| 56 | } else { |
| 57 | int ret = this->init_storage(storage, meta); |
| 58 | if (ailego_unlikely(ret != 0)) { |
| 59 | LOG_ERROR("Failed to load storage index"); |
| 60 | return ret; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | if (init_metric(meta) != 0) { |
| 65 | LOG_ERROR("Failed to init metric"); |
| 66 | return IndexError_InvalidFormat; |
| 67 | } |
| 68 | |
| 69 | // reserve data chunk |
| 70 | meta.streamer_params().get(PARAM_FLAT_SPARSE_STREAMER_MAX_DATA_CHUNK_CNT, |
| 71 | &max_data_chunk_cnt_); |
| 72 | sparse_data_chunks_.reserve(max_data_chunk_cnt_); |
| 73 | |
| 74 | // reserve offset chunk |
| 75 | meta.streamer_params().get(PARAM_FLAT_SPARSE_STREAMER_MAX_DOC_CNT, |
| 76 | &max_doc_cnt_); |
| 77 | sparse_offset_chunks_.reserve(max_doc_cnt_ / doc_cnt_per_offset_chunk() + 1); |
| 78 | sparse_unit_size_ = meta.unit_size(); |
| 79 | |
| 80 | LOG_DEBUG( |
| 81 | "FlatSparseStreamerEntity open success, doc_count[%u], " |
| 82 | "data_chunk_size[%u], offset_chunk_size[%u], data_chunk_count[%zu], " |
| 83 | "offset_chunk_count[%zu]", |
| 84 | meta_.doc_cnt, streamer_meta_.data_chunk_size, |
| 85 | streamer_meta_.offset_chunk_size, sparse_data_chunks_.size(), |
| 86 | sparse_offset_chunks_.size()); |
| 87 | |
| 88 | storage_ = storage; |
| 89 | return 0; |
| 90 | } |
| 91 | |
| 92 | int FlatSparseStreamerEntity::init_metric(const IndexMeta &meta) { |
nothing calls this directly
no test coverage detected