Skip to content

Commit 4574879

Browse files
author
Qi Chen
committed
fix SPFreshTest compiling issue
1 parent 7665ad7 commit 4574879

File tree

3 files changed

+33
-26
lines changed

3 files changed

+33
-26
lines changed

AnnService/inc/Core/SPANN/ExtraFileController.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -563,10 +563,15 @@ namespace SPTAG::SPANN {
563563
else {
564564
r = m_pBlockMapping.R();
565565
}
566-
if (key >= r) return ErrorCode::Key_OverFlow;
567-
566+
if (key >= r) {
567+
SPTAGLIB_LOG(Helper::LogLevel::LL_Error, "Key OverFlow! Key:%d R:%d\n", key, r);
568+
return ErrorCode::Key_OverFlow;
569+
}
568570
AddressType* addr = (AddressType*)(At(key));
569-
if (((uintptr_t)addr) == 0xffffffffffffffff) return ErrorCode::Key_NotFound;
571+
if (((uintptr_t)addr) == 0xffffffffffffffff) {
572+
SPTAGLIB_LOG(Helper::LogLevel::LL_Error, "Key NotFound! Key:%d\n", key);
573+
return ErrorCode::Key_NotFound;
574+
}
570575

571576
auto size = addr[0];
572577
if (size < 0) return ErrorCode::Posting_SizeError;

AnnService/src/Core/VectorIndex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ std::shared_ptr<VectorIndex> VectorIndex::Clone(std::string p_clone)
10101010
else
10111011
{
10121012
std::string indexFolder = GetParameter("IndexDirectory", "Base");
1013-
ret = SaveIndex(indexFolder);
1013+
//ret = SaveIndex(indexFolder);
10141014
if (!copydirectory(indexFolder, p_clone))
10151015
{
10161016
SPTAGLIB_LOG(Helper::LogLevel::LL_Error, "Failed to copy index directory contents to %s!\n",

Test/src/SPFreshTest.cpp

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,7 @@ BOOST_AUTO_TEST_CASE(CacheTest)
10151015

10161016
std::cout << "=================No Cache===================" << std::endl;
10171017
std::string prevPath = "original_index";
1018+
float recall = 0.0;
10181019
for (int iter = 0; iter < iterations; iter++)
10191020
{
10201021
std::string clone_path = "clone_index_" + std::to_string(iter);
@@ -1032,7 +1033,9 @@ BOOST_AUTO_TEST_CASE(CacheTest)
10321033
static_cast<SPANN::Index<int8_t> *>(prevIndex.get())->GetDBStat();
10331034

10341035
auto cloneIndex = prevIndex->Clone(clone_path);
1035-
1036+
prevIndex = nullptr;
1037+
BOOST_REQUIRE(cloneIndex->Check() == ErrorCode::Success);
1038+
10361039
auto t1 = std::chrono::high_resolution_clock::now();
10371040
InsertVectors<int8_t>(static_cast<SPANN::Index<int8_t> *>(cloneIndex.get()), 1, insertBatchSize, addvecset,
10381041
metaset, iter * insertBatchSize);
@@ -1051,26 +1054,26 @@ BOOST_AUTO_TEST_CASE(CacheTest)
10511054
prevPath = clone_path;
10521055
}
10531056

1054-
std::shared_ptr<VectorIndex> prevIndex;
1055-
BOOST_REQUIRE(VectorIndex::LoadIndex(prevPath, prevIndex) == ErrorCode::Success);
1056-
BOOST_REQUIRE(prevIndex != nullptr);
1057-
auto t0 = std::chrono::high_resolution_clock::now();
1058-
BOOST_REQUIRE(prevIndex->Check() == ErrorCode::Success);
1057+
std::shared_ptr<VectorIndex> finalIndex;
1058+
BOOST_REQUIRE(VectorIndex::LoadIndex(prevPath, finalIndex) == ErrorCode::Success);
1059+
BOOST_REQUIRE(finalIndex != nullptr);
1060+
auto t = std::chrono::high_resolution_clock::now();
1061+
BOOST_REQUIRE(finalIndex->Check() == ErrorCode::Success);
10591062
std::cout << "[INFO] Check time for iteration " << iterations << ": "
1060-
<< std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - t0).count()
1063+
<< std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - t).count()
10611064
<< " ms" << std::endl;
10621065

1063-
recall = Search<int8_t>(prevIndex, queryset, vecset, addvecset, K, truth, N, iterations);
1066+
recall = Search<int8_t>(finalIndex, queryset, vecset, addvecset, K, truth, N, iterations);
10641067
std::cout << "[INFO] After Save and Load:" << " recall@5=" << recall << std::endl;
1065-
static_cast<SPANN::Index<int8_t> *>(prevIndex.get())->GetDBStat();
1066-
prevIndex = nullptr;
1067-
for (int iter = 0; iter < insertIterations; iter++)
1068+
static_cast<SPANN::Index<int8_t> *>(finalIndex.get())->GetDBStat();
1069+
finalIndex = nullptr;
1070+
for (int iter = 0; iter < iterations; iter++)
10681071
{
10691072
std::filesystem::remove_all("clone_index_" + std::to_string(iter));
10701073
}
10711074

10721075
std::cout << "=================Enable Cache===================" << std::endl;
1073-
std::string prevPath = "original_index";
1076+
prevPath = "original_index";
10741077
for (int iter = 0; iter < iterations; iter++)
10751078
{
10761079
std::string clone_path = "clone_index_" + std::to_string(iter);
@@ -1110,21 +1113,20 @@ BOOST_AUTO_TEST_CASE(CacheTest)
11101113
cloneIndex = nullptr;
11111114
prevPath = clone_path;
11121115
}
1113-
std::shared_ptr<VectorIndex> prevIndex;
1114-
BOOST_REQUIRE(VectorIndex::LoadIndex(prevPath, prevIndex) == ErrorCode::Success);
1115-
BOOST_REQUIRE(prevIndex != nullptr);
1116-
auto t0 = std::chrono::high_resolution_clock::now();
1117-
BOOST_REQUIRE(prevIndex->Check() == ErrorCode::Success);
1116+
BOOST_REQUIRE(VectorIndex::LoadIndex(prevPath, finalIndex) == ErrorCode::Success);
1117+
BOOST_REQUIRE(finalIndex != nullptr);
1118+
t = std::chrono::high_resolution_clock::now();
1119+
BOOST_REQUIRE(finalIndex->Check() == ErrorCode::Success);
11181120
std::cout << "[INFO] Check time for iteration " << iterations << ": "
1119-
<< std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - t0).count()
1121+
<< std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - t).count()
11201122
<< " ms" << std::endl;
11211123

1122-
recall = Search<int8_t>(prevIndex, queryset, vecset, addvecset, K, truth, N, iterations);
1124+
recall = Search<int8_t>(finalIndex, queryset, vecset, addvecset, K, truth, N, iterations);
11231125
std::cout << "[INFO] After Save and Load:" << " recall@5=" << recall << std::endl;
1124-
static_cast<SPANN::Index<int8_t> *>(prevIndex.get())->GetDBStat();
1125-
prevIndex = nullptr;
1126+
static_cast<SPANN::Index<int8_t> *>(finalIndex.get())->GetDBStat();
1127+
finalIndex = nullptr;
11261128

1127-
for (int iter = 0; iter < insertIterations; iter++)
1129+
for (int iter = 0; iter < iterations; iter++)
11281130
{
11291131
std::filesystem::remove_all("clone_index_" + std::to_string(iter));
11301132
}

0 commit comments

Comments
 (0)