| 262 | |
| 263 | template <size_t BATCH_SIZE> |
| 264 | int FlatStreamer<BATCH_SIZE>::add_with_id_impl(uint32_t id, const void *query, |
| 265 | const IndexQueryMeta &qmeta, |
| 266 | Context::Pointer &context) { |
| 267 | if (!query || qmeta.dimension() != meta_.dimension() || |
| 268 | qmeta.data_type() != meta_.data_type() || |
| 269 | qmeta.element_size() != meta_.element_size()) { |
| 270 | LOG_ERROR( |
| 271 | "Failed to add for invalid arguments, query=%p, qmeta(type=%u " |
| 272 | "dim=%u size=%u) vs meta(type=%u dim=%u size=%u)", |
| 273 | query, qmeta.data_type(), qmeta.dimension(), qmeta.element_size(), |
| 274 | meta_.data_type(), meta_.dimension(), meta_.element_size()); |
| 275 | (*stats_.mutable_discarded_count())++; |
| 276 | return IndexError_InvalidArgument; |
| 277 | } |
| 278 | |
| 279 | auto *ctx = dynamic_cast<FlatStreamerContext<BATCH_SIZE> *>(context.get()); |
| 280 | if (!ctx) { |
| 281 | LOG_ERROR("Failed to cast FlatStreamerContext"); |
| 282 | (*stats_.mutable_discarded_count())++; |
| 283 | return IndexError_Cast; |
| 284 | } |
| 285 | |
| 286 | READ_LOCK_GUARD_DEFER(dump_mutex_, dump_lock); |
| 287 | |
| 288 | if (!dump_lock.try_lock()) { |
| 289 | LOG_ERROR("Cannot add vector while dumping index"); |
| 290 | (*stats_.mutable_discarded_count())++; |
| 291 | return IndexError_Unsupported; |
| 292 | } |
| 293 | |
| 294 | int ret = entity_.add_vector_with_id(id, query, qmeta.element_size()); |
| 295 | if (ret != 0) { |
| 296 | LOG_ERROR("Failed to add record for %s", IndexError::What(ret)); |
| 297 | (*stats_.mutable_discarded_count())++; |
| 298 | return ret; |
| 299 | } |
| 300 | |
| 301 | return 0; |
| 302 | } |
| 303 | |
| 304 | template <size_t BATCH_SIZE> |
| 305 | int FlatStreamer<BATCH_SIZE>::search_bf_impl(const void *query, |