feat: windows support (#216)

Preliminary support for Windows with remaining TODOs
This commit is contained in:
Jalin Wang
2026-03-30 20:47:34 +08:00
committed by GitHub
parent cef9fbf2ab
commit 8182cfff93
150 changed files with 2115 additions and 979 deletions
+17 -18
View File
@@ -17,6 +17,7 @@
#include <iostream>
#include <vector>
#include <gtest/gtest.h>
#include "tests/test_util.h"
#if defined(__GNUC__) || defined(__GNUG__)
#pragma GCC diagnostic push
@@ -43,7 +44,7 @@ class FlatBuilderTest : public testing::Test {
static IndexMeta meta_;
};
std::string FlatBuilderTest ::dir_("flat_builder_test");
std::string FlatBuilderTest ::dir_("flat_builder_test/");
IndexMeta FlatBuilderTest::meta_;
void FlatBuilderTest::SetUp(void) {
@@ -54,9 +55,7 @@ void FlatBuilderTest::SetUp(void) {
//! self-check column-major and row-major search.
void FlatBuilderTest::TearDown(void) {
char cmdBuf[100];
snprintf(cmdBuf, 100, "rm -rf %s", dir_.c_str());
system(cmdBuf);
zvec::test_util::RemoveTestPath(dir_);
}
void build_process(IndexBuilder::Pointer &builder,
@@ -68,7 +67,7 @@ void build_process(IndexBuilder::Pointer &builder,
auto dumper = IndexFactory::CreateDumper("FileDumper");
ASSERT_NE(dumper, nullptr);
std::string path = FlatBuilderTest::dir_ + "/TestGeneral";
std::string path = FlatBuilderTest::dir_ + "TestGeneral";
ASSERT_EQ(0, dumper->create(path));
ASSERT_EQ(0, builder->dump(dumper));
ASSERT_EQ(0, dumper->close());
@@ -128,7 +127,7 @@ TEST_F(FlatBuilderTest, TestBinaryInvalidColumnMajor) {
ASSERT_NE(builder, nullptr);
Params params;
ASSERT_EQ(0, builder->init(meta_, params));
std::string path = dir_ + "/TestGeneral";
std::string path = dir_ + "TestGeneral";
}
TEST_F(FlatBuilderTest, TestBuildWithRowMajor) {
@@ -138,7 +137,7 @@ TEST_F(FlatBuilderTest, TestBuildWithRowMajor) {
ASSERT_NE(builder, nullptr);
Params params;
ASSERT_EQ(0, builder->init(meta_, params));
std::string path = dir_ + "/TestGeneral";
std::string path = dir_ + "TestGeneral";
auto holder =
std::make_shared<OnePassIndexHolder<IndexMeta::DT_FP32>>(DIMENSION);
@@ -166,7 +165,7 @@ TEST_F(FlatBuilderTest, TestInt8BuildWithRowMajor) {
ASSERT_NE(builder, nullptr);
Params params;
ASSERT_EQ(0, builder->init(meta_, params));
std::string path = dir_ + "/TestGeneral";
std::string path = dir_ + "TestGeneral";
auto holder =
std::make_shared<OnePassIndexHolder<IndexMeta::DT_INT8>>(DIMENSION);
@@ -195,7 +194,7 @@ TEST_F(FlatBuilderTest, TestBinaryBuildWithRowMajor) {
ASSERT_NE(builder, nullptr);
Params params;
ASSERT_EQ(0, builder->init(meta_, params));
std::string path = dir_ + "/TestGeneral";
std::string path = dir_ + "TestGeneral";
auto holder =
std::make_shared<OnePassIndexHolder<IndexMeta::DT_BINARY32>>(dim);
@@ -223,7 +222,7 @@ TEST_F(FlatBuilderTest, TestBuildWithColumnMajor) {
ASSERT_NE(builder, nullptr);
Params params;
ASSERT_EQ(0, builder->init(meta_, params));
std::string path = dir_ + "/TestGeneral";
std::string path = dir_ + "TestGeneral";
auto holder =
std::make_shared<OnePassIndexHolder<IndexMeta::DT_FP32>>(DIMENSION);
@@ -252,7 +251,7 @@ TEST_F(FlatBuilderTest, TestInt8BuildWithColumnMajor) {
ASSERT_NE(builder, nullptr);
Params params;
ASSERT_EQ(0, builder->init(meta_, params));
std::string path = dir_ + "/TestGeneral";
std::string path = dir_ + "TestGeneral";
auto holder = std::make_shared<OnePassIndexHolder<IndexMeta::DT_INT8>>(dim);
size_t doc_cnt = 128UL;
@@ -280,7 +279,7 @@ TEST_F(FlatBuilderTest, TestBinaryBuildWithColumnMajor) {
ASSERT_NE(builder, nullptr);
Params params;
ASSERT_EQ(0, builder->init(meta_, params));
std::string path = dir_ + "/TestGeneral";
std::string path = dir_ + "TestGeneral";
auto holder =
std::make_shared<OnePassIndexHolder<IndexMeta::DT_BINARY32>>(dim);
@@ -307,7 +306,7 @@ TEST_F(FlatBuilderTest, TestWithRowMajor) {
IndexBuilder::Pointer builder = IndexFactory::CreateBuilder("FlatBuilder");
ASSERT_NE(builder, nullptr);
Params params;
std::string path = dir_ + "/TestGeneral";
std::string path = dir_ + "TestGeneral";
auto holder =
std::make_shared<OnePassIndexHolder<IndexMeta::DT_FP32>>(DIMENSION);
@@ -332,7 +331,7 @@ TEST_F(FlatBuilderTest, TestInt8WithRowMajor) {
IndexBuilder::Pointer builder = IndexFactory::CreateBuilder("FlatBuilder");
ASSERT_NE(builder, nullptr);
Params params;
std::string path = dir_ + "/TestGeneral";
std::string path = dir_ + "TestGeneral";
auto holder =
std::make_shared<OnePassIndexHolder<IndexMeta::DT_INT8>>(DIMENSION);
@@ -358,7 +357,7 @@ TEST_F(FlatBuilderTest, TestBinaryWithRowMajor) {
IndexBuilder::Pointer builder = IndexFactory::CreateBuilder("FlatBuilder");
ASSERT_NE(builder, nullptr);
Params params;
std::string path = dir_ + "/TestGeneral";
std::string path = dir_ + "TestGeneral";
auto holder =
std::make_shared<OnePassIndexHolder<IndexMeta::DT_BINARY32>>(dim);
@@ -383,7 +382,7 @@ TEST_F(FlatBuilderTest, TestWithColumnMajor) {
IndexBuilder::Pointer builder = IndexFactory::CreateBuilder("FlatBuilder");
ASSERT_NE(builder, nullptr);
Params params;
std::string path = dir_ + "/TestGeneral";
std::string path = dir_ + "TestGeneral";
auto holder =
std::make_shared<OnePassIndexHolder<IndexMeta::DT_FP32>>(DIMENSION);
@@ -409,7 +408,7 @@ TEST_F(FlatBuilderTest, TestInt8WithColumnMajor) {
IndexBuilder::Pointer builder = IndexFactory::CreateBuilder("FlatBuilder");
ASSERT_NE(builder, nullptr);
Params params;
std::string path = dir_ + "/TestGeneral";
std::string path = dir_ + "TestGeneral";
auto holder = std::make_shared<OnePassIndexHolder<IndexMeta::DT_INT8>>(dim);
size_t doc_cnt = 128UL;
@@ -434,7 +433,7 @@ TEST_F(FlatBuilderTest, TestBinaryWithColumnMajor) {
IndexBuilder::Pointer builder = IndexFactory::CreateBuilder("FlatBuilder");
ASSERT_NE(builder, nullptr);
Params params;
std::string path = dir_ + "/TestGeneral";
std::string path = dir_ + "TestGeneral";
auto holder =
std::make_shared<OnePassIndexHolder<IndexMeta::DT_BINARY32>>(dim);
@@ -7,6 +7,7 @@
#include <zvec/ailego/buffer/buffer_manager.h>
#include <zvec/core/framework/index_framework.h>
#include <zvec/core/framework/index_streamer.h>
#include "tests/test_util.h"
using namespace zvec::core;
using namespace zvec::ailego;
@@ -30,7 +31,7 @@ class FlatStreamerTest : public testing::Test {
static std::shared_ptr<IndexMeta> index_meta_ptr_;
};
std::string FlatStreamerTest::dir_("streamer_test/");
std::string FlatStreamerTest::dir_("flat_streamer_buffer_test_dir/");
std::shared_ptr<IndexMeta> FlatStreamerTest::index_meta_ptr_;
void FlatStreamerTest::SetUp(void) {
@@ -38,15 +39,11 @@ void FlatStreamerTest::SetUp(void) {
IndexMeta(IndexMeta::DataType::DT_FP32, dim));
index_meta_ptr_->set_metric("SquaredEuclidean", 0, Params());
char cmdBuf[100];
snprintf(cmdBuf, 100, "rm -rf %s", dir_.c_str());
system(cmdBuf);
zvec::test_util::RemoveTestPath(dir_);
}
void FlatStreamerTest::TearDown(void) {
char cmdBuf[100];
snprintf(cmdBuf, 100, "rm -rf %s", dir_.c_str());
system(cmdBuf);
zvec::test_util::RemoveTestPath(dir_);
}
TEST_F(FlatStreamerTest, TestLinearSearch) {
@@ -60,7 +57,7 @@ TEST_F(FlatStreamerTest, TestLinearSearch) {
ASSERT_NE(nullptr, storage);
Params stg_params;
ASSERT_EQ(0, storage->init(stg_params));
ASSERT_EQ(0, storage->open(dir_ + "/Test/LinearSearch", true));
ASSERT_EQ(0, storage->open(dir_ + "Test/LinearSearch", true));
ASSERT_EQ(0, write_streamer->open(storage));
auto ctx = write_streamer->create_context();
@@ -78,7 +75,7 @@ TEST_F(FlatStreamerTest, TestLinearSearch) {
write_streamer->flush(0UL);
write_streamer->close();
write_streamer.reset();
storage->close();
IndexStreamer::Pointer read_streamer =
IndexFactory::CreateStreamer("FlatStreamer");
@@ -86,7 +83,7 @@ TEST_F(FlatStreamerTest, TestLinearSearch) {
auto read_storage = IndexFactory::CreateStorage("BufferStorage");
ASSERT_NE(nullptr, read_storage);
ASSERT_EQ(0, read_storage->init(stg_params));
ASSERT_EQ(0, read_storage->open(dir_ + "/Test/LinearSearch", false));
ASSERT_EQ(0, read_storage->open(dir_ + "Test/LinearSearch", false));
ASSERT_EQ(0, read_streamer->open(read_storage));
size_t topk = 3;
auto provider = read_streamer->create_provider();
@@ -202,6 +199,7 @@ TEST_F(FlatStreamerTest, TestLinearSearchWithLRU) {
write_streamer->flush(0UL);
write_streamer->close();
write_streamer.reset();
storage->close();
IndexStreamer::Pointer read_streamer =
@@ -260,7 +258,7 @@ TEST_F(FlatStreamerTest, TestLinearSearchMMap) {
ASSERT_NE(nullptr, storage);
Params stg_params;
ASSERT_EQ(0, storage->init(stg_params));
ASSERT_EQ(0, storage->open(dir_ + "/Test/LinearSearchMMap", true));
ASSERT_EQ(0, storage->open(dir_ + "Test/LinearSearchMMap", true));
ASSERT_EQ(0, write_streamer->open(storage));
auto ctx = write_streamer->create_context();
@@ -278,6 +276,7 @@ TEST_F(FlatStreamerTest, TestLinearSearchMMap) {
write_streamer->flush(0UL);
write_streamer->close();
write_streamer.reset();
storage->close();
IndexStreamer::Pointer read_streamer =
IndexFactory::CreateStreamer("FlatStreamer");
@@ -285,7 +284,7 @@ TEST_F(FlatStreamerTest, TestLinearSearchMMap) {
auto read_storage = IndexFactory::CreateStorage("MMapFileStorage");
ASSERT_NE(nullptr, read_storage);
ASSERT_EQ(0, read_storage->init(stg_params));
ASSERT_EQ(0, read_storage->open(dir_ + "/Test/LinearSearchMMap", false));
ASSERT_EQ(0, read_storage->open(dir_ + "Test/LinearSearchMMap", false));
ASSERT_EQ(0, read_streamer->open(read_storage));
size_t topk = 3;
auto provider = read_streamer->create_provider();
+18 -20
View File
@@ -24,6 +24,7 @@
#include <zvec/core/framework/index_framework.h>
#include <zvec/core/framework/index_streamer.h>
#include "algorithm/flat/flat_utility.h"
#include "tests/test_util.h"
#if defined(__GNUC__) || defined(__GNUG__)
#pragma GCC diagnostic push
@@ -47,7 +48,7 @@ class FlatStreamerTest : public testing::Test {
static std::shared_ptr<IndexMeta> index_meta_ptr_;
};
std::string FlatStreamerTest::dir_("streamer_test/");
std::string FlatStreamerTest::dir_("flat_streamer_test_dir/");
std::shared_ptr<IndexMeta> FlatStreamerTest::index_meta_ptr_;
void FlatStreamerTest::SetUp(void) {
@@ -55,15 +56,11 @@ void FlatStreamerTest::SetUp(void) {
IndexMeta(IndexMeta::DataType::DT_FP32, dim));
index_meta_ptr_->set_metric("SquaredEuclidean", 0, Params());
char cmdBuf[100];
snprintf(cmdBuf, 100, "rm -rf %s", dir_.c_str());
system(cmdBuf);
zvec::test_util::RemoveTestPath(dir_);
}
void FlatStreamerTest::TearDown(void) {
char cmdBuf[100];
snprintf(cmdBuf, 100, "rm -rf %s", dir_.c_str());
system(cmdBuf);
zvec::test_util::RemoveTestPath(dir_);
}
TEST_F(FlatStreamerTest, TestAddVector) {
@@ -77,7 +74,7 @@ TEST_F(FlatStreamerTest, TestAddVector) {
ASSERT_NE(nullptr, storage);
Params stg_params;
ASSERT_EQ(0, storage->init(stg_params));
ASSERT_EQ(0, storage->open(dir_ + "/Test/AddVector", true));
ASSERT_EQ(0, storage->open(dir_ + "Test/AddVector", true));
ASSERT_EQ(0, streamer->open(storage));
auto ctx = streamer->create_context();
@@ -112,7 +109,7 @@ TEST_F(FlatStreamerTest, TestLinearSearch) {
ASSERT_NE(nullptr, storage);
Params stg_params;
ASSERT_EQ(0, storage->init(stg_params));
ASSERT_EQ(0, storage->open(dir_ + "/Test/AddVector", true));
ASSERT_EQ(0, storage->open(dir_ + "Test/AddVector", true));
ASSERT_EQ(0, streamer->open(storage));
auto ctx = streamer->create_context();
@@ -186,7 +183,7 @@ TEST_F(FlatStreamerTest, TestAddAndSearch) {
Params stg_params;
auto storage = IndexFactory::CreateStorage("MMapFileStorage");
ASSERT_EQ(0, storage->init(stg_params));
ASSERT_EQ(0, storage->open(dir_ + "/TestAddAndSearch.index", true));
ASSERT_EQ(0, storage->open(dir_ + "TestAddAndSearch.index", true));
ASSERT_EQ(0, streamer->init(*index_meta_ptr_, params));
ASSERT_EQ(0, streamer->open(storage));
@@ -219,7 +216,7 @@ TEST_F(FlatStreamerTest, TestAddAndSearcherSearch) {
Params stg_params;
auto storage = IndexFactory::CreateStorage("MMapFileStorage");
ASSERT_EQ(0, storage->init(stg_params));
ASSERT_EQ(0, storage->open(dir_ + "/TestAddAndSearcherSearch.index", true));
ASSERT_EQ(0, storage->open(dir_ + "TestAddAndSearcherSearch.index", true));
ASSERT_EQ(0, streamer->init(*index_meta_ptr_, params));
ASSERT_EQ(0, streamer->open(storage));
@@ -236,7 +233,7 @@ TEST_F(FlatStreamerTest, TestAddAndSearcherSearch) {
streamer->add_impl(i, vec.data(), qmeta, ctx);
}
std::string path1 = dir_ + "/TestAddAndSearcherSearchDump";
std::string path1 = dir_ + "TestAddAndSearcherSearchDump";
auto dumper = IndexFactory::CreateDumper("FileDumper");
ASSERT_EQ(0, dumper->init(Params()));
ASSERT_EQ(0, dumper->create(path1));
@@ -277,7 +274,7 @@ TEST_F(FlatStreamerTest, TestLinearSearchRandomData) {
ASSERT_NE(nullptr, storage);
Params stg_params;
ASSERT_EQ(0, storage->init(stg_params));
ASSERT_EQ(0, storage->open(dir_ + "/TestKnnSearchRandomData", true));
ASSERT_EQ(0, storage->open(dir_ + "TestKnnSearchRandomData", true));
ASSERT_EQ(0, streamer->init(meta, params));
ASSERT_EQ(0, streamer->open(storage));
@@ -451,7 +448,7 @@ TEST_F(FlatStreamerTest, TestForceFlush) {
stg_params.set("proxima.mmap_file.storage.copy_on_write", true);
stg_params.set("proxima.mmap_file.storage.force_flush", true);
ASSERT_EQ(0, storage->init(stg_params));
ASSERT_EQ(0, storage->open(dir_ + "/TestForceFlush", true));
ASSERT_EQ(0, storage->open(dir_ + "TestForceFlush", true));
ASSERT_EQ(0, streamer->init(*index_meta_ptr_, params));
ASSERT_EQ(0, streamer->open(storage));
@@ -491,7 +488,7 @@ TEST_F(FlatStreamerTest, TestForceFlush) {
storage = IndexFactory::CreateStorage("MMapFileStorage");
ASSERT_NE(nullptr, storage);
ASSERT_EQ(0, storage->init(stg_params));
ASSERT_EQ(0, storage->open(dir_ + "/TestForceFlush", true));
ASSERT_EQ(0, storage->open(dir_ + "TestForceFlush", true));
ASSERT_EQ(0, streamer->open(storage));
checkIter(cnt, streamer);
@@ -936,7 +933,7 @@ TEST_F(FlatStreamerTest, TestGroup) {
Params stg_params;
auto storage = IndexFactory::CreateStorage("MMapFileStorage");
ASSERT_EQ(0, storage->init(stg_params));
ASSERT_EQ(0, storage->open(dir_ + "/TestGroup.index", true));
ASSERT_EQ(0, storage->open(dir_ + "TestGroup.index", true));
ASSERT_EQ(0, streamer->init(*index_meta_ptr_, params));
ASSERT_EQ(0, streamer->open(storage));
auto ctx = streamer->create_context();
@@ -1044,7 +1041,7 @@ TEST_F(FlatStreamerTest, TestAddAndSearchWithID) {
Params stg_params;
auto storage = IndexFactory::CreateStorage("MMapFileStorage");
ASSERT_EQ(0, storage->init(stg_params));
ASSERT_EQ(0, storage->open(dir_ + "/TestGroup.index", true));
ASSERT_EQ(0, storage->open(dir_ + "TestGroup.index", true));
ASSERT_EQ(0, streamer->init(*index_meta_ptr_, params));
ASSERT_EQ(0, streamer->open(storage));
auto ctx = streamer->create_context();
@@ -1125,7 +1122,7 @@ TEST_F(FlatStreamerTest, TestAddAndSearchWithID2) {
Params write_stg_params;
auto write_storage = IndexFactory::CreateStorage("MMapFileStorage");
ASSERT_EQ(0, write_storage->init(write_stg_params));
ASSERT_EQ(0, write_storage->open(dir_ + "/TestGroup.index", true));
ASSERT_EQ(0, write_storage->open(dir_ + "TestGroup.index", true));
ASSERT_EQ(0, write_streamer->init(*index_meta_ptr_, write_params));
ASSERT_EQ(0, write_streamer->open(write_storage));
auto ctx = write_streamer->create_context();
@@ -1148,7 +1145,8 @@ TEST_F(FlatStreamerTest, TestAddAndSearchWithID2) {
}
write_streamer->flush(0UL);
write_streamer->close();
write_streamer.reset(); //
write_streamer.reset();
write_storage->close();
IndexStreamer::Pointer read_streamer =
IndexFactory::CreateStreamer("FlatStreamer");
@@ -1157,7 +1155,7 @@ TEST_F(FlatStreamerTest, TestAddAndSearchWithID2) {
Params read_stg_params;
auto read_storage = IndexFactory::CreateStorage("MMapFileStorage");
ASSERT_EQ(0, read_storage->init(read_stg_params));
ASSERT_EQ(0, read_storage->open(dir_ + "/TestGroup.index", true));
ASSERT_EQ(0, read_storage->open(dir_ + "TestGroup.index", true));
ASSERT_EQ(0, read_streamer->init(*index_meta_ptr_, read_params));
ASSERT_EQ(0, read_streamer->open(read_storage));
auto linearCtx = read_streamer->create_context();