diff options
Diffstat (limited to 'icing/file')
-rw-r--r-- | icing/file/file-backed-vector_benchmark.cc | 2 | ||||
-rw-r--r-- | icing/file/persistent-hash-map.cc | 2 | ||||
-rw-r--r-- | icing/file/portable-file-backed-proto-log_test.cc | 3 | ||||
-rw-r--r-- | icing/file/posting_list/flash-index-storage.cc | 8 | ||||
-rw-r--r-- | icing/file/posting_list/flash-index-storage_test.cc | 9 | ||||
-rw-r--r-- | icing/file/posting_list/index-block_test.cc | 2 | ||||
-rw-r--r-- | icing/file/posting_list/posting-list-accessor.cc | 11 | ||||
-rw-r--r-- | icing/file/posting_list/posting-list-identifier.h | 2 | ||||
-rw-r--r-- | icing/file/version-util.cc | 4 | ||||
-rw-r--r-- | icing/file/version-util.h | 15 | ||||
-rw-r--r-- | icing/file/version-util_test.cc | 12 |
11 files changed, 50 insertions, 20 deletions
diff --git a/icing/file/file-backed-vector_benchmark.cc b/icing/file/file-backed-vector_benchmark.cc index b2e660b..0447e93 100644 --- a/icing/file/file-backed-vector_benchmark.cc +++ b/icing/file/file-backed-vector_benchmark.cc @@ -68,7 +68,7 @@ void BM_Set(benchmark::State& state) { MemoryMappedFile::Strategy::READ_WRITE_AUTO_SYNC)); // Extend to num_elts - fbv->Set(num_elts - 1, 0); + ICING_ASSERT_OK(fbv->Set(num_elts - 1, 0)); std::uniform_int_distribution<> distrib(0, num_elts - 1); for (auto _ : state) { diff --git a/icing/file/persistent-hash-map.cc b/icing/file/persistent-hash-map.cc index 558c242..6936c45 100644 --- a/icing/file/persistent-hash-map.cc +++ b/icing/file/persistent-hash-map.cc @@ -716,7 +716,7 @@ libtextclassifier3::Status PersistentHashMap::RehashIfNecessary( // # of vector elements may be greater than the actual # of entries. // Therefore, we have to truncate entry_storage_ to the correct size. if (entry_idx < entry_storage_->num_elements()) { - entry_storage_->TruncateTo(entry_idx); + ICING_RETURN_IF_ERROR(entry_storage_->TruncateTo(entry_idx)); } info().num_deleted_entries = 0; diff --git a/icing/file/portable-file-backed-proto-log_test.cc b/icing/file/portable-file-backed-proto-log_test.cc index bf5e604..cc70151 100644 --- a/icing/file/portable-file-backed-proto-log_test.cc +++ b/icing/file/portable-file-backed-proto-log_test.cc @@ -1124,7 +1124,8 @@ TEST_F(PortableFileBackedProtoLogTest, EraseProtoShouldSetZero) { // document1_offset + sizeof(int) is the start byte of the proto where // sizeof(int) is the size of the proto metadata. - mmapped_file.Remap(document1_offset + sizeof(int), file_size - 1); + ICING_ASSERT_OK( + mmapped_file.Remap(document1_offset + sizeof(int), file_size - 1)); for (size_t i = 0; i < mmapped_file.region_size(); ++i) { ASSERT_THAT(mmapped_file.region()[i], Eq(0)); } diff --git a/icing/file/posting_list/flash-index-storage.cc b/icing/file/posting_list/flash-index-storage.cc index 21fea8a..2198d2c 100644 --- a/icing/file/posting_list/flash-index-storage.cc +++ b/icing/file/posting_list/flash-index-storage.cc @@ -75,7 +75,11 @@ FlashIndexStorage::ReadHeaderMagic(const Filesystem* filesystem, FlashIndexStorage::~FlashIndexStorage() { if (header_block_ != nullptr) { - FlushInMemoryFreeList(); + libtextclassifier3::Status status = FlushInMemoryFreeList(); + if (!status.ok()) { + ICING_LOG(ERROR) << "Cannot flush in memory free list: " + << status.error_message(); + } PersistToDisk(); } } @@ -488,7 +492,7 @@ libtextclassifier3::Status FlashIndexStorage::FreePostingList( ICING_ASSIGN_OR_RETURN(IndexBlock block, GetIndexBlock(holder.id.block_index())); if (block.posting_list_bytes() == max_posting_list_bytes()) { - block.SetNextBlockIndex(kInvalidBlockIndex); + ICING_RETURN_IF_ERROR(block.SetNextBlockIndex(kInvalidBlockIndex)); } uint32_t posting_list_bytes = block.posting_list_bytes(); diff --git a/icing/file/posting_list/flash-index-storage_test.cc b/icing/file/posting_list/flash-index-storage_test.cc index 3e2d239..ef60037 100644 --- a/icing/file/posting_list/flash-index-storage_test.cc +++ b/icing/file/posting_list/flash-index-storage_test.cc @@ -249,7 +249,8 @@ TEST_F(FlashIndexStorageTest, FreeListInMemory) { IsOkAndHolds(ElementsAreArray(hits2.rbegin(), hits2.rend()))); // 3. Now, free the first posting list. This should add it to the free list - flash_index_storage.FreePostingList(std::move(posting_list_holder1)); + ICING_ASSERT_OK( + flash_index_storage.FreePostingList(std::move(posting_list_holder1))); // 4. Request another posting list. This should NOT grow the index because // the first posting list is free. @@ -349,7 +350,8 @@ TEST_F(FlashIndexStorageTest, FreeListNotInMemory) { IsOkAndHolds(ElementsAreArray(hits2.rbegin(), hits2.rend()))); // 3. Now, free the first posting list. This should add it to the free list - flash_index_storage.FreePostingList(std::move(posting_list_holder1)); + ICING_ASSERT_OK( + flash_index_storage.FreePostingList(std::move(posting_list_holder1))); // 4. Request another posting list. This should NOT grow the index because // the first posting list is free. @@ -452,7 +454,8 @@ TEST_F(FlashIndexStorageTest, FreeListInMemoryPersistence) { // 3. Now, free the first posting list. This should add it to the free // list - flash_index_storage.FreePostingList(std::move(posting_list_holder1)); + ICING_ASSERT_OK( + flash_index_storage.FreePostingList(std::move(posting_list_holder1))); } EXPECT_THAT(flash_index_storage.GetDiskUsage(), diff --git a/icing/file/posting_list/index-block_test.cc b/icing/file/posting_list/index-block_test.cc index fcc134a..ebc9ba4 100644 --- a/icing/file/posting_list/index-block_test.cc +++ b/icing/file/posting_list/index-block_test.cc @@ -292,7 +292,7 @@ TEST_F(IndexBlockTest, IndexBlockReallocatingPostingLists) { // Now free the first posting list. Then, reallocate it and fill it with a // different set of hits. - block.FreePostingList(alloc_info_1.posting_list_index); + ICING_ASSERT_OK(block.FreePostingList(alloc_info_1.posting_list_index)); EXPECT_THAT(block.HasFreePostingLists(), IsOkAndHolds(IsTrue())); std::vector<Hit> hits_in_posting_list3{ diff --git a/icing/file/posting_list/posting-list-accessor.cc b/icing/file/posting_list/posting-list-accessor.cc index 67d7a21..a7cdb17 100644 --- a/icing/file/posting_list/posting-list-accessor.cc +++ b/icing/file/posting_list/posting-list-accessor.cc @@ -16,7 +16,10 @@ #include <cstdint> #include <memory> +#include <utility> +#include "icing/text_classifier/lib3/utils/base/status.h" +#include "icing/text_classifier/lib3/utils/base/statusor.h" #include "icing/absl_ports/canonical_errors.h" #include "icing/file/posting_list/flash-index-storage.h" #include "icing/file/posting_list/posting-list-identifier.h" @@ -40,13 +43,15 @@ libtextclassifier3::Status PostingListAccessor::FlushPreexistingPostingList() { // and free this posting list. // // Move will always succeed since in_memory_posting_list_ is max_pl_bytes. - GetSerializer()->MoveFrom(/*dst=*/&in_memory_posting_list_, - /*src=*/&preexisting_posting_list_->posting_list); + ICING_RETURN_IF_ERROR(GetSerializer()->MoveFrom( + /*dst=*/&in_memory_posting_list_, + /*src=*/&preexisting_posting_list_->posting_list)); // Now that all the contents of this posting list have been copied, there's // no more use for it. Make it available to be used for another posting // list. - storage_->FreePostingList(std::move(*preexisting_posting_list_)); + ICING_RETURN_IF_ERROR( + storage_->FreePostingList(std::move(*preexisting_posting_list_))); } preexisting_posting_list_.reset(); return libtextclassifier3::Status::OK; diff --git a/icing/file/posting_list/posting-list-identifier.h b/icing/file/posting_list/posting-list-identifier.h index 78821e8..8a0229b 100644 --- a/icing/file/posting_list/posting-list-identifier.h +++ b/icing/file/posting_list/posting-list-identifier.h @@ -59,6 +59,8 @@ class PostingListIdentifier { public: static PostingListIdentifier kInvalid; + explicit PostingListIdentifier() { *this = kInvalid; } + // 1. block_index - the index of this block within the FlashIndexStorage file // 2. posting_list_index - the index of this posting list within the block // 3. posting_list_index_bits - the number of bits needed to encode the diff --git a/icing/file/version-util.cc b/icing/file/version-util.cc index 7684262..dd233e0 100644 --- a/icing/file/version-util.cc +++ b/icing/file/version-util.cc @@ -131,6 +131,10 @@ bool ShouldRebuildDerivedFiles(const VersionInfo& existing_version_info, // version 1 -> version 2 upgrade, no need to rebuild break; } + case 2: { + // version 2 -> version 3 upgrade, no need to rebuild + break; + } default: // This should not happen. Rebuild anyway if unsure. should_rebuild |= true; diff --git a/icing/file/version-util.h b/icing/file/version-util.h index 30c457d..b2d51df 100644 --- a/icing/file/version-util.h +++ b/icing/file/version-util.h @@ -27,17 +27,18 @@ namespace lib { namespace version_util { -// - Version 0: Android T. Can be identified only by flash index magic. -// - Version 1: Android U release 2023-06. -// - Version 2: Android U 1st mainline release 2023-09. Schema is compatible -// with version 1. -// TODO(b/288969109): bump kVersion to 2 before finalizing the 1st Android U -// mainline release. +// - Version 0: Android T base. Can be identified only by flash index magic. +// - Version 1: Android U base and M-2023-08. +// - Version 2: M-2023-09, M-2023-11, M-2024-01. Schema is compatible with v1. +// (There were no M-2023-10, M-2023-12). +// - Version 3: M-2024-02. Schema is compatible with v1 and v2. +// // LINT.IfChange(kVersion) -inline static constexpr int32_t kVersion = 2; +inline static constexpr int32_t kVersion = 3; // LINT.ThenChange(//depot/google3/icing/schema/schema-store.cc:min_overlay_version_compatibility) inline static constexpr int32_t kVersionOne = 1; inline static constexpr int32_t kVersionTwo = 2; +inline static constexpr int32_t kVersionThree = 3; inline static constexpr int kVersionZeroFlashIndexMagic = 0x6dfba6ae; diff --git a/icing/file/version-util_test.cc b/icing/file/version-util_test.cc index e94c351..9dedb1d 100644 --- a/icing/file/version-util_test.cc +++ b/icing/file/version-util_test.cc @@ -458,13 +458,23 @@ TEST(VersionUtilTest, ShouldRebuildDerivedFilesCompatible) { IsFalse()); } -TEST(VersionUtilTest, ShouldRebuildDerivedFilesUpgrade) { +TEST(VersionUtilTest, Upgrade) { // Unlike other state changes, upgrade depends on the actual "encoded path". // kVersionOne -> kVersionTwo EXPECT_THAT(ShouldRebuildDerivedFiles(VersionInfo(kVersionOne, kVersionOne), /*curr_version=*/kVersionTwo), IsFalse()); + + // kVersionTwo -> kVersionThree + EXPECT_THAT(ShouldRebuildDerivedFiles(VersionInfo(kVersionTwo, kVersionTwo), + /*curr_version=*/kVersionThree), + IsFalse()); + + // kVersionOne -> kVersionThree. + EXPECT_THAT(ShouldRebuildDerivedFiles(VersionInfo(kVersionOne, kVersionOne), + /*curr_version=*/kVersionThree), + IsFalse()); } } // namespace |