2 * DEBUG: section 47 Store Directory Routines
7 #include "ConfigOption.h"
8 #include "DiskIO/DiskIOModule.h"
9 #include "DiskIO/DiskIOStrategy.h"
10 #include "DiskIO/ReadRequest.h"
11 #include "DiskIO/WriteRequest.h"
12 #include "fs/rock/RockSwapDir.h"
13 #include "fs/rock/RockIoState.h"
14 #include "fs/rock/RockIoRequests.h"
15 #include "fs/rock/RockRebuild.h"
17 #include "ipc/mem/Pages.h"
18 #include "MemObject.h"
20 #include "SquidConfig.h"
21 #include "SquidMath.h"
31 const int64_t Rock::SwapDir::HeaderSize
= 16*1024;
33 Rock::SwapDir::SwapDir(): ::SwapDir("rock"),
34 slotSize(HeaderSize
), filePath(NULL
), map(NULL
), io(NULL
),
39 Rock::SwapDir::~SwapDir()
47 Rock::SwapDir::search(String
const url
, HttpRequest
*)
50 return NULL
; // XXX: implement
54 Rock::SwapDir::get(String
const key
, STOREGETCLIENT cb
, void *data
)
56 ::SwapDir::get(key
, cb
, data
);
59 // called when Squid core needs a StoreEntry with a given key
61 Rock::SwapDir::get(const cache_key
*key
)
63 if (!map
|| !theFile
|| !theFile
->canRead())
67 const Ipc::StoreMapAnchor
*const slot
= map
->openForReading(key
, filen
);
71 const Ipc::StoreMapAnchor::Basics
&basics
= slot
->basics
;
73 // create a brand new store entry and initialize it with stored basics
74 StoreEntry
*e
= new StoreEntry();
77 e
->swap_filen
= filen
;
78 e
->swap_file_sz
= basics
.swap_file_sz
;
79 e
->lastref
= basics
.lastref
;
80 e
->timestamp
= basics
.timestamp
;
81 e
->expires
= basics
.expires
;
82 e
->lastmod
= basics
.lastmod
;
83 e
->refcount
= basics
.refcount
;
84 e
->flags
= basics
.flags
;
85 e
->store_status
= STORE_OK
;
86 e
->setMemStatus(NOT_IN_MEMORY
);
87 e
->swap_status
= SWAPOUT_DONE
;
88 e
->ping_status
= PING_NONE
;
89 EBIT_SET(e
->flags
, ENTRY_CACHABLE
);
90 EBIT_CLR(e
->flags
, RELEASE_REQUEST
);
91 EBIT_CLR(e
->flags
, KEY_PRIVATE
);
92 EBIT_SET(e
->flags
, ENTRY_VALIDATED
);
97 // the disk entry remains open for reading, protected from modifications
100 void Rock::SwapDir::disconnect(StoreEntry
&e
)
102 assert(e
.swap_dirn
== index
);
103 assert(e
.swap_filen
>= 0);
104 // cannot have SWAPOUT_NONE entry with swap_filen >= 0
105 assert(e
.swap_status
!= SWAPOUT_NONE
);
107 // do not rely on e.swap_status here because there is an async delay
108 // before it switches from SWAPOUT_WRITING to SWAPOUT_DONE.
110 // since e has swap_filen, its slot is locked for either reading or writing
111 map
->abortIo(e
.swap_filen
);
114 e
.swap_status
= SWAPOUT_NONE
;
118 Rock::SwapDir::currentSize() const
120 const uint64_t spaceSize
= !freeSlots
?
121 maxSize() : (slotSize
* freeSlots
->size());
122 // everything that is not free is in use
123 return maxSize() - spaceSize
;
127 Rock::SwapDir::currentCount() const
129 return map
? map
->entryCount() : 0;
132 /// In SMP mode only the disker process reports stats to avoid
133 /// counting the same stats by multiple processes.
135 Rock::SwapDir::doReportStat() const
137 return ::SwapDir::doReportStat() && (!UsingSmp() || IamDiskProcess());
141 Rock::SwapDir::swappedOut(const StoreEntry
&)
143 // stats are not stored but computed when needed
147 Rock::SwapDir::entryLimitAllowed() const
149 const int64_t eLimitLo
= map
? map
->entryLimit() : 0; // dynamic shrinking unsupported
150 const int64_t eWanted
= (maxSize() - HeaderSize
)/slotSize
;
151 return min(max(eLimitLo
, eWanted
), entryLimitHigh());
154 // TODO: encapsulate as a tool; identical to CossSwapDir::create()
156 Rock::SwapDir::create()
161 if (UsingSmp() && !IamDiskProcess()) {
162 debugs (47,3, HERE
<< "disker will create in " << path
);
166 debugs (47,3, HERE
<< "creating in " << path
);
169 if (::stat(path
, &dir_sb
) == 0) {
171 if (::stat(filePath
, &file_sb
) == 0) {
172 debugs (47, DBG_IMPORTANT
, "Skipping existing Rock db: " << filePath
);
175 // else the db file is not there or is not accessible, and we will try
176 // to create it later below, generating a detailed error on failures.
177 } else { // path does not exist or is inaccessible
178 // If path exists but is not accessible, mkdir() below will fail, and
179 // the admin should see the error and act accordingly, so there is
180 // no need to distinguish ENOENT from other possible stat() errors.
181 debugs (47, DBG_IMPORTANT
, "Creating Rock db directory: " << path
);
182 const int res
= mkdir(path
, 0700);
184 createError("mkdir");
187 debugs (47, DBG_IMPORTANT
, "Creating Rock db: " << filePath
);
188 const int swap
= open(filePath
, O_WRONLY
|O_CREAT
|O_TRUNC
|O_BINARY
, 0600);
190 createError("create");
192 #if SLOWLY_FILL_WITH_ZEROS
194 Must(maxSize() % sizeof(block
) == 0);
195 memset(block
, '\0', sizeof(block
));
197 for (off_t offset
= 0; offset
< maxSize(); offset
+= sizeof(block
)) {
198 if (write(swap
, block
, sizeof(block
)) != sizeof(block
))
199 createError("write");
202 if (ftruncate(swap
, maxSize()) != 0)
203 createError("truncate");
205 char header
[HeaderSize
];
206 memset(header
, '\0', sizeof(header
));
207 if (write(swap
, header
, sizeof(header
)) != sizeof(header
))
208 createError("write");
214 // report Rock DB creation error and exit
216 Rock::SwapDir::createError(const char *const msg
) {
217 debugs(47, DBG_CRITICAL
, "ERROR: Failed to initialize Rock Store db in " <<
218 filePath
<< "; " << msg
<< " error: " << xstrerror());
219 fatal("Rock Store db creation error");
223 Rock::SwapDir::init()
227 // XXX: SwapDirs aren't refcounted. We make IORequestor calls, which
228 // are refcounted. We up our count once to avoid implicit delete's.
231 freeSlots
= shm_old(Ipc::Mem::PageStack
)(freeSlotsPath());
234 map
= new DirMap(inodeMapPath());
237 const char *ioModule
= needsDiskStrand() ? "IpcIo" : "Blocking";
238 if (DiskIOModule
*m
= DiskIOModule::Find(ioModule
)) {
239 debugs(47,2, HERE
<< "Using DiskIO module: " << ioModule
);
240 io
= m
->createStrategy();
243 debugs(47, DBG_CRITICAL
, "FATAL: Rock store is missing DiskIO module: " <<
245 fatal("Rock Store missing a required DiskIO module");
248 theFile
= io
->newFile(filePath
);
249 theFile
->configure(fileConfig
);
250 theFile
->open(O_RDWR
, 0644, this);
252 // Increment early. Otherwise, if one SwapDir finishes rebuild before
253 // others start, storeRebuildComplete() will think the rebuild is over!
254 // TODO: move store_dirs_rebuilding hack to store modules that need it.
255 ++StoreController::store_dirs_rebuilding
;
259 Rock::SwapDir::needsDiskStrand() const
261 const bool wontEvenWorkWithoutDisker
= Config
.workers
> 1;
262 const bool wouldWorkBetterWithDisker
= DiskIOModule::Find("IpcIo");
263 return InDaemonMode() && (wontEvenWorkWithoutDisker
||
264 wouldWorkBetterWithDisker
);
268 Rock::SwapDir::parse(int anIndex
, char *aPath
)
272 path
= xstrdup(aPath
);
274 // cache store is located at path/db
276 fname
.append("/rock");
277 filePath
= xstrdup(fname
.termedBuf());
282 // Current openForWriting() code overwrites the old slot if needed
283 // and possible, so proactively removing old slots is probably useless.
284 assert(!repl
); // repl = createRemovalPolicy(Config.replPolicy);
290 Rock::SwapDir::reconfigure()
294 // TODO: can we reconfigure the replacement policy (repl)?
298 /// parse maximum db disk size
300 Rock::SwapDir::parseSize(const bool reconfig
)
302 const int i
= GetInteger();
304 fatal("negative Rock cache_dir size value");
305 const uint64_t new_max_size
=
306 static_cast<uint64_t>(i
) << 20; // MBytes to Bytes
308 max_size
= new_max_size
;
309 else if (new_max_size
!= max_size
) {
310 debugs(3, DBG_IMPORTANT
, "WARNING: cache_dir '" << path
<< "' size "
311 "cannot be changed dynamically, value left unchanged (" <<
312 (max_size
>> 20) << " MB)");
317 Rock::SwapDir::getOptionTree() const
319 ConfigOptionVector
*vector
= dynamic_cast<ConfigOptionVector
*>(::SwapDir::getOptionTree());
321 vector
->options
.push_back(new ConfigOptionAdapter
<SwapDir
>(*const_cast<SwapDir
*>(this), &SwapDir::parseSizeOption
, &SwapDir::dumpSizeOption
));
322 vector
->options
.push_back(new ConfigOptionAdapter
<SwapDir
>(*const_cast<SwapDir
*>(this), &SwapDir::parseTimeOption
, &SwapDir::dumpTimeOption
));
323 vector
->options
.push_back(new ConfigOptionAdapter
<SwapDir
>(*const_cast<SwapDir
*>(this), &SwapDir::parseRateOption
, &SwapDir::dumpRateOption
));
328 Rock::SwapDir::allowOptionReconfigure(const char *const option
) const
330 return strcmp(option
, "slot-size") != 0 &&
331 ::SwapDir::allowOptionReconfigure(option
);
334 /// parses time-specific options; mimics ::SwapDir::optionObjectSizeParse()
336 Rock::SwapDir::parseTimeOption(char const *option
, const char *value
, int reconfig
)
338 // TODO: ::SwapDir or, better, Config should provide time-parsing routines,
339 // including time unit handling. Same for size and rate.
341 time_msec_t
*storedTime
;
342 if (strcmp(option
, "swap-timeout") == 0)
343 storedTime
= &fileConfig
.ioTimeout
;
350 // TODO: handle time units and detect parsing errors better
351 const int64_t parsedValue
= strtoll(value
, NULL
, 10);
352 if (parsedValue
< 0) {
353 debugs(3, DBG_CRITICAL
, "FATAL: cache_dir " << path
<< ' ' << option
<< " must not be negative but is: " << parsedValue
);
357 const time_msec_t newTime
= static_cast<time_msec_t
>(parsedValue
);
360 *storedTime
= newTime
;
361 else if (*storedTime
!= newTime
) {
362 debugs(3, DBG_IMPORTANT
, "WARNING: cache_dir " << path
<< ' ' << option
363 << " cannot be changed dynamically, value left unchanged: " <<
370 /// reports time-specific options; mimics ::SwapDir::optionObjectSizeDump()
372 Rock::SwapDir::dumpTimeOption(StoreEntry
* e
) const
374 if (fileConfig
.ioTimeout
)
375 storeAppendPrintf(e
, " swap-timeout=%" PRId64
,
376 static_cast<int64_t>(fileConfig
.ioTimeout
));
379 /// parses rate-specific options; mimics ::SwapDir::optionObjectSizeParse()
381 Rock::SwapDir::parseRateOption(char const *option
, const char *value
, int isaReconfig
)
384 if (strcmp(option
, "max-swap-rate") == 0)
385 storedRate
= &fileConfig
.ioRate
;
392 // TODO: handle time units and detect parsing errors better
393 const int64_t parsedValue
= strtoll(value
, NULL
, 10);
394 if (parsedValue
< 0) {
395 debugs(3, DBG_CRITICAL
, "FATAL: cache_dir " << path
<< ' ' << option
<< " must not be negative but is: " << parsedValue
);
399 const int newRate
= static_cast<int>(parsedValue
);
402 debugs(3, DBG_CRITICAL
, "FATAL: cache_dir " << path
<< ' ' << option
<< " must not be negative but is: " << newRate
);
407 *storedRate
= newRate
;
408 else if (*storedRate
!= newRate
) {
409 debugs(3, DBG_IMPORTANT
, "WARNING: cache_dir " << path
<< ' ' << option
410 << " cannot be changed dynamically, value left unchanged: " <<
417 /// reports rate-specific options; mimics ::SwapDir::optionObjectSizeDump()
419 Rock::SwapDir::dumpRateOption(StoreEntry
* e
) const
421 if (fileConfig
.ioRate
>= 0)
422 storeAppendPrintf(e
, " max-swap-rate=%d", fileConfig
.ioRate
);
425 /// parses size-specific options; mimics ::SwapDir::optionObjectSizeParse()
427 Rock::SwapDir::parseSizeOption(char const *option
, const char *value
, int reconfig
)
429 uint64_t *storedSize
;
430 if (strcmp(option
, "slot-size") == 0)
431 storedSize
= &slotSize
;
438 // TODO: handle size units and detect parsing errors better
439 const uint64_t newSize
= strtoll(value
, NULL
, 10);
441 debugs(3, DBG_CRITICAL
, "FATAL: cache_dir " << path
<< ' ' << option
<< " must be positive; got: " << newSize
);
445 if (newSize
<= sizeof(DbCellHeader
)) {
446 debugs(3, DBG_CRITICAL
, "FATAL: cache_dir " << path
<< ' ' << option
<< " must exceed " << sizeof(DbCellHeader
) << "; got: " << newSize
);
451 *storedSize
= newSize
;
452 else if (*storedSize
!= newSize
) {
453 debugs(3, DBG_IMPORTANT
, "WARNING: cache_dir " << path
<< ' ' << option
454 << " cannot be changed dynamically, value left unchanged: " <<
461 /// reports size-specific options; mimics ::SwapDir::optionObjectSizeDump()
463 Rock::SwapDir::dumpSizeOption(StoreEntry
* e
) const
465 storeAppendPrintf(e
, " slot-size=%" PRId64
, slotSize
);
468 /// check the results of the configuration; only level-0 debugging works here
470 Rock::SwapDir::validateOptions()
473 fatal("Rock store requires a positive slot-size");
475 const int64_t maxSizeRoundingWaste
= 1024 * 1024; // size is configured in MB
476 const int64_t slotSizeRoundingWaste
= slotSize
;
477 const int64_t maxRoundingWaste
=
478 max(maxSizeRoundingWaste
, slotSizeRoundingWaste
);
479 const int64_t usableDiskSize
= diskOffset(entryLimitAllowed());
480 const int64_t diskWasteSize
= maxSize() - usableDiskSize
;
481 Must(diskWasteSize
>= 0);
483 // warn if maximum db size is not reachable due to sfileno limit
484 if (entryLimitAllowed() == entryLimitHigh() &&
485 diskWasteSize
>= maxRoundingWaste
) {
486 debugs(47, DBG_CRITICAL
, "Rock store cache_dir[" << index
<< "] '" << path
<< "':");
487 debugs(47, DBG_CRITICAL
, "\tmaximum number of entries: " << entryLimitAllowed());
488 debugs(47, DBG_CRITICAL
, "\tdb slot size: " << slotSize
<< " Bytes");
489 debugs(47, DBG_CRITICAL
, "\tmaximum db size: " << maxSize() << " Bytes");
490 debugs(47, DBG_CRITICAL
, "\tusable db size: " << usableDiskSize
<< " Bytes");
491 debugs(47, DBG_CRITICAL
, "\tdisk space waste: " << diskWasteSize
<< " Bytes");
492 debugs(47, DBG_CRITICAL
, "WARNING: Rock store config wastes space.");
497 Rock::SwapDir::rebuild()
499 //++StoreController::store_dirs_rebuilding; // see Rock::SwapDir::init()
500 AsyncJob::Start(new Rebuild(this));
504 Rock::SwapDir::canStore(const StoreEntry
&e
, int64_t diskSpaceNeeded
, int &load
) const
506 if (!::SwapDir::canStore(e
, sizeof(DbCellHeader
)+diskSpaceNeeded
, load
))
509 if (!theFile
|| !theFile
->canWrite())
515 // Do not start I/O transaction if there are less than 10% free pages left.
516 // TODO: reserve page instead
517 if (needsDiskStrand() &&
518 Ipc::Mem::PageLevel(Ipc::Mem::PageId::ioPage
) >= 0.9 * Ipc::Mem::PageLimit(Ipc::Mem::PageId::ioPage
)) {
519 debugs(47, 5, HERE
<< "too few shared pages for IPC I/O left");
530 StoreIOState::Pointer
531 Rock::SwapDir::createStoreIO(StoreEntry
&e
, StoreIOState::STFNCB
*cbFile
, StoreIOState::STIOCB
*cbIo
, void *data
)
533 if (!theFile
|| theFile
->error()) {
534 debugs(47,4, HERE
<< theFile
);
539 Ipc::StoreMapAnchor
*const slot
=
540 map
->openForWriting(reinterpret_cast<const cache_key
*>(e
.key
), filen
);
542 debugs(47, 5, HERE
<< "map->add failed");
549 // XXX: We rely on our caller, storeSwapOutStart(), to set e.fileno.
550 // If that does not happen, the entry will not decrement the read level!
552 Rock::SwapDir::Pointer
self(this);
553 IoState
*sio
= new IoState(self
, &e
, cbFile
, cbIo
, data
);
555 sio
->swap_dirn
= index
;
556 sio
->swap_filen
= filen
;
557 sio
->writeableAnchor_
= slot
;
559 debugs(47,5, HERE
<< "dir " << index
<< " created new filen " <<
560 std::setfill('0') << std::hex
<< std::uppercase
<< std::setw(8) <<
561 sio
->swap_filen
<< std::dec
<< " starting at " <<
562 diskOffset(sio
->swap_filen
));
571 Rock::SwapDir::diskOffset(int filen
) const
574 return HeaderSize
+ slotSize
*filen
;
578 Rock::SwapDir::diskOffset(Ipc::Mem::PageId
&pageId
) const
581 return diskOffset(pageId
.number
- 1);
585 Rock::SwapDir::diskOffsetLimit() const
588 return diskOffset(map
->entryLimit());
592 Rock::SwapDir::entryMaxPayloadSize() const
594 return slotSize
- sizeof(DbCellHeader
);
598 Rock::SwapDir::entriesNeeded(const int64_t objSize
) const
600 return (objSize
+ entryMaxPayloadSize() - 1) / entryMaxPayloadSize();
604 Rock::SwapDir::useFreeSlot(Ipc::Mem::PageId
&pageId
)
606 if (freeSlots
->pop(pageId
)) {
607 debugs(47, 5, "got a previously free slot: " << pageId
);
611 // catch free slots delivered to noteFreeMapSlice()
612 assert(!waitingForPage
);
613 waitingForPage
= &pageId
;
614 if (map
->purgeOne()) {
615 assert(!waitingForPage
); // noteFreeMapSlice() should have cleared it
616 assert(pageId
.set());
617 debugs(47, 5, "got a previously busy slot: " << pageId
);
620 assert(waitingForPage
== &pageId
);
621 waitingForPage
= NULL
;
623 debugs(47, 3, "cannot get a slot; entries: " << map
->entryCount());
628 Rock::SwapDir::validSlotId(const SlotId slotId
) const
630 return 0 <= slotId
&& slotId
< entryLimitAllowed();
634 Rock::SwapDir::noteFreeMapSlice(const sfileno sliceId
)
636 Ipc::Mem::PageId pageId
;
637 pageId
.pool
= index
+1;
638 pageId
.number
= sliceId
+1;
639 if (waitingForPage
) {
640 *waitingForPage
= pageId
;
641 waitingForPage
= NULL
;
643 freeSlots
->push(pageId
);
647 // tries to open an old entry with swap_filen for reading
648 StoreIOState::Pointer
649 Rock::SwapDir::openStoreIO(StoreEntry
&e
, StoreIOState::STFNCB
*cbFile
, StoreIOState::STIOCB
*cbIo
, void *data
)
651 if (!theFile
|| theFile
->error()) {
652 debugs(47,4, HERE
<< theFile
);
656 if (e
.swap_filen
< 0) {
657 debugs(47,4, HERE
<< e
);
661 // Do not start I/O transaction if there are less than 10% free pages left.
662 // TODO: reserve page instead
663 if (needsDiskStrand() &&
664 Ipc::Mem::PageLevel(Ipc::Mem::PageId::ioPage
) >= 0.9 * Ipc::Mem::PageLimit(Ipc::Mem::PageId::ioPage
)) {
665 debugs(47, 5, HERE
<< "too few shared pages for IPC I/O left");
669 // The are two ways an entry can get swap_filen: our get() locked it for
670 // reading or our storeSwapOutStart() locked it for writing. Peeking at our
671 // locked entry is safe, but no support for reading a filling entry.
672 const Ipc::StoreMapAnchor
*slot
= map
->peekAtReader(e
.swap_filen
);
674 return NULL
; // we were writing afterall
676 Rock::SwapDir::Pointer
self(this);
677 IoState
*sio
= new IoState(self
, &e
, cbFile
, cbIo
, data
);
679 sio
->swap_dirn
= index
;
680 sio
->swap_filen
= e
.swap_filen
;
681 sio
->readableAnchor_
= slot
;
684 debugs(47,5, HERE
<< "dir " << index
<< " has old filen: " <<
685 std::setfill('0') << std::hex
<< std::uppercase
<< std::setw(8) <<
688 assert(slot
->sameKey(static_cast<const cache_key
*>(e
.key
)));
689 assert(slot
->basics
.swap_file_sz
> 0);
690 assert(slot
->basics
.swap_file_sz
== e
.swap_file_sz
);
696 Rock::SwapDir::ioCompletedNotification()
699 fatalf("Rock cache_dir failed to initialize db file: %s", filePath
);
701 if (theFile
->error())
702 fatalf("Rock cache_dir at %s failed to open db file: %s", filePath
,
705 debugs(47, 2, "Rock cache_dir[" << index
<< "] limits: " <<
706 std::setw(12) << maxSize() << " disk bytes and " <<
707 std::setw(7) << map
->entryLimit() << " entries");
713 Rock::SwapDir::closeCompleted()
719 Rock::SwapDir::readCompleted(const char *buf
, int rlen
, int errflag
, RefCount
< ::ReadRequest
> r
)
721 ReadRequest
*request
= dynamic_cast<Rock::ReadRequest
*>(r
.getRaw());
723 IoState::Pointer sio
= request
->sio
;
725 if (errflag
== DISK_OK
&& rlen
> 0)
726 sio
->offset_
+= rlen
;
728 StoreIOState::STRCB
*callb
= sio
->read
.callback
;
730 sio
->read
.callback
= NULL
;
732 if (cbdataReferenceValidDone(sio
->read
.callback_data
, &cbdata
))
733 callb(cbdata
, r
->buf
, rlen
, sio
.getRaw());
737 Rock::SwapDir::writeCompleted(int errflag
, size_t rlen
, RefCount
< ::WriteRequest
> r
)
739 Rock::WriteRequest
*request
= dynamic_cast<Rock::WriteRequest
*>(r
.getRaw());
741 assert(request
->sio
!= NULL
);
742 IoState
&sio
= *request
->sio
;
744 // quit if somebody called IoState::close() while we were waiting
745 if (!sio
.stillWaiting()) {
746 debugs(79, 3, "ignoring closed entry " << sio
.swap_filen
);
750 if (errflag
== DISK_OK
) {
751 // do not increment sio.offset_ because we do it in sio->write()
752 if (request
->isLast
) {
753 // close, the entry gets the read lock
754 map
->closeForWriting(sio
.swap_filen
, true);
755 sio
.finishedWriting(errflag
);
758 writeError(sio
.swap_filen
);
759 sio
.finishedWriting(errflag
);
760 // and hope that Core will call disconnect() to close the map entry
765 Rock::SwapDir::writeError(const sfileno fileno
)
767 // Do not abortWriting here. The entry should keep the write lock
768 // instead of losing association with the store and confusing core.
769 map
->freeEntry(fileno
); // will mark as unusable, just in case
770 // All callers must also call IoState callback, to propagate the error.
774 Rock::SwapDir::full() const
776 return freeSlots
!= NULL
&& !freeSlots
->size();
779 // storeSwapOutFileClosed calls this nethod on DISK_NO_SPACE_LEFT,
780 // but it should not happen for us
782 Rock::SwapDir::diskFull()
784 debugs(20, DBG_IMPORTANT
, "BUG: No space left with rock cache_dir: " <<
788 /// purge while full(); it should be sufficient to purge just one
790 Rock::SwapDir::maintain()
792 // The Store calls this to free some db space, but there is nothing wrong
793 // with a full() db, except when db has to shrink after reconfigure, and
794 // we do not support shrinking yet (it would have to purge specific slots).
795 // TODO: Disable maintain() requests when they are pointless.
799 Rock::SwapDir::reference(StoreEntry
&e
)
801 debugs(47, 5, HERE
<< &e
<< ' ' << e
.swap_dirn
<< ' ' << e
.swap_filen
);
802 if (repl
&& repl
->Referenced
)
803 repl
->Referenced(repl
, &e
, &e
.repl
);
807 Rock::SwapDir::dereference(StoreEntry
&e
, bool)
809 debugs(47, 5, HERE
<< &e
<< ' ' << e
.swap_dirn
<< ' ' << e
.swap_filen
);
810 if (repl
&& repl
->Dereferenced
)
811 repl
->Dereferenced(repl
, &e
, &e
.repl
);
813 // no need to keep e in the global store_table for us; we have our own map
818 Rock::SwapDir::unlinkdUseful() const
820 // no entry-specific files to unlink
825 Rock::SwapDir::unlink(StoreEntry
&e
)
827 debugs(47, 5, HERE
<< e
);
829 map
->freeEntry(e
.swap_filen
);
834 Rock::SwapDir::trackReferences(StoreEntry
&e
)
836 debugs(47, 5, HERE
<< e
);
838 repl
->Add(repl
, &e
, &e
.repl
);
842 Rock::SwapDir::ignoreReferences(StoreEntry
&e
)
844 debugs(47, 5, HERE
<< e
);
846 repl
->Remove(repl
, &e
, &e
.repl
);
850 Rock::SwapDir::statfs(StoreEntry
&e
) const
852 storeAppendPrintf(&e
, "\n");
853 storeAppendPrintf(&e
, "Maximum Size: %" PRIu64
" KB\n", maxSize() >> 10);
854 storeAppendPrintf(&e
, "Current Size: %.2f KB %.2f%%\n",
855 currentSize() / 1024.0,
856 Math::doublePercent(currentSize(), maxSize()));
859 const int limit
= map
->entryLimit();
860 storeAppendPrintf(&e
, "Maximum entries: %9d\n", limit
);
862 const int entryCount
= map
->entryCount();
863 storeAppendPrintf(&e
, "Current entries: %9d %.2f%%\n",
864 entryCount
, (100.0 * entryCount
/ limit
));
866 const unsigned int slotsFree
= !freeSlots
? 0 : freeSlots
->size();
867 if (slotsFree
<= static_cast<const unsigned int>(limit
)) {
868 const int usedSlots
= limit
- static_cast<const int>(slotsFree
);
869 storeAppendPrintf(&e
, "Used slots: %9d %.2f%%\n",
870 usedSlots
, (100.0 * usedSlots
/ limit
));
872 if (limit
< 100) { // XXX: otherwise too expensive to count
873 Ipc::ReadWriteLockStats stats
;
874 map
->updateStats(stats
);
880 storeAppendPrintf(&e
, "Pending operations: %d out of %d\n",
881 store_open_disk_fd
, Config
.max_open_disk_fds
);
883 storeAppendPrintf(&e
, "Flags:");
886 storeAppendPrintf(&e
, " SELECTED");
889 storeAppendPrintf(&e
, " READ-ONLY");
891 storeAppendPrintf(&e
, "\n");
896 Rock::SwapDir::inodeMapPath() const {
897 static String inodesPath
;
899 inodesPath
.append("_inodes");
900 return inodesPath
.termedBuf();
904 Rock::SwapDir::freeSlotsPath() const {
905 static String spacesPath
;
907 spacesPath
.append("_spaces");
908 return spacesPath
.termedBuf();
913 RunnerRegistrationEntry(rrAfterConfig
, SwapDirRr
);
916 void Rock::SwapDirRr::create(const RunnerRegistry
&)
918 Must(mapOwners
.empty() && freeSlotsOwners
.empty());
919 for (int i
= 0; i
< Config
.cacheSwap
.n_configured
; ++i
) {
920 if (const Rock::SwapDir
*const sd
= dynamic_cast<Rock::SwapDir
*>(INDEXSD(i
))) {
921 const int64_t capacity
= sd
->entryLimitAllowed();
923 SwapDir::DirMap::Owner
*const mapOwner
=
924 SwapDir::DirMap::Init(sd
->inodeMapPath(), capacity
);
925 mapOwners
.push_back(mapOwner
);
927 // XXX: remove pool id and counters from PageStack
928 Ipc::Mem::Owner
<Ipc::Mem::PageStack
> *const freeSlotsOwner
=
929 shm_new(Ipc::Mem::PageStack
)(sd
->freeSlotsPath(),
931 sizeof(DbCellHeader
));
932 freeSlotsOwners
.push_back(freeSlotsOwner
);
934 // XXX: add method to initialize PageStack with no free pages
936 Ipc::Mem::PageId pageId
;
937 if (!freeSlotsOwner
->object()->pop(pageId
))
944 Rock::SwapDirRr::~SwapDirRr()
946 for (size_t i
= 0; i
< mapOwners
.size(); ++i
) {
948 delete freeSlotsOwners
[i
];