You've already forked mariadb-columnstore-engine
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:
@@ -44,7 +44,7 @@ bool AppendTask::run()
|
||||
check_error("AppendTask read", false);
|
||||
|
||||
#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
|
||||
|
||||
size_t readCount = 0, writeCount = 0;
|
||||
|
||||
3
src/CopyTask.cpp
Normal file → Executable file
3
src/CopyTask.cpp
Normal file → Executable file
@@ -1,6 +1,7 @@
|
||||
|
||||
#include "CopyTask.h"
|
||||
#include <errno.h>
|
||||
#include "syslog.h"
|
||||
#include "messageFormat.h"
|
||||
|
||||
using namespace std;
|
||||
@@ -41,7 +42,7 @@ bool CopyTask::run()
|
||||
f_name *filename2 = (f_name *) &buf[sizeof(copy_cmd) + cmd->file1.flen];
|
||||
|
||||
#ifdef SM_TRACE
|
||||
cout << "copy " << filename1 << " to " << filename2 << endl;
|
||||
syslog(LOG_DEBUG, "copy %s to %s.",filename1,filename2);
|
||||
#endif
|
||||
|
||||
int err = ioc->copyFile(filename1.c_str(), filename2->filename);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <syslog.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
@@ -199,7 +200,7 @@ int IOCoordinator::copyFile(const char *filename1, const char *filename2)
|
||||
l_errno = e.code().value(); // why not.
|
||||
// eh, not going to translate all of boost's errors into our errors for this.
|
||||
// log the error
|
||||
cout << "IOCoordinator::copy(): got " << e.what() << endl;
|
||||
syslog(LOG_ERR, "IOCoordinator::copy(): got %s",e.what());
|
||||
}
|
||||
catch (...) {
|
||||
err = -1;
|
||||
|
||||
@@ -71,7 +71,7 @@ bool ListDirectoryTask::run()
|
||||
listdir_cmd *cmd = (listdir_cmd *) buf;
|
||||
|
||||
#ifdef SM_TRACE
|
||||
cout << "list_directory " << cmd->path << endl;
|
||||
syslog(LOG_DEBUG, "list_directory %s.",cmd->path);
|
||||
#endif
|
||||
|
||||
vector<string> listing;
|
||||
|
||||
@@ -45,7 +45,7 @@ bool OpenTask::run()
|
||||
open_cmd *cmd = (open_cmd *) buf;
|
||||
|
||||
#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
|
||||
sm_response *resp = (sm_response *) buf;
|
||||
int err = ioc->open(cmd->filename, cmd->openmode, (struct stat *) &resp->payload);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <iostream>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <syslog.h>
|
||||
#include <string.h>
|
||||
|
||||
#define min(x, y) (x < y ? x : y)
|
||||
@@ -42,7 +43,7 @@ void PosixTask::handleError(const char *name, int errCode)
|
||||
write(*resp, 4);
|
||||
|
||||
// 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()
|
||||
@@ -186,7 +187,7 @@ void PosixTask::consumeMsg()
|
||||
|
||||
while (remainingLengthInStream > 0)
|
||||
{
|
||||
cout << "ERROR: eating data" << endl;
|
||||
syslog(LOG_ERR, "ERROR: eating data.");
|
||||
err = ::recv(sock, buf, min(remainingLengthInStream, 1024), 0);
|
||||
if (err <= 0) {
|
||||
remainingLengthInStream = 0;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <iostream>
|
||||
#include "messageFormat.h"
|
||||
#include <sys/socket.h>
|
||||
#include <syslog.h>
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
|
||||
#include "AppendTask.h"
|
||||
@@ -39,7 +40,7 @@ void ProcessTask::handleError(int saved_errno)
|
||||
SessionManager::get()->socketError(sock);
|
||||
returnedSock = true;
|
||||
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()()
|
||||
|
||||
@@ -41,7 +41,7 @@ bool ReadTask::run()
|
||||
read_cmd *cmd = (read_cmd *) buf;
|
||||
|
||||
#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
|
||||
|
||||
// read from IOC, write to the socket
|
||||
|
||||
70
src/SessionManager.cpp
Normal file → Executable file
70
src/SessionManager.cpp
Normal file → Executable file
@@ -12,6 +12,7 @@
|
||||
#include <string>
|
||||
#include <assert.h>
|
||||
#include <iostream>
|
||||
#include <syslog.h>
|
||||
using namespace std;
|
||||
|
||||
#include <exception>
|
||||
@@ -32,7 +33,7 @@ namespace storagemanager
|
||||
|
||||
SessionManager::SessionManager()
|
||||
{
|
||||
crp = ClientRequestProcessor::get();
|
||||
crp = ClientRequestProcessor::get();
|
||||
}
|
||||
|
||||
SessionManager::~SessionManager()
|
||||
@@ -60,25 +61,25 @@ int SessionManager::start()
|
||||
int current_size = 0;
|
||||
bool running = true;
|
||||
|
||||
printf("SessionManager starting...\n");
|
||||
syslog(LOG_INFO, "SessionManager starting...");
|
||||
|
||||
if (pipe(socketCtrl)==-1)
|
||||
{
|
||||
perror("Pipe Failed" );
|
||||
syslog(LOG_CRIT, "Pipe Failed: %s", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
listenSockfd = ::socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (listenSockfd < 0)
|
||||
{
|
||||
perror("socket() failed");
|
||||
syslog(LOG_CRIT, "socket() failed: %s", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc = ::setsockopt(listenSockfd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on));
|
||||
if (rc < 0)
|
||||
{
|
||||
perror("setsockopt() failed");
|
||||
syslog(LOG_CRIT, "setsockopt() failed: %s", strerror(errno));
|
||||
close(listenSockfd);
|
||||
return -1;
|
||||
}
|
||||
@@ -86,7 +87,7 @@ int SessionManager::start()
|
||||
rc = ::ioctl(listenSockfd, FIONBIO, (char *)&on);
|
||||
if (rc < 0)
|
||||
{
|
||||
perror("ioctl() failed");
|
||||
syslog(LOG_CRIT, "ioctl() failed: %s", strerror(errno));
|
||||
close(listenSockfd);
|
||||
return -1;
|
||||
}
|
||||
@@ -97,7 +98,7 @@ int SessionManager::start()
|
||||
rc = ::bind(listenSockfd,(struct sockaddr *)&addr, sizeof(addr));
|
||||
if (rc < 0)
|
||||
{
|
||||
perror("bind() failed");
|
||||
syslog(LOG_CRIT, "bind() failed: %s", strerror(errno));
|
||||
close(listenSockfd);
|
||||
return -1;
|
||||
}
|
||||
@@ -105,7 +106,7 @@ int SessionManager::start()
|
||||
rc = ::listen(listenSockfd, 32);
|
||||
if (rc < 0)
|
||||
{
|
||||
perror("listen() failed");
|
||||
syslog(LOG_CRIT, "listen() failed: %s", strerror(errno));
|
||||
close(listenSockfd);
|
||||
return -1;
|
||||
}
|
||||
@@ -117,17 +118,18 @@ int SessionManager::start()
|
||||
fds[1].events = POLLIN;
|
||||
nfds = 2;
|
||||
|
||||
printf("SessionManager waiting for sockets....\n");
|
||||
syslog(LOG_INFO, "SessionManager waiting for sockets.");
|
||||
while (running)
|
||||
{
|
||||
try
|
||||
{
|
||||
//if (current_size != nfds)
|
||||
//syslog(LOG_DEBUG, "polling %i fds %i", nfds,fds);
|
||||
//cout << "polling " << nfds << " fds" << endl;
|
||||
rc = ::poll(fds, nfds, pollTimeout);
|
||||
if (rc < 0)
|
||||
{
|
||||
perror("poll() failed");
|
||||
syslog(LOG_CRIT, "poll() failed: %s", strerror(errno));
|
||||
break;
|
||||
}
|
||||
current_size = nfds;
|
||||
@@ -137,16 +139,16 @@ int SessionManager::start()
|
||||
if(fds[socketIncr].revents == 0)
|
||||
continue;
|
||||
//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)
|
||||
{
|
||||
//printf("Error! revents = %d\n", fds[socketIncr].revents);
|
||||
//syslog(LOG_DEBUG, "Error! revents = %d", fds[socketIncr].revents,);
|
||||
close(fds[socketIncr].fd);
|
||||
fds[socketIncr].fd = -1;
|
||||
}
|
||||
if (fds[socketIncr].fd == listenSockfd)
|
||||
{
|
||||
//printf(" Listening socket is readable\n");
|
||||
//syslog(LOG_DEBUG, "Listening socket is readable");
|
||||
incomingSockfd = 0;
|
||||
while (incomingSockfd != -1)
|
||||
{
|
||||
@@ -158,12 +160,12 @@ int SessionManager::start()
|
||||
{
|
||||
if (errno != EWOULDBLOCK)
|
||||
{
|
||||
perror("accept() failed");
|
||||
syslog(LOG_CRIT, "accept() failed: %s", strerror(errno));
|
||||
running = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
//printf(" New incoming connection - %d\n", incomingSockfd);
|
||||
//syslog(LOG_DEBUG, "New incoming connection - %d",incomingSockfd);
|
||||
fds[nfds].fd = incomingSockfd;
|
||||
fds[nfds].events = POLLIN;
|
||||
nfds++;
|
||||
@@ -171,7 +173,7 @@ int SessionManager::start()
|
||||
}
|
||||
else if (fds[socketIncr].fd == socketCtrl[0])
|
||||
{
|
||||
//printf(" SocketControl is readable\n");
|
||||
//syslog(LOG_DEBUG, "SocketControl is readable");
|
||||
uint8_t ctrlCode;
|
||||
int len,socket;
|
||||
|
||||
@@ -192,7 +194,7 @@ int SessionManager::start()
|
||||
{
|
||||
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;
|
||||
break;
|
||||
}
|
||||
@@ -220,8 +222,7 @@ int SessionManager::start()
|
||||
}
|
||||
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;
|
||||
char recv_buffer[8192];
|
||||
uint recvMsgLength = 0;
|
||||
@@ -232,7 +233,7 @@ int SessionManager::start()
|
||||
struct timespec ts;
|
||||
ts.tv_sec = 0;
|
||||
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())
|
||||
{
|
||||
SockState &state = sockState[fds[socketIncr].fd];
|
||||
@@ -247,7 +248,6 @@ int SessionManager::start()
|
||||
{
|
||||
if (errno != EWOULDBLOCK)
|
||||
{
|
||||
//perror("recv() failed");
|
||||
closeConn = true;
|
||||
break;
|
||||
}
|
||||
@@ -260,7 +260,7 @@ int SessionManager::start()
|
||||
sockState[fds[socketIncr].fd] = state;
|
||||
break;
|
||||
}
|
||||
//cout << "recv got " << peakLength << " bytes" << endl;
|
||||
//syslog(LOG_DEBUG, "recv got %i bytes", peakLength);
|
||||
endOfData = remainingBytes + peakLength;
|
||||
if (endOfData < SM_HEADER_LEN)
|
||||
{
|
||||
@@ -276,12 +276,12 @@ int SessionManager::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
|
||||
recvMsgLength = *((uint *) &recv_buffer[i+4]);
|
||||
//cout << "got length = " << recvMsgLength << endl;
|
||||
//syslog(LOG_DEBUG, "got length = %i", recvMsgLength);
|
||||
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 (recvMsgStart >= endOfData)
|
||||
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
|
||||
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);
|
||||
assert(len == peakLength);
|
||||
// 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
|
||||
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...
|
||||
// recvMsgStart is the position in the buffer
|
||||
// peakLength is the amount peeked this time
|
||||
@@ -316,7 +316,7 @@ int SessionManager::start()
|
||||
}
|
||||
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);
|
||||
}
|
||||
//Disable polling on this socket
|
||||
@@ -327,7 +327,7 @@ int SessionManager::start()
|
||||
/*
|
||||
//Doing this to work with cloudio_component_test
|
||||
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
|
||||
uint32_t response[4] = { storagemanager::SM_MSG_START, 8, (uint32_t ) -1, EINVAL };
|
||||
len = ::send(fds[socketIncr].fd, response, 16, 0);
|
||||
@@ -356,18 +356,8 @@ int SessionManager::start()
|
||||
{
|
||||
if (fds[i].fd == -1)
|
||||
{
|
||||
// this should be the same
|
||||
if (i < nfds - 1)
|
||||
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--;
|
||||
nfds--;
|
||||
}
|
||||
@@ -397,7 +387,7 @@ void SessionManager::returnSocket(int socket)
|
||||
void SessionManager::socketError(int socket)
|
||||
{
|
||||
boost::mutex::scoped_lock s(ctrlMutex);
|
||||
cout << " ****** socket error!" << endl;
|
||||
syslog(LOG_CRIT, " ****** socket error!");
|
||||
int err;
|
||||
uint8_t ctrlCode = REMOVEFD;
|
||||
err = ::write(socketCtrl[1], &ctrlCode, 1);
|
||||
|
||||
@@ -43,7 +43,7 @@ bool StatTask::run()
|
||||
sm_response *resp = (sm_response *) buf;
|
||||
|
||||
#ifdef SM_TRACE
|
||||
cout << "stat " << cmd->filename << endl;
|
||||
syslog(LOG_DEBUG, "stat %s.",cmd->filename);
|
||||
#endif
|
||||
|
||||
int err = ioc->stat(cmd->filename, (struct stat *) resp->payload);
|
||||
|
||||
@@ -38,7 +38,7 @@ bool TruncateTask::run()
|
||||
truncate_cmd *cmd = (truncate_cmd *) buf;
|
||||
|
||||
#ifdef SM_TRACE
|
||||
cout << "truncate " << cmd->filename << " newlength " << cmd->length << endl;
|
||||
syslog(LOG_DEBUG, "truncate %s newlength %i.",cmd->filename,cmd->length);
|
||||
#endif
|
||||
|
||||
int err = ioc->truncate(cmd->filename, cmd->length);
|
||||
|
||||
@@ -39,7 +39,7 @@ bool UnlinkTask::run()
|
||||
unlink_cmd *cmd = (unlink_cmd *) buf;
|
||||
|
||||
#ifdef SM_TRACE
|
||||
cout << "unlink " << cmd->filename << endl;
|
||||
syslog(LOG_DEBUG, "unlink %s.",cmd->filename);
|
||||
#endif
|
||||
|
||||
int err = ioc->unlink(cmd->filename);
|
||||
|
||||
@@ -44,7 +44,7 @@ bool WriteTask::run()
|
||||
check_error("WriteTask read", false);
|
||||
|
||||
#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
|
||||
|
||||
size_t readCount = 0, writeCount = 0;
|
||||
|
||||
12
src/main.cpp
Normal file → Executable file
12
src/main.cpp
Normal file → Executable file
@@ -8,6 +8,8 @@
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <signal.h>
|
||||
#include <syslog.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include "SessionManager.h"
|
||||
@@ -22,10 +24,20 @@ int main(int argc, char** argv)
|
||||
sigaction(SIGPIPE, &sa, NULL);
|
||||
|
||||
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();
|
||||
|
||||
ret = sm->start();
|
||||
|
||||
closelog ();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user