1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-08-01 06:46:55 +03:00

MCOL-4347: catch exceptions during smcat/smls/smput/smrm on IOC::get()

This commit is contained in:
benthompson15
2020-10-14 11:02:42 -05:00
parent ac258dc94d
commit 8ff81e5d45
4 changed files with 107 additions and 80 deletions

View File

@ -55,30 +55,37 @@ void catFileOffline(const char *filename, int prefixlen)
uint8_t data[8192];
off_t offset = 0;
int read_err, write_err, count;
boost::scoped_ptr<IOCoordinator> ioc(IOCoordinator::get());
do {
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;
}
try
{
boost::scoped_ptr<IOCoordinator> ioc(IOCoordinator::get());
while (count < read_err)
{
write_err = write(STDOUT_FILENO, &data[count], read_err - count);
if (write_err < 0)
do {
count = 0;
read_err = ioc->read(filename, data, offset, 8192);
if (read_err < 0)
{
int l_errno = errno;
cerr << "Error writing to stdout: " << strerror_r(l_errno, (char *) data, 8192) << endl;
exit(1);
cerr << "Error reading " << &filename[prefixlen] << ": " << strerror_r(l_errno, (char *) data, 8192) << endl;
}
count += write_err;
}
offset += read_err;
} while (read_err > 0);
while (count < read_err)
{
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)

View File

@ -58,42 +58,49 @@ bool SMOnline()
void lsOffline(const char *path)
{
boost::scoped_ptr<IOCoordinator> ioc(IOCoordinator::get());
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)
try
{
p = base / entry;
err = ioc->stat(p.string().c_str(), &_stat);
if (!err)
boost::scoped_ptr<IOCoordinator> ioc(IOCoordinator::get());
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)
{
if (_stat.st_mode & S_IFDIR)
p = base / entry;
err = ioc->stat(p.string().c_str(), &_stat);
if (!err)
{
cout << "d";
cout.width(14);
if (_stat.st_mode & S_IFDIR)
{
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
{
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
{
cout.width(15);
cout << right << "error" << left << " " << entry << endl;
cout << right << "error" << left << " " << entry << endl;
}
}
}
catch (exception &e)
{
cerr << "smls lsOffline FAIL: " << e.what() << endl;
}
}
void lsOnline(const char *path)

View File

@ -57,42 +57,48 @@ void putOffline(const char *fname, int prefixlen)
uint8_t data[8192];
int read_err, write_err;
ssize_t count, offset = 0;
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)
try
{
int l_errno = errno;
cerr << "Failed to open/create " << &fname[prefixlen] << ": " <<
strerror_r(l_errno, (char *) data, 8192) << endl;
exit(1);
}
do
{
read_err = ::read(STDIN_FILENO, data, 8192);
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;
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);
}
count = 0;
while (count < read_err)
do
{
write_err = ioc->write(fname, &data[count], offset + count, read_err - count);
if (write_err < 0)
read_err = ::read(STDIN_FILENO, data, 8192);
if (read_err < 0)
{
int l_errno = errno;
cerr << "Error writing to " << &fname[prefixlen] << ": " <<
strerror_r(l_errno, (char *) data, 8192) << endl;
cerr << "Error reading stdin: " << strerror_r(l_errno, (char *) data, 8192) << endl;
exit(1);
}
count += write_err;
}
offset += read_err;
} while (read_err > 0);
count = 0;
while (count < read_err)
{
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)

View File

@ -54,14 +54,21 @@ bool SMOnline()
void rmOffline(int argCount, const char **args, const char *prefix, uint prefixlen)
{
boost::scoped_ptr<IOCoordinator> ioc(IOCoordinator::get());
char buf[16384];
strncpy(buf, prefix, prefixlen);
for (int i = 1; i < argCount; i++)
try
{
memcpy(&buf[prefixlen], args[i], min(16383 - prefixlen, strlen(args[i])) + 1);
ioc->unlink(buf);
boost::scoped_ptr<IOCoordinator> ioc(IOCoordinator::get());
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;
}
}