]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/store_rebuild.h
Maintenance: rework SASL detection (#1694)
[thirdparty/squid.git] / src / store_rebuild.h
index ae8947a6d3e9f0eee36779718ae5042b2d784bb9..8d9e647ba865fe50c771a2a6fa3e1e48e523d561 100644 (file)
@@ -1,61 +1,88 @@
-#ifndef SQUID_STORE_REBUILD_H_
-#define SQUID_STORE_REBUILD_H_
 /*
- * DEBUG: section 20    Store Rebuild Routines
- * AUTHOR: Duane Wessels
- *
- * SQUID Web Proxy Cache          http://www.squid-cache.org/
- * ----------------------------------------------------------
- *
- *  Squid is the result of efforts by numerous individuals from
- *  the Internet community; see the CONTRIBUTORS file for full
- *  details.   Many organizations have provided support for Squid's
- *  development; see the SPONSORS file for full details.  Squid is
- *  Copyrighted (C) 2001 by the Regents of the University of
- *  California; see the COPYRIGHT file for full details.  Squid
- *  incorporates software developed and/or copyrighted by other
- *  sources; see the CREDITS file for full details.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
+ * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
  *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
  */
-class StoreRebuildData {
+
+/* DEBUG: section 20    Store Rebuild Routines */
+
+#ifndef SQUID_SRC_STORE_REBUILD_H
+#define SQUID_SRC_STORE_REBUILD_H
+
+#include "store_key_md5.h"
+
+class MemBuf;
+
+/// cache_dir(s) indexing statistics
+class StoreRebuildData
+{
+public:
+    /// maintain earliest initiation time across multiple indexing cache_dirs
+    void updateStartTime(const timeval &dirStartTime);
+
+    /// whether we have worked on indexing this(these) cache_dir(s) before
+    bool started() const { return startTime.tv_sec > 0; }
+
+    // when adding members, keep the class compatible with placement new onto a
+    // zeroed shared memory segment (see Rock::Rebuild::Stats usage)
+
+    int objcount = 0;       /* # objects successfully reloaded */
+    int expcount = 0;       /* # objects expired */
+    int scancount = 0;      /* # entries scanned or read from state file */
+    int clashcount = 0;     /* # swapfile clashes avoided */
+    int dupcount = 0;       /* # duplicates purged */
+    int cancelcount = 0;    /* # SWAP_LOG_DEL objects purged */
+    int invalid = 0;        /* # bad lines */
+    int badflags = 0;       /* # bad e->flags */
+    int bad_log_op = 0;
+    int zero_object_sz = 0;
+    int64_t validations = 0; ///< the number of validated cache entries, slots
+    timeval startTime = {}; ///< absolute time when the rebuild was initiated
+};
+
+/// advancement of work that consists of (usually known number) of similar steps
+class Progress
+{
 public:
-    int objcount;       /* # objects successfully reloaded */
-    int expcount;       /* # objects expired */
-    int scancount;      /* # entries scanned or read from state file */
-    int clashcount;     /* # swapfile clashes avoided */
-    int dupcount;       /* # duplicates purged */
-    int cancelcount;        /* # SWAP_LOG_DEL objects purged */
-    int invalid;        /* # bad lines */
-    int badflags;       /* # bad e->flags */
-    int bad_log_op;
-    int zero_object_sz;
+    Progress(const int64_t stepsCompleted, const int64_t stepsTotal):
+        completed(stepsCompleted), goal(stepsTotal) {}
+
+    /// brief progress report suitable for level-0/1 debugging
+    void print(std::ostream &os) const;
+
+    int64_t completed; ///< the number of finished work steps
+    int64_t goal; ///< the known total number of work steps (or negative)
 };
 
-extern void storeRebuildStart(void);
-extern void storeRebuildComplete(StoreRebuildData *);
-extern void storeRebuildProgress(int sd_index, int total, int sofar);
+inline std::ostream &
+operator <<(std::ostream &os, const Progress &p)
+{
+    p.print(os);
+    return os;
+}
+
+void storeRebuildStart(void);
+void storeRebuildComplete(StoreRebuildData *);
+void storeRebuildProgress(int sd_index, int total, int sofar);
 
 /// loads entry from disk; fills supplied memory buffer on success
-extern bool storeRebuildLoadEntry(int fd, int diskIndex, MemBuf &buf, StoreRebuildData &counts);
-/// parses entry buffer and validates entry metadata; fills e on success
-extern bool storeRebuildParseEntry(MemBuf &buf, StoreEntry &e, cache_key *key, StoreRebuildData &counts, uint64_t expectedSize);
-/// checks whether the loaded entry should be kept; updates counters
-extern bool storeRebuildKeepEntry(const StoreEntry &e, const cache_key *key, StoreRebuildData &counts);
+bool storeRebuildLoadEntry(int fd, int diskIndex, MemBuf &buf, StoreRebuildData &counts);
 
+/**
+ * Parses the given Store entry metadata, filling e and key.
+ * Optimization: Both e and key parameters may be updated even on failures.
+ *
+ * \param buf memory containing serialized Store entry swap metadata (at least)
+ * \param e caller's temporary StoreEntry object for returning parsed metadata
+ * \param key caller's temporary Store entry key buffer; usable to set e.key
+ * \param expectedSize either total entry size (including swap metadata) or 0
+ *
+ * \retval true success; e/key filled with parsed metadata
+ * \retval false failure; e/key ought to be ignored (may be filled/dirty)
+ */
+bool storeRebuildParseEntry(MemBuf &buf, StoreEntry &e, cache_key *key, StoreRebuildData &counts, uint64_t expectedSize);
 
+#endif /* SQUID_SRC_STORE_REBUILD_H */
 
-#endif /* SQUID_STORE_REBUILD_H_ */