You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-12-13 23:02:14 +03:00
Added more Cache tests, fixed a couple bugs.
This commit is contained in:
@@ -189,7 +189,7 @@ void Cache::exists(const vector<string> &keys, vector<bool> *out)
|
||||
out->resize(keys.size());
|
||||
boost::unique_lock<boost::mutex> s(lru_mutex);
|
||||
for (int i = 0; i < keys.size(); i++)
|
||||
(*out)[i] = (m_lru.find(keys[i]) == m_lru.end());
|
||||
(*out)[i] = (m_lru.find(keys[i]) != m_lru.end());
|
||||
}
|
||||
|
||||
void Cache::newObject(const string &key, size_t size)
|
||||
@@ -248,7 +248,7 @@ void Cache::makeSpace(size_t size)
|
||||
}
|
||||
|
||||
/*
|
||||
TODO: tell Synchronizer that this key will be evicted
|
||||
tell Synchronizer that this key will be evicted
|
||||
delete the file
|
||||
remove it from our structs
|
||||
update current size
|
||||
@@ -264,6 +264,10 @@ void Cache::makeSpace(size_t size)
|
||||
}
|
||||
}
|
||||
|
||||
size_t Cache::getCurrentCacheSize() const
|
||||
{
|
||||
return currentCacheSize;
|
||||
}
|
||||
|
||||
/* The helper classes */
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ class Cache : public boost::noncopyable
|
||||
void newObject(const std::string &key, size_t size);
|
||||
void deletedObject(const std::string &key, size_t size);
|
||||
void setMaxCacheSize(size_t size);
|
||||
size_t getCurrentCacheSize();
|
||||
size_t getCurrentCacheSize() const;
|
||||
|
||||
// test helpers
|
||||
const boost::filesystem::path &getCachePath();
|
||||
|
||||
@@ -105,6 +105,7 @@ int Downloader::download(const vector<const string *> &keys, vector<int> *errnos
|
||||
if (dl->dl_errno != 0)
|
||||
{
|
||||
char buf[80];
|
||||
// not sure why yet, but valgrind complains about the call below
|
||||
logger->log(LOG_ERR, "Downloader: failed to download %s, got '%s'", keys[i]->c_str(), strerror_r(dl->dl_errno, buf, 80));
|
||||
ret = -1;
|
||||
}
|
||||
@@ -122,7 +123,7 @@ inline const string & Downloader::getDownloadPath() const
|
||||
}
|
||||
|
||||
/* The helper fcns */
|
||||
Downloader::Download::Download(const string *source, Downloader *dl) : key(source), dler(dl), dl_errno(0), size(0)
|
||||
Downloader::Download::Download(const string *source, Downloader *dl) : dler(dl), key(source), dl_errno(0), size(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -482,21 +482,41 @@ bool cacheTest1()
|
||||
bf::path storagePath = ls->getPrefix();
|
||||
bf::path cachePath = cache.getCachePath();
|
||||
vector<string> v_bogus;
|
||||
vector<bool> exists;
|
||||
|
||||
// make sure nothing shows up in the cache path for files that don't exist
|
||||
v_bogus.push_back("does-not-exist");
|
||||
cache.read(v_bogus);
|
||||
assert(!bf::exists(cachePath / "does-not-exist"));
|
||||
cache.exists(v_bogus, &exists);
|
||||
assert(exists.size() == 1);
|
||||
assert(!exists[0]);
|
||||
|
||||
// make sure a file that does exist does show up in the cache path
|
||||
bf::copy_file("storagemanager.cnf", storagePath / "storagemanager.cnf", bf::copy_option::overwrite_if_exists);
|
||||
v_bogus[0] = "storagemanager.cnf";
|
||||
string realFile("storagemanager.cnf");
|
||||
bf::copy_file(realFile, storagePath / realFile, bf::copy_option::overwrite_if_exists);
|
||||
v_bogus[0] = realFile;
|
||||
cache.read(v_bogus);
|
||||
assert(bf::exists(cachePath / "storagemanager.cnf"));
|
||||
assert(bf::exists(cachePath / realFile));
|
||||
exists.clear();
|
||||
cache.exists(v_bogus, &exists);
|
||||
assert(exists.size() == 1);
|
||||
assert(exists[0]);
|
||||
ssize_t currentSize = cache.getCurrentCacheSize();
|
||||
assert(currentSize == bf::file_size(cachePath / realFile));
|
||||
|
||||
// lie about the file being deleted and then replaced
|
||||
cache.deletedObject(realFile, currentSize);
|
||||
assert(cache.getCurrentCacheSize() == 0);
|
||||
cache.newObject(realFile, currentSize);
|
||||
assert(cache.getCurrentCacheSize() == currentSize);
|
||||
cache.exists(v_bogus, &exists);
|
||||
assert(exists.size() == 1);
|
||||
assert(exists[0]);
|
||||
|
||||
// cleanup
|
||||
bf::remove(cachePath / "storagemanager.cnf");
|
||||
bf::remove(storagePath / "storagemanager.cnf");
|
||||
bf::remove(cachePath / realFile);
|
||||
bf::remove(storagePath / realFile);
|
||||
cout << "cache test 1 OK" << endl;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user