1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-12-18 13:54:11 +03:00

Logging to syslog instead of cout/printf

This commit is contained in:
Ben Thompson
2019-02-14 10:50:22 -06:00
parent 17aba1a272
commit 83a6e77278
14 changed files with 59 additions and 53 deletions

View File

@@ -44,7 +44,7 @@ bool AppendTask::run()
check_error("AppendTask read", false); check_error("AppendTask read", false);
#ifdef SM_TRACE #ifdef SM_TRACE
cout << "append " << cmd->count << " bytes to " << cmd->filename << endl; syslog(LOG_DEBUG, "append %d bytes to %s.",cmd->count,cmd->filename);
#endif #endif
size_t readCount = 0, writeCount = 0; size_t readCount = 0, writeCount = 0;

3
src/CopyTask.cpp Normal file → Executable file
View File

@@ -1,6 +1,7 @@
#include "CopyTask.h" #include "CopyTask.h"
#include <errno.h> #include <errno.h>
#include "syslog.h"
#include "messageFormat.h" #include "messageFormat.h"
using namespace std; using namespace std;
@@ -41,7 +42,7 @@ bool CopyTask::run()
f_name *filename2 = (f_name *) &buf[sizeof(copy_cmd) + cmd->file1.flen]; f_name *filename2 = (f_name *) &buf[sizeof(copy_cmd) + cmd->file1.flen];
#ifdef SM_TRACE #ifdef SM_TRACE
cout << "copy " << filename1 << " to " << filename2 << endl; syslog(LOG_DEBUG, "copy %s to %s.",filename1,filename2);
#endif #endif
int err = ioc->copyFile(filename1.c_str(), filename2->filename); int err = ioc->copyFile(filename1.c_str(), filename2->filename);

View File

@@ -3,6 +3,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <syslog.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
@@ -199,7 +200,7 @@ int IOCoordinator::copyFile(const char *filename1, const char *filename2)
l_errno = e.code().value(); // why not. l_errno = e.code().value(); // why not.
// eh, not going to translate all of boost's errors into our errors for this. // eh, not going to translate all of boost's errors into our errors for this.
// log the error // log the error
cout << "IOCoordinator::copy(): got " << e.what() << endl; syslog(LOG_ERR, "IOCoordinator::copy(): got %s",e.what());
} }
catch (...) { catch (...) {
err = -1; err = -1;

View File

@@ -71,7 +71,7 @@ bool ListDirectoryTask::run()
listdir_cmd *cmd = (listdir_cmd *) buf; listdir_cmd *cmd = (listdir_cmd *) buf;
#ifdef SM_TRACE #ifdef SM_TRACE
cout << "list_directory " << cmd->path << endl; syslog(LOG_DEBUG, "list_directory %s.",cmd->path);
#endif #endif
vector<string> listing; vector<string> listing;

View File

@@ -45,7 +45,7 @@ bool OpenTask::run()
open_cmd *cmd = (open_cmd *) buf; open_cmd *cmd = (open_cmd *) buf;
#ifdef SM_TRACE #ifdef SM_TRACE
cout << "open filename " << cmd->filename << " mode " << oct << cmd->openmode << dec << endl; syslog(LOG_DEBUG, "open filename %s mode %o.",cmd->filename,cmd->openmode);
#endif #endif
sm_response *resp = (sm_response *) buf; sm_response *resp = (sm_response *) buf;
int err = ioc->open(cmd->filename, cmd->openmode, (struct stat *) &resp->payload); int err = ioc->open(cmd->filename, cmd->openmode, (struct stat *) &resp->payload);

View File

@@ -4,6 +4,7 @@
#include <iostream> #include <iostream>
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <syslog.h>
#include <string.h> #include <string.h>
#define min(x, y) (x < y ? x : y) #define min(x, y) (x < y ? x : y)
@@ -42,7 +43,7 @@ void PosixTask::handleError(const char *name, int errCode)
write(*resp, 4); write(*resp, 4);
// TODO: construct and log a message // TODO: construct and log a message
cout << name << " caught an error: " << strerror_r(errCode, buf, 80) << endl; syslog(LOG_ERR, "%s caught an error: %s.",name,strerror_r(errCode, buf, 80));
} }
uint PosixTask::getRemainingLength() uint PosixTask::getRemainingLength()
@@ -186,7 +187,7 @@ void PosixTask::consumeMsg()
while (remainingLengthInStream > 0) while (remainingLengthInStream > 0)
{ {
cout << "ERROR: eating data" << endl; syslog(LOG_ERR, "ERROR: eating data.");
err = ::recv(sock, buf, min(remainingLengthInStream, 1024), 0); err = ::recv(sock, buf, min(remainingLengthInStream, 1024), 0);
if (err <= 0) { if (err <= 0) {
remainingLengthInStream = 0; remainingLengthInStream = 0;

View File

@@ -4,6 +4,7 @@
#include <iostream> #include <iostream>
#include "messageFormat.h" #include "messageFormat.h"
#include <sys/socket.h> #include <sys/socket.h>
#include <syslog.h>
#include <boost/scoped_ptr.hpp> #include <boost/scoped_ptr.hpp>
#include "AppendTask.h" #include "AppendTask.h"
@@ -39,7 +40,7 @@ void ProcessTask::handleError(int saved_errno)
SessionManager::get()->socketError(sock); SessionManager::get()->socketError(sock);
returnedSock = true; returnedSock = true;
char buf[80]; char buf[80];
cout << "ProcessTask: got an error during a socket read: " << strerror_r(saved_errno, buf, 80) << endl; syslog(LOG_ERR, "ProcessTask: got an error during a socket read: %s.",strerror_r(saved_errno, buf, 80));
} }
void ProcessTask::operator()() void ProcessTask::operator()()

View File

@@ -41,7 +41,7 @@ bool ReadTask::run()
read_cmd *cmd = (read_cmd *) buf; read_cmd *cmd = (read_cmd *) buf;
#ifdef SM_TRACE #ifdef SM_TRACE
cout << "read " << cmd->filename << " count " << cmd->count << " offset " << cmd->offset << endl; syslog(LOG_DEBUG, "read %s count %i offset %i.",cmd->filename,cmd->count,cmd->offset);
#endif #endif
// read from IOC, write to the socket // read from IOC, write to the socket

70
src/SessionManager.cpp Normal file → Executable file
View File

@@ -12,6 +12,7 @@
#include <string> #include <string>
#include <assert.h> #include <assert.h>
#include <iostream> #include <iostream>
#include <syslog.h>
using namespace std; using namespace std;
#include <exception> #include <exception>
@@ -32,7 +33,7 @@ namespace storagemanager
SessionManager::SessionManager() SessionManager::SessionManager()
{ {
crp = ClientRequestProcessor::get(); crp = ClientRequestProcessor::get();
} }
SessionManager::~SessionManager() SessionManager::~SessionManager()
@@ -60,25 +61,25 @@ int SessionManager::start()
int current_size = 0; int current_size = 0;
bool running = true; bool running = true;
printf("SessionManager starting...\n"); syslog(LOG_INFO, "SessionManager starting...");
if (pipe(socketCtrl)==-1) if (pipe(socketCtrl)==-1)
{ {
perror("Pipe Failed" ); syslog(LOG_CRIT, "Pipe Failed: %s", strerror(errno));
return 1; return 1;
} }
listenSockfd = ::socket(AF_UNIX, SOCK_STREAM, 0); listenSockfd = ::socket(AF_UNIX, SOCK_STREAM, 0);
if (listenSockfd < 0) if (listenSockfd < 0)
{ {
perror("socket() failed"); syslog(LOG_CRIT, "socket() failed: %s", strerror(errno));
return -1; return -1;
} }
rc = ::setsockopt(listenSockfd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)); rc = ::setsockopt(listenSockfd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on));
if (rc < 0) if (rc < 0)
{ {
perror("setsockopt() failed"); syslog(LOG_CRIT, "setsockopt() failed: %s", strerror(errno));
close(listenSockfd); close(listenSockfd);
return -1; return -1;
} }
@@ -86,7 +87,7 @@ int SessionManager::start()
rc = ::ioctl(listenSockfd, FIONBIO, (char *)&on); rc = ::ioctl(listenSockfd, FIONBIO, (char *)&on);
if (rc < 0) if (rc < 0)
{ {
perror("ioctl() failed"); syslog(LOG_CRIT, "ioctl() failed: %s", strerror(errno));
close(listenSockfd); close(listenSockfd);
return -1; return -1;
} }
@@ -97,7 +98,7 @@ int SessionManager::start()
rc = ::bind(listenSockfd,(struct sockaddr *)&addr, sizeof(addr)); rc = ::bind(listenSockfd,(struct sockaddr *)&addr, sizeof(addr));
if (rc < 0) if (rc < 0)
{ {
perror("bind() failed"); syslog(LOG_CRIT, "bind() failed: %s", strerror(errno));
close(listenSockfd); close(listenSockfd);
return -1; return -1;
} }
@@ -105,7 +106,7 @@ int SessionManager::start()
rc = ::listen(listenSockfd, 32); rc = ::listen(listenSockfd, 32);
if (rc < 0) if (rc < 0)
{ {
perror("listen() failed"); syslog(LOG_CRIT, "listen() failed: %s", strerror(errno));
close(listenSockfd); close(listenSockfd);
return -1; return -1;
} }
@@ -117,17 +118,18 @@ int SessionManager::start()
fds[1].events = POLLIN; fds[1].events = POLLIN;
nfds = 2; nfds = 2;
printf("SessionManager waiting for sockets....\n"); syslog(LOG_INFO, "SessionManager waiting for sockets.");
while (running) while (running)
{ {
try try
{ {
//if (current_size != nfds) //if (current_size != nfds)
//syslog(LOG_DEBUG, "polling %i fds %i", nfds,fds);
//cout << "polling " << nfds << " fds" << endl; //cout << "polling " << nfds << " fds" << endl;
rc = ::poll(fds, nfds, pollTimeout); rc = ::poll(fds, nfds, pollTimeout);
if (rc < 0) if (rc < 0)
{ {
perror("poll() failed"); syslog(LOG_CRIT, "poll() failed: %s", strerror(errno));
break; break;
} }
current_size = nfds; current_size = nfds;
@@ -137,16 +139,16 @@ int SessionManager::start()
if(fds[socketIncr].revents == 0) if(fds[socketIncr].revents == 0)
continue; continue;
//if (socketIncr >= 2) //if (socketIncr >= 2)
//cout << "got event on fd " << fds[socketIncr].fd << " index is " << socketIncr << endl; //syslog(LOG_DEBUG, "got event on fd %i index is %i", fds[socketIncr].fd,socketIncr);
if(fds[socketIncr].revents != POLLIN) if(fds[socketIncr].revents != POLLIN)
{ {
//printf("Error! revents = %d\n", fds[socketIncr].revents); //syslog(LOG_DEBUG, "Error! revents = %d", fds[socketIncr].revents,);
close(fds[socketIncr].fd); close(fds[socketIncr].fd);
fds[socketIncr].fd = -1; fds[socketIncr].fd = -1;
} }
if (fds[socketIncr].fd == listenSockfd) if (fds[socketIncr].fd == listenSockfd)
{ {
//printf(" Listening socket is readable\n"); //syslog(LOG_DEBUG, "Listening socket is readable");
incomingSockfd = 0; incomingSockfd = 0;
while (incomingSockfd != -1) while (incomingSockfd != -1)
{ {
@@ -158,12 +160,12 @@ int SessionManager::start()
{ {
if (errno != EWOULDBLOCK) if (errno != EWOULDBLOCK)
{ {
perror("accept() failed"); syslog(LOG_CRIT, "accept() failed: %s", strerror(errno));
running = false; running = false;
} }
break; break;
} }
//printf(" New incoming connection - %d\n", incomingSockfd); //syslog(LOG_DEBUG, "New incoming connection - %d",incomingSockfd);
fds[nfds].fd = incomingSockfd; fds[nfds].fd = incomingSockfd;
fds[nfds].events = POLLIN; fds[nfds].events = POLLIN;
nfds++; nfds++;
@@ -171,7 +173,7 @@ int SessionManager::start()
} }
else if (fds[socketIncr].fd == socketCtrl[0]) else if (fds[socketIncr].fd == socketCtrl[0])
{ {
//printf(" SocketControl is readable\n"); //syslog(LOG_DEBUG, "SocketControl is readable");
uint8_t ctrlCode; uint8_t ctrlCode;
int len,socket; int len,socket;
@@ -192,7 +194,7 @@ int SessionManager::start()
{ {
if(fds[i].fd == socket) if(fds[i].fd == socket)
{ {
//cout << "returned socket " << fds[i].fd << " at index " << i << endl; //syslog(LOG_DEBUG, "returned socket %i at index %i", fds[i].fd,i);
fds[i].events = POLLIN; fds[i].events = POLLIN;
break; break;
} }
@@ -220,8 +222,7 @@ int SessionManager::start()
} }
else else
{ {
//printf(" socketIncr %d -- Descriptor %d is readable\n", socketIncr,fds[socketIncr].fd); //syslog(LOG_DEBUG, "socketIncr %d -- Descriptor %d is readable",socketIncr,fds[socketIncr].fd);
bool closeConn = false; bool closeConn = false;
char recv_buffer[8192]; char recv_buffer[8192];
uint recvMsgLength = 0; uint recvMsgLength = 0;
@@ -232,7 +233,7 @@ int SessionManager::start()
struct timespec ts; struct timespec ts;
ts.tv_sec = 0; ts.tv_sec = 0;
ts.tv_nsec = 100000000; // .1 sec ts.tv_nsec = 100000000; // .1 sec
//cout << "reading from fd " << fds[socketIncr].fd << " index is " << socketIncr << endl; //syslog(LOG_DEBUG, "reading from fd %i index is %i", fds[socketIncr].fd,socketIncr);
if (sockState.find(fds[socketIncr].fd) != sockState.end()) if (sockState.find(fds[socketIncr].fd) != sockState.end())
{ {
SockState &state = sockState[fds[socketIncr].fd]; SockState &state = sockState[fds[socketIncr].fd];
@@ -247,7 +248,6 @@ int SessionManager::start()
{ {
if (errno != EWOULDBLOCK) if (errno != EWOULDBLOCK)
{ {
//perror("recv() failed");
closeConn = true; closeConn = true;
break; break;
} }
@@ -260,7 +260,7 @@ int SessionManager::start()
sockState[fds[socketIncr].fd] = state; sockState[fds[socketIncr].fd] = state;
break; break;
} }
//cout << "recv got " << peakLength << " bytes" << endl; //syslog(LOG_DEBUG, "recv got %i bytes", peakLength);
endOfData = remainingBytes + peakLength; endOfData = remainingBytes + peakLength;
if (endOfData < SM_HEADER_LEN) if (endOfData < SM_HEADER_LEN)
{ {
@@ -276,12 +276,12 @@ int SessionManager::start()
{ {
if (*((uint *) &recv_buffer[i]) == SM_MSG_START) if (*((uint *) &recv_buffer[i]) == SM_MSG_START)
{ {
//printf("Received SM_MSG_START\n"); //syslog(LOG_DEBUG, "Received SM_MSG_START");
//found it set msgLength and recvMsgStart offset of SM_MSG_START //found it set msgLength and recvMsgStart offset of SM_MSG_START
recvMsgLength = *((uint *) &recv_buffer[i+4]); recvMsgLength = *((uint *) &recv_buffer[i+4]);
//cout << "got length = " << recvMsgLength << endl; //syslog(LOG_DEBUG, "got length = %i", recvMsgLength);
recvMsgStart = i + SM_HEADER_LEN; recvMsgStart = i + SM_HEADER_LEN;
//printf(" recvMsgLength %d recvMsgStart %d endofData %d\n", recvMsgLength,recvMsgStart,endOfData); //syslog(LOG_DEBUG, "recvMsgLength %d recvMsgStart %d endofData %d", recvMsgLength,recvMsgStart,endOfData);
// if >= endOfData then the start of the message data is the beginning of next message // if >= endOfData then the start of the message data is the beginning of next message
if (recvMsgStart >= endOfData) if (recvMsgStart >= endOfData)
recvMsgStart = 0; recvMsgStart = 0;
@@ -292,7 +292,7 @@ int SessionManager::start()
// didn't find SM_MSG_START in this message consume the data and loop back through on next message // didn't find SM_MSG_START in this message consume the data and loop back through on next message
if (recvMsgLength == 0) if (recvMsgLength == 0)
{ {
printf("No SM_MSG_START\n"); //syslog(LOG_DEBUG, "No SM_MSG_START");
len = ::read(fds[socketIncr].fd, &recv_buffer[remainingBytes], peakLength); len = ::read(fds[socketIncr].fd, &recv_buffer[remainingBytes], peakLength);
assert(len == peakLength); assert(len == peakLength);
// we know the msg header isn't in position [0, endOfData - i), so throw that out // we know the msg header isn't in position [0, endOfData - i), so throw that out
@@ -307,7 +307,7 @@ int SessionManager::start()
//remove the junk in front of the message //remove the junk in front of the message
if (recvMsgStart > 0) if (recvMsgStart > 0)
{ {
//printf("SM_MSG_START data is here\n"); //syslog(LOG_DEBUG, "SM_MSG_START data is here");
// how many to consume here... // how many to consume here...
// recvMsgStart is the position in the buffer // recvMsgStart is the position in the buffer
// peakLength is the amount peeked this time // peakLength is the amount peeked this time
@@ -316,7 +316,7 @@ int SessionManager::start()
} }
else else
{ {
//printf("SM_MSG_START data is next message\n"); //syslog(LOG_DEBUG, "SM_MSG_START data is next message");
len = ::read(fds[socketIncr].fd, &recv_buffer[remainingBytes], peakLength); len = ::read(fds[socketIncr].fd, &recv_buffer[remainingBytes], peakLength);
} }
//Disable polling on this socket //Disable polling on this socket
@@ -327,7 +327,7 @@ int SessionManager::start()
/* /*
//Doing this to work with cloudio_component_test //Doing this to work with cloudio_component_test
len = ::read(fds[socketIncr].fd, out, recvMsgLength); len = ::read(fds[socketIncr].fd, out, recvMsgLength);
printf("Read %d bytes.\n",len); syslog(LOG_DEBUG, "Read %d bytes.",len);
//Debug test lets send a reponse back //Debug test lets send a reponse back
uint32_t response[4] = { storagemanager::SM_MSG_START, 8, (uint32_t ) -1, EINVAL }; uint32_t response[4] = { storagemanager::SM_MSG_START, 8, (uint32_t ) -1, EINVAL };
len = ::send(fds[socketIncr].fd, response, 16, 0); len = ::send(fds[socketIncr].fd, response, 16, 0);
@@ -356,18 +356,8 @@ int SessionManager::start()
{ {
if (fds[i].fd == -1) if (fds[i].fd == -1)
{ {
// this should be the same
if (i < nfds - 1) if (i < nfds - 1)
memmove(&fds[i], &fds[i+1], sizeof(struct pollfd) * nfds); memmove(&fds[i], &fds[i+1], sizeof(struct pollfd) * nfds);
/*
for (int j = i; j < nfds-1; j++)
{
fds[j].fd = fds[j + 1].fd;
fds[j].events = fds[j + 1].events;
fds[j].revents = fds[j + 1].revents;
}
*/
i--; i--;
nfds--; nfds--;
} }
@@ -397,7 +387,7 @@ void SessionManager::returnSocket(int socket)
void SessionManager::socketError(int socket) void SessionManager::socketError(int socket)
{ {
boost::mutex::scoped_lock s(ctrlMutex); boost::mutex::scoped_lock s(ctrlMutex);
cout << " ****** socket error!" << endl; syslog(LOG_CRIT, " ****** socket error!");
int err; int err;
uint8_t ctrlCode = REMOVEFD; uint8_t ctrlCode = REMOVEFD;
err = ::write(socketCtrl[1], &ctrlCode, 1); err = ::write(socketCtrl[1], &ctrlCode, 1);

View File

@@ -43,7 +43,7 @@ bool StatTask::run()
sm_response *resp = (sm_response *) buf; sm_response *resp = (sm_response *) buf;
#ifdef SM_TRACE #ifdef SM_TRACE
cout << "stat " << cmd->filename << endl; syslog(LOG_DEBUG, "stat %s.",cmd->filename);
#endif #endif
int err = ioc->stat(cmd->filename, (struct stat *) resp->payload); int err = ioc->stat(cmd->filename, (struct stat *) resp->payload);

View File

@@ -38,7 +38,7 @@ bool TruncateTask::run()
truncate_cmd *cmd = (truncate_cmd *) buf; truncate_cmd *cmd = (truncate_cmd *) buf;
#ifdef SM_TRACE #ifdef SM_TRACE
cout << "truncate " << cmd->filename << " newlength " << cmd->length << endl; syslog(LOG_DEBUG, "truncate %s newlength %i.",cmd->filename,cmd->length);
#endif #endif
int err = ioc->truncate(cmd->filename, cmd->length); int err = ioc->truncate(cmd->filename, cmd->length);

View File

@@ -39,7 +39,7 @@ bool UnlinkTask::run()
unlink_cmd *cmd = (unlink_cmd *) buf; unlink_cmd *cmd = (unlink_cmd *) buf;
#ifdef SM_TRACE #ifdef SM_TRACE
cout << "unlink " << cmd->filename << endl; syslog(LOG_DEBUG, "unlink %s.",cmd->filename);
#endif #endif
int err = ioc->unlink(cmd->filename); int err = ioc->unlink(cmd->filename);

View File

@@ -44,7 +44,7 @@ bool WriteTask::run()
check_error("WriteTask read", false); check_error("WriteTask read", false);
#ifdef SM_TRACE #ifdef SM_TRACE
cout << "write filename " << cmd->filename << " offset " << cmd->offset << " count " << cmd->count << endl; syslog(LOG_DEBUG, "write filename %s offset %i count %i.",cmd->filename,cmd->offset,cmd->count);
#endif #endif
size_t readCount = 0, writeCount = 0; size_t readCount = 0, writeCount = 0;

12
src/main.cpp Normal file → Executable file
View File

@@ -8,6 +8,8 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <signal.h> #include <signal.h>
#include <syslog.h>
using namespace std; using namespace std;
#include "SessionManager.h" #include "SessionManager.h"
@@ -22,10 +24,20 @@ int main(int argc, char** argv)
sigaction(SIGPIPE, &sa, NULL); sigaction(SIGPIPE, &sa, NULL);
int ret = 0; int ret = 0;
//TODO: make this configurable
setlogmask (LOG_UPTO (LOG_DEBUG));
openlog ("StorageManager", LOG_PID | LOG_NDELAY, LOG_LOCAL2);
syslog(LOG_NOTICE, "StorageManager started.");
SessionManager* sm = SessionManager::get(); SessionManager* sm = SessionManager::get();
ret = sm->start(); ret = sm->start();
closelog ();
return ret; return ret;
} }