2 * Copyright (C) 1996-2019 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 #ifndef SQUID_FS_ROCK_HEADER_UPDATER_H
10 #define SQUID_FS_ROCK_HEADER_UPDATER_H
12 #include "base/AsyncJob.h"
14 #include "fs/rock/forward.h"
15 #include "fs/rock/RockSwapDir.h"
16 #include "ipc/StoreMap.h"
21 /// Updates HTTP headers of a single Rock store entry:
22 /// * reads old body data in the same slot as the last old headers slot, if any
23 /// * writes new headers (1+ slots)
24 /// * writes old data (0-2 slots)
25 /// * chains the new entry prefix (1+ slots) to the old entry suffix (0+ slots)
26 class HeaderUpdater
: public AsyncJob
28 CBDATA_CHILD(HeaderUpdater
);
33 IoCbParams(const char *aBuf
, ssize_t aSize
) : buf(aBuf
), size(aSize
) {}
37 HeaderUpdater(const Rock::SwapDir::Pointer
&aStore
, const Ipc::StoreMapUpdate
&update
);
38 virtual ~HeaderUpdater() override
= default;
42 virtual void start() override
;
43 virtual bool doneAll() const override
;
44 virtual void swanSong() override
;
47 static StoreIOState::STRCB NoteRead
;
48 static StoreIOState::STIOCB NoteDoneReading
;
49 static StoreIOState::STIOCB NoteDoneWriting
;
52 void stopReading(const char *why
);
53 void readMore(const char *why
);
54 void noteRead(const IoCbParams result
);
55 void noteDoneReading(int errflag
);
56 void parseReadBytes();
59 void noteDoneWriting(int errflag
);
61 Rock::SwapDir::Pointer store
; ///< cache_dir where the entry is stored
62 Ipc::StoreMapUpdate update
; ///< Ipc::StoreMap update reservation
64 StoreIOState::Pointer reader
; ///< reads old headers and old data
65 StoreIOState::Pointer writer
; ///< writes new headers and old data
67 SBuf readerBuffer
; ///< I/O buffer for a single read operation
68 SBuf exchangeBuffer
; ///< bytes read but not yet discarded or written
69 uint64_t bytesRead
; ///< total entry bytes read from Store so far
71 int staleSwapHeaderSize
; ///< stored size of the stale entry metadata
73 SlotId staleSplicingPointNext
; ///< non-updatable old HTTP body suffix start
77 std::ostream
&operator <<(std::ostream
&os
, const HeaderUpdater::IoCbParams
¶ms
)
79 os
<< static_cast<const void *>(params
.buf
) << "," << params
.size
;
85 #endif /* SQUID_FS_ROCK_HEADER_UPDATER_H */