1 // Copyright (C) 2025 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef ICING_FILE_DERIVED_FILE_UTIL_H_ 16 #define ICING_FILE_DERIVED_FILE_UTIL_H_ 17 18 namespace icing { 19 namespace lib { 20 21 namespace derived_file_util { 22 23 // Contains information about whether the derived files of each component need 24 // to be rebuild. Whether the derived files of a component need to be rebuilt 25 // (during initialization) depends on the following conditions: 26 // - Version change. 27 // - Feature flag change. 28 // - General marker file presence. It means that something wonky happened when 29 // we last tried to do some complex operations (e.g. SetSchema, Optimize). 30 // 31 // These flags only reflect whether each component should be rebuilt, but do not 32 // handle any dependencies. The caller should handle the dependencies by 33 // themselves. 34 // e.g. - qualified id join index depends on document store derived files, but 35 // it's possible to have needs_document_store_derived_files_rebuild = 36 // true and needs_qualified_id_join_index_rebuild = false. 37 // - The caller should know that join index should also be rebuilt in this 38 // case even though needs_qualified_id_join_index_rebuild = false. 39 struct DerivedFilesRebuildInfo { 40 bool needs_document_store_derived_files_rebuild = false; 41 bool needs_schema_store_derived_files_rebuild = false; 42 bool needs_term_index_rebuild = false; 43 bool needs_integer_index_rebuild = false; 44 bool needs_qualified_id_join_index_rebuild = false; 45 bool needs_embedding_index_rebuild = false; 46 47 DerivedFilesRebuildInfo() = default; 48 DerivedFilesRebuildInfoDerivedFilesRebuildInfo49 explicit DerivedFilesRebuildInfo( 50 bool needs_document_store_derived_files_rebuild_in, 51 bool needs_schema_store_derived_files_rebuild_in, 52 bool needs_term_index_rebuild_in, bool needs_integer_index_rebuild_in, 53 bool needs_qualified_id_join_index_rebuild_in, 54 bool needs_embedding_index_rebuild_in) 55 : needs_document_store_derived_files_rebuild( 56 needs_document_store_derived_files_rebuild_in), 57 needs_schema_store_derived_files_rebuild( 58 needs_schema_store_derived_files_rebuild_in), 59 needs_term_index_rebuild(needs_term_index_rebuild_in), 60 needs_integer_index_rebuild(needs_integer_index_rebuild_in), 61 needs_qualified_id_join_index_rebuild( 62 needs_qualified_id_join_index_rebuild_in), 63 needs_embedding_index_rebuild(needs_embedding_index_rebuild_in) {} 64 IsRebuildNeededDerivedFilesRebuildInfo65 bool IsRebuildNeeded() const { 66 return needs_document_store_derived_files_rebuild || 67 needs_schema_store_derived_files_rebuild || 68 needs_term_index_rebuild || needs_integer_index_rebuild || 69 needs_qualified_id_join_index_rebuild || 70 needs_embedding_index_rebuild; 71 } 72 RebuildAllDerivedFilesRebuildInfo73 void RebuildAll() { 74 needs_document_store_derived_files_rebuild = true; 75 needs_schema_store_derived_files_rebuild = true; 76 needs_term_index_rebuild = true; 77 needs_integer_index_rebuild = true; 78 needs_qualified_id_join_index_rebuild = true; 79 needs_embedding_index_rebuild = true; 80 } 81 82 bool operator==(const DerivedFilesRebuildInfo& other) const { 83 return needs_document_store_derived_files_rebuild == 84 other.needs_document_store_derived_files_rebuild && 85 needs_schema_store_derived_files_rebuild == 86 other.needs_schema_store_derived_files_rebuild && 87 needs_term_index_rebuild == other.needs_term_index_rebuild && 88 needs_integer_index_rebuild == other.needs_integer_index_rebuild && 89 needs_qualified_id_join_index_rebuild == 90 other.needs_qualified_id_join_index_rebuild && 91 needs_embedding_index_rebuild == other.needs_embedding_index_rebuild; 92 } 93 94 DerivedFilesRebuildInfo& operator|=(const DerivedFilesRebuildInfo& other) { 95 needs_document_store_derived_files_rebuild |= 96 other.needs_document_store_derived_files_rebuild; 97 needs_schema_store_derived_files_rebuild |= 98 other.needs_schema_store_derived_files_rebuild; 99 needs_term_index_rebuild |= other.needs_term_index_rebuild; 100 needs_integer_index_rebuild |= other.needs_integer_index_rebuild; 101 needs_qualified_id_join_index_rebuild |= 102 other.needs_qualified_id_join_index_rebuild; 103 needs_embedding_index_rebuild |= other.needs_embedding_index_rebuild; 104 return *this; 105 } 106 }; 107 108 } // namespace derived_file_util 109 110 } // namespace lib 111 } // namespace icing 112 113 #endif // ICING_FILE_DERIVED_FILE_UTIL_H_ 114