Skip to content

Commit

Permalink
testing loading relations done
Browse files Browse the repository at this point in the history
  • Loading branch information
billsioros committed Dec 5, 2018
1 parent 1ee9dc8 commit fc5ecdb
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 18 deletions.
7 changes: 5 additions & 2 deletions inc/relation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ namespace RHJ
{
extern struct Meta
{
uint64_t rowSize, columnSize;
tuple_key_t** columns;
__off_t mappingSize;
void * mapping;

tuple_key_t rowSize, columnSize;
tuple_payload_t ** columns;
} * meta;

struct Relation {
Expand Down
125 changes: 125 additions & 0 deletions test/executioner_unit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@

#include <iostream>
#include <cstring>
#include <climits>
#include <cassert>

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

#include <sys/mman.h>

#include <fcntl.h>

#include <relation.hpp>
#include <list.hpp>

// Generate a list of the full paths of the relations and store it in files.txt
// for file in "$(ls ./test_data/small/r*)"; do echo "$(realpath $file)"; done > ./test_data/files.txt && echo "Done" >> ./test_data/files.txt

// Macro used in order to exit if condition is met
#define exit_if(condition, message) \
do \
{ \
if (condition) \
{ \
std::perror(message); std::exit(errno); \
} \
} while (false) \

// Macro definition for consistency with above declaration
#define exit_if_not(condition) assert(condition)

int main()
{
utility::list<char *> paths;

// Throw exception if any of the following flags are set for std::cin
std::cin.exceptions(std::ios_base::badbit | std::ios_base::failbit);

while(true)
{
char buff[PATH_MAX + 1UL];

// Atempt to read the current line
try
{
std::cin.getline(buff, sizeof(buff));
}
catch (std::ios_base::failure& f)
{
std::cerr
<< "iteration: " << paths.size()
<< " exception: " << f.what()
<< std::endl;

std::exit(f.code().value());
}

if (!std::strcmp(buff, "Done"))
break;

paths.push_back(new char[std::strlen(buff) + 1UL]);

std::strcpy(paths.back(), buff);
}

std::size_t total = paths.size(); exit_if_not(total > 0UL);

RHJ::meta = new RHJ::Meta[total];

for (std::size_t i = 0UL; i < total; i++)
{
// Open file
int fd = open(paths.front(), O_RDONLY);
exit_if(fd < 0, paths.front());

// Retrieve its size
struct stat st;
exit_if(fstat(fd, &st) < 0, paths.front());

// Map file to memory
RHJ::meta[i].mapping = mmap(nullptr, (RHJ::meta[i].mappingSize = st.st_size), PROT_READ, MAP_PRIVATE, fd, 0);
exit_if(RHJ::meta[i].mapping == MAP_FAILED, paths.front());

// Close file
exit_if(close(fd) < 0, paths.front());

// Deallocate uneccessary memory
delete[] paths.front(); paths.erase(paths.begin());

// Copy Metadata
void * mapping_clone = RHJ::meta[i].mapping;

void * rsptr = reinterpret_cast<void *>(&RHJ::meta[i].rowSize);
std::memmove(rsptr, mapping_clone, sizeof(tuple_key_t));
reinterpret_cast<tuple_key_t *&>(mapping_clone)++;

void * csptr = reinterpret_cast<void *>(&RHJ::meta[i].columnSize);
std::memmove(csptr, mapping_clone, sizeof(tuple_key_t));
reinterpret_cast<tuple_key_t *&>(mapping_clone)++;

// Create Index
RHJ::meta[i].columns = new tuple_payload_t*[RHJ::meta[i].columnSize];
for(tuple_key_t j = 0UL; j < RHJ::meta[i].columnSize; j++)
{
const tuple_key_t index = j * RHJ::meta[i].rowSize;

tuple_payload_t * const mapping = &(reinterpret_cast<tuple_payload_t*>(RHJ::meta[i].mapping)[index]);

RHJ::meta[i].columns[j] = mapping;
}
}

for(std::size_t i = 0; i < total; i++)
{
exit_if(munmap(RHJ::meta[i].mapping, RHJ::meta[i].mappingSize) < 0, ("munmap No." + std::to_string(i)).c_str());

delete[] RHJ::meta[i].columns;
}

delete[] RHJ::meta;

return 0;
}
30 changes: 15 additions & 15 deletions test_data/files.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
./test_data/small/r0
./test_data/small/r1
./test_data/small/r2
./test_data/small/r3
./test_data/small/r4
./test_data/small/r5
./test_data/small/r6
./test_data/small/r7
./test_data/small/r8
./test_data/small/r9
./test_data/small/r10
./test_data/small/r11
./test_data/small/r12
./test_data/small/r13
Done
/home/massiva/Documents/Courses/Application-Development-for-Information-Systems/test_data/small/r0
/home/massiva/Documents/Courses/Application-Development-for-Information-Systems/test_data/small/r1
/home/massiva/Documents/Courses/Application-Development-for-Information-Systems/test_data/small/r10
/home/massiva/Documents/Courses/Application-Development-for-Information-Systems/test_data/small/r11
/home/massiva/Documents/Courses/Application-Development-for-Information-Systems/test_data/small/r12
/home/massiva/Documents/Courses/Application-Development-for-Information-Systems/test_data/small/r13
/home/massiva/Documents/Courses/Application-Development-for-Information-Systems/test_data/small/r2
/home/massiva/Documents/Courses/Application-Development-for-Information-Systems/test_data/small/r3
/home/massiva/Documents/Courses/Application-Development-for-Information-Systems/test_data/small/r4
/home/massiva/Documents/Courses/Application-Development-for-Information-Systems/test_data/small/r5
/home/massiva/Documents/Courses/Application-Development-for-Information-Systems/test_data/small/r6
/home/massiva/Documents/Courses/Application-Development-for-Information-Systems/test_data/small/r7
/home/massiva/Documents/Courses/Application-Development-for-Information-Systems/test_data/small/r8
/home/massiva/Documents/Courses/Application-Development-for-Information-Systems/test_data/small/r9
Done
2 changes: 1 addition & 1 deletion utility.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ then
confirm "${target////}.tar.gz"

tar -zcvf "${target////}".tar.gz "$target"
fi
fi
else
echo "# Options:"
echo "# -t, --transfer Transfer a file / directory over ssh"
Expand Down

0 comments on commit fc5ecdb

Please sign in to comment.