Skip to content

Commit

Permalink
call free only when an error occurs
Browse files Browse the repository at this point in the history
  • Loading branch information
wxingda committed Apr 23, 2024
1 parent 6ff3513 commit f00b2a9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 30 deletions.
29 changes: 13 additions & 16 deletions internal/engine/c_api/api_data/request.cc
Expand Up @@ -6,6 +6,7 @@
*/

#include "request.h"

#include "util/status.h"

namespace vearch {
Expand All @@ -25,8 +26,7 @@ int Request::Serialize(char **out, int *out_len) {

auto vector_query = gamma_api::CreateVectorQuery(
builder, builder.CreateString(name), builder.CreateVector(value),
min_score, max_score,
builder.CreateString(vec_field.index_type));
min_score, max_score, builder.CreateString(vec_field.index_type));
vec_fields_vector.push_back(vector_query);
}

Expand Down Expand Up @@ -65,14 +65,14 @@ int Request::Serialize(char **out, int *out_len) {
builder.CreateVector(value), is_union));
}

auto res =
gamma_api::CreateRequest(builder, req_num_, topn_, brute_force_search_,
builder.CreateVector(vec_fields_vector),
builder.CreateVector(fields_vector),
builder.CreateVector(range_filter_vector),
builder.CreateVector(term_filter_vector),
builder.CreateString(index_params_),
multi_vector_rank_, l2_sqrt_, builder.CreateString(ranker_->raw_str));
auto res = gamma_api::CreateRequest(
builder, req_num_, topn_, brute_force_search_,
builder.CreateVector(vec_fields_vector),
builder.CreateVector(fields_vector),
builder.CreateVector(range_filter_vector),
builder.CreateVector(term_filter_vector),
builder.CreateString(index_params_), multi_vector_rank_, l2_sqrt_,
builder.CreateString(ranker_->raw_str));

builder.Finish(res);
*out_len = builder.GetSize();
Expand Down Expand Up @@ -226,16 +226,13 @@ bool Request::L2Sqrt() {

void Request::SetL2Sqrt(bool l2_sqrt) { l2_sqrt_ = l2_sqrt; }

vearch::Ranker *Request::Ranker() {
return ranker_;
}
vearch::Ranker *Request::Ranker() { return ranker_; }

int Request::SetRanker(std::string params, int weight_num) {
ranker_ = new WeightedRanker(params, weight_num);
if (params == "")
return 0;
if (params == "") return 0;
Status status = ranker_->Parse();
if (status.code() != status::Code::kOk) {
if (!status.ok()) {
delete ranker_;
ranker_ = nullptr;
return -1;
Expand Down
8 changes: 6 additions & 2 deletions internal/engine/sdk/go/gamma/gamma.go
Expand Up @@ -43,7 +43,9 @@ func CreateTable(engine unsafe.Pointer, table *Table) *Status {
Code: int32(cstatus.code),
Msg: C.GoString(cstatus.msg),
}
C.free(unsafe.Pointer(cstatus.msg))
if status.Code != 0 {
C.free(unsafe.Pointer(cstatus.msg))
}
return status
}

Expand Down Expand Up @@ -153,7 +155,9 @@ func Search(engine unsafe.Pointer, reqByte []byte) ([]byte, *Status) {
Code: int32(cstatus.code),
Msg: C.GoString(cstatus.msg),
}
C.free(unsafe.Pointer(cstatus.msg))
if status.Code != 0 {
C.free(unsafe.Pointer(cstatus.msg))
}
return respByte, status
}

Expand Down
6 changes: 3 additions & 3 deletions internal/engine/search/engine.cc
Expand Up @@ -318,7 +318,7 @@ Status Engine::Search(Request &request, Response &response_results) {
return Status::InvalidArgument();
} else {
status = gamma_query.condition->ranker->Parse();
if (status.code() != status::Code::kOk) {
if (!status.ok()) {
std::string msg = "ranker parse err, ranker: " +
gamma_query.condition->ranker->ToString();
LOG(WARNING) << msg;
Expand Down Expand Up @@ -491,7 +491,7 @@ Status Engine::CreateTable(TableInfo &table) {
}

Status status = vec_manager_->CreateVectorTable(table, meta_jp);
if (status != Status::OK()) {
if (!status.ok()) {
std::string msg =
space_name_ + " cannot create VectorTable: " + status.ToString();
LOG(ERROR) << msg;
Expand Down Expand Up @@ -799,7 +799,7 @@ int Engine::RebuildIndex(int drop_before_rebuild, int limit_cpu, int describe) {
if (drop_before_rebuild) {
Status status = vec_manager_->CreateVectorIndexes(
training_threshold_, vec_manager_->VectorIndexes());
if (status != Status::OK()) {
if (!status.ok()) {
LOG(ERROR) << "RebuildIndex CreateVectorIndexes failed: "
<< status.ToString();
vec_manager_->DestroyVectorIndexes();
Expand Down
8 changes: 4 additions & 4 deletions internal/engine/vector/vector_manager.cc
Expand Up @@ -80,7 +80,7 @@ Status VectorManager::CreateRawVector(struct VectorInfo &vector_info,

VectorStorageType store_type = default_store_type_;
Status status = SetVectorStoreType(index_type, store_type_str, store_type);
if (status != Status::OK()) {
if (!status.ok()) {
LOG(ERROR) << "set vector store type failed, store_type=" << store_type_str
<< ", index_type=" << index_type;
return status;
Expand Down Expand Up @@ -244,7 +244,7 @@ Status VectorManager::CreateVectorIndexes(
Status status =
CreateVectorIndex(index_types_[i], index_params_[i], index,
training_threshold, false, vector_indexes);
if (status != Status::OK()) {
if (!status.ok()) {
LOG(ERROR) << vec_name
<< " create index failed: " << status.ToString();
return status;
Expand Down Expand Up @@ -301,7 +301,7 @@ Status VectorManager::CreateVectorTable(TableInfo &table,
std::string &vec_name = vector_info.name;
vec_status = CreateRawVector(vector_info, index_types_[0], vec_dups, table,
vectors_jp, &vec);
if (vec_status != Status::OK()) {
if (!vec_status.ok()) {
std::stringstream msg;
msg << vec_name << " create vector failed:" << vec_status.ToString();
LOG(ERROR) << msg.str();
Expand All @@ -320,7 +320,7 @@ Status VectorManager::CreateVectorTable(TableInfo &table,
status =
CreateVectorIndex(index_types_[i], index_params_[i], vec,
table.TrainingThreshold(), true, vector_indexes_);
if (status != Status::OK()) {
if (!status.ok()) {
LOG(ERROR) << vec_name << " create index failed: " << status.ToString();
return status;
}
Expand Down
8 changes: 3 additions & 5 deletions internal/master/cluster_service.go
Expand Up @@ -422,7 +422,6 @@ func (ms *masterService) createSpaceService(ctx context.Context, dbName string,
case <-ctx.Done():
return fmt.Errorf("create space has error")
default:

}

partition, err := ms.Master().QueryPartition(ctx, space.Partitions[i].Id)
Expand All @@ -432,11 +431,10 @@ func (ms *masterService) createSpaceService(ctx context.Context, dbName string,
if err != nil && vearchpb.NewError(vearchpb.ErrorEnum_INTERNAL_ERROR, err).GetError().Code != vearchpb.ErrorEnum_PARTITION_NOT_EXIST {
return err
}
if partition == nil {
time.Sleep(50 * time.Millisecond)
continue
if partition != nil {
break
}
break
time.Sleep(50 * time.Millisecond)
}
}

Expand Down

0 comments on commit f00b2a9

Please sign in to comment.