Skip to content

Commit

Permalink
Refactor group version check (#547)
Browse files Browse the repository at this point in the history
  • Loading branch information
jparismorgan authored Oct 15, 2024
1 parent a5091c7 commit acb2ddb
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 14 deletions.
6 changes: 6 additions & 0 deletions src/include/index/index_group.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,12 @@ class base_index_group {
if (opened_for_ == TILEDB_WRITE) {
set_dimensions(dimensions);
}
if (empty(this->version_)) {
this->version_ = current_storage_version;
}
if (storage_formats.find(this->version_) == storage_formats.end()) {
throw std::runtime_error("Invalid storage version: " + this->version_);
}
}

/**
Expand Down
3 changes: 0 additions & 3 deletions src/include/index/ivf_flat_group.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@ class ivf_flat_group : public base_index_group<index_type> {
}

void create_default_impl() {
if (empty(this->version_)) {
this->version_ = current_storage_version;
}
this->init_valid_array_names();

static const int32_t tile_size{
Expand Down
3 changes: 0 additions & 3 deletions src/include/index/ivf_pq_group.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,6 @@ class ivf_pq_group : public base_index_group<index_type> {
* Create a ready-to-use group with default arrays
****************************************************************************/
void create_default_impl() {
if (empty(this->version_)) {
this->version_ = current_storage_version;
}
this->init_valid_array_names();

static const int32_t tile_size{
Expand Down
3 changes: 0 additions & 3 deletions src/include/index/vamana_group.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,6 @@ class vamana_index_group : public base_index_group<index_type> {
}

void create_default_impl() {
if (empty(this->version_)) {
this->version_ = current_storage_version;
}
this->init_valid_array_names();

static const int32_t tile_size{
Expand Down
2 changes: 1 addition & 1 deletion src/include/test/unit_api_ivf_pq_index.cc
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ TEST_CASE("storage_version", "[api_ivf_pq_index]") {
// Throw with the wrong version.
CHECK_THROWS_WITH(
index.write_index(ctx, index_uri, std::nullopt, "0.4"),
"Version mismatch. Requested 0.4 but found 0.3");
"Invalid storage version: 0.4");
// Succeed without a version.
index.write_index(ctx, index_uri);
// Succeed with the same version.
Expand Down
2 changes: 1 addition & 1 deletion src/include/test/unit_api_vamana_index.cc
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ TEST_CASE("storage_version", "[api_vamana_index]") {
// Throw with the wrong version.
CHECK_THROWS_WITH(
index.write_index(ctx, index_uri, std::nullopt, "0.4"),
"Version mismatch. Requested 0.4 but found 0.3");
"Invalid storage version: 0.4");
// Succeed without a version.
index.write_index(ctx, index_uri);
// Succeed with the same version.
Expand Down
2 changes: 1 addition & 1 deletion src/include/test/unit_ivf_flat_group.cc
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ TEST_CASE("mismatched storage version", "[ivf_flat_group]") {
TemporalPolicy{TimeTravel, 0},
"different_version",
10),
"Version mismatch. Requested different_version but found 0.3");
"Invalid storage version: different_version");
}

TEST_CASE("clear history", "[ivf_flat_group]") {
Expand Down
2 changes: 1 addition & 1 deletion src/include/test/unit_ivf_pq_group.cc
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ TEST_CASE("mismatched storage version", "[ivf_pq_group]") {
TemporalPolicy{TimeTravel, 0},
"different_version",
10),
"Version mismatch. Requested different_version but found 0.3");
"Invalid storage version: different_version");
}

TEST_CASE("clear history", "[ivf_pq_group]") {
Expand Down
2 changes: 1 addition & 1 deletion src/include/test/unit_vamana_group.cc
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ TEST_CASE("mismatched storage version", "[vamana_group]") {
TemporalPolicy{TimeTravel, 0},
"different_version",
10),
"Version mismatch. Requested different_version but found 0.3");
"Invalid storage version: different_version");
}

TEST_CASE("clear history", "[vamana_group]") {
Expand Down

0 comments on commit acb2ddb

Please sign in to comment.