1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-29 08:21:15 +03:00

Updated the storage-manager ref. Made SMComm send absolute

paths rather than relative ones.
This commit is contained in:
Patrick LeBlanc
2019-02-01 13:13:30 -06:00
parent a9a5c2ebb7
commit 8ad3188162
5 changed files with 60 additions and 17 deletions

View File

@ -71,19 +71,31 @@ SMComm * SMComm::get()
SMComm::SMComm()
{
char buf[4096];
cwd = ::getcwd(buf, 4096);
cout << "got cwd = " << cwd << endl;
}
SMComm::~SMComm()
{
}
string SMComm::getAbsFilename(const string &filename)
{
if (filename[0] == '/')
return filename;
else
return cwd + '/' + filename;
}
int SMComm::open(const string &filename, const int mode, struct stat *statbuf)
{
ByteStream *command = buffers.getByteStream();
ByteStream *response = buffers.getByteStream();
int err;
string absfilename(getAbsFilename(filename));
*command << (uint8_t) storagemanager::OPEN << mode << filename;
*command << (uint8_t) storagemanager::OPEN << mode << absfilename;
err = sockets.send_recv(*command, response);
if (err)
common_exit(command, response, err);
@ -98,8 +110,9 @@ ssize_t SMComm::pread(const string &filename, void *buf, const size_t count, con
ByteStream *command = buffers.getByteStream();
ByteStream *response = buffers.getByteStream();
int err;
string absfilename(getAbsFilename(filename));
*command << (uint8_t) storagemanager::READ << count << offset << filename;
*command << (uint8_t) storagemanager::READ << count << offset << absfilename;
err = sockets.send_recv(*command, response);
if (err)
common_exit(command, response, err);
@ -114,8 +127,9 @@ ssize_t SMComm::pwrite(const string &filename, const void *buf, const size_t cou
ByteStream *command = buffers.getByteStream();
ByteStream *response = buffers.getByteStream();
int err;
string absfilename(getAbsFilename(filename));
*command << (uint8_t) storagemanager::WRITE << count << offset << filename;
*command << (uint8_t) storagemanager::WRITE << count << offset << absfilename;
command->needAtLeast(count);
uint8_t *cmdBuf = command->getInputPtr();
memcpy(cmdBuf, buf, count);
@ -132,8 +146,9 @@ ssize_t SMComm::append(const string &filename, const void *buf, const size_t cou
ByteStream *command = buffers.getByteStream();
ByteStream *response = buffers.getByteStream();
int err;
string absfilename(getAbsFilename(filename));
*command << (uint8_t) storagemanager::APPEND << count << filename;
*command << (uint8_t) storagemanager::APPEND << count << absfilename;
command->needAtLeast(count);
uint8_t *cmdBuf = command->getInputPtr();
memcpy(cmdBuf, buf, count);
@ -150,8 +165,9 @@ int SMComm::unlink(const string &filename)
ByteStream *command = buffers.getByteStream();
ByteStream *response = buffers.getByteStream();
int err;
string absfilename(getAbsFilename(filename));
*command << (uint8_t) storagemanager::UNLINK << filename;
*command << (uint8_t) storagemanager::UNLINK << absfilename;
err = sockets.send_recv(*command, response);
if (err)
common_exit(command, response, err);
@ -164,8 +180,9 @@ int SMComm::stat(const string &filename, struct stat *statbuf)
ByteStream *command = buffers.getByteStream();
ByteStream *response = buffers.getByteStream();
int err;
string absfilename(getAbsFilename(filename));
*command << (uint8_t) storagemanager::STAT << filename;
*command << (uint8_t) storagemanager::STAT << absfilename;
err = sockets.send_recv(*command, response);
if (err)
common_exit(command, response, err);
@ -180,8 +197,9 @@ int SMComm::truncate(const string &filename, const off64_t length)
ByteStream *command = buffers.getByteStream();
ByteStream *response = buffers.getByteStream();
int err;
string absfilename(getAbsFilename(filename));
*command << (uint8_t) storagemanager::TRUNCATE << length << filename;
*command << (uint8_t) storagemanager::TRUNCATE << length << absfilename;
err = sockets.send_recv(*command, response);
if (err)
common_exit(command, response, err);
@ -194,8 +212,9 @@ int SMComm::listDirectory(const string &path, list<string> *entries)
ByteStream *command = buffers.getByteStream();
ByteStream *response = buffers.getByteStream();
int err;
string abspath(getAbsFilename(path));
*command << (uint8_t) storagemanager::LIST_DIRECTORY << path;
*command << (uint8_t) storagemanager::LIST_DIRECTORY << abspath;
err = sockets.send_recv(*command, response);
if (err)
common_exit(command, response, err);
@ -226,4 +245,20 @@ int SMComm::ping()
common_exit(command, response, err);
}
int SMComm::copyFile(const string &file1, const string &file2)
{
ByteStream *command = buffers.getByteStream();
ByteStream *response = buffers.getByteStream();
int err;
string absfilename1(getAbsFilename(file1));
string absfilename2(getAbsFilename(file2));
*command << (uint8_t) storagemanager::COPY << absfilename1 << absfilename2;
err = sockets.send_recv(*command, response);
if (err)
common_exit(command, response, err);
check_for_error(command, response, err);
common_exit(command, response, err);
}
}

View File

@ -59,13 +59,18 @@ class SMComm : public boost::noncopyable
// the specified S3 bucket. Need to define specific error codes.
int ping();
int copyFile(const std::string &file1, const std::string &file2);
virtual ~SMComm();
private:
SMComm();
std::string getAbsFilename(const std::string &filename);
SocketPool sockets;
messageqcpp::ByteStreamPool buffers;
std::string cwd;
};
}

View File

@ -65,9 +65,11 @@ int SMFileSystem::remove(const char *filename)
int SMFileSystem::rename(const char *oldFile, const char *newFile)
{
// This will actually be pretty expensive to do b/c we store the filename in
// the key in cloud. If we do this a lot, we'll have to implement copy() in the SM.
throw NotImplementedYet(__func__);
int err = copyFile(oldFile, newFile);
if (err)
return err;
err = unlink(oldFile);
return err;
}
bool SMFileSystem::exists(const char *filename) const
@ -98,7 +100,8 @@ bool SMFileSystem::isDir(const char *path) const
int SMFileSystem::copyFile(const char *src, const char *dest) const
{
throw NotImplementedYet(__func__);
SMComm *comm = SMComm::get();
return comm->copyFile(src, dest);
}
bool SMFileSystem::filesystemIsUp() const

View File

@ -78,7 +78,7 @@ SocketPool::~SocketPool()
if (err < 0) \
{ \
cout << "SP: got an error on the socket" << endl; \
returnSocket(sock); \
remoteClosed(sock); \
return -1; \
}