1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-12-17 01:02:23 +03:00

Implemented IOC::open() + updated unit test

This commit is contained in:
Patrick LeBlanc
2019-03-28 16:05:18 -05:00
parent a2897e593a
commit 9be168eb64
4 changed files with 62 additions and 32 deletions

View File

@@ -223,26 +223,6 @@ int IOCoordinator::read(const char *filename, uint8_t *data, off_t offset, size_
// all done // all done
return count; return count;
/*
int fd, err;
OPEN(filename, O_RDONLY);
size_t count = 0;
::lseek(fd, offset, SEEK_SET);
while (count < length) {
err = ::read(fd, &data[count], length - count);
if (err <= 0)
if (count > 0) // return what was successfully read
return count;
else
return err;
count += err;
}
return count;
*/
} }
int IOCoordinator::write(const char *filename, const uint8_t *data, off_t offset, size_t length) int IOCoordinator::write(const char *filename, const uint8_t *data, off_t offset, size_t length)
@@ -352,6 +332,25 @@ int IOCoordinator::append(const char *filename, const uint8_t *data, size_t leng
int IOCoordinator::open(const char *filename, int openmode, struct stat *out) int IOCoordinator::open(const char *filename, int openmode, struct stat *out)
{ {
if (openmode & O_CREAT)
{
MetadataFile meta(filename);
meta.stat(out);
}
else
{
MetadataFile meta(filename, MetadataFile::no_create_t());
if (!meta.exists())
{
errno = ENOENT;
return -1;
}
meta.stat(out);
}
return 0;
#if 0
int fd, err; int fd, err;
/* create all subdirs if necessary. We don't care if directories actually get created. */ /* create all subdirs if necessary. We don't care if directories actually get created. */
@@ -362,6 +361,7 @@ int IOCoordinator::open(const char *filename, int openmode, struct stat *out)
} }
OPEN(filename, openmode); OPEN(filename, openmode);
return fstat(fd, out); return fstat(fd, out);
#endif
} }
int IOCoordinator::listDirectory(const char *filename, vector<string> *listing) int IOCoordinator::listDirectory(const char *filename, vector<string> *listing)

View File

@@ -10,6 +10,7 @@
#include <boost/uuid/uuid_io.hpp> #include <boost/uuid/uuid_io.hpp>
#include <boost/uuid/random_generator.hpp> #include <boost/uuid/random_generator.hpp>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <unistd.h>
#define max(x, y) (x > y ? x : y) #define max(x, y) (x > y ? x : y)
#define min(x, y) (x < y ? x : y) #define min(x, y) (x < y ? x : y)
@@ -69,6 +70,7 @@ MetadataFile::MetadataFile(const char* filename)
mpLogger = SMLogging::get(); mpLogger = SMLogging::get();
mObjectSize = 5 * (1<<20); mObjectSize = 5 * (1<<20);
_exists = true; _exists = true;
try try
{ {
mObjectSize = stoul(mpConfig->getValue("ObjectStorage", "object_size")); mObjectSize = stoul(mpConfig->getValue("ObjectStorage", "object_size"));
@@ -97,11 +99,11 @@ MetadataFile::MetadataFile(const char* filename)
syslog(LOG_CRIT, "Failed to create %s, got: %s", msMetadataPath.c_str(), e.what()); syslog(LOG_CRIT, "Failed to create %s, got: %s", msMetadataPath.c_str(), e.what());
throw e; throw e;
} }
string metadataFilename = msMetadataPath + "/" + string(filename) + ".meta"; mFilename = msMetadataPath + "/" + string(filename) + ".meta";
if (boost::filesystem::exists(metadataFilename)) if (boost::filesystem::exists(mFilename))
{ {
boost::property_tree::ptree jsontree; boost::property_tree::ptree jsontree;
boost::property_tree::read_json(metadataFilename, jsontree); boost::property_tree::read_json(mFilename, jsontree);
metadataObject newObject; metadataObject newObject;
//try catch //try catch
mVersion = jsontree.get<int>("version"); mVersion = jsontree.get<int>("version");
@@ -157,12 +159,12 @@ MetadataFile::MetadataFile(const char* filename, no_create_t)
syslog(LOG_CRIT, "Failed to create %s, got: %s", msMetadataPath.c_str(), e.what()); syslog(LOG_CRIT, "Failed to create %s, got: %s", msMetadataPath.c_str(), e.what());
throw e; throw e;
} }
string metadataFilename = msMetadataPath + "/" + string(filename) + ".meta"; mFilename = msMetadataPath + "/" + string(filename) + ".meta";
if (boost::filesystem::exists(metadataFilename)) if (boost::filesystem::exists(mFilename))
{ {
_exists = true; _exists = true;
boost::property_tree::ptree jsontree; boost::property_tree::ptree jsontree;
boost::property_tree::read_json(metadataFilename, jsontree); boost::property_tree::read_json(mFilename, jsontree);
metadataObject newObject; metadataObject newObject;
//try catch //try catch
mVersion = jsontree.get<int>("version"); mVersion = jsontree.get<int>("version");
@@ -190,7 +192,24 @@ MetadataFile::~MetadataFile()
} }
bool MetadataFile::exists() int MetadataFile::stat(struct stat *out) const
{
int err = ::stat(mFilename.c_str(), out);
if (err)
{
cout << "Failed to stat " << mFilename << endl;
return err;
}
cout << "Got the stat for " << mFilename << endl;
size_t totalSize = 0;
for (auto &object : mObjects)
totalSize += object.length;
out->st_size = totalSize;
return 0;
}
bool MetadataFile::exists() const
{ {
return _exists; return _exists;
} }
@@ -278,6 +297,7 @@ int MetadataFile::writeMetadata(const char *filename)
int error=0; int error=0;
string metadataFilename = msMetadataPath + "/" + string(filename) + ".meta"; string metadataFilename = msMetadataPath + "/" + string(filename) + ".meta";
boost::filesystem::path pMetadataFilename = metadataFilename;
boost::property_tree::ptree jsontree; boost::property_tree::ptree jsontree;
boost::property_tree::ptree objs; boost::property_tree::ptree objs;
jsontree.put("version",mVersion); jsontree.put("version",mVersion);
@@ -291,8 +311,12 @@ int MetadataFile::writeMetadata(const char *filename)
objs.push_back(std::make_pair("", object)); objs.push_back(std::make_pair("", object));
} }
jsontree.add_child("objects", objs); jsontree.add_child("objects", objs);
if (!boost::filesystem::exists(pMetadataFilename.parent_path()))
boost::filesystem::create_directories(pMetadataFilename.parent_path());
write_json(metadataFilename, jsontree); write_json(metadataFilename, jsontree);
_exists = true; _exists = true;
mFilename = metadataFilename;
return error; return error;
} }

View File

@@ -8,6 +8,7 @@
#include "SMLogging.h" #include "SMLogging.h"
#include <string> #include <string>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h>
#include <stdint.h> #include <stdint.h>
#include <vector> #include <vector>
#include <iostream> #include <iostream>
@@ -32,8 +33,9 @@ class MetadataFile
MetadataFile(const char* filename, no_create_t); // this one won't create it if it doesn't exist MetadataFile(const char* filename, no_create_t); // this one won't create it if it doesn't exist
~MetadataFile(); ~MetadataFile();
bool exists(); bool exists() const;
void printObjects(); void printObjects();
int stat(struct stat *) const;
// returns the objects needed to update // returns the objects needed to update
std::vector<metadataObject> metadataRead(off_t offset, size_t length); std::vector<metadataObject> metadataRead(off_t offset, size_t length);
// updates the metadatafile with new object // updates the metadatafile with new object
@@ -55,12 +57,12 @@ class MetadataFile
private: private:
Config *mpConfig; Config *mpConfig;
std::string prefix;
SMLogging *mpLogger; SMLogging *mpLogger;
int mVersion; int mVersion;
int mRevision; int mRevision;
size_t mObjectSize; size_t mObjectSize;
std::string msMetadataPath; std::string msMetadataPath;
std::string mFilename;
std::set<metadataObject> mObjects; std::set<metadataObject> mObjects;
bool _exists; bool _exists;
//vector<metadataObject> mObjects; //vector<metadataObject> mObjects;

View File

@@ -134,8 +134,12 @@ bool opentask()
assert(_stat->st_size == 0); assert(_stat->st_size == 0);
/* verify the file is there */ /* verify the file is there */
assert(boost::filesystem::exists(filename)); string metaPath = Config::get()->getValue("ObjectStorage", "metadata_path");
::unlink(filename); assert(!metaPath.empty());
metaPath += string("/") + filename + ".meta";
assert(boost::filesystem::exists(metaPath));
::unlink(metaPath.c_str());
cout << "opentask OK" << endl; cout << "opentask OK" << endl;
return true; return true;
} }