You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-12-15 12:09:09 +03:00
Made Cache populate itself on init.
This commit is contained in:
@@ -11,7 +11,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace boost::filesystem;
|
namespace bf = boost::filesystem;
|
||||||
|
|
||||||
namespace storagemanager
|
namespace storagemanager
|
||||||
{
|
{
|
||||||
@@ -64,7 +64,7 @@ Cache::Cache() : currentCacheSize(0)
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
boost::filesystem::create_directories(prefix);
|
bf::create_directories(prefix);
|
||||||
}
|
}
|
||||||
catch (exception &e)
|
catch (exception &e)
|
||||||
{
|
{
|
||||||
@@ -74,13 +74,40 @@ Cache::Cache() : currentCacheSize(0)
|
|||||||
//cout << "Cache got prefix " << prefix << endl;
|
//cout << "Cache got prefix " << prefix << endl;
|
||||||
|
|
||||||
downloader.setDownloadPath(prefix.string());
|
downloader.setDownloadPath(prefix.string());
|
||||||
/* todo: populate structures with existing files in the cache path */
|
populate();
|
||||||
}
|
}
|
||||||
|
|
||||||
Cache::~Cache()
|
Cache::~Cache()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Cache::populate()
|
||||||
|
{
|
||||||
|
bf::directory_iterator dir(prefix);
|
||||||
|
bf::diretory_iterator dend;
|
||||||
|
while (dir != dend)
|
||||||
|
{
|
||||||
|
// put everything that doesn't end with '.journal' in lru & m_lru
|
||||||
|
if (bf::is_regular_file(*dir))
|
||||||
|
{
|
||||||
|
size_t size = bf::file_size(*dir);
|
||||||
|
if (dir->extension() == "obj")
|
||||||
|
{
|
||||||
|
lru.push_back(dir->string());
|
||||||
|
m_lru.insert(lru.end() - 1);
|
||||||
|
currentCacheSize += size;
|
||||||
|
}
|
||||||
|
else if (dir->extension() == "journal")
|
||||||
|
currentCacheSize += size;
|
||||||
|
else
|
||||||
|
logger->log(LOG_WARN, "Cache: found a file in the cache that does not belong '%s'", dir->string().c_str());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
logger->log(LOG_WARN, "Cache: found something in the cache that does not belong '%s'", dir->string().c_str());
|
||||||
|
++dir;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Cache::read(const vector<string> &keys)
|
void Cache::read(const vector<string> &keys)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@@ -178,7 +205,7 @@ void Cache::removeFromDNE(const LRU_t::iterator &key)
|
|||||||
doNotEvict.erase(it);
|
doNotEvict.erase(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
const boost::filesystem::path & Cache::getCachePath()
|
const bf::path & Cache::getCachePath()
|
||||||
{
|
{
|
||||||
return prefix;
|
return prefix;
|
||||||
}
|
}
|
||||||
@@ -257,7 +284,7 @@ void Cache::makeSpace(size_t size)
|
|||||||
continue; // it's in the do-not-evict list
|
continue; // it's in the do-not-evict list
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::filesystem::path cachedFile = prefix / *it;
|
bf::path cachedFile = prefix / *it;
|
||||||
int err = stat(cachedFile.string().c_str(), &statbuf);
|
int err = stat(cachedFile.string().c_str(), &statbuf);
|
||||||
if (err)
|
if (err)
|
||||||
{
|
{
|
||||||
@@ -277,7 +304,7 @@ void Cache::makeSpace(size_t size)
|
|||||||
thisMuch -= statbuf.st_size;
|
thisMuch -= statbuf.st_size;
|
||||||
sync->flushObject(*it);
|
sync->flushObject(*it);
|
||||||
// Deleting the files will be done through Synchronizer->Replicator
|
// Deleting the files will be done through Synchronizer->Replicator
|
||||||
//boost::filesystem::remove(cachedFile);
|
//bf::remove(cachedFile);
|
||||||
LRU_t::iterator toRemove = it++;
|
LRU_t::iterator toRemove = it++;
|
||||||
lru.erase(toRemove);
|
lru.erase(toRemove);
|
||||||
m_lru.erase(*toRemove);
|
m_lru.erase(*toRemove);
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ class Cache : public boost::noncopyable
|
|||||||
Synchronizer *sync;
|
Synchronizer *sync;
|
||||||
SMLogging *logger;
|
SMLogging *logger;
|
||||||
|
|
||||||
|
void populate();
|
||||||
void makeSpace(size_t size);
|
void makeSpace(size_t size);
|
||||||
|
|
||||||
/* The main cache structures */
|
/* The main cache structures */
|
||||||
|
|||||||
Reference in New Issue
Block a user