Commit 591250eb authored by Matthieu Dorier's avatar Matthieu Dorier

added UUID to DataSet

parent 06c5e3ef
......@@ -43,6 +43,7 @@ xpkg_import_module (margo REQUIRED margo)
xpkg_import_module (sdskv-client REQUIRED sdskv-client)
xpkg_import_module (sdskv-server REQUIRED sdskv-server)
xpkg_import_module (ch-placement REQUIRED ch-placement)
xpkg_import_module (uuid REQUIRED uuid)
find_package (yaml-cpp REQUIRED)
find_package (CppUnit)
......
#ifndef __HEPNOS_UUID_UTIL_HPP
#define __HEPNOS_UUID_UTIL_HPP
#include <string>
#include <cstring>
#include <thallium/serialization/stl/string.hpp>
#include <boost/serialization/split_member.hpp>
namespace hepnos {
struct UUID {
unsigned char data[16];
public:
UUID();
UUID(const UUID& other) = default;
UUID(UUID&& other) = default;
UUID& operator=(const UUID& other) = default;
UUID& operator=(UUID&& other) = default;
std::string to_string() const;
BOOST_SERIALIZATION_SPLIT_MEMBER()
template<typename Archive>
void save(Archive& a, const unsigned int version) const {
(void)version;
a & std::string(data, 16);
}
template<typename Archive>
void load(Archive& a, const unsigned int version) {
(void)version;
std::string s;
a & s;
std::memcpy(data, s.data(), 16);
}
template<typename T>
friend T& operator<<(T& stream, const UUID& id);
static UUID generate();
void randomize();
};
template<typename T>
T& operator<<(T& stream, const UUID& id) {
stream << (std::string)id;
return stream;
}
}
#endif
......@@ -5,6 +5,7 @@ set(hepnos-src DataStore.cpp
Run.cpp
SubRun.cpp
Event.cpp
UUID.cpp
WriteBatch.cpp)
set(hepnos-service-src service/HEPnOSService.cpp
......@@ -27,7 +28,7 @@ set (hepnos-vers "${HEPNOS_VERSION_MAJOR}.${HEPNOS_VERSION_MINOR}")
set (HEPNOS_VERSION "${hepnos-vers}.${HEPNOS_VERSION_PATCH}")
add_library(hepnos ${hepnos-src})
target_link_libraries (hepnos mercury margo yaml-cpp sdskv-client ch-placement)
target_link_libraries (hepnos uuid mercury margo yaml-cpp sdskv-client ch-placement)
target_include_directories (hepnos PUBLIC $<INSTALL_INTERFACE:include>)
# local include's BEFORE, in case old incompatable .h files in prefix/include
......@@ -41,7 +42,7 @@ set_target_properties (hepnos
SOVERSION ${HEPNOS_VERSION_MAJOR})
add_library(hepnos-service ${hepnos-service-src})
target_link_libraries (hepnos thallium mercury margo yaml-cpp sdskv-client sdskv-server ch-placement)
target_link_libraries (hepnos uuid thallium mercury margo yaml-cpp sdskv-client sdskv-server ch-placement)
target_include_directories (hepnos-service PUBLIC $<INSTALL_INTERFACE:include>)
# local include's BEFORE, in case old incompatable .h files in prefix/include
......
......@@ -119,10 +119,11 @@ DataSet DataSet::createDataSet(const std::string& name) {
throw Exception("Invalid character '/' or '%' in dataset name");
}
std::string parent = fullname();
m_impl->m_datastore->createDataSet(m_impl->m_level+1, parent, name);
return DataSet(std::make_shared<DataSetImpl>(
m_impl->m_datastore, m_impl->m_level+1,
std::make_shared<std::string>(parent), name));
auto new_dataset_impl = std::make_shared<DataSetImpl>(
m_impl->m_datastore, m_impl->m_level+1,
std::make_shared<std::string>(parent), name);
m_impl->m_datastore->createDataSet(m_impl->m_level+1, parent, name, new_dataset_impl->m_uuid);
return DataSet(new_dataset_impl);
}
Run DataSet::createRun(const RunNumber& runNumber) {
......@@ -190,7 +191,8 @@ DataSet::iterator DataSet::find(const std::string& datasetPath) {
datasetName = datasetPath.substr(c+1);
}
bool b = m_impl->m_datastore->dataSetExists(level, containerName, datasetName);
UUID uuid;
bool b = m_impl->m_datastore->loadDataSet(level, containerName, datasetName, uuid);
if(!b) {
return DataSetImpl::m_end;
}
......@@ -200,7 +202,8 @@ DataSet::iterator DataSet::find(const std::string& datasetPath) {
m_impl->m_datastore,
level,
std::make_shared<std::string>(containerName),
datasetName)));
datasetName,
uuid)));
}
DataSet::const_iterator DataSet::find(const std::string& datasetName) const {
......
......@@ -8,6 +8,7 @@
#include "hepnos/DataSet.hpp"
#include "hepnos/RunSet.hpp"
#include "hepnos/UUID.hpp"
namespace hepnos {
......@@ -21,23 +22,28 @@ class DataSetImpl {
uint8_t m_level;
std::shared_ptr<std::string> m_container;
std::string m_name;
UUID m_uuid;
static DataSet::iterator m_end;
DataSetImpl(const std::shared_ptr<DataStoreImpl>& ds,
uint8_t level,
const std::shared_ptr<std::string>& container,
const std::string& name)
const std::string& name,
const UUID& uuid = UUID())
: m_datastore(ds)
, m_level(level)
, m_container(container)
, m_name(name) {}
, m_name(name)
, m_uuid(uuid) {}
DataSetImpl(const std::shared_ptr<DataStoreImpl>& ds,
uint8_t level,
const std::string& fullname)
const std::string& fullname,
const UUID& uuid = UUID())
: m_datastore(ds)
, m_level(level) {
, m_level(level)
, m_uuid(uuid) {
size_t p = fullname.find_last_of('/');
m_name = fullname.substr(p+1);
m_container = std::make_shared<std::string>(fullname.substr(0, p));
......
......@@ -19,9 +19,27 @@
#include "hepnos/DataSet.hpp"
#include "StringHash.hpp"
#include "DataSetImpl.hpp"
#include "hepnos/UUID.hpp"
namespace hepnos {
inline void object_resize(hepnos::UUID& uuid, size_t new_size) {
(void)uuid;
(void)new_size;
}
inline void* object_data(hepnos::UUID& uuid) {
return uuid.data;
}
inline const void* object_data(const hepnos::UUID& uuid) {
return uuid.data;
}
inline size_t object_size(const hepnos::UUID& uuid) {
return sizeof(uuid);
}
////////////////////////////////////////////////////////////////////////////////////////////
// DataStoreImpl implementation
////////////////////////////////////////////////////////////////////////////////////////////
......@@ -166,7 +184,6 @@ class DataStoreImpl {
for(auto provider_it = providers.begin(); provider_it != providers.end(); provider_it++) {
// provider entry should be a sequence
if(!provider_it->second.IsSequence()) {
std::cerr << "Error, provider_it->second is " << provider_it->second << std::endl;
throw Exception("provider entry should be a sequence");
}
for(auto db : provider_it->second) {
......@@ -408,8 +425,9 @@ class DataStoreImpl {
}
// issue an sdskv_list_keys
std::vector<std::string> entries(maxDataSets, std::string(1024,'\0'));
std::vector<UUID> uuids(maxDataSets);
try {
db.list_keys(lb_entry, prefix, entries);
db.list_keyvals(lb_entry, prefix, entries, uuids);
} catch(sdskv::exception& ex) {
throw Exception("Error occured when calling sdskv::database::list_keys (SDSKV error="+std::string(ex.what()) + ")");
}
......@@ -423,7 +441,8 @@ class DataStoreImpl {
current->m_datastore,
level,
current->m_container,
entry.substr(i)
entry.substr(i),
uuids[i]
)
);
}
......@@ -434,8 +453,6 @@ class DataStoreImpl {
* @brief Checks if a particular dataset exists.
*/
bool dataSetExists(uint8_t level, const std::string& containerName, const std::string& objectName) const {
std::cerr << "Checking if dataset [" << (int)level
<< ", " << containerName << ", " << objectName << "] exists ... ";
int ret;
// build key
auto key = buildKey(level, containerName, objectName);
......@@ -443,26 +460,49 @@ class DataStoreImpl {
auto& db = _locateDataSetDb(containerName);
try {
bool b = db.exists(key);
std::cerr << b << std::endl;
return b;
} catch(sdskv::exception& ex) {
throw Exception("Error occured when calling sdskv::database::exists (SDSKV error="+std::to_string(ex.error())+")");
}
return false;
}
/*
* @brief Loads a dataset.
*/
bool loadDataSet(uint8_t level, const std::string& containerName, const std::string& objectName, UUID& uuid) const {
int ret;
// build key
auto key = buildKey(level, containerName, objectName);
// find out which DB to access
auto& db = _locateDataSetDb(containerName);
try {
size_t s = sizeof(uuid);
db.get(static_cast<const void*>(key.data()),
key.size(),
static_cast<void*>(uuid.data),
&s);
return s == sizeof(uuid);
} catch(sdskv::exception& ex) {
if(ex.error() == SDSKV_ERR_UNKNOWN_KEY) {
return false;
}
throw Exception("Error occured when calling sdskv::database::get (SDSKV error="+std::to_string(ex.error())+")");
}
return false;
}
/**
* Creates a DataSet
*/
bool createDataSet(uint8_t level, const std::string& containerName, const std::string& objectName) {
std::cerr << "Creating dataset [" << (int)level
<< ", " << containerName << ", " << objectName << "]" << std::endl;
bool createDataSet(uint8_t level, const std::string& containerName, const std::string& objectName, UUID& uuid) {
// build full name
auto key = _buildDataSetKey(level, containerName, objectName);
// find out which DB to access
auto& db = _locateDataSetDb(containerName);
uuid.randomize();
try {
db.put(key.data(), key.size(), nullptr, 0);
db.put(key.data(), key.size(), uuid.data, sizeof(uuid));
} catch(sdskv::exception& ex) {
if(!ex.error() == SDSKV_ERR_KEYEXISTS) {
return false;
......
#include "hepnos/UUID.hpp"
#include <uuid/uuid.h>
#include <cstring>
namespace hepnos {
UUID::UUID() {}
std::string UUID::to_string() const {
std::string result(32,'\0');
uuid_unparse(data, const_cast<char*>(result.data()));
return result;
}
void UUID::randomize() {
uuid_generate_random(data);
}
UUID UUID::generate() {
UUID result;
result.randomize();
return result;
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment