Commit 3212cc47 authored by unknown's avatar unknown

new parameter BackupDataDir

parent c42ce285
...@@ -90,7 +90,7 @@ ...@@ -90,7 +90,7 @@
#define CFG_DB_LONG_SIGNAL_BUFFER 157 #define CFG_DB_LONG_SIGNAL_BUFFER 157
#define CFG_DB_BACKUP_DATA_PATH 158 #define CFG_DB_BACKUP_DATADIR 158
#define CFG_NODE_ARBIT_RANK 200 #define CFG_NODE_ARBIT_RANK 200
#define CFG_NODE_ARBIT_DELAY 201 #define CFG_NODE_ARBIT_DELAY 201
......
...@@ -89,7 +89,7 @@ static bool fixExtConnection(InitConfigFileParser::Context & ctx, const char * d ...@@ -89,7 +89,7 @@ static bool fixExtConnection(InitConfigFileParser::Context & ctx, const char * d
static bool fixDepricated(InitConfigFileParser::Context & ctx, const char *); static bool fixDepricated(InitConfigFileParser::Context & ctx, const char *);
static bool saveInConfigValues(InitConfigFileParser::Context & ctx, const char *); static bool saveInConfigValues(InitConfigFileParser::Context & ctx, const char *);
static bool fixFileSystemPath(InitConfigFileParser::Context & ctx, const char * data); static bool fixFileSystemPath(InitConfigFileParser::Context & ctx, const char * data);
static bool fixBackupDataPath(InitConfigFileParser::Context & ctx, const char * data); static bool fixBackupDataDir(InitConfigFileParser::Context & ctx, const char * data);
const ConfigInfo::SectionRule const ConfigInfo::SectionRule
ConfigInfo::m_SectionRules[] = { ConfigInfo::m_SectionRules[] = {
...@@ -145,7 +145,7 @@ ConfigInfo::m_SectionRules[] = { ...@@ -145,7 +145,7 @@ ConfigInfo::m_SectionRules[] = {
{ "*", applyDefaultValues, "system" }, { "*", applyDefaultValues, "system" },
{ DB_TOKEN, fixFileSystemPath, 0 }, { DB_TOKEN, fixFileSystemPath, 0 },
{ DB_TOKEN, fixBackupDataPath, 0 }, { DB_TOKEN, fixBackupDataDir, 0 },
{ DB_TOKEN, checkDbConstraints, 0 }, { DB_TOKEN, checkDbConstraints, 0 },
...@@ -1101,8 +1101,8 @@ const ConfigInfo::ParamInfo ConfigInfo::m_ParamInfo[] = { ...@@ -1101,8 +1101,8 @@ const ConfigInfo::ParamInfo ConfigInfo::m_ParamInfo[] = {
"1" }, "1" },
{ {
CFG_DB_BACKUP_DATA_PATH, CFG_DB_BACKUP_DATADIR,
"BackupDataPath", "BackupDataDir",
DB_TOKEN, DB_TOKEN,
"Path to where to store backups", "Path to where to store backups",
ConfigInfo::USED, ConfigInfo::USED,
...@@ -2497,14 +2497,14 @@ fixFileSystemPath(InitConfigFileParser::Context & ctx, const char * data){ ...@@ -2497,14 +2497,14 @@ fixFileSystemPath(InitConfigFileParser::Context & ctx, const char * data){
} }
bool bool
fixBackupDataPath(InitConfigFileParser::Context & ctx, const char * data){ fixBackupDataDir(InitConfigFileParser::Context & ctx, const char * data){
const char * path; const char * path;
if (ctx.m_currentSection->get("BackupDataPath", &path)) if (ctx.m_currentSection->get("BackupDataDir", &path))
return true; return true;
if (ctx.m_currentSection->get("FileSystemPath", &path)) { if (ctx.m_currentSection->get("FileSystemPath", &path)) {
require(ctx.m_currentSection->put("BackupDataPath", path)); require(ctx.m_currentSection->put("BackupDataDir", path));
return true; return true;
} }
......
...@@ -108,8 +108,10 @@ AsyncFile::AsyncFile() : ...@@ -108,8 +108,10 @@ AsyncFile::AsyncFile() :
} }
void void
AsyncFile::doStart(Uint32 nodeId, const char * filesystemPath) { AsyncFile::doStart(Uint32 nodeId,
theFileName.init(nodeId, filesystemPath); const char * filesystemPath,
const char * backup_path) {
theFileName.init(nodeId, filesystemPath, backup_path);
// Stacksize for filesystem threads // Stacksize for filesystem threads
// An 8k stack should be enough // An 8k stack should be enough
......
...@@ -181,7 +181,7 @@ public: ...@@ -181,7 +181,7 @@ public:
void execute( Request* request ); void execute( Request* request );
void doStart(Uint32 nodeId, const char * fspath); void doStart(Uint32 nodeId, const char * fspath, const char * backup_path);
// its a thread so its always running // its a thread so its always running
void run(); void run();
......
...@@ -46,43 +46,31 @@ Filename::Filename() : ...@@ -46,43 +46,31 @@ Filename::Filename() :
} }
void void
Filename::init(Uint32 nodeid, const char * pFileSystemPath){ Filename::init(Uint32 nodeid,
const char * pFileSystemPath,
const char * pBackupDirPath){
DBUG_ENTER("Filename::init");
if (pFileSystemPath == NULL) { if (pFileSystemPath == NULL) {
ERROR_SET(fatal, AFS_ERROR_NOPATH, ""," Filename::init()"); ERROR_SET(fatal, AFS_ERROR_NOPATH, ""," Filename::init()");
return; return;
} }
strncpy(theBaseDirectory, pFileSystemPath, PATH_MAX); snprintf(theFileSystemDirectory, sizeof(theFileSystemDirectory),
"%sndb_%u_fs%s", pFileSystemPath, nodeid, DIR_SEPARATOR);
// the environment variable is set, strncpy(theBackupDirectory, pBackupDirPath, sizeof(theBackupDirectory));
// check that it is pointing on a valid directory
//
char buf2[PATH_MAX]; memset(buf2, 0,sizeof(buf2));
#ifdef NDB_WIN32
char* szFilePart;
if(!GetFullPathName(theBaseDirectory, sizeof(buf2), buf2, &szFilePart)
|| (::GetFileAttributes(theBaseDirectory)&FILE_ATTRIBUTE_READONLY))
#else
if((::realpath(theBaseDirectory, buf2) == NULL)||
(::access(theBaseDirectory, W_OK) != 0))
#endif
{
ERROR_SET(fatal, AFS_ERROR_INVALIDPATH, pFileSystemPath, " Filename::init()");
}
strncpy(theBaseDirectory, buf2, sizeof(theBaseDirectory));
// path seems ok, add delimiter if missing
if (strcmp(&theBaseDirectory[strlen(theBaseDirectory) - 1],
DIR_SEPARATOR) != 0)
strcat(theBaseDirectory, DIR_SEPARATOR);
snprintf(buf2, sizeof(buf2), "ndb_%u_fs%s", nodeid, DIR_SEPARATOR); DBUG_PRINT("info", ("theFileSystemDirectory=%s", theFileSystemDirectory));
strcat(theBaseDirectory, buf2); DBUG_PRINT("info", ("theBackupDirectory=%s", theBackupDirectory));
#ifdef NDB_WIN32 #ifdef NDB_WIN32
CreateDirectory(theBaseDirectory, 0); CreateDirectory(theFileSystemDirectory, 0);
#else #else
mkdir(theBaseDirectory, S_IRUSR | S_IWUSR | S_IXUSR | S_IXGRP | S_IRGRP); mkdir(theFileSystemDirectory, S_IRUSR | S_IWUSR | S_IXUSR | S_IXGRP | S_IRGRP);
#endif #endif
theBaseDirectory= 0;
DBUG_VOID_RETURN;
} }
Filename::~Filename(){ Filename::~Filename(){
...@@ -94,10 +82,16 @@ Filename::set(BlockReference blockReference, ...@@ -94,10 +82,16 @@ Filename::set(BlockReference blockReference,
{ {
char buf[PATH_MAX]; char buf[PATH_MAX];
theLevelDepth = 0; theLevelDepth = 0;
strncpy(theName, theBaseDirectory, PATH_MAX);
const Uint32 type = FsOpenReq::getSuffix(filenumber); const Uint32 type = FsOpenReq::getSuffix(filenumber);
const Uint32 version = FsOpenReq::getVersion(filenumber); const Uint32 version = FsOpenReq::getVersion(filenumber);
if (version == 2)
theBaseDirectory= theBackupDirectory;
else
theBaseDirectory= theFileSystemDirectory;
strncpy(theName, theBaseDirectory, PATH_MAX);
switch(version){ switch(version){
case 1 :{ case 1 :{
const Uint32 diskNo = FsOpenReq::v1_getDisk(filenumber); const Uint32 diskNo = FsOpenReq::v1_getDisk(filenumber);
......
...@@ -68,12 +68,15 @@ public: ...@@ -68,12 +68,15 @@ public:
int levels() const; int levels() const;
const char* c_str() const; const char* c_str() const;
void init(Uint32 nodeid, const char * fileSystemPath); void init(Uint32 nodeid, const char * fileSystemPath,
const char * backupDirPath);
private: private:
int theLevelDepth; int theLevelDepth;
char theName[PATH_MAX]; char theName[PATH_MAX];
char theBaseDirectory[PATH_MAX]; char theFileSystemDirectory[PATH_MAX];
char theBackupDirectory[PATH_MAX];
char *theBaseDirectory;
char theDirectory[PATH_MAX]; char theDirectory[PATH_MAX];
}; };
......
...@@ -58,6 +58,8 @@ Ndbfs::Ndbfs(const Configuration & conf) : ...@@ -58,6 +58,8 @@ Ndbfs::Ndbfs(const Configuration & conf) :
m_maxOpenedFiles(0) m_maxOpenedFiles(0)
{ {
theFileSystemPath = conf.fileSystemPath(); theFileSystemPath = conf.fileSystemPath();
theBackupFilePath = conf.backupFilePath();
theRequestPool = new Pool<Request>; theRequestPool = new Pool<Request>;
const ndb_mgm_configuration_iterator * p = conf.getOwnConfigIterator(); const ndb_mgm_configuration_iterator * p = conf.getOwnConfigIterator();
...@@ -559,7 +561,7 @@ Ndbfs::createAsyncFile(){ ...@@ -559,7 +561,7 @@ Ndbfs::createAsyncFile(){
} }
AsyncFile* file = new AsyncFile; AsyncFile* file = new AsyncFile;
file->doStart(getOwnNodeId(), theFileSystemPath); file->doStart(getOwnNodeId(), theFileSystemPath, theBackupFilePath);
// Put the file in list of all files // Put the file in list of all files
theFiles.push_back(file); theFiles.push_back(file);
......
...@@ -80,6 +80,7 @@ private: ...@@ -80,6 +80,7 @@ private:
Vector<AsyncFile*> theIdleFiles; // List of idle AsyncFiles Vector<AsyncFile*> theIdleFiles; // List of idle AsyncFiles
OpenFiles theOpenFiles; // List of open AsyncFiles OpenFiles theOpenFiles; // List of open AsyncFiles
const char * theFileSystemPath; const char * theFileSystemPath;
const char * theBackupFilePath;
// Statistics variables // Statistics variables
Uint32 m_maxOpenedFiles; Uint32 m_maxOpenedFiles;
......
...@@ -144,6 +144,7 @@ Configuration::Configuration() ...@@ -144,6 +144,7 @@ Configuration::Configuration()
_programName = 0; _programName = 0;
_connectString = 0; _connectString = 0;
_fsPath = 0; _fsPath = 0;
_backupPath = 0;
_initialStart = false; _initialStart = false;
_daemonMode = false; _daemonMode = false;
m_config_retriever= 0; m_config_retriever= 0;
...@@ -156,6 +157,9 @@ Configuration::~Configuration(){ ...@@ -156,6 +157,9 @@ Configuration::~Configuration(){
if(_fsPath != NULL) if(_fsPath != NULL)
free(_fsPath); free(_fsPath);
if(_backupPath != NULL)
free(_backupPath);
if (m_config_retriever) { if (m_config_retriever) {
delete m_config_retriever; delete m_config_retriever;
} }
...@@ -237,8 +241,48 @@ Configuration::fetch_configuration(){ ...@@ -237,8 +241,48 @@ Configuration::fetch_configuration(){
} }
} }
static char * get_and_validate_path(ndb_mgm_configuration_iterator &iter,
Uint32 param, const char *param_string)
{
const char* path = NULL;
if(iter.get(param, &path)){
ERROR_SET(fatal, ERR_INVALID_CONFIG, "Invalid configuration fetched missing ",
param_string);
}
if(path == 0 || strlen(path) == 0){
ERROR_SET(fatal, ERR_INVALID_CONFIG,
"Invalid configuration fetched. Configuration does not contain valid ",
param_string);
}
// check that it is pointing on a valid directory
//
char buf2[PATH_MAX];
memset(buf2, 0,sizeof(buf2));
#ifdef NDB_WIN32
char* szFilePart;
if(!GetFullPathName(path, sizeof(buf2), buf2, &szFilePart)
|| (::GetFileAttributes(alloc_path)&FILE_ATTRIBUTE_READONLY))
#else
if((::realpath(path, buf2) == NULL)||
(::access(buf2, W_OK) != 0))
#endif
{
ERROR_SET(fatal, AFS_ERROR_INVALIDPATH, path, " Filename::init()");
}
if (strcmp(&buf2[strlen(buf2) - 1], DIR_SEPARATOR))
strcat(buf2, DIR_SEPARATOR);
return strdup(buf2);
}
void void
Configuration::setupConfiguration(){ Configuration::setupConfiguration(){
DBUG_ENTER("Configuration::setupConfiguration");
ndb_mgm_configuration * p = m_clusterConfig; ndb_mgm_configuration * p = m_clusterConfig;
/** /**
...@@ -284,28 +328,14 @@ Configuration::setupConfiguration(){ ...@@ -284,28 +328,14 @@ Configuration::setupConfiguration(){
} }
/** /**
* Get filesystem path * Get paths
*/ */
{ if (_fsPath)
const char* pFileSystemPath = NULL; free(_fsPath);
if(iter.get(CFG_DB_FILESYSTEM_PATH, &pFileSystemPath)){ _fsPath= get_and_validate_path(iter, CFG_DB_FILESYSTEM_PATH, "FileSystemPath");
ERROR_SET(fatal, ERR_INVALID_CONFIG, "Invalid configuration fetched", if (_backupPath)
"FileSystemPath missing"); free(_backupPath);
} _backupPath= get_and_validate_path(iter, CFG_DB_BACKUP_DATADIR, "BackupDataDir");
if(pFileSystemPath == 0 || strlen(pFileSystemPath) == 0){
ERROR_SET(fatal, ERR_INVALID_CONFIG, "Invalid configuration fetched",
"Configuration does not contain valid filesystem path");
}
if(pFileSystemPath[strlen(pFileSystemPath) - 1] == '/')
_fsPath = strdup(pFileSystemPath);
else {
_fsPath = (char *)NdbMem_Allocate(strlen(pFileSystemPath) + 2);
strcpy(_fsPath, pFileSystemPath);
strcat(_fsPath, "/");
}
}
if(iter.get(CFG_DB_STOP_ON_ERROR_INSERT, &m_restartOnErrorInsert)){ if(iter.get(CFG_DB_STOP_ON_ERROR_INSERT, &m_restartOnErrorInsert)){
ERROR_SET(fatal, ERR_INVALID_CONFIG, "Invalid configuration fetched", ERROR_SET(fatal, ERR_INVALID_CONFIG, "Invalid configuration fetched",
...@@ -327,6 +357,8 @@ Configuration::setupConfiguration(){ ...@@ -327,6 +357,8 @@ Configuration::setupConfiguration(){
(p, CFG_SECTION_NODE); (p, CFG_SECTION_NODE);
calcSizeAlt(cf); calcSizeAlt(cf);
DBUG_VOID_RETURN;
} }
bool bool
......
...@@ -53,6 +53,7 @@ public: ...@@ -53,6 +53,7 @@ public:
// Cluster configuration // Cluster configuration
const char * programName() const; const char * programName() const;
const char * fileSystemPath() const; const char * fileSystemPath() const;
const char * backupFilePath() const;
char * getConnectStringCopy() const; char * getConnectStringCopy() const;
/** /**
...@@ -89,6 +90,7 @@ private: ...@@ -89,6 +90,7 @@ private:
*/ */
char * _programName; char * _programName;
char * _fsPath; char * _fsPath;
char * _backupPath;
bool _initialStart; bool _initialStart;
char * _connectString; char * _connectString;
bool _daemonMode; bool _daemonMode;
...@@ -108,6 +110,12 @@ Configuration::fileSystemPath() const { ...@@ -108,6 +110,12 @@ Configuration::fileSystemPath() const {
return _fsPath; return _fsPath;
} }
inline
const char *
Configuration::backupFilePath() const {
return _backupPath;
}
inline inline
bool bool
Configuration::getInitialStart() const { Configuration::getInitialStart() const {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment