1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-12-17 01:02:23 +03:00

Finished first cut of CRP & PosixTasks. No way it builds yet.

This commit is contained in:
Patrick LeBlanc
2019-01-29 09:52:14 -06:00
parent b38c92738c
commit 8d926202ac
13 changed files with 283 additions and 6 deletions

View File

@@ -106,7 +106,7 @@ enum Opcodes {
TRUNCATE
--------
command format:
1-byte opcode|4-byte filename length|filename|off64_t length
1-byte opcode|off64_t length|4-byte filename length|filename
response format:

View File

@@ -59,9 +59,9 @@ bool ListDirectoryTask::writeString(uint8_t buf, int *offset, int size, const st
void ListDirectoryTask::run()
{
bool success;
uint8_t buf[1024];
uint8_t buf[1024] = {0};
if (getLength() > 1024) {
if (getLength() > 1023) {
handleError("ListDirectoryTask read", ENAMETOOLONG);
return;
}
@@ -71,7 +71,7 @@ void ListDirectoryTask::run()
cmd_overlay *cmd = (cmd_overlay *) buf;
vector<string> listing;
// IOC->listDirectory(path, &listing)
// IOC->listDirectory(cmd->path, &listing)
// bogus response
listing.push_back("dummy1");

View File

@@ -18,9 +18,9 @@ class ListDirectoryTask : public PosixTask
private:
ListDirectoryTask();
void writeString(uint8_t buf, int *offset, int size, const std::string &str)
void writeString(uint8_t buf, int *offset, int size, const std::string &str);
struct cmd_overlay {
uint flen;
uint plen;
char path[];
};
};

View File

@@ -0,0 +1,20 @@
#include "PingTask.h"
namespace storagemanager
{
PingTask::PingTask(int sock, uint len) : PosixTask(sock, len)
{
}
PingTask::~PingTask()
{
}
void PingTask::run()
{
// not much to check on for Milestone 1
uint32_t buf[3] = { SM_MSG_START, 4, 0 }; // generic success response
write((uint8_t *) buf, 12);
}

View File

@@ -0,0 +1,24 @@
#ifndef PINGTASK_H_
#define PINGTASK_H_
#include "PosixTask.h"
namespace storagemanager
{
class PingTask : PosixTask
{
public:
PingTask(int sock, uint length);
virtual ~PingTask();
void run();
private:
PingTask();
};
}
#endif

View File

@@ -19,6 +19,7 @@ PosixTask::PosixTask(int _sock, uint _length) :
PosixTask::~PosixTask()
{
comsumeMsg();
if (!socketReturned)
returnSocket();
}
@@ -60,11 +61,15 @@ uint PosixTask::getLength()
return totalLength;
}
// todo, need this to return an int instead of a bool b/c it modifies the length of the read
bool PosixTask::read(uint8_t *buf, uint length)
{
if (length > remainingLengthForCaller)
length = remainingLengthForCaller;
if (length == 0)
return false;
uint count = 0;
int err;
@@ -156,4 +161,24 @@ bool PosixTask::write(const vector<uint8_t> &buf)
return write(&buf[0], buf.size());
}
void PosixTask::consumeMsg()
{
uint8_t buf[1024];
int err;
bufferLen = 0;
bufferPos = 0;
remainingLengthForCaller = 0;
while (remainingLengthInStream > 0)
{
err = ::read(sock, buf, min(remainingLengthInStream, 1024));
if (err <= 0) {
remainingLengthInStream = 0;
break;
}
remainingLengthInStream -= err;
}
}
}

View File

@@ -18,6 +18,7 @@ class PosixTask
int read(uint8_t *buf, uint length);
bool write(const std::vector<uint8_t> &buf);
bool write(void *buf, uint length);
void consumeMsg(); // drains the remaining portion of the message
uint getLength(); // returns the total length of the msg
uint getRemainingLength(); // returns the remaining length from the caller's perspective
void handleError(const char *name, int errCode);

View File

@@ -0,0 +1,41 @@
#include "StatTask.h"
using namespace std;
namespace storagemanager
{
StatTask::StatTask(int sock, uint len) : PosixTask(sock, len)
{
}
StatTask::~StatTask()
{
}
void StatTask::run()
{
bool success;
uint8_t buf[1024] = {0};
if (getLength() > 1023) {
handleError("StatTask read", ENAMETOOLONG);
return;
}
success = read(buf, getLength());
check_error("StatTask read");
cmd_overlay *cmd = (cmd_overlay *) buf;
struct stat _stat;
// IOC->stat(cmd->path, &_stat);
// bogus response
memset(&_stat, 0, sizeof(_stat));
uint32_t *buf32 = (uint32_t *) buf;
buf32[0] = SM_MSG_START;
buf32[1] = sizeof(_stat);
memcpy(&buf[SM_HEADER_LEN], &_stat, sizeof(_stat));
write(buf, SM_HEADER_LEN + sizeof(_stat));
}

View File

@@ -0,0 +1,29 @@
#ifndef STATTASK_H_
#define STATTASK_H_
#include "PosixTask.h"
namespace storagemanager
{
class StatTask : public PosixTask
{
public:
StatTask(int sock, uint length);
virtual ~StatTask();
void run();
private:
StatTask();
struct cmd_overlay {
uint plen;
char path[];
};
};
}
#endif

View File

@@ -0,0 +1,39 @@
#include "TruncateTask.h"
using namespace std;
namespace storagemanager
{
TruncateTask::TruncateTask(int sock, uint len) : PosixTask(sock, len)
{
}
TruncateTask::~TruncateTask()
{
}
void TruncateTask::run()
{
bool success;
uint8_t buf[1024] = {0};
if (getLength() > 1023) {
handleError("TruncateTask read", ENAMETOOLONG);
return;
}
success = read(buf, getLength());
check_error("TruncateTask read");
cmd_overlay *cmd = (cmd_overlay *) buf;
// IOC->truncate(cmd->filename, cmd->newSize);
// generic success msg
uint32_t *buf32 = buf;
buf32[0] = SM_MSG_START;
buf32[1] = 4;
buf32[2] = 0;
write(buf, 12);
}

View File

@@ -0,0 +1,30 @@
#ifndef TRUNCATETASK_H_
#define TRUNCATETASK_H_
#include "PosixTask.h"
namespace storagemanager
{
class TruncateTask : public PosixTask
{
public:
TruncateTask(int sock, uint length);
virtual ~TruncateTask();
void run();
private:
TruncateTask();
struct cmd_overlay {
off64_t newSize;
uint flen;
char filename[];
};
};
}
#endif

View File

@@ -0,0 +1,39 @@
#include "UnlinkTask.h"
using namespace std;
namespace storagemanager
{
UnlinkTask::UnlinkTask(int sock, uint len) : PosixTask(sock, len)
{
}
UnlinkTask::~UnlinkTask()
{
}
void UnlinkTask::run()
{
bool success;
uint8_t buf[1024] = {0};
if (getLength() > 1023) {
handleError("UnlinkTask read", ENAMETOOLONG);
return;
}
success = read(buf, getLength());
check_error("UnlinkTask read");
cmd_overlay *cmd = (cmd_overlay *) buf;
// IOC->unlink(cmd->filename);
// generic success msg
uint32_t *buf32 = buf;
buf32[0] = SM_MSG_START;
buf32[1] = 4;
buf32[2] = 0;
write(buf, 12);
}

View File

@@ -0,0 +1,29 @@
#ifndef UNLINKTASK_H_
#define UNLINKTASK_H_
#include "PosixTask.h"
namespace storagemanager
{
class UnlinkTask : public PosixTask
{
public:
UnlinkTask(int sock, uint length);
virtual ~UnlinkTask();
void run();
private:
UnlinkTask();
struct cmd_overlay {
uint flen;
char filename[];
};
};
}
#endif