]> git.sesse.net Git - plocate/commitdiff
Honor the “require visibility” flag (in the negative).
authorSteinar H. Gunderson <steinar+git@gunderson.no>
Sat, 28 Nov 2020 17:17:23 +0000 (18:17 +0100)
committerSteinar H. Gunderson <steinar+git@gunderson.no>
Sat, 28 Nov 2020 17:17:23 +0000 (18:17 +0100)
access_rx_cache.cpp
access_rx_cache.h
db.h
plocate.cpp

index c6f56347e8ecf543ebfeb4af567c351d5039f77f..a16a1fc58f1cadc0a9a15bad663e107a8e125d5c 100644 (file)
@@ -11,6 +11,11 @@ using namespace std;
 
 void AccessRXCache::check_access(const char *filename, bool allow_async, function<void(bool)> cb)
 {
+       if (!require_visibility) {
+               cb(true);
+               return;
+       }
+
        lock_guard<mutex> lock(mu);
        if (engine == nullptr || !engine->get_supports_stat()) {
                allow_async = false;
index 8757b94e6f9a07328c938c16f601f933dde7d45a..80383ea6512a221e3a9baaaa87e660d143fd7582 100644 (file)
@@ -12,8 +12,8 @@ class IOUringEngine;
 
 class AccessRXCache {
 public:
-       AccessRXCache(IOUringEngine *engine)
-               : engine(engine) {}
+       AccessRXCache(IOUringEngine *engine, bool require_visibility)
+               : engine(engine), require_visibility(require_visibility) {}
        void check_access(const char *filename, bool allow_async, std::function<void(bool)> cb);
 
 private:
@@ -25,6 +25,7 @@ private:
        std::map<std::string, std::vector<PendingStat>> pending_stats;
        IOUringEngine *engine;
        std::mutex mu;
+       bool require_visibility;
 };
 
 #endif  // !defined(_ACCESS_RX_CACHE_H)
diff --git a/db.h b/db.h
index e23d47885ecedb85039fca8a71206ec765d071ba..722e567076eb36551e03c56eb02db2682c834292 100644 (file)
--- a/db.h
+++ b/db.h
@@ -24,6 +24,9 @@ struct Header {
        uint64_t next_zstd_dictionary_offset_bytes;
        uint64_t conf_block_length_bytes;
        uint64_t conf_block_offset_bytes;
+
+       // Only if max_version >= 2.
+       bool require_visibility;
 };
 
 struct Trigram {
index 6fe46a4f77e36a1aa1f75ec2fc7e2036079b25fc..4f88b4bd74c2ffe230052997939a1cbe30a5ffb0 100644 (file)
@@ -105,6 +105,10 @@ Corpus::Corpus(int fd, IOUringEngine *engine)
                hdr.zstd_dictionary_offset_bytes = 0;
                hdr.zstd_dictionary_length_bytes = 0;
        }
+       if (hdr.max_version < 2) {
+               // This too. (We ignore the other max_version 2 fields.)
+               hdr.require_visibility = true;
+       }
 }
 
 Corpus::~Corpus()
@@ -230,7 +234,7 @@ void scan_file_block(const vector<Needle> &needles, string_view compressed,
 size_t scan_docids(const vector<Needle> &needles, const vector<uint32_t> &docids, const Corpus &corpus, IOUringEngine *engine)
 {
        Serializer docids_in_order;
-       AccessRXCache access_rx_cache(engine);
+       AccessRXCache access_rx_cache(engine, corpus.get_hdr().require_visibility);
        atomic<uint64_t> matched{ 0 };
        for (size_t i = 0; i < docids.size(); ++i) {
                uint32_t docid = docids[i];
@@ -306,7 +310,7 @@ uint64_t scan_all_docids(const vector<Needle> &needles, int fd, const Corpus &co
                }
        }
 
-       AccessRXCache access_rx_cache(nullptr);
+       AccessRXCache access_rx_cache(nullptr, corpus.get_hdr().require_visibility);
        Serializer serializer;
        uint32_t num_blocks = corpus.get_num_filename_blocks();
        unique_ptr<uint64_t[]> offsets(new uint64_t[num_blocks + 1]);