|
22 | 22 |
|
23 | 23 | #include <chrono> |
24 | 24 | #include <filesystem> |
| 25 | +#include <lance/lance.hpp> |
25 | 26 | #include <memory> |
26 | 27 | #include <string> |
27 | 28 | #include <utility> |
28 | 29 |
|
29 | 30 | #include "common/metrics/doris_metrics.h" |
30 | 31 | #include "common/metrics/metrics.h" |
| 32 | +#include "util/defer_op.h" |
31 | 33 |
|
32 | 34 | namespace doris::format::lance { |
33 | 35 | namespace { |
@@ -99,6 +101,59 @@ TEST(LanceSessionManagerTest, PublishesSessionCacheMetrics) { |
99 | 101 | EXPECT_NE(entity->get_metric("lance_session_metadata_cache_misses_total"), nullptr); |
100 | 102 | } |
101 | 103 |
|
| 104 | +TEST(LanceSessionManagerTest, PrewarmRequiresPinnedVersionAndIndex) { |
| 105 | + LanceSessionManager manager( |
| 106 | + {.lance_index_cache_size_bytes = 8 * 1024 * 1024, .lance_data_cache_path = ""}); |
| 107 | + EXPECT_FALSE(manager.prewarm_index(nullptr, nullptr, 1, "idx").ok()); |
| 108 | + EXPECT_FALSE(manager.prewarm_index("dataset.lance", nullptr, 0, "idx").ok()); |
| 109 | + EXPECT_FALSE(manager.prewarm_index("dataset.lance", nullptr, 1, nullptr).ok()); |
| 110 | + EXPECT_FALSE(manager.prewarm_index("dataset.lance", nullptr, 1, "").ok()); |
| 111 | +} |
| 112 | + |
| 113 | +TEST(LanceSessionManagerTest, PrewarmErrorsDoNotExposeStorageDetails) { |
| 114 | + LanceSessionManager manager( |
| 115 | + {.lance_index_cache_size_bytes = 8 * 1024 * 1024, .lance_data_cache_path = ""}); |
| 116 | + const auto status = |
| 117 | + manager.prewarm_index("/nonexistent/private-dataset.lance", nullptr, 1, "idx"); |
| 118 | + EXPECT_FALSE(status.ok()); |
| 119 | + EXPECT_EQ(std::string::npos, status.to_string().find("private-dataset")); |
| 120 | + EXPECT_FALSE( |
| 121 | + manager.prewarm_index(lance_fixture_path().c_str(), nullptr, 1, "missing_idx").ok()); |
| 122 | +} |
| 123 | + |
| 124 | +TEST(LanceSessionManagerTest, PrewarmUsesTheQuerySessionAndFixedSnapshot) { |
| 125 | + const auto path = unique_cache_path(); |
| 126 | + std::filesystem::copy(lance_fixture_path(), path, std::filesystem::copy_options::recursive); |
| 127 | + Defer cleanup {[&] { |
| 128 | + std::error_code error; |
| 129 | + std::filesystem::remove_all(path, error); |
| 130 | + }}; |
| 131 | + auto writer = ::lance::Dataset::open(path.string()); |
| 132 | + writer.create_scalar_index("row_id", LANCE_SCALAR_BTREE, "value_idx"); |
| 133 | + const uint64_t version = writer.version(); |
| 134 | + LanceSessionManager manager({.lance_index_cache_size_bytes = 8 * 1024 * 1024, |
| 135 | + .lance_metadata_cache_size_bytes = 4 * 1024 * 1024, |
| 136 | + .lance_data_cache_path = ""}); |
| 137 | + ASSERT_TRUE(manager.prewarm_index(path.c_str(), nullptr, version, "value_idx").ok()); |
| 138 | + auto* entity = DorisMetrics::instance()->server_entity(); |
| 139 | + entity->trigger_hook_unlocked(true); |
| 140 | + auto* hits = |
| 141 | + static_cast<IntCounter*>(entity->get_metric("lance_session_index_cache_hits_total")); |
| 142 | + const auto before = hits->value(); |
| 143 | + |
| 144 | + // A separate query handle must see the cache populated by the completed prewarm call. |
| 145 | + LanceDataset* raw_dataset = nullptr; |
| 146 | + ASSERT_TRUE(manager.open_dataset(path.c_str(), nullptr, version, &raw_dataset).ok()); |
| 147 | + LanceDatasetPtr query(raw_dataset, lance_dataset_close); |
| 148 | + ASSERT_EQ(0, lance_dataset_prewarm_index(query.get(), "value_idx")); |
| 149 | + entity->trigger_hook_unlocked(true); |
| 150 | + EXPECT_GT(hits->value(), before); |
| 151 | + |
| 152 | + writer.drop_index("value_idx"); |
| 153 | + EXPECT_FALSE(manager.prewarm_index(path.c_str(), nullptr, writer.version(), "value_idx").ok()); |
| 154 | + EXPECT_TRUE(manager.prewarm_index(path.c_str(), nullptr, version, "value_idx").ok()); |
| 155 | +} |
| 156 | + |
102 | 157 | TEST(LanceSessionManagerTest, CreatesFoyerBackedSession) { |
103 | 158 | const auto cache_path = unique_cache_path(); |
104 | 159 | std::filesystem::create_directories(cache_path); |
|
0 commit comments