#include "ConfigOption.h"
SwapDir::SwapDir(char const *aType): theType(aType),
- cur_size (0), max_size(0), n_disk_objects(0),
+ max_size(0),
path(NULL), index(-1), min_objsize(0), max_objsize (-1),
repl(NULL), removals(0), scanned(0),
cleanLog(NULL)
virtual uint64_t minSize() const;
- virtual uint64_t currentSize() const { return cur_size; }
-
- virtual uint64_t currentCount() const { return n_disk_objects; }
-
virtual int64_t maxObjectSize() const { return max_objsize; }
virtual void stat (StoreEntry &anEntry) const;
virtual StoreSearch *search(String const url, HttpRequest *) = 0;
- virtual void updateSize(int64_t size, int sign);
-
/* migrated from store_dir.cc */
bool objectSizeIsAcceptable(int64_t objsize) const;
void dumpOptions(StoreEntry * e) const;
virtual ConfigOption *getOptionTree() const;
+ int64_t sizeInBlocks(const int64_t size) const { return (size + fs.blksize - 1) / fs.blksize; }
+
private:
bool optionReadOnlyParse(char const *option, const char *value, int reconfiguring);
void optionReadOnlyDump(StoreEntry * e) const;
void optionObjectSizeDump(StoreEntry * e) const;
char const *theType;
-private:
- uint64_t cur_size; ///< currently used space in the storage area
-
protected:
uint64_t max_size; ///< maximum allocatable size of the storage area
public:
- uint64_t n_disk_objects; ///< total number of objects stored
char *path;
int index; /* This entry's index into the swapDirs array */
int64_t min_objsize;
virtual void parse (int index, char *path);
virtual void reconfigure (int, char *);
virtual void swappedOut(const StoreEntry &e);
+ virtual uint64_t currentSize() const { return cur_size; }
+ virtual uint64_t currentCount() const { return n_disk_objects; }
/* internals */
virtual off_t storeCossFilenoToDiskOffset(sfileno);
virtual sfileno storeCossDiskOffsetToFileno(off_t);
CossMemBuf *createMemBuf(off_t start, sfileno curfn, int *collision);
sfileno allocate(const StoreEntry * e, int which);
void startMembuf();
+ StoreEntry *addDiskRestore(const cache_key *const key,
+ int file_number,
+ uint64_t swap_file_sz,
+ time_t expires,
+ time_t timestamp,
+ time_t lastref,
+ time_t lastmod,
+ uint32_t refcount,
+ uint16_t flags,
+ int clean);
private:
void changeIO(DiskIOModule *module);
const char *ioModule;
mutable ConfigOptionVector *currentIOOptions;
const char *stripe_path;
+ uint64_t cur_size; ///< currently used space in the storage area
+ uint64_t n_disk_objects; ///< total number of objects stored
};
/// \ingroup COSS
static char *storeCossDirSwapLogFile(SwapDir *, const char *);
static EVH storeCossRebuildFromSwapLog;
-static StoreEntry *storeCossAddDiskRestore(CossSwapDir * SD, const cache_key * key,
- int file_number,
- uint64_t swap_file_sz,
- time_t expires,
- time_t timestamp,
- time_t lastref,
- time_t lastmod,
- uint32_t refcount,
- uint16_t flags,
- int clean);
static void storeCossDirRebuild(CossSwapDir * sd);
static void storeCossDirCloseTmpSwapLog(CossSwapDir * sd);
static FILE *storeCossDirOpenTmpSwapLog(CossSwapDir *, int *, int *);
rb->counts.objcount++;
- e = storeCossAddDiskRestore(rb->sd, s.key,
+ e = rb->sd->addDiskRestore(s.key,
s.swap_filen,
s.swap_file_sz,
s.expires,
/* Add a new object to the cache with empty memory copy and pointer to disk
* use to rebuild store from disk. */
-static StoreEntry *
-storeCossAddDiskRestore(CossSwapDir * SD, const cache_key * key,
+StoreEntry *
+CossSwapDir::addDiskRestore(const cache_key *const key,
int file_number,
uint64_t swap_file_sz,
time_t expires,
* already in use! */
e = new StoreEntry();
e->store_status = STORE_OK;
- e->swap_dirn = SD->index;
+ e->swap_dirn = index;
e->setMemStatus(NOT_IN_MEMORY);
e->swap_status = SWAPOUT_DONE;
e->swap_filen = file_number;
EBIT_CLR(e->flags, KEY_PRIVATE);
e->ping_status = PING_NONE;
EBIT_CLR(e->flags, ENTRY_VALIDATED);
- SD->updateSize(e->swap_file_sz, 1);
+ cur_size += fs.blksize * sizeInBlocks(e->swap_file_sz);
+ ++n_disk_objects;
e->hashInsert(key); /* do it after we clear KEY_PRIVATE */
- storeCossAdd(SD, e);
+ storeCossAdd(this, e);
assert(e->swap_filen >= 0);
return e;
}
void
CossSwapDir::swappedOut(const StoreEntry &e)
{
- updateSize(e.swap_file_sz, 1);
+ cur_size += fs.blksize * sizeInBlocks(e.swap_file_sz);
+ ++n_disk_objects;
}
void
dumpOptions(&entry);
}
-CossSwapDir::CossSwapDir() : SwapDir ("coss"), swaplog_fd(-1), count(0), current_membuf (NULL), current_offset(0), numcollisions(0), blksz_bits(0), io (NULL), ioModule(NULL), currentIOOptions(new ConfigOptionVector()), stripe_path(NULL)
+CossSwapDir::CossSwapDir() : SwapDir ("coss"), swaplog_fd(-1), count(0), current_membuf (NULL), current_offset(0), numcollisions(0), blksz_bits(0), io (NULL), ioModule(NULL), currentIOOptions(new ConfigOptionVector()), stripe_path(NULL), cur_size(0), n_disk_objects(0)
{
membufs.head = NULL;
membufs.tail = NULL;
CossSwapDir::unlink(StoreEntry & e)
{
debugs(79, 3, "storeCossUnlink: offset " << e.swap_filen);
- if (e.swap_status == SWAPOUT_DONE && EBIT_TEST(e.flags, ENTRY_VALIDATED))
- updateSize(e.swap_file_sz, -1);
+ if (e.swap_status == SWAPOUT_DONE && EBIT_TEST(e.flags, ENTRY_VALIDATED)) {
+ cur_size -= fs.blksize * sizeInBlocks(e.swap_file_sz);
+ --n_disk_objects;
+ }
StoreFScoss::GetInstance().stats.unlink.ops++;
StoreFScoss::GetInstance().stats.unlink.success++;
storeCossRemove(this, &e);
createSwapSubDirs();
}
-UFSSwapDir::UFSSwapDir(char const *aType, const char *anIOType) : SwapDir(aType), IO(NULL), map(file_map_create()), suggest(0), swaplog_fd (-1), currentIOOptions(new ConfigOptionVector()), ioType(xstrdup(anIOType))
+UFSSwapDir::UFSSwapDir(char const *aType, const char *anIOType) : SwapDir(aType), IO(NULL), map(file_map_create()), suggest(0), swaplog_fd (-1), currentIOOptions(new ConfigOptionVector()), ioType(xstrdup(anIOType)), cur_size(0), n_disk_objects(0)
{
/* modulename is only set to disk modules that are built, by configure,
* so the Find call should never return NULL here.
e->ping_status = PING_NONE;
EBIT_CLR(e->flags, ENTRY_VALIDATED);
mapBitSet(e->swap_filen);
- updateSize(e->swap_file_sz, 1);
+ cur_size += fs.blksize * sizeInBlocks(e->swap_file_sz);
+ ++n_disk_objects;
e->hashInsert(key); /* do it after we clear KEY_PRIVATE */
replacementAdd (e);
return e;
{
debugs(79, 3, "storeUfsUnlink: dirno " << index << ", fileno "<<
std::setfill('0') << std::hex << std::uppercase << std::setw(8) << e.swap_filen);
- if (e.swap_status == SWAPOUT_DONE && EBIT_TEST(e.flags, ENTRY_VALIDATED))
- updateSize(e.swap_file_sz, -1);
+ if (e.swap_status == SWAPOUT_DONE && EBIT_TEST(e.flags, ENTRY_VALIDATED)) {
+ cur_size -= fs.blksize * sizeInBlocks(e.swap_file_sz);
+ --n_disk_objects;
+ }
replacementRemove(&e);
mapBitReset(e.swap_filen);
UFSSwapDir::unlinkFile(e.swap_filen);
void
UFSSwapDir::swappedOut(const StoreEntry &e)
{
- updateSize(e.swap_file_sz, 1);
+ cur_size += fs.blksize * sizeInBlocks(e.swap_file_sz);
+ ++n_disk_objects;
}
StoreSearch *
virtual int callback();
virtual void sync();
virtual void swappedOut(const StoreEntry &e);
+ virtual uint64_t currentSize() const { return cur_size; }
+ virtual uint64_t currentCount() const { return n_disk_objects; }
void unlinkFile(sfileno f);
// move down when unlink is a virtual method
void optionIODump(StoreEntry * e) const;
mutable ConfigOptionVector *currentIOOptions;
char const *ioType;
-
+ uint64_t cur_size; ///< currently used space in the storage area
+ uint64_t n_disk_objects; ///< total number of objects stored
};
#include "RefCount.h"
dynamic_cast<SwapDir *>(INDEXSD(e->swap_dirn))->logEntry(*e, op);
}
-void
-SwapDir::updateSize(int64_t size, int sign)
-{
- const int64_t blks = (size + fs.blksize - 1) / fs.blksize;
- const int64_t k = blks * fs.blksize * sign;
- cur_size += k;
-
- if (sign > 0)
- n_disk_objects++;
- else if (sign < 0)
- n_disk_objects--;
-}
-
void
StoreController::stat(StoreEntry &output) const
{