diff options
3 files changed, 34 insertions, 14 deletions
diff --git a/searchcore/src/tests/proton/index/indexmanager_test.cpp b/searchcore/src/tests/proton/index/indexmanager_test.cpp index b1081eb3338..9d8f4d8b7f6 100644 --- a/searchcore/src/tests/proton/index/indexmanager_test.cpp +++ b/searchcore/src/tests/proton/index/indexmanager_test.cpp @@ -690,22 +690,36 @@ TEST_F("requireThatFailedFusionIsRetried", Fixture) { EXPECT_EQUAL(2u, spec.flush_ids[1]); } -TEST_F("require that wipeHistory updates schema on disk", Fixture) { - Schema empty_schema; - f.addDocument(docid); - f.flushIndexManager(); - f.runAsMaster([&]() { f._index_manager->setSchema(empty_schema, 1000); }); - f.addDocument(docid); - f.flushIndexManager(); +namespace { +void expectSchemaIndexFields(uint32_t expIndexFields) { Schema s; s.loadFromFile("test_data/index.flush.1/schema.txt"); - EXPECT_EQUAL(1u, s.getNumIndexFields()); + EXPECT_EQUAL(expIndexFields, s.getNumIndexFields()); +} - f.runAsMaster([&]() { f._index_manager->wipeHistory(f._serial_num); }); +} - s.loadFromFile("test_data/index.flush.1/schema.txt"); - EXPECT_EQUAL(0u, s.getNumIndexFields()); +TEST_F("require that setSchema updates schema on disk, wiping removed fields", Fixture) +{ + Schema empty_schema; + f.addDocument(docid); + f.flushIndexManager(); + TEST_DO(expectSchemaIndexFields(1)); + f.runAsMaster([&]() { f._index_manager->setSchema(empty_schema, ++f._serial_num); }); + TEST_DO(expectSchemaIndexFields(0)); +} + +TEST_F("require that wipeHistory updates schema on disk", Fixture) +{ + Schema empty_schema; + f.addDocument(docid); + f.flushIndexManager(); + TEST_DO(expectSchemaIndexFields(1)); + f.runAsMaster([&]() { f._index_manager->setSchema(empty_schema, f._serial_num); }); + TEST_DO(expectSchemaIndexFields(1)); + f.runAsMaster([&]() { f._index_manager->wipeHistory(++f._serial_num); }); + TEST_DO(expectSchemaIndexFields(0)); } TEST_F("require that indexes manager stats can be generated", Fixture) diff --git a/searchcorespi/src/vespa/searchcorespi/index/indexmaintainer.cpp b/searchcorespi/src/vespa/searchcorespi/index/indexmaintainer.cpp index 64a58da3757..c075e98e1fc 100644 --- a/searchcorespi/src/vespa/searchcorespi/index/indexmaintainer.cpp +++ b/searchcorespi/src/vespa/searchcorespi/index/indexmaintainer.cpp @@ -1182,8 +1182,8 @@ IndexMaintainer::getFlushTargets(void) void IndexMaintainer::setSchema(const Schema & schema, SerialNum serialNum) { - (void) serialNum; assert(_ctx.getThreadingService().master().isCurrentThread()); + internalWipeHistory(schema, serialNum); IMemoryIndex::SP new_index(_operations.createMemoryIndex(schema, _current_serial_num)); SetSchemaArgs args; @@ -1198,11 +1198,10 @@ IndexMaintainer::setSchema(const Schema & schema, SerialNum serialNum) } void -IndexMaintainer::wipeHistory(SerialNum wipeSerial) +IndexMaintainer::internalWipeHistory(const Schema &schema, SerialNum wipeSerial) { assert(_ctx.getThreadingService().master().isCurrentThread()); ISearchableIndexCollection::SP new_source_list; - const Schema schema = getSchema(); IIndexCollection::SP coll = getSourceCollection(); updateIndexSchemas(*coll, schema, wipeSerial); updateActiveFusionWipeTimeSchema(schema); @@ -1225,5 +1224,11 @@ IndexMaintainer::wipeHistory(SerialNum wipeSerial) } } +void +IndexMaintainer::wipeHistory(SerialNum wipeSerial) +{ + internalWipeHistory(getSchema(), wipeSerial); +} + } // namespace index } // namespace searchcorespi diff --git a/searchcorespi/src/vespa/searchcorespi/index/indexmaintainer.h b/searchcorespi/src/vespa/searchcorespi/index/indexmaintainer.h index b242a4a0933..34c25632012 100644 --- a/searchcorespi/src/vespa/searchcorespi/index/indexmaintainer.h +++ b/searchcorespi/src/vespa/searchcorespi/index/indexmaintainer.h @@ -287,6 +287,7 @@ class IndexMaintainer : public IIndexManager, bool makeSureAllRemainingWarmupIsDone(ISearchableIndexCollection::SP keepAlive); void scheduleCommit(); void commit(); + void internalWipeHistory(const Schema &schema, SerialNum wipeSerial); public: IndexMaintainer(const IndexMaintainer &) = delete; |