You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-12-15 12:09:09 +03:00
Updated the unit test for copytask, fixed up IOC::copyFile().
This commit is contained in:
@@ -605,18 +605,31 @@ int IOCoordinator::copyFile(const char *filename1, const char *filename2)
|
|||||||
Synchronizer *sync = Synchronizer::get();
|
Synchronizer *sync = Synchronizer::get();
|
||||||
bf::path metaFile1 = metaPath/(string(filename1) + ".meta");
|
bf::path metaFile1 = metaPath/(string(filename1) + ".meta");
|
||||||
bf::path metaFile2 = metaPath/(string(filename2) + ".meta");
|
bf::path metaFile2 = metaPath/(string(filename2) + ".meta");
|
||||||
|
int err;
|
||||||
|
char errbuf[80];
|
||||||
|
|
||||||
if (bf::exists(metaFile2))
|
if (bf::exists(metaFile2))
|
||||||
deleteMetaFile(metaFile2);
|
deleteMetaFile(metaFile2);
|
||||||
|
// since we don't implement mkdir(), assume the caller did that and
|
||||||
|
// create any necessary parent dirs for filename2
|
||||||
|
try
|
||||||
|
{
|
||||||
|
bf::create_directories(metaFile2.parent_path());
|
||||||
|
}
|
||||||
|
catch(bf::filesystem_error &e)
|
||||||
|
{
|
||||||
|
logger->log(LOG_CRIT, "IOCoordinator::copyFile(): failed to create directory %s. Got %s",
|
||||||
|
metaFile2.parent_path().string().c_str(), strerror_r(e.code().value(), errbuf, 80));
|
||||||
|
errno = e.code().value();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
vector<string> newJournalEntries;
|
vector<string> newJournalEntries;
|
||||||
ScopedReadLock lock(this, filename1);
|
ScopedReadLock lock(this, filename1);
|
||||||
MetadataFile meta1(metaFile1);
|
MetadataFile meta1(metaFile1);
|
||||||
MetadataFile meta2(metaFile2);
|
MetadataFile meta2(metaFile2);
|
||||||
vector<metadataObject> objects = meta1.metadataRead(0, meta1.getLength());
|
vector<metadataObject> objects = meta1.metadataRead(0, meta1.getLength());
|
||||||
|
|
||||||
int err;
|
|
||||||
char errbuf[80];
|
|
||||||
// TODO. I dislike large try-catch blocks, and large loops. Maybe a little refactoring is in order.
|
// TODO. I dislike large try-catch blocks, and large loops. Maybe a little refactoring is in order.
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -766,23 +766,18 @@ bool copytask()
|
|||||||
copy it
|
copy it
|
||||||
verify it exists
|
verify it exists
|
||||||
*/
|
*/
|
||||||
const char *filename = "copytest1";
|
const char *source = "dummy1";
|
||||||
::unlink(filename);
|
const char *dest = "dummy2";
|
||||||
int fd = ::open(filename, O_CREAT | O_RDWR, 0666);
|
MetadataFile meta1(source);
|
||||||
assert(fd > 0);
|
|
||||||
scoped_closer f(fd);
|
|
||||||
int err = ::write(fd, "testjunk", 8);
|
|
||||||
assert(err == 8);
|
|
||||||
|
|
||||||
uint8_t buf[1024];
|
uint8_t buf[1024];
|
||||||
copy_cmd *cmd = (copy_cmd *) buf;
|
copy_cmd *cmd = (copy_cmd *) buf;
|
||||||
cmd->opcode = COPY;
|
cmd->opcode = COPY;
|
||||||
cmd->file1.flen = strlen(filename);
|
cmd->file1.flen = strlen(source);
|
||||||
strncpy(cmd->file1.filename, filename, cmd->file1.flen);
|
strncpy(cmd->file1.filename, source, cmd->file1.flen);
|
||||||
const char *filename2 = "copytest2";
|
|
||||||
f_name *file2 = (f_name *) &cmd->file1.filename[cmd->file1.flen];
|
f_name *file2 = (f_name *) &cmd->file1.filename[cmd->file1.flen];
|
||||||
file2->flen = strlen(filename2);
|
file2->flen = strlen(dest);
|
||||||
strncpy(file2->filename, filename2, file2->flen);
|
strncpy(file2->filename, dest, file2->flen);
|
||||||
|
|
||||||
uint len = (uint64_t) &file2->filename[file2->flen] - (uint64_t) buf;
|
uint len = (uint64_t) &file2->filename[file2->flen] - (uint64_t) buf;
|
||||||
::write(sessionSock, buf, len);
|
::write(sessionSock, buf, len);
|
||||||
@@ -790,7 +785,7 @@ bool copytask()
|
|||||||
c.run();
|
c.run();
|
||||||
|
|
||||||
// read the response
|
// read the response
|
||||||
err = ::recv(sessionSock, buf, 1024, MSG_DONTWAIT);
|
int err = ::recv(sessionSock, buf, 1024, MSG_DONTWAIT);
|
||||||
sm_response *resp = (sm_response *) buf;
|
sm_response *resp = (sm_response *) buf;
|
||||||
assert(err == sizeof(sm_response));
|
assert(err == sizeof(sm_response));
|
||||||
assert(resp->header.type == SM_MSG_START);
|
assert(resp->header.type == SM_MSG_START);
|
||||||
@@ -799,9 +794,12 @@ bool copytask()
|
|||||||
assert(resp->returnCode == 0);
|
assert(resp->returnCode == 0);
|
||||||
|
|
||||||
// verify copytest2 is there
|
// verify copytest2 is there
|
||||||
assert(boost::filesystem::exists(filename2));
|
MetadataFile meta2(dest, MetadataFile::no_create_t());
|
||||||
::unlink(filename);
|
assert(meta2.exists());
|
||||||
::unlink(filename2);
|
|
||||||
|
bf::path metaPath = IOCoordinator::get()->getMetadataPath();
|
||||||
|
bf::remove(metaPath/(string(source) + ".meta"));
|
||||||
|
bf::remove(metaPath/(string(dest) + ".meta"));
|
||||||
cout << "copytask OK " << endl;
|
cout << "copytask OK " << endl;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1295,7 +1293,7 @@ int main()
|
|||||||
makeConnection();
|
makeConnection();
|
||||||
cout << "connected" << endl;
|
cout << "connected" << endl;
|
||||||
scoped_closer sc1(serverSock), sc2(sessionSock), sc3(clientSock);
|
scoped_closer sc1(serverSock), sc2(sessionSock), sc3(clientSock);
|
||||||
|
|
||||||
opentask();
|
opentask();
|
||||||
metadataUpdateTest();
|
metadataUpdateTest();
|
||||||
// requires 8K object size to test boundries
|
// requires 8K object size to test boundries
|
||||||
|
|||||||
Reference in New Issue
Block a user