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
All tools will now work when SM is on- and offline.
This commit is contained in:
@@ -44,7 +44,7 @@ bool SMOnline()
|
|||||||
int err = ::connect(clientSocket, (const struct sockaddr *) &addr, sizeof(addr));
|
int err = ::connect(clientSocket, (const struct sockaddr *) &addr, sizeof(addr));
|
||||||
if (err >= 0)
|
if (err >= 0)
|
||||||
{
|
{
|
||||||
::close(err);
|
::close(clientSocket);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -55,7 +55,7 @@ void catFileOffline(const char *filename)
|
|||||||
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;
|
||||||
IOCoordinator *ioc = IOCoordinator::get();
|
boost::scoped_ptr<IOCoordinator> ioc(IOCoordinator::get());
|
||||||
|
|
||||||
do {
|
do {
|
||||||
count = 0;
|
count = 0;
|
||||||
@@ -79,7 +79,6 @@ void catFileOffline(const char *filename)
|
|||||||
}
|
}
|
||||||
offset += read_err;
|
offset += read_err;
|
||||||
} while (read_err > 0);
|
} while (read_err > 0);
|
||||||
delete ioc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void catFileOnline(const char *filename)
|
void catFileOnline(const char *filename)
|
||||||
|
@@ -48,7 +48,7 @@ bool SMOnline()
|
|||||||
int err = ::connect(clientSocket, (const struct sockaddr *) &addr, sizeof(addr));
|
int err = ::connect(clientSocket, (const struct sockaddr *) &addr, sizeof(addr));
|
||||||
if (err >= 0)
|
if (err >= 0)
|
||||||
{
|
{
|
||||||
::close(err);
|
::close(clientSocket);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -56,16 +56,12 @@ bool SMOnline()
|
|||||||
|
|
||||||
void lsOffline(const char *path)
|
void lsOffline(const char *path)
|
||||||
{
|
{
|
||||||
IOCoordinator *ioc = IOCoordinator::get();
|
boost::scoped_ptr<IOCoordinator> ioc(IOCoordinator::get());
|
||||||
vector<string> listing;
|
vector<string> listing;
|
||||||
char buf[80];
|
|
||||||
int err = ioc->listDirectory(path, &listing);
|
int err = ioc->listDirectory(path, &listing);
|
||||||
if (err)
|
if (err)
|
||||||
{
|
|
||||||
int l_errno = errno;
|
|
||||||
cerr << strerror_r(l_errno, buf, 80) << endl;
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
|
||||||
|
|
||||||
struct stat _stat;
|
struct stat _stat;
|
||||||
boost::filesystem::path base(path);
|
boost::filesystem::path base(path);
|
||||||
@@ -92,22 +88,16 @@ void lsOffline(const char *path)
|
|||||||
cout << right << "error" << left << " " << entry << endl;
|
cout << right << "error" << left << " " << entry << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete ioc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void lsOnline(const char *path)
|
void lsOnline(const char *path)
|
||||||
{
|
{
|
||||||
idbdatafile::SMFileSystem fs;
|
idbdatafile::SMFileSystem fs;
|
||||||
list<string> listing;
|
list<string> listing;
|
||||||
char buf[80];
|
|
||||||
|
|
||||||
int err = fs.listDirectory(path, listing);
|
int err = fs.listDirectory(path, listing);
|
||||||
if (err)
|
if (err)
|
||||||
{
|
|
||||||
int l_errno = errno;
|
|
||||||
cerr << strerror_r(l_errno, buf, 80) << endl;
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
|
||||||
|
|
||||||
boost::filesystem::path base(path);
|
boost::filesystem::path base(path);
|
||||||
boost::filesystem::path p;
|
boost::filesystem::path p;
|
||||||
@@ -130,7 +120,6 @@ void lsOnline(const char *path)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cout << strerror_r(errno, buf, 80) << endl;
|
|
||||||
cout.width(15);
|
cout.width(15);
|
||||||
cout << right << "error" << left << " " << entry << endl;
|
cout << right << "error" << left << " " << entry << endl;
|
||||||
}
|
}
|
||||||
|
@@ -18,21 +18,122 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/un.h>
|
||||||
#include "IOCoordinator.h"
|
#include "IOCoordinator.h"
|
||||||
|
#include "SMFileFactory.h"
|
||||||
|
#include "SMDataFile.h"
|
||||||
|
#include "messageFormat.h"
|
||||||
|
#include "boost/scoped_ptr.hpp"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace storagemanager;
|
using namespace storagemanager;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void usage(const char *progname)
|
void usage(const char *progname)
|
||||||
{
|
{
|
||||||
cerr << progname << " reads from stdin and puts it in a file managed by StorageManager" << endl;
|
cerr << progname << " reads from stdin and puts it in a file managed by StorageManager" << endl;
|
||||||
cerr << "Usage: " << progname << " output_file" << endl;
|
cerr << "Usage: " << progname << " output_file" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SMOnline()
|
||||||
|
{
|
||||||
|
struct sockaddr_un addr;
|
||||||
|
memset(&addr, 0, sizeof(addr));
|
||||||
|
addr.sun_family = AF_UNIX;
|
||||||
|
strcpy(&addr.sun_path[1], &socket_name[1]); // first char is null...
|
||||||
|
int clientSocket = ::socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
|
int err = ::connect(clientSocket, (const struct sockaddr *) &addr, sizeof(addr));
|
||||||
|
if (err >= 0)
|
||||||
|
{
|
||||||
|
::close(clientSocket);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void putOffline(const char *fname)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
int l_errno = errno;
|
||||||
|
cerr << "Failed to open/create " << fname << ": " << strerror_r(l_errno, (char *) data, 8192) << endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
read_err = ::read(STDIN_FILENO, data, 8192);
|
||||||
|
if (read_err < 0)
|
||||||
|
{
|
||||||
|
int l_errno = errno;
|
||||||
|
cerr << "Error reading stdin: " << strerror_r(l_errno, (char *) data, 8192) << endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
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 << ": " << strerror_r(l_errno, (char *) data, 8192) << endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
count += write_err;
|
||||||
|
}
|
||||||
|
offset += read_err;
|
||||||
|
} while (read_err > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void putOnline(const char *fname)
|
||||||
|
{
|
||||||
|
uint8_t data[8192];
|
||||||
|
int read_err, write_err;
|
||||||
|
ssize_t count;
|
||||||
|
|
||||||
|
idbdatafile::SMFileFactory ffactory;
|
||||||
|
boost::scoped_ptr<idbdatafile::SMDataFile> df(
|
||||||
|
dynamic_cast<idbdatafile::SMDataFile *>(ffactory.open(fname, "w", 0, 0)));
|
||||||
|
|
||||||
|
if (!df)
|
||||||
|
{
|
||||||
|
int l_errno = errno;
|
||||||
|
cerr << "Failed to open/create " << fname << ": " << strerror_r(l_errno, (char *) data, 8192) << endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
read_err = ::read(STDIN_FILENO, data, 8192);
|
||||||
|
if (read_err < 0)
|
||||||
|
{
|
||||||
|
int l_errno = errno;
|
||||||
|
cerr << "Error reading stdin: " << strerror_r(l_errno, (char *) data, 8192) << endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
count = 0;
|
||||||
|
while (count < read_err)
|
||||||
|
{
|
||||||
|
write_err = df->write(&data[count], read_err - count);
|
||||||
|
if (write_err < 0)
|
||||||
|
{
|
||||||
|
int l_errno = errno;
|
||||||
|
cerr << "Error writing to " << fname << ": " << strerror_r(l_errno, (char *) data, 8192) << endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
count += write_err;
|
||||||
|
}
|
||||||
|
} while (read_err > 0);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
if (argc != 2)
|
if (argc != 2)
|
||||||
@@ -41,43 +142,11 @@ int main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t data[8192];
|
if (SMOnline())
|
||||||
int read_err, write_err;
|
putOnline(argv[1]);
|
||||||
ssize_t count, offset = 0;
|
else
|
||||||
|
putOffline(argv[1]);
|
||||||
IOCoordinator *ioc = IOCoordinator::get();
|
|
||||||
struct stat _stat;
|
|
||||||
read_err = ioc->open(argv[1], O_CREAT | O_TRUNC | O_WRONLY, &_stat);
|
|
||||||
if (read_err < 0)
|
|
||||||
{
|
|
||||||
int l_errno = errno;
|
|
||||||
cerr << "Failed to open/create " << argv[1] << ": " << strerror_r(l_errno, (char *) data, 8192) << endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
read_err = ::read(STDIN_FILENO, data, 8192);
|
|
||||||
if (read_err < 0)
|
|
||||||
{
|
|
||||||
int l_errno = errno;
|
|
||||||
cerr << "Error reading stdin: " << strerror_r(l_errno, (char *) data, 8192) << endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
count = 0;
|
|
||||||
while (count < read_err)
|
|
||||||
{
|
|
||||||
write_err = ioc->write(argv[1], &data[count], offset + count, read_err - count);
|
|
||||||
if (write_err < 0)
|
|
||||||
{
|
|
||||||
int l_errno = errno;
|
|
||||||
cerr << "Error writing to " << argv[1] << ": " << strerror_r(l_errno, (char *) data, 8192) << endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
count += write_err;
|
|
||||||
}
|
|
||||||
offset += read_err;
|
|
||||||
} while (read_err > 0);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -17,6 +17,13 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "IOCoordinator.h"
|
#include "IOCoordinator.h"
|
||||||
|
#include "messageFormat.h"
|
||||||
|
#include "SMFileSystem.h"
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/un.h>
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace storagemanager;
|
using namespace storagemanager;
|
||||||
@@ -27,7 +34,38 @@ void usage(const char *progname)
|
|||||||
cerr << "Usage: " << progname << " file-or-dir1 file-or-dir2 .. file-or-dirN" << endl;
|
cerr << "Usage: " << progname << " file-or-dir1 file-or-dir2 .. file-or-dirN" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
bool SMOnline()
|
||||||
|
{
|
||||||
|
struct sockaddr_un addr;
|
||||||
|
memset(&addr, 0, sizeof(addr));
|
||||||
|
addr.sun_family = AF_UNIX;
|
||||||
|
strcpy(&addr.sun_path[1], &socket_name[1]); // first char is null...
|
||||||
|
int clientSocket = ::socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
|
int err = ::connect(clientSocket, (const struct sockaddr *) &addr, sizeof(addr));
|
||||||
|
if (err >= 0)
|
||||||
|
{
|
||||||
|
::close(clientSocket);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void rmOffline(int argCount, const char **args)
|
||||||
|
{
|
||||||
|
boost::scoped_ptr<IOCoordinator> ioc(IOCoordinator::get());
|
||||||
|
for (int i = 1; i < argCount; i++)
|
||||||
|
ioc->unlink(args[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void rmOnline(int argCount, const char **args)
|
||||||
|
{
|
||||||
|
idbdatafile::SMFileSystem fs;
|
||||||
|
|
||||||
|
for (int i = 1; i < argCount; i++)
|
||||||
|
fs.remove(args[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, const char **argv)
|
||||||
{
|
{
|
||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
{
|
{
|
||||||
@@ -35,9 +73,9 @@ int main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
IOCoordinator *ioc = IOCoordinator::get();
|
if (SMOnline())
|
||||||
for (int i = 1; i < argc; i++)
|
rmOnline(argc, argv);
|
||||||
ioc->unlink(argv[i]);
|
else
|
||||||
|
rmOffline(argc, argv);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user