You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-30 19:23:07 +03:00
clang format apply
This commit is contained in:
@ -15,7 +15,6 @@
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
|
||||
#include "WriteTask.h"
|
||||
#include "messageFormat.h"
|
||||
#include "IOCoordinator.h"
|
||||
@ -26,7 +25,6 @@ using namespace std;
|
||||
|
||||
namespace storagemanager
|
||||
{
|
||||
|
||||
WriteTask::WriteTask(int sock, uint len) : PosixTask(sock, len)
|
||||
{
|
||||
}
|
||||
@ -36,85 +34,85 @@ WriteTask::~WriteTask()
|
||||
}
|
||||
|
||||
#define check_error(msg, ret) \
|
||||
if (success<0) \
|
||||
{ \
|
||||
handleError(msg, errno); \
|
||||
return ret; \
|
||||
}
|
||||
if (success < 0) \
|
||||
{ \
|
||||
handleError(msg, errno); \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
#define min(x, y) (x < y ? x : y)
|
||||
|
||||
bool WriteTask::run()
|
||||
{
|
||||
SMLogging* logger = SMLogging::get();
|
||||
int success;
|
||||
uint8_t cmdbuf[1024] = {0};
|
||||
|
||||
success = read(cmdbuf, sizeof(write_cmd));
|
||||
check_error("WriteTask read", false);
|
||||
write_cmd *cmd = (write_cmd *) cmdbuf;
|
||||
|
||||
if (cmd->flen > 1023 - sizeof(*cmd))
|
||||
{
|
||||
handleError("WriteTask", ENAMETOOLONG);
|
||||
return true;
|
||||
}
|
||||
success = read(&cmdbuf[sizeof(*cmd)], cmd->flen);
|
||||
check_error("WriteTask read", false);
|
||||
|
||||
#ifdef SM_TRACE
|
||||
logger->log(LOG_DEBUG,"write filename %s offset %i count %i.",cmd->filename,cmd->offset,cmd->count);
|
||||
#endif
|
||||
|
||||
ssize_t readCount = 0, writeCount = 0;
|
||||
vector<uint8_t> databuf;
|
||||
uint bufsize = min(100 << 20, cmd->count); // 100 MB
|
||||
//uint bufsize = cmd->count;
|
||||
databuf.resize(bufsize);
|
||||
SMLogging* logger = SMLogging::get();
|
||||
int success;
|
||||
uint8_t cmdbuf[1024] = {0};
|
||||
|
||||
while (readCount < cmd->count)
|
||||
success = read(cmdbuf, sizeof(write_cmd));
|
||||
check_error("WriteTask read", false);
|
||||
write_cmd* cmd = (write_cmd*)cmdbuf;
|
||||
|
||||
if (cmd->flen > 1023 - sizeof(*cmd))
|
||||
{
|
||||
handleError("WriteTask", ENAMETOOLONG);
|
||||
return true;
|
||||
}
|
||||
success = read(&cmdbuf[sizeof(*cmd)], cmd->flen);
|
||||
check_error("WriteTask read", false);
|
||||
|
||||
#ifdef SM_TRACE
|
||||
logger->log(LOG_DEBUG, "write filename %s offset %i count %i.", cmd->filename, cmd->offset, cmd->count);
|
||||
#endif
|
||||
|
||||
ssize_t readCount = 0, writeCount = 0;
|
||||
vector<uint8_t> databuf;
|
||||
uint bufsize = min(100 << 20, cmd->count); // 100 MB
|
||||
// uint bufsize = cmd->count;
|
||||
databuf.resize(bufsize);
|
||||
|
||||
while (readCount < cmd->count)
|
||||
{
|
||||
uint toRead = min(static_cast<uint>(cmd->count - readCount), bufsize);
|
||||
success = read(&databuf[0], toRead);
|
||||
check_error("WriteTask read data", false);
|
||||
if (success == 0)
|
||||
break;
|
||||
readCount += success;
|
||||
uint writePos = 0;
|
||||
ssize_t err;
|
||||
while (writeCount < readCount)
|
||||
{
|
||||
uint toRead = min(static_cast<uint>(cmd->count - readCount), bufsize);
|
||||
success = read(&databuf[0], toRead);
|
||||
check_error("WriteTask read data", false);
|
||||
if (success==0)
|
||||
break;
|
||||
readCount += success;
|
||||
uint writePos = 0;
|
||||
ssize_t err;
|
||||
while (writeCount < readCount)
|
||||
{
|
||||
try
|
||||
{
|
||||
err = ioc->write(cmd->filename, &databuf[writePos], cmd->offset + writeCount, success - writePos);
|
||||
}
|
||||
catch (exception &e)
|
||||
{
|
||||
logger->log(LOG_ERR, "WriteTask: caught '%s'", e.what());
|
||||
errno = EIO;
|
||||
err = -1;
|
||||
}
|
||||
if (err <= 0)
|
||||
break;
|
||||
writeCount += err;
|
||||
writePos += err;
|
||||
}
|
||||
if (writeCount != readCount)
|
||||
break;
|
||||
try
|
||||
{
|
||||
err = ioc->write(cmd->filename, &databuf[writePos], cmd->offset + writeCount, success - writePos);
|
||||
}
|
||||
catch (exception& e)
|
||||
{
|
||||
logger->log(LOG_ERR, "WriteTask: caught '%s'", e.what());
|
||||
errno = EIO;
|
||||
err = -1;
|
||||
}
|
||||
if (err <= 0)
|
||||
break;
|
||||
writeCount += err;
|
||||
writePos += err;
|
||||
}
|
||||
|
||||
uint8_t respbuf[sizeof(sm_response) + 4];
|
||||
sm_response *resp = (sm_response *) respbuf;
|
||||
uint payloadLen = 0;
|
||||
if (cmd->count != 0 && writeCount == 0)
|
||||
{
|
||||
payloadLen = 4;
|
||||
resp->returnCode = -1;
|
||||
*((int *) &resp[1]) = errno;
|
||||
}
|
||||
else
|
||||
resp->returnCode = writeCount;
|
||||
return write(*resp, payloadLen);
|
||||
if (writeCount != readCount)
|
||||
break;
|
||||
}
|
||||
|
||||
uint8_t respbuf[sizeof(sm_response) + 4];
|
||||
sm_response* resp = (sm_response*)respbuf;
|
||||
uint payloadLen = 0;
|
||||
if (cmd->count != 0 && writeCount == 0)
|
||||
{
|
||||
payloadLen = 4;
|
||||
resp->returnCode = -1;
|
||||
*((int*)&resp[1]) = errno;
|
||||
}
|
||||
else
|
||||
resp->returnCode = writeCount;
|
||||
return write(*resp, payloadLen);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace storagemanager
|
||||
|
Reference in New Issue
Block a user