You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-08-05 16:15:50 +03:00
Relocating everything in the repo s.t. it can be merged into
the columnstore repo.
This commit is contained in:
86
storage-manager/src/TruncateTask.cpp
Normal file
86
storage-manager/src/TruncateTask.cpp
Normal file
@@ -0,0 +1,86 @@
|
||||
/* Copyright (C) 2019 MariaDB Corporation
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
|
||||
#include "TruncateTask.h"
|
||||
#include <errno.h>
|
||||
#include "messageFormat.h"
|
||||
#include "SMLogging.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace storagemanager
|
||||
{
|
||||
|
||||
TruncateTask::TruncateTask(int sock, uint len) : PosixTask(sock, len)
|
||||
{
|
||||
}
|
||||
|
||||
TruncateTask::~TruncateTask()
|
||||
{
|
||||
}
|
||||
|
||||
#define check_error(msg, ret) \
|
||||
if (!success) \
|
||||
{ \
|
||||
handleError(msg, errno); \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
bool TruncateTask::run()
|
||||
{
|
||||
SMLogging* logger = SMLogging::get();
|
||||
bool success;
|
||||
uint8_t buf[1024] = {0};
|
||||
|
||||
if (getLength() > 1023) {
|
||||
handleError("TruncateTask read", ENAMETOOLONG);
|
||||
return false;
|
||||
}
|
||||
|
||||
success = read(buf, getLength());
|
||||
check_error("TruncateTask read", false);
|
||||
truncate_cmd *cmd = (truncate_cmd *) buf;
|
||||
|
||||
#ifdef SM_TRACE
|
||||
logger->log(LOG_DEBUG,"truncate %s newlength %i.",cmd->filename,cmd->length);
|
||||
#endif
|
||||
int err;
|
||||
|
||||
try
|
||||
{
|
||||
err = ioc->truncate(cmd->filename, cmd->length);
|
||||
}
|
||||
catch (exception &e)
|
||||
{
|
||||
logger->log(LOG_DEBUG, "TruncateTask: caught '%s'", e.what());
|
||||
errno = EIO;
|
||||
err = -1;
|
||||
}
|
||||
if (err)
|
||||
{
|
||||
handleError("TruncateTask truncate", errno);
|
||||
return true;
|
||||
}
|
||||
|
||||
sm_response *resp = (sm_response *) buf;
|
||||
resp->returnCode = 0;
|
||||
success = write(*resp, 0);
|
||||
return success;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user