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
Updated IOC::listdirectory & its unit test.
This commit is contained in:
@@ -34,17 +34,32 @@ IOCoordinator::IOCoordinator()
|
|||||||
cache = Cache::get();
|
cache = Cache::get();
|
||||||
logger = SMLogging::get();
|
logger = SMLogging::get();
|
||||||
replicator = Replicator::get();
|
replicator = Replicator::get();
|
||||||
objectSize = 5 * (1<<20);
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
objectSize = stoul(config->getValue("ObjectStorage", "object_size"));
|
objectSize = stoul(config->getValue("ObjectStorage", "object_size"));
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
cerr << "ObjectStorage/object_size must be set to a numeric value" << endl;
|
logger->log(LOG_ERR, "ObjectStorage/object_size must be set to a numeric value");
|
||||||
throw;
|
throw runtime_error("Please set ObjectStorage/object_size in the storagemanager.cnf file");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
metaPath = config->getValue("ObjectStorage", "metadata_path");
|
||||||
|
if (metaPath.empty())
|
||||||
|
{
|
||||||
|
logger->log(LOG_ERR, "ObjectStorage/journal_path is not set");
|
||||||
|
throw runtime_error("Please set ObjectStorage/journal_path in the storagemanager.cnf file");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
logger->log(LOG_ERR, "ObjectStorage/metadata_path is not set");
|
||||||
|
throw runtime_error("Please set ObjectStorage/metadata_path in the storagemanager.cnf file");
|
||||||
|
}
|
||||||
|
|
||||||
cachePath = cache->getCachePath();
|
cachePath = cache->getCachePath();
|
||||||
journalPath = cache->getJournalPath();
|
journalPath = cache->getJournalPath();
|
||||||
}
|
}
|
||||||
@@ -360,7 +375,7 @@ int IOCoordinator::open(const char *filename, int openmode, struct stat *out)
|
|||||||
|
|
||||||
int IOCoordinator::listDirectory(const char *filename, vector<string> *listing)
|
int IOCoordinator::listDirectory(const char *filename, vector<string> *listing)
|
||||||
{
|
{
|
||||||
bf::path p(filename);
|
bf::path p(metaPath / filename);
|
||||||
|
|
||||||
listing->clear();
|
listing->clear();
|
||||||
if (!bf::exists(p))
|
if (!bf::exists(p))
|
||||||
@@ -410,8 +425,6 @@ int IOCoordinator::unlink(const char *path)
|
|||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
//return ::unlink(path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int IOCoordinator::copyFile(const char *filename1, const char *filename2)
|
int IOCoordinator::copyFile(const char *filename1, const char *filename2)
|
||||||
@@ -435,6 +448,21 @@ int IOCoordinator::copyFile(const char *filename1, const char *filename2)
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bf::path &IOCoordinator::getCachePath() const
|
||||||
|
{
|
||||||
|
return cachePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
const bf::path &IOCoordinator::getJournalPath() const
|
||||||
|
{
|
||||||
|
return journalPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
const bf::path &IOCoordinator::getMetadataPath() const
|
||||||
|
{
|
||||||
|
return metaPath;
|
||||||
|
}
|
||||||
|
|
||||||
// this is not generic by any means. This is assuming a version 1 journal header, and is looking
|
// this is not generic by any means. This is assuming a version 1 journal header, and is looking
|
||||||
// for the end of it, which is the first \0 char. It returns with fd pointing at the
|
// for the end of it, which is the first \0 char. It returns with fd pointing at the
|
||||||
// first byte after the header.
|
// first byte after the header.
|
||||||
|
|||||||
@@ -62,7 +62,12 @@ class IOCoordinator : public boost::noncopyable
|
|||||||
bool writeLock(const std::string &filename);
|
bool writeLock(const std::string &filename);
|
||||||
void readUnlock(const std::string &filename);
|
void readUnlock(const std::string &filename);
|
||||||
void writeUnlock(const std::string &filename);
|
void writeUnlock(const std::string &filename);
|
||||||
|
|
||||||
|
// some accessors...
|
||||||
|
const boost::filesystem::path &getCachePath() const;
|
||||||
|
const boost::filesystem::path &getJournalPath() const;
|
||||||
|
const boost::filesystem::path &getMetadataPath() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IOCoordinator();
|
IOCoordinator();
|
||||||
Config *config;
|
Config *config;
|
||||||
@@ -72,6 +77,7 @@ class IOCoordinator : public boost::noncopyable
|
|||||||
size_t objectSize;
|
size_t objectSize;
|
||||||
boost::filesystem::path journalPath;
|
boost::filesystem::path journalPath;
|
||||||
boost::filesystem::path cachePath;
|
boost::filesystem::path cachePath;
|
||||||
|
boost::filesystem::path metaPath;
|
||||||
|
|
||||||
std::map<std::string, RWLock *> locks;
|
std::map<std::string, RWLock *> locks;
|
||||||
boost::mutex lockMutex; // lol
|
boost::mutex lockMutex; // lol
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
#include "MetadataFile.h"
|
#include "MetadataFile.h"
|
||||||
#include "Replicator.h"
|
#include "Replicator.h"
|
||||||
#include "S3Storage.h"
|
#include "S3Storage.h"
|
||||||
|
#include "Utilities.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -517,19 +518,31 @@ bool truncatetask()
|
|||||||
|
|
||||||
bool listdirtask()
|
bool listdirtask()
|
||||||
{
|
{
|
||||||
// make a file, make sure it's in the list returned.
|
IOCoordinator *ioc = IOCoordinator::get();
|
||||||
const char *filename = "listdirtest1";
|
const bf::path metaPath = ioc->getMetadataPath();
|
||||||
::unlink(filename);
|
const char *relPath = "listdirtask";
|
||||||
int fd = ::open(filename, O_CREAT | O_RDWR, 0666);
|
bf::path tmpPath = metaPath/relPath;
|
||||||
assert(fd > 0);
|
|
||||||
scoped_closer f(fd);
|
// make some dummy files, make sure they are in the list returned.
|
||||||
|
set<string> files;
|
||||||
|
int err;
|
||||||
|
vector<SharedCloser> fdMinders;
|
||||||
|
|
||||||
|
bf::create_directories(tmpPath);
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
string file(tmpPath.string() + "/dummy" + to_string(i));
|
||||||
|
files.insert(file);
|
||||||
|
err = ::open(file.c_str(), O_CREAT | O_WRONLY, 0600);
|
||||||
|
assert(err >= 0);
|
||||||
|
fdMinders.push_back(err);
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t buf[8192];
|
uint8_t buf[8192];
|
||||||
listdir_cmd *cmd = (listdir_cmd *) buf;
|
listdir_cmd *cmd = (listdir_cmd *) buf;
|
||||||
|
|
||||||
cmd->opcode = LIST_DIRECTORY;
|
cmd->opcode = LIST_DIRECTORY;
|
||||||
cmd->plen = 1;
|
cmd->plen = strlen(relPath);
|
||||||
cmd->path[0] = '.';
|
memcpy(cmd->path, relPath, cmd->plen);
|
||||||
|
|
||||||
::write(sessionSock, cmd, sizeof(*cmd) + cmd->plen);
|
::write(sessionSock, cmd, sizeof(*cmd) + cmd->plen);
|
||||||
ListDirectoryTask l(clientSock, sizeof(*cmd) + cmd->plen);
|
ListDirectoryTask l(clientSock, sizeof(*cmd) + cmd->plen);
|
||||||
@@ -537,32 +550,31 @@ bool listdirtask()
|
|||||||
|
|
||||||
/* going to keep this simple. Don't run this in a big dir. */
|
/* going to keep this simple. Don't run this in a big dir. */
|
||||||
/* maybe later I'll make a dir, put a file in it, and etc. For now run it in a small dir. */
|
/* maybe later I'll make a dir, put a file in it, and etc. For now run it in a small dir. */
|
||||||
int err = ::recv(sessionSock, buf, 8192, MSG_DONTWAIT);
|
err = ::recv(sessionSock, buf, 8192, MSG_DONTWAIT);
|
||||||
sm_response *resp = (sm_response *) buf;
|
sm_response *resp = (sm_response *) buf;
|
||||||
assert(err > 0);
|
assert(err > 0);
|
||||||
assert(resp->header.type == SM_MSG_START);
|
assert(resp->header.type == SM_MSG_START);
|
||||||
assert(resp->header.flags == 0);
|
assert(resp->header.flags == 0);
|
||||||
assert(resp->returnCode == 0);
|
assert(resp->returnCode == 0);
|
||||||
listdir_resp *r = (listdir_resp *) resp->payload;
|
listdir_resp *r = (listdir_resp *) resp->payload;
|
||||||
//cout << "resp has " << r->elements << " elements" << endl;
|
cout << "resp has " << r->elements << " elements" << endl;
|
||||||
|
assert(r->elements == 10);
|
||||||
int off = sizeof(sm_response) + sizeof(listdir_resp);
|
int off = sizeof(sm_response) + sizeof(listdir_resp);
|
||||||
|
int fileCounter = 0;
|
||||||
while (off < err)
|
while (off < err)
|
||||||
{
|
{
|
||||||
listdir_resp_entry *e = (listdir_resp_entry *) &buf[off];
|
listdir_resp_entry *e = (listdir_resp_entry *) &buf[off];
|
||||||
//cout << "len = " << e->flen << endl;
|
//cout << "len = " << e->flen << endl;
|
||||||
assert(off + e->flen + sizeof(listdir_resp_entry) < 1024);
|
assert(off + e->flen + sizeof(listdir_resp_entry) < 8092);
|
||||||
if (!strncmp(e->filename, filename, strlen(filename))) {
|
string file(e->filename, e->flen);
|
||||||
cout << "listdirtask OK" << endl;
|
assert(files.find((tmpPath/file).string()) != files.end());
|
||||||
::unlink(filename);
|
fileCounter++;
|
||||||
return true;
|
//cout << "name = " << file << endl;
|
||||||
}
|
|
||||||
//string name(e->filename, e->flen);
|
|
||||||
//cout << "name = " << name << endl;
|
|
||||||
off += e->flen + sizeof(listdir_resp_entry);
|
off += e->flen + sizeof(listdir_resp_entry);
|
||||||
}
|
}
|
||||||
cout << "listdirtask(). Didn't find '" << filename << " in the listing. Dir too large for this test?" << endl;
|
assert(fileCounter == r->elements);
|
||||||
assert(1);
|
bf::remove_all(tmpPath);
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pingtask()
|
bool pingtask()
|
||||||
|
|||||||
Reference in New Issue
Block a user