diff options
Diffstat (limited to 'icing/store/document-store.h')
-rw-r--r-- | icing/store/document-store.h | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/icing/store/document-store.h b/icing/store/document-store.h index 3e02636..7c414d7 100644 --- a/icing/store/document-store.h +++ b/icing/store/document-store.h @@ -59,13 +59,19 @@ namespace lib { class DocumentStore { public: struct Header { - static constexpr int32_t kMagic = 0x746f7265; + static int32_t GetCurrentMagic(bool namespace_id_fingerprint) { + return namespace_id_fingerprint ? kNewMagic : kOldMagic; + } // Holds the magic as a quick sanity check against file corruption. int32_t magic; // Checksum of the DocumentStore's sub-component's checksums. uint32_t checksum; + + private: + static constexpr int32_t kOldMagic = 0x746f7265; + static constexpr int32_t kNewMagic = 0x1b99c8b0; }; struct OptimizeInfo { @@ -136,6 +142,7 @@ class DocumentStore { const Filesystem* filesystem, const std::string& base_dir, const Clock* clock, const SchemaStore* schema_store, bool force_recovery_and_revalidate_documents = false, + bool namespace_id_fingerprint = false, InitializeStatsProto* initialize_stats = nullptr); // Returns the maximum DocumentId that the DocumentStore has assigned. If @@ -472,7 +479,8 @@ class DocumentStore { private: // Use DocumentStore::Create() to instantiate. DocumentStore(const Filesystem* filesystem, std::string_view base_dir, - const Clock* clock, const SchemaStore* schema_store); + const Clock* clock, const SchemaStore* schema_store, + bool namespace_id_fingerprint); const Filesystem* const filesystem_; const std::string base_dir_; @@ -485,6 +493,10 @@ class DocumentStore { // Used to validate incoming documents DocumentValidator document_validator_; + // Whether to use namespace id or namespace name to build up fingerprint for + // document_key_mapper_ and corpus_mapper_. + bool namespace_id_fingerprint_; + // A log used to store all documents, it serves as a ground truth of doc // store. key_mapper_ and document_id_mapper_ can be regenerated from it. std::unique_ptr<PortableFileBackedProtoLog<DocumentWrapper>> document_log_; @@ -733,6 +745,13 @@ class DocumentStore { libtextclassifier3::StatusOr< google::protobuf::RepeatedPtrField<DocumentDebugInfoProto::CorpusInfo>> CollectCorpusInfo() const; + + // Build fingerprint for the keys of document_key_mapper_ and corpus_mapper_. + // Note that namespace_id_fingerprint_ controls the way that a fingerprint is + // built. + std::string MakeFingerprint(NamespaceId namespace_id, + std::string_view namespace_, + std::string_view uri_or_schema) const; }; } // namespace lib |