You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-08-08 14:22:09 +03:00
MCOL-4328 There is a new option in both cpimport and cpimport.bin to asign
an owner for all data files created by cpimport The patch consists of two parts: cpimport.bin changes, cpimport splitter changes cpimport.bin computes uid_t and gid_t early and propagates it down the stack where MCS creates data files
This commit is contained in:
@@ -153,6 +153,7 @@ const int ERR_VB_FILE_NOT_EXIST = ERR_FILEBASE + 17;// Version buffer file n
|
||||
const int ERR_FILE_FLUSH = ERR_FILEBASE + 18;// Error flushing file
|
||||
const int ERR_FILE_GLOBBING = ERR_FILEBASE + 19;// Error globbing a file name
|
||||
const int ERR_FILE_EOF = ERR_FILEBASE + 20;// EOF
|
||||
const int ERR_FILE_CHOWN = ERR_FILEBASE + 21;// EOF
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// XML level error
|
||||
|
@@ -785,10 +785,18 @@ int FileOp::extendFile(
|
||||
|
||||
// if obsolete file exists, "w+b" will truncate and write over
|
||||
pFile = openFile( fileName, "w+b" );//new file
|
||||
|
||||
if (pFile == 0)
|
||||
return ERR_FILE_CREATE;
|
||||
|
||||
{
|
||||
// We presume the path will contain /
|
||||
std::string filePath(fileName);
|
||||
std::ostringstream ossChown;
|
||||
if (chownDataFileDir(ossChown, filePath))
|
||||
return ERR_FILE_CHOWN;
|
||||
}
|
||||
|
||||
|
||||
newFile = true;
|
||||
|
||||
if ( isDebug(DEBUG_1) && getLogger() )
|
||||
@@ -2923,5 +2931,24 @@ void FileOp::setFixFlag(bool isFix)
|
||||
{
|
||||
m_isFix = isFix;
|
||||
}
|
||||
|
||||
bool FileOp::chownDataFileDir(std::ostringstream& error,
|
||||
const std::string& fileName)
|
||||
{
|
||||
std::string dirName = fileName.substr(0, fileName.find_last_of('/'));
|
||||
if (chownFileDir(error, fileName, dirName))
|
||||
{
|
||||
logging::Message::Args args;
|
||||
logging::Message message(1);
|
||||
args.add(error.str());
|
||||
message.format(args);
|
||||
logging::LoggingID lid(SUBSYSTEM_ID_WE_BULK);
|
||||
logging::MessageLog ml(lid);
|
||||
ml.logErrorMessage( message );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} //end of namespace
|
||||
|
||||
|
@@ -59,7 +59,7 @@ namespace WriteEngine
|
||||
{
|
||||
|
||||
/** Class FileOp */
|
||||
class FileOp : public BlockOp
|
||||
class FileOp : public BlockOp, public WeUIDGID
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -502,6 +502,10 @@ public:
|
||||
bool bAbbrevExtent,
|
||||
bool bOptExtension=false );
|
||||
|
||||
// Calls a chown and logs an error message
|
||||
bool chownDataFileDir(std::ostringstream& error,
|
||||
const std::string& fileName);
|
||||
|
||||
protected:
|
||||
EXPORT virtual int updateColumnExtent(IDBDataFile* pFile, int nBlocks);
|
||||
EXPORT virtual int updateDctnryExtent(IDBDataFile* pFile, int nBlocks);
|
||||
|
@@ -452,6 +452,12 @@ std::string RBMetaWriter::openMetaFile ( uint16_t dbRoot )
|
||||
throw WeException( oss.str(), ERR_FILE_OPEN );
|
||||
}
|
||||
|
||||
{
|
||||
std::ostringstream ossChown;
|
||||
if (chownFileDir(ossChown, tmpMetaFileName, bulkRollbackPath))
|
||||
throw WeException(ossChown.str(), ERR_FILE_CHOWN);
|
||||
}
|
||||
|
||||
fMetaDataStream <<
|
||||
"# VERSION: 4" << std::endl <<
|
||||
"# APPLICATION: " << fAppDesc << std::endl <<
|
||||
@@ -1196,6 +1202,7 @@ int RBMetaWriter::writeHWMChunk(
|
||||
std::ostringstream ossFile;
|
||||
ossFile << "/" << columnOID << ".p" << partition << ".s" << segment;
|
||||
std::string fileName;
|
||||
std::string dirPath;
|
||||
int rc = getSubDirPath( dbRoot, fileName );
|
||||
|
||||
if (rc != NO_ERROR)
|
||||
@@ -1207,6 +1214,8 @@ int RBMetaWriter::writeHWMChunk(
|
||||
return ERR_METADATABKUP_COMP_OPEN_BULK_BKUP;
|
||||
}
|
||||
|
||||
dirPath = fileName;
|
||||
|
||||
fileName += ossFile.str();
|
||||
|
||||
std::string fileNameTmp = fileName;
|
||||
@@ -1325,9 +1334,14 @@ int RBMetaWriter::writeHWMChunk(
|
||||
return ERR_METADATABKUP_COMP_RENAME;
|
||||
}
|
||||
|
||||
{
|
||||
std::ostringstream ossChown;
|
||||
if (chownFileDir(ossChown, fileName, dirPath))
|
||||
throw WeException(ossChown.str(), ERR_FILE_CHOWN);
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Returns the directory path to be used for storing any backup data files.
|
||||
//
|
||||
|
@@ -136,7 +136,7 @@ typedef std::set< RBChunkInfo, RBChunkInfoCompare > RBChunkSet;
|
||||
* parallel by several threads for different dictionary columns.
|
||||
*/
|
||||
//------------------------------------------------------------------------------
|
||||
class RBMetaWriter
|
||||
class RBMetaWriter: public WeUIDGID
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -229,7 +229,7 @@ public:
|
||||
|
||||
/** @brief Verify that specified record type is a DStore2 record */
|
||||
static bool verifyDStore2Rec(const char* recType);
|
||||
|
||||
|
||||
private:
|
||||
// disable copy constructor and assignment operator
|
||||
RBMetaWriter(const RBMetaWriter&);
|
||||
|
@@ -30,6 +30,8 @@
|
||||
#define _WE_TYPEEXT_H_
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <pwd.h>
|
||||
#include <sstream>
|
||||
|
||||
/** Namespace WriteEngine */
|
||||
namespace WriteEngine
|
||||
@@ -55,6 +57,53 @@ struct Token
|
||||
}
|
||||
};
|
||||
|
||||
constexpr uid_t UID_NONE = (uid_t) -1;
|
||||
constexpr gid_t GID_NONE = (gid_t) -1;
|
||||
|
||||
class WeUIDGID
|
||||
{
|
||||
public:
|
||||
WeUIDGID(): uid(UID_NONE), gid(GID_NONE) {}
|
||||
virtual ~WeUIDGID() {};
|
||||
virtual void setUIDGID(const uid_t uid, const gid_t gid);
|
||||
void setUIDGID(const WeUIDGID* id);
|
||||
bool chownFileDir(std::ostringstream& error,
|
||||
const std::string& fileName, const std::string& dirName) const;
|
||||
;
|
||||
|
||||
private:
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
};
|
||||
|
||||
inline void WeUIDGID::setUIDGID(const uid_t p_uid, const gid_t p_gid)
|
||||
{
|
||||
uid = p_uid; gid = p_gid;
|
||||
}
|
||||
|
||||
inline void WeUIDGID::setUIDGID(const WeUIDGID* id)
|
||||
{
|
||||
if (id->uid != UID_NONE)
|
||||
*this = *id;
|
||||
}
|
||||
|
||||
inline bool WeUIDGID::chownFileDir(std::ostringstream& error,
|
||||
const std::string& fileName, const std::string& dirName) const
|
||||
{
|
||||
if (uid != UID_NONE)
|
||||
{
|
||||
errno = 0;
|
||||
if (chown(fileName.c_str(), uid, gid) == -1 ||
|
||||
chown(dirName.c_str(), uid, gid) == -1)
|
||||
{
|
||||
error << "Error calling chown() with uid " << uid
|
||||
<< " and gid " << gid << " with the file "
|
||||
<< fileName << " with errno " << errno;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} //end of namespace
|
||||
|
||||
|
Reference in New Issue
Block a user