Merge pull request #1639 from dvzubarev/fix-crashes

Fix crashes with sptag index
This commit is contained in:
Jin Hai 2020-03-13 00:11:33 +08:00 committed by GitHub
commit 24c39535be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 4 deletions

View File

@ -10,6 +10,7 @@
// or implied. See the License for the specific language governing permissions and limitations under the License.
#include "knowhere/adapter/SptagAdapter.h"
#include "VectorAdapter.h"
namespace knowhere {
@ -19,7 +20,7 @@ ConvertToMetadataSet(const DatasetPtr& dataset) {
auto elems = dataset->Get<int64_t>(meta::ROWS);
auto p_data = dataset->Get<const int64_t*>(meta::IDS);
auto p_offset = (int64_t*)malloc(sizeof(int64_t) * elems);
auto p_offset = (int64_t*)malloc(sizeof(int64_t) * (elems + 1));
for (auto i = 0; i <= elems; ++i) p_offset[i] = i * 8;
std::shared_ptr<SPTAG::MetadataSet> metaset(

View File

@ -11,6 +11,8 @@
#pragma once
#include <string.h>
#include <map>
#include <memory>
#include <string>
@ -28,6 +30,13 @@ struct Binary {
};
using BinaryPtr = std::shared_ptr<Binary>;
inline uint8_t*
CopyBinary(const BinaryPtr& bin) {
uint8_t* newdata = new uint8_t[bin->size];
memcpy(newdata, bin->data.get(), bin->size);
return newdata;
}
class BinarySet {
public:
BinaryPtr

View File

@ -104,7 +104,7 @@ CPUSPTAGRNG::Load(const BinarySet& binary_set) {
index_blobs.push_back(SPTAG::ByteArray(deleteid->data.get(), deleteid->size, false));
auto metadata1 = binary_set.GetByName("metadata1");
index_blobs.push_back(SPTAG::ByteArray(metadata1->data.get(), metadata1->size, false));
index_blobs.push_back(SPTAG::ByteArray(CopyBinary(metadata1), metadata1->size, true));
auto metadata2 = binary_set.GetByName("metadata2");
index_blobs.push_back(SPTAG::ByteArray(metadata2->data.get(), metadata2->size, false));

View File

@ -39,9 +39,10 @@ BuildIndexJob::AddToIndexFiles(const engine::meta::TableFileSchemaPtr& to_index_
<< ", location: " << to_index_file->location_;
to_index_files_[to_index_file->id_] = to_index_file;
return true;
}
Status&
void
BuildIndexJob::WaitBuildIndexFinish() {
std::unique_lock<std::mutex> lock(mutex_);
cv_.wait(lock, [this] { return to_index_files_.empty(); });

View File

@ -44,7 +44,7 @@ class BuildIndexJob : public Job, public server::CacheConfigHandler {
bool
AddToIndexFiles(const TableFileSchemaPtr& to_index_file);
Status&
void
WaitBuildIndexFinish();
void