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-892 - changed from using the flock command
This commit is contained in:
2
VERSION
2
VERSION
@@ -1,4 +1,4 @@
|
||||
COLUMNSTORE_VERSION_MAJOR=1
|
||||
COLUMNSTORE_VERSION_MINOR=0
|
||||
COLUMNSTORE_VERSION_PATCH=11
|
||||
COLUMNSTORE_VERSION_RELEASE=1
|
||||
COLUMNSTORE_VERSION_RELEASE=2
|
||||
|
@@ -2523,6 +2523,9 @@ namespace oam
|
||||
string Section = "AlarmConfig";
|
||||
int returnValue;
|
||||
|
||||
struct flock fl;
|
||||
int fd;
|
||||
|
||||
// validate Alarm ID
|
||||
|
||||
if( alarmid > MAX_ALARM_ID )
|
||||
@@ -2544,11 +2547,24 @@ namespace oam
|
||||
|
||||
string fileName = AlarmConfigFile;
|
||||
|
||||
int fd = open(fileName.c_str(), O_RDWR|O_CREAT, 0644);
|
||||
memset(&fl, 0, sizeof(fl));
|
||||
fl.l_type = F_RDLCK; // read lock
|
||||
fl.l_whence = SEEK_SET;
|
||||
fl.l_start = 0;
|
||||
fl.l_len = 0; //lock whole file
|
||||
|
||||
// Aquire an exclusive lock
|
||||
if (flock(fd,LOCK_EX) == -1) {
|
||||
throw runtime_error ("Lock file error: " + fileName);
|
||||
// open config file
|
||||
if ((fd = open(fileName.c_str(), O_RDWR)) >= 0)
|
||||
{ // lock file
|
||||
if (fcntl(fd, F_SETLKW, &fl) != 0)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Oam::setAlarmConfig: error locking file " <<
|
||||
fileName <<
|
||||
": " <<
|
||||
strerror(errno) <<
|
||||
", proceding anyway.";
|
||||
cerr << oss.str() << endl;
|
||||
}
|
||||
|
||||
// write parameter to disk
|
||||
@@ -2561,24 +2577,25 @@ namespace oam
|
||||
alaConfig->write();
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
// Release lock
|
||||
if (flock(fd,LOCK_UN)==-1)
|
||||
{
|
||||
throw runtime_error ("Release lock file error: " + fileName);
|
||||
}
|
||||
{}
|
||||
|
||||
exceptionControl("setAlarmConfig", API_FAILURE);
|
||||
}
|
||||
|
||||
// Release lock
|
||||
if (flock(fd,LOCK_UN)==-1)
|
||||
{
|
||||
throw runtime_error ("Release lock file error: " + fileName);
|
||||
}
|
||||
fl.l_type = F_UNLCK; //unlock
|
||||
fcntl(fd, F_SETLK, &fl);
|
||||
|
||||
close(fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Oam::setAlarmConfig: error opening file " <<
|
||||
fileName <<
|
||||
": " <<
|
||||
strerror(errno);
|
||||
throw runtime_error(oss.str());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/********************************************************************
|
||||
*
|
||||
|
@@ -97,6 +97,9 @@ ALARMManager::~ALARMManager()
|
||||
*****************************************************************************************/
|
||||
void rewriteActiveLog (const AlarmList& alarmList)
|
||||
{
|
||||
struct flock fl;
|
||||
int fd;
|
||||
|
||||
if (ALARM_DEBUG) {
|
||||
LoggingID lid(11);
|
||||
MessageLog ml(lid);
|
||||
@@ -110,12 +113,24 @@ void rewriteActiveLog (const AlarmList& alarmList)
|
||||
// delete the old file
|
||||
unlink (ACTIVE_ALARM_FILE.c_str());
|
||||
|
||||
// create new file
|
||||
int fd = open(ACTIVE_ALARM_FILE.c_str(), O_RDWR|O_CREAT, 0644);
|
||||
memset(&fl, 0, sizeof(fl));
|
||||
fl.l_type = F_RDLCK; // read lock
|
||||
fl.l_whence = SEEK_SET;
|
||||
fl.l_start = 0;
|
||||
fl.l_len = 0; //lock whole file
|
||||
|
||||
// Aquire an exclusive lock
|
||||
if (flock(fd,LOCK_EX) == -1) {
|
||||
throw runtime_error ("Lock active alarm log file error");
|
||||
// create new file
|
||||
if ((fd = open(ACTIVE_ALARM_FILE.c_str(), O_RDWR|O_CREAT, 0664)) >= 0)
|
||||
{ // lock file
|
||||
if (fcntl(fd, F_SETLKW, &fl) != 0)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "rewriteActiveLog: error locking file " <<
|
||||
ACTIVE_ALARM_FILE <<
|
||||
": " <<
|
||||
strerror(errno) <<
|
||||
", proceding anyway.";
|
||||
cerr << oss.str() << endl;
|
||||
}
|
||||
|
||||
ofstream activeAlarmFile (ACTIVE_ALARM_FILE.c_str());
|
||||
@@ -128,13 +143,23 @@ void rewriteActiveLog (const AlarmList& alarmList)
|
||||
|
||||
activeAlarmFile.close();
|
||||
|
||||
// Release lock
|
||||
if (flock(fd,LOCK_UN)==-1)
|
||||
{
|
||||
throw runtime_error ("Release lock active alarm log file error");
|
||||
}
|
||||
fl.l_type = F_UNLCK; //unlock
|
||||
fcntl(fd, F_SETLK, &fl);
|
||||
|
||||
close(fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "rewriteActiveLog: error opening file " <<
|
||||
ACTIVE_ALARM_FILE <<
|
||||
": " <<
|
||||
strerror(errno);
|
||||
throw runtime_error(oss.str());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*****************************************************************************************
|
||||
* @brief logAlarm
|
||||
@@ -144,6 +169,9 @@ void rewriteActiveLog (const AlarmList& alarmList)
|
||||
*****************************************************************************************/
|
||||
void logAlarm (const Alarm& calAlarm, const string& fileName)
|
||||
{
|
||||
struct flock fl;
|
||||
int fd;
|
||||
|
||||
if (ALARM_DEBUG) {
|
||||
LoggingID lid(11);
|
||||
MessageLog ml(lid);
|
||||
@@ -154,25 +182,49 @@ void logAlarm (const Alarm& calAlarm, const string& fileName)
|
||||
ml.logDebugMessage(msg);
|
||||
}
|
||||
|
||||
int fd = open(fileName.c_str(), O_RDWR|O_CREAT, 0644);
|
||||
ofstream AlarmFile (fileName.c_str(), ios::app);
|
||||
memset(&fl, 0, sizeof(fl));
|
||||
fl.l_type = F_RDLCK; // read lock
|
||||
fl.l_whence = SEEK_SET;
|
||||
fl.l_start = 0;
|
||||
fl.l_len = 0; //lock whole file
|
||||
|
||||
// Aquire an exclusive lock
|
||||
if (flock(fd,LOCK_EX) == -1) {
|
||||
throw runtime_error ("Lock file error: " + fileName);
|
||||
// create new file
|
||||
if ((fd = open(fileName.c_str(), O_RDWR|O_CREAT, 0664)) >= 0)
|
||||
{ // lock file
|
||||
if (fcntl(fd, F_SETLKW, &fl) != 0)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "logAlarm: error locking file " <<
|
||||
fileName <<
|
||||
": " <<
|
||||
strerror(errno) <<
|
||||
", proceding anyway.";
|
||||
cerr << oss.str() << endl;
|
||||
}
|
||||
|
||||
ofstream AlarmFile (fileName.c_str(), ios::app);
|
||||
|
||||
AlarmFile << calAlarm;
|
||||
AlarmFile.close();
|
||||
|
||||
// Release lock
|
||||
if (flock(fd,LOCK_UN)==-1)
|
||||
{
|
||||
throw runtime_error ("Release lock file error: " + fileName);
|
||||
}
|
||||
fl.l_type = F_UNLCK; //unlock
|
||||
fcntl(fd, F_SETLK, &fl);
|
||||
|
||||
close(fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "logAlarm: error opening file " <<
|
||||
fileName <<
|
||||
": " <<
|
||||
strerror(errno);
|
||||
throw runtime_error(oss.str());
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
/*****************************************************************************************
|
||||
* @brief processAlarm
|
||||
@@ -323,7 +375,6 @@ void configAlarm (Alarm& calAlarm)
|
||||
oam.setAlarmConfig (alarmID, "LastIssueTime", now);
|
||||
oam.setAlarmConfig (alarmID, "Occurrences", 1);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
// increment counter and check the ctnThreshold
|
||||
@@ -475,30 +526,35 @@ void ALARMManager::sendAlarmReport (const char* componentID, int alarmID, int st
|
||||
*****************************************************************************************/
|
||||
void ALARMManager::getActiveAlarm(AlarmList& alarmList) const
|
||||
{
|
||||
struct flock fl;
|
||||
int fd;
|
||||
|
||||
//add-on to fileName with mount name if on non Parent Module
|
||||
Oam oam;
|
||||
string fileName = ACTIVE_ALARM_FILE;
|
||||
|
||||
int fd = open(fileName.c_str(),O_RDONLY);
|
||||
memset(&fl, 0, sizeof(fl));
|
||||
fl.l_type = F_RDLCK; // read lock
|
||||
fl.l_whence = SEEK_SET;
|
||||
fl.l_start = 0;
|
||||
fl.l_len = 0; //lock whole file
|
||||
|
||||
if (fd == -1) {
|
||||
// file may being deleted temporarily by trapHandler
|
||||
sleep (1);
|
||||
fd = open(fileName.c_str(),O_RDONLY);
|
||||
if (fd == -1) {
|
||||
// no active alarms, return
|
||||
return;
|
||||
}
|
||||
// create new file
|
||||
if (fd = open(fileName.c_str(),O_RDONLY) >= 0)
|
||||
{ // lock file
|
||||
if (fcntl(fd, F_SETLKW, &fl) != 0)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "getActiveAlarm: error locking file " <<
|
||||
fileName <<
|
||||
": " <<
|
||||
strerror(errno) <<
|
||||
", proceding anyway.";
|
||||
cerr << oss.str() << endl;
|
||||
}
|
||||
|
||||
ifstream activeAlarm (fileName.c_str(), ios::in);
|
||||
|
||||
// acquire read lock
|
||||
if (flock(fd,LOCK_SH) == -1)
|
||||
{
|
||||
throw runtime_error ("Lock active alarm log file error");
|
||||
}
|
||||
|
||||
Alarm alarm;
|
||||
|
||||
while (!activeAlarm.eof())
|
||||
@@ -511,11 +567,8 @@ void ALARMManager::getActiveAlarm(AlarmList& alarmList) const
|
||||
}
|
||||
activeAlarm.close();
|
||||
|
||||
// release lock
|
||||
if (flock(fd,LOCK_UN) == -1)
|
||||
{
|
||||
throw runtime_error ("Release lock active alarm log file error");
|
||||
}
|
||||
fl.l_type = F_UNLCK; //unlock
|
||||
fcntl(fd, F_SETLK, &fl);
|
||||
|
||||
close(fd);
|
||||
|
||||
@@ -527,6 +580,8 @@ void ALARMManager::getActiveAlarm(AlarmList& alarmList) const
|
||||
cout << i->second << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -540,6 +595,9 @@ void ALARMManager::getActiveAlarm(AlarmList& alarmList) const
|
||||
*****************************************************************************************/
|
||||
void ALARMManager::getAlarm(std::string date, AlarmList& alarmList) const
|
||||
{
|
||||
struct flock fl;
|
||||
int fd;
|
||||
|
||||
string alarmFile = "/tmp/alarms";
|
||||
|
||||
//make 1 alarm log file made up of archive and current alarm.log
|
||||
@@ -568,20 +626,28 @@ void ALARMManager::getAlarm(std::string date, AlarmList& alarmList) const
|
||||
cmd = "cat " + ALARM_FILE + " >> /tmp/alarms";
|
||||
(void)system(cmd.c_str());
|
||||
|
||||
int fd = open(alarmFile.c_str(),O_RDONLY);
|
||||
memset(&fl, 0, sizeof(fl));
|
||||
fl.l_type = F_RDLCK; // read lock
|
||||
fl.l_whence = SEEK_SET;
|
||||
fl.l_start = 0;
|
||||
fl.l_len = 0; //lock whole file
|
||||
|
||||
if (fd == -1)
|
||||
// doesn't exist yet, return
|
||||
return;
|
||||
// create new file
|
||||
if (fd = open(alarmFile.c_str(),O_RDONLY) >= 0)
|
||||
{ // lock file
|
||||
if (fcntl(fd, F_SETLKW, &fl) != 0)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "getAlarm: error locking file " <<
|
||||
alarmFile <<
|
||||
": " <<
|
||||
strerror(errno) <<
|
||||
", proceding anyway.";
|
||||
cerr << oss.str() << endl;
|
||||
}
|
||||
|
||||
ifstream hisAlarm (alarmFile.c_str(), ios::in);
|
||||
|
||||
// acquire read lock
|
||||
if (flock(fd,LOCK_SH) == -1)
|
||||
{
|
||||
throw runtime_error ("Lock alarm log file error");
|
||||
}
|
||||
|
||||
//get mm / dd / yy from incoming date
|
||||
string mm = date.substr(0,2);
|
||||
string dd = date.substr(3,2);
|
||||
@@ -616,11 +682,9 @@ void ALARMManager::getAlarm(std::string date, AlarmList& alarmList) const
|
||||
hisAlarm.close();
|
||||
unlink (alarmFile.c_str());
|
||||
|
||||
// release lock
|
||||
if (flock(fd,LOCK_UN) == -1)
|
||||
{
|
||||
throw runtime_error ("Release lock active alarm log file error");
|
||||
}
|
||||
fl.l_type = F_UNLCK; //unlock
|
||||
fcntl(fd, F_SETLK, &fl);
|
||||
|
||||
|
||||
if (ALARM_DEBUG)
|
||||
{
|
||||
@@ -630,6 +694,11 @@ void ALARMManager::getAlarm(std::string date, AlarmList& alarmList) const
|
||||
cout << i->second << endl;
|
||||
}
|
||||
}
|
||||
|
||||
close(fd);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
} //namespace alarmmanager
|
||||
|
@@ -2840,6 +2840,8 @@ int ProcessMonitor::updateLog(std::string action, std::string level)
|
||||
{
|
||||
MonitorLog log;
|
||||
Oam oam;
|
||||
struct flock fl;
|
||||
int fd;
|
||||
|
||||
string fileName;
|
||||
oam.getSystemConfig("SystemLogConfigFile", fileName);
|
||||
@@ -3080,30 +3082,47 @@ int ProcessMonitor::updateLog(std::string action, std::string level)
|
||||
unlink (fileName.c_str());
|
||||
ofstream newFile (fileName.c_str());
|
||||
|
||||
// create new file
|
||||
int fd = open(fileName.c_str(),O_RDWR|O_CREAT, 0644);
|
||||
memset(&fl, 0, sizeof(fl));
|
||||
fl.l_type = F_RDLCK; // read lock
|
||||
fl.l_whence = SEEK_SET;
|
||||
fl.l_start = 0;
|
||||
fl.l_len = 0; //lock whole file
|
||||
|
||||
// Aquire an exclusive lock
|
||||
if (flock(fd,LOCK_EX) == -1) {
|
||||
log.writeLog(__LINE__, "ERROR: file lock failure on " + fileName, LOG_TYPE_ERROR );
|
||||
close(fd);
|
||||
return -1;
|
||||
// create new file
|
||||
if ((fd = open(fileName.c_str(), O_RDWR|O_CREAT, 0644)) >= 0)
|
||||
{ // lock file
|
||||
|
||||
if (fcntl(fd, F_SETLKW, &fl) != 0)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "ProcessMonitor::updateLog: error locking file " <<
|
||||
fileName <<
|
||||
": " <<
|
||||
strerror(errno) <<
|
||||
", proceding anyway.";
|
||||
cerr << oss.str() << endl;
|
||||
}
|
||||
|
||||
copy(lines.begin(), lines.end(), ostream_iterator<string>(newFile, "\n"));
|
||||
newFile.close();
|
||||
|
||||
// Release lock
|
||||
if (flock(fd,LOCK_UN) == -1)
|
||||
{
|
||||
log.writeLog(__LINE__, "ERROR: file unlock failure on " + fileName, LOG_TYPE_ERROR );
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
fl.l_type = F_UNLCK; //unlock
|
||||
fcntl(fd, F_SETLK, &fl);
|
||||
|
||||
close(fd);
|
||||
|
||||
oam.syslogAction("restart");
|
||||
}
|
||||
else
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "ProcessMonitor::updateLog: error opening file " <<
|
||||
fileName <<
|
||||
": " <<
|
||||
strerror(errno);
|
||||
throw runtime_error(oss.str());
|
||||
}
|
||||
}
|
||||
|
||||
//update file priviledges
|
||||
changeModLog();
|
||||
|
Reference in New Issue
Block a user