1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-12-15 12:09:09 +03:00

Got a basic unit test to work for IOC::read()

This commit is contained in:
Patrick LeBlanc
2019-03-28 14:13:21 -05:00
parent 28ccac81c4
commit e164cbc364
7 changed files with 180 additions and 14 deletions

View File

@@ -47,18 +47,19 @@ MetadataFile::MetadataFile()
mpLogger->log(LOG_CRIT, "ObjectStorage/metadata_path is not set");
throw runtime_error("Please set ObjectStorage/metadata_path in the storagemanager.cnf file");
}
boost::filesystem::create_directories(msMetadataPath);
try
{
boost::filesystem::create_directories(msMetadataPath);
}
catch (exception &e)
{
syslog(LOG_CRIT, "Failed to create %s, got: %s", msMetadataPath.c_str(), e.what());
mpLogger->log(LOG_CRIT, "Failed to create %s, got: %s", msMetadataPath.c_str(), e.what());
throw e;
}
mVersion=1;
mRevision=1;
_exists = false;
}
@@ -67,6 +68,7 @@ MetadataFile::MetadataFile(const char* filename)
mpConfig = Config::get();
mpLogger = SMLogging::get();
mObjectSize = 5 * (1<<20);
_exists = true;
try
{
mObjectSize = stoul(mpConfig->getValue("ObjectStorage", "object_size"));
@@ -122,11 +124,77 @@ MetadataFile::MetadataFile(const char* filename)
}
}
MetadataFile::MetadataFile(const char* filename, no_create_t)
{
mpConfig = Config::get();
mpLogger = SMLogging::get();
mObjectSize = 5 * (1<<20);
try
{
mObjectSize = stoul(mpConfig->getValue("ObjectStorage", "object_size"));
}
catch (...)
{
cerr << "ObjectStorage/object_size must be set to a numeric value" << endl;
throw;
}
try
{
msMetadataPath = mpConfig->getValue("ObjectStorage", "metadata_path");
}
catch (...)
{
mpLogger->log(LOG_CRIT, "Could not load metadata_path from storagemanger.cnf file.");
throw runtime_error("Please set ObjectStorage/metadata_path in the storagemanager.cnf file");
}
boost::filesystem::create_directories(msMetadataPath);
try
{
boost::filesystem::create_directories(msMetadataPath);
}
catch (exception &e)
{
syslog(LOG_CRIT, "Failed to create %s, got: %s", msMetadataPath.c_str(), e.what());
throw e;
}
string metadataFilename = msMetadataPath + "/" + string(filename) + ".meta";
if (boost::filesystem::exists(metadataFilename))
{
_exists = true;
boost::property_tree::ptree jsontree;
boost::property_tree::read_json(metadataFilename, jsontree);
metadataObject newObject;
//try catch
mVersion = jsontree.get<int>("version");
mRevision = jsontree.get<int>("revision");
BOOST_FOREACH(const boost::property_tree::ptree::value_type &v, jsontree.get_child("objects"))
{
metadataObject newObject;
newObject.offset = v.second.get<uint64_t>("offset");
newObject.length = v.second.get<uint64_t>("length");
newObject.key = v.second.get<string>("key");
mObjects.insert(newObject);
}
}
else
{
mVersion = 1;
mRevision = 1;
_exists = false;
}
}
MetadataFile::~MetadataFile()
{
}
bool MetadataFile::exists()
{
return _exists;
}
vector<metadataObject> MetadataFile::metadataRead(off_t offset, size_t length)
{
// this version assumes mObjects is sorted by offset, and there are no gaps between objects
@@ -224,6 +292,7 @@ int MetadataFile::writeMetadata(const char *filename)
}
jsontree.add_child("objects", objs);
write_json(metadataFilename, jsontree);
_exists = true;
return error;
}