You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-08-07 03:22:57 +03:00
MCOL-4347: catch exceptions during smcat/smls/smput/smrm on IOC::get()
This commit is contained in:
@@ -55,30 +55,37 @@ void catFileOffline(const char *filename, int prefixlen)
|
|||||||
uint8_t data[8192];
|
uint8_t data[8192];
|
||||||
off_t offset = 0;
|
off_t offset = 0;
|
||||||
int read_err, write_err, count;
|
int read_err, write_err, count;
|
||||||
boost::scoped_ptr<IOCoordinator> ioc(IOCoordinator::get());
|
try
|
||||||
|
{
|
||||||
do {
|
boost::scoped_ptr<IOCoordinator> ioc(IOCoordinator::get());
|
||||||
count = 0;
|
|
||||||
read_err = ioc->read(filename, data, offset, 8192);
|
|
||||||
if (read_err < 0)
|
|
||||||
{
|
|
||||||
int l_errno = errno;
|
|
||||||
cerr << "Error reading " << &filename[prefixlen] << ": " << strerror_r(l_errno, (char *) data, 8192) << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (count < read_err)
|
do {
|
||||||
{
|
count = 0;
|
||||||
write_err = write(STDOUT_FILENO, &data[count], read_err - count);
|
read_err = ioc->read(filename, data, offset, 8192);
|
||||||
if (write_err < 0)
|
if (read_err < 0)
|
||||||
{
|
{
|
||||||
int l_errno = errno;
|
int l_errno = errno;
|
||||||
cerr << "Error writing to stdout: " << strerror_r(l_errno, (char *) data, 8192) << endl;
|
cerr << "Error reading " << &filename[prefixlen] << ": " << strerror_r(l_errno, (char *) data, 8192) << endl;
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
count += write_err;
|
|
||||||
}
|
while (count < read_err)
|
||||||
offset += read_err;
|
{
|
||||||
} while (read_err > 0);
|
write_err = write(STDOUT_FILENO, &data[count], read_err - count);
|
||||||
|
if (write_err < 0)
|
||||||
|
{
|
||||||
|
int l_errno = errno;
|
||||||
|
cerr << "Error writing to stdout: " << strerror_r(l_errno, (char *) data, 8192) << endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
count += write_err;
|
||||||
|
}
|
||||||
|
offset += read_err;
|
||||||
|
} while (read_err > 0);
|
||||||
|
}
|
||||||
|
catch (exception &e)
|
||||||
|
{
|
||||||
|
cerr << "smcat catFileOffline FAIL: " << e.what() << endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void catFileOnline(const char *filename, int prefixlen)
|
void catFileOnline(const char *filename, int prefixlen)
|
||||||
|
@@ -58,42 +58,49 @@ bool SMOnline()
|
|||||||
|
|
||||||
void lsOffline(const char *path)
|
void lsOffline(const char *path)
|
||||||
{
|
{
|
||||||
boost::scoped_ptr<IOCoordinator> ioc(IOCoordinator::get());
|
try
|
||||||
vector<string> listing;
|
|
||||||
|
|
||||||
int err = ioc->listDirectory(path, &listing);
|
|
||||||
if (err)
|
|
||||||
exit(1);
|
|
||||||
|
|
||||||
struct stat _stat;
|
|
||||||
boost::filesystem::path base(path);
|
|
||||||
boost::filesystem::path p;
|
|
||||||
cout.fill(' ');
|
|
||||||
for (auto &entry : listing)
|
|
||||||
{
|
{
|
||||||
p = base / entry;
|
boost::scoped_ptr<IOCoordinator> ioc(IOCoordinator::get());
|
||||||
err = ioc->stat(p.string().c_str(), &_stat);
|
vector<string> listing;
|
||||||
if (!err)
|
|
||||||
|
int err = ioc->listDirectory(path, &listing);
|
||||||
|
if (err)
|
||||||
|
exit(1);
|
||||||
|
|
||||||
|
struct stat _stat;
|
||||||
|
boost::filesystem::path base(path);
|
||||||
|
boost::filesystem::path p;
|
||||||
|
cout.fill(' ');
|
||||||
|
for (auto &entry : listing)
|
||||||
{
|
{
|
||||||
if (_stat.st_mode & S_IFDIR)
|
p = base / entry;
|
||||||
|
err = ioc->stat(p.string().c_str(), &_stat);
|
||||||
|
if (!err)
|
||||||
{
|
{
|
||||||
cout << "d";
|
if (_stat.st_mode & S_IFDIR)
|
||||||
cout.width(14);
|
{
|
||||||
|
cout << "d";
|
||||||
|
cout.width(14);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
cout.width(15);
|
||||||
|
|
||||||
|
struct tm *my_tm = localtime(&_stat.st_mtim.tv_sec);
|
||||||
|
char date[100];
|
||||||
|
strftime(date, 100, "%b %e %H:%M", my_tm);
|
||||||
|
cout << right << _stat.st_size << left << " " << date << left << " " << entry << endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
cout.width(15);
|
cout.width(15);
|
||||||
|
cout << right << "error" << left << " " << entry << endl;
|
||||||
struct tm *my_tm = localtime(&_stat.st_mtim.tv_sec);
|
}
|
||||||
char date[100];
|
|
||||||
strftime(date, 100, "%b %e %H:%M", my_tm);
|
|
||||||
cout << right << _stat.st_size << left << " " << date << left << " " << entry << endl;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cout.width(15);
|
|
||||||
cout << right << "error" << left << " " << entry << endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (exception &e)
|
||||||
|
{
|
||||||
|
cerr << "smls lsOffline FAIL: " << e.what() << endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void lsOnline(const char *path)
|
void lsOnline(const char *path)
|
||||||
|
@@ -57,42 +57,48 @@ void putOffline(const char *fname, int prefixlen)
|
|||||||
uint8_t data[8192];
|
uint8_t data[8192];
|
||||||
int read_err, write_err;
|
int read_err, write_err;
|
||||||
ssize_t count, offset = 0;
|
ssize_t count, offset = 0;
|
||||||
|
try
|
||||||
boost::scoped_ptr<IOCoordinator> ioc(IOCoordinator::get());
|
|
||||||
struct stat _stat;
|
|
||||||
read_err = ioc->open(fname, O_CREAT | O_TRUNC | O_WRONLY, &_stat);
|
|
||||||
if (read_err < 0)
|
|
||||||
{
|
{
|
||||||
int l_errno = errno;
|
boost::scoped_ptr<IOCoordinator> ioc(IOCoordinator::get());
|
||||||
cerr << "Failed to open/create " << &fname[prefixlen] << ": " <<
|
struct stat _stat;
|
||||||
strerror_r(l_errno, (char *) data, 8192) << endl;
|
read_err = ioc->open(fname, O_CREAT | O_TRUNC | O_WRONLY, &_stat);
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
read_err = ::read(STDIN_FILENO, data, 8192);
|
|
||||||
if (read_err < 0)
|
if (read_err < 0)
|
||||||
{
|
{
|
||||||
int l_errno = errno;
|
int l_errno = errno;
|
||||||
cerr << "Error reading stdin: " << strerror_r(l_errno, (char *) data, 8192) << endl;
|
cerr << "Failed to open/create " << &fname[prefixlen] << ": " <<
|
||||||
|
strerror_r(l_errno, (char *) data, 8192) << endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
count = 0;
|
|
||||||
while (count < read_err)
|
do
|
||||||
{
|
{
|
||||||
write_err = ioc->write(fname, &data[count], offset + count, read_err - count);
|
read_err = ::read(STDIN_FILENO, data, 8192);
|
||||||
if (write_err < 0)
|
if (read_err < 0)
|
||||||
{
|
{
|
||||||
int l_errno = errno;
|
int l_errno = errno;
|
||||||
cerr << "Error writing to " << &fname[prefixlen] << ": " <<
|
cerr << "Error reading stdin: " << strerror_r(l_errno, (char *) data, 8192) << endl;
|
||||||
strerror_r(l_errno, (char *) data, 8192) << endl;
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
count += write_err;
|
count = 0;
|
||||||
}
|
while (count < read_err)
|
||||||
offset += read_err;
|
{
|
||||||
} while (read_err > 0);
|
write_err = ioc->write(fname, &data[count], offset + count, read_err - count);
|
||||||
|
if (write_err < 0)
|
||||||
|
{
|
||||||
|
int l_errno = errno;
|
||||||
|
cerr << "Error writing to " << &fname[prefixlen] << ": " <<
|
||||||
|
strerror_r(l_errno, (char *) data, 8192) << endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
count += write_err;
|
||||||
|
}
|
||||||
|
offset += read_err;
|
||||||
|
} while (read_err > 0);
|
||||||
|
}
|
||||||
|
catch (exception &e)
|
||||||
|
{
|
||||||
|
cerr << "smput putOffline FAIL: " << e.what() << endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void putOnline(const char *fname, int prefixlen)
|
void putOnline(const char *fname, int prefixlen)
|
||||||
|
@@ -54,14 +54,21 @@ bool SMOnline()
|
|||||||
|
|
||||||
void rmOffline(int argCount, const char **args, const char *prefix, uint prefixlen)
|
void rmOffline(int argCount, const char **args, const char *prefix, uint prefixlen)
|
||||||
{
|
{
|
||||||
boost::scoped_ptr<IOCoordinator> ioc(IOCoordinator::get());
|
try
|
||||||
char buf[16384];
|
|
||||||
strncpy(buf, prefix, prefixlen);
|
|
||||||
|
|
||||||
for (int i = 1; i < argCount; i++)
|
|
||||||
{
|
{
|
||||||
memcpy(&buf[prefixlen], args[i], min(16383 - prefixlen, strlen(args[i])) + 1);
|
boost::scoped_ptr<IOCoordinator> ioc(IOCoordinator::get());
|
||||||
ioc->unlink(buf);
|
char buf[16384];
|
||||||
|
strncpy(buf, prefix, prefixlen);
|
||||||
|
|
||||||
|
for (int i = 1; i < argCount; i++)
|
||||||
|
{
|
||||||
|
memcpy(&buf[prefixlen], args[i], min(16383 - prefixlen, strlen(args[i])) + 1);
|
||||||
|
ioc->unlink(buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (exception &e)
|
||||||
|
{
|
||||||
|
cerr << "smrm rmOffline FAIL: " << e.what() << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user