Commit 1d242627 authored by Philipp Götze's avatar Philipp Götze
Browse files

Added JetBrains and catch to gitgnore +++ removed nvm directory

parent b99eb531
......@@ -425,6 +425,12 @@ FakesAssemblies/
# VSCode
.vscode/
###################################
#
# JetBrains IDEs
#
###################################
**/.idea
###################################
#
......@@ -505,7 +511,8 @@ $RECYCLE.BIN/
# Misc
#
###################################
# ignore catch.hpp header as it is downloaded automatically
**/catch.hpp
# ignore everything in the build directory
# (explicitly included here because separate .gitignore inside that directory)
......
/*
* Copyright (c) 2014-17 The PipeFabric team,
* All Rights Reserved.
*
* This file is part of the PipeFabric package.
*
* PipeFabric is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License (GPL) as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file LICENSE.
* If not you can find the GPL at http://www.gnu.org/copyleft/gpl.html
*/
#ifndef BDCCInfo_hpp_
#define BDCCInfo_hpp_
#include <map>
#include <unordered_map>
#include <algorithm>
#include <iterator>
#include "nvm/PTableInfo.hpp"
#include <numeric>
#include "nvml/include/libpmemobj++/allocator.hpp"
#include "nvml/include/libpmemobj++/p.hpp"
namespace pfabric {
namespace nvm {
using nvml::obj::allocator;
using nvml::obj::p;
/**************************************************************************//**
* \brief Info structure about the BDCC meta data.
*
* It is used in persistent tables to store the BDCC meta data and statistics.
*****************************************************************************/
class BDCCInfo {
using DimensionUses = std::vector<std::tuple<uint16_t, uint16_t, std::bitset<32>>,
nvml::obj::allocator<std::tuple<uint16_t, uint16_t, std::bitset<32>>>>;
p<size_t> numberOfBins;
p<DimensionUses> dimensions;
public:
using ColumnBitsMap = std::map<uint16_t, uint16_t>; //<mapping from column id to number of bits
BDCCInfo() : numberOfBins(0), dimensions() {}
explicit BDCCInfo(const ColumnBitsMap &_bitMap) :
numberOfBins(std::accumulate(_bitMap.begin(), _bitMap.end(), 0,
[](const size_t sum, decltype(*_bitMap.begin()) p) {
return sum + p.second;
})),
dimensions() { deriveMasks(_bitMap); }
const auto find(uint16_t item) const {
for (auto it = dimensions.get_ro().cbegin(); it != dimensions.get_ro().cend(); it++) {
if (std::get<0>(*it) == item) return it;
}
return dimensions.get_ro().cend();
}
const auto numBins() const {
return numberOfBins.get_ro();
}
const auto begin() const {
return dimensions.get_ro().cbegin();
}
const auto end() const {
return dimensions.get_ro().cend();
}
private:
void deriveMasks(ColumnBitsMap colToBits) {
/* Initialize */
for (const auto &dim: colToBits) {
dimensions.get_rw()
.emplace_back(dim.first,
dim.second,
std::bitset<32>());
}
/* Round robin the bins for mapping */
auto bdccSize = numBins();
while (bdccSize > 0) {
auto i = 0ul;
for (auto &dim: colToBits) {
if (std::get<1>(dim)-- > 0) {
std::get<2>(dimensions.get_rw()[i++])[--bdccSize] = 1;
}
}
}
}
};/* struct BDCCInfo */
}
} /* namespace pfabric::nvm */
#endif /* PTuple_hpp_ */
/*
* Copyright (c) 2014-17 The PipeFabric team,
* All Rights Reserved.
*
* This file is part of the PipeFabric package.
*
* PipeFabric is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License (GPL) as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file LICENSE.
* If not you can find the GPL at http://www.gnu.org/copyleft/gpl.html
*/
#ifndef DataNode_hpp_
#define DataNode_hpp_
#include <array>
#include "nvml/include/libpmemobj++/make_persistent.hpp"
#include "nvml/include/libpmemobj++/persistent_ptr.hpp"
#define PLOG(msg) if(DO_LOG) std::cout << "[PTable] " << msg << '\n';
namespace pfabric {
namespace nvm {
using nvml::obj::persistent_ptr;
using nvml::obj::make_persistent;
using nvml::obj::delete_persistent;
/** Positions in NVM_Block */
const int gDDCRangePos1 = 0;
const int gDDCRangePos2 = 4;
const int gCountPos = 8;
const int gFreeSpacePos = 12;
const int gSmaOffsetPos = 14;
const int gDataOffsetPos = 16;
/** Sizes/Lengths in NVM_Block */
const int gFixedHeaderSize = 14;
const int gDDCValueSize = 4;
const int gAttrOffsetSize = 4;
const int gOffsetSize = 2;
/** The size of a single block in persistent memory */
static constexpr std::size_t gBlockSize = 1 << 14; // 12->4KB, 15->32KB, max 16 due to data types
/**
* \brief This type represents a byte array used for persistent structures.
*
* A BDCC_Block is a PAX oriented data block with the following structure for 32KB:
* <ddc_range><ddc_cnt><sma_offset_0><data_offset_0> ...<sma_offset_n><data_offset_n>
* <sma_min_0><sma_max_0><data_vector_0> ... <sma_min_n><sma_max_n><data_vector_n>
* 0 ddc_range -> long (x2) - 8 Byte
* 8 ddc_cnt -> long - 4 Byte
* 12 free_space -> unsigned short
* for each attribute:
* 14 sma_offset_x -> unsigned short - 2 Byte (depends on block size)
* 16 data_offset_x -> unsigned short
* ...
*
* for each attribute (int, double):
* . sma_min_x -> size of attributes data type
* . sma_max_x -> size of attributes data type
* . data_vector -> size of attributes data type * ddc_cnt
* ...
*
* for each attribute (string - data starts at the end of the minipage):
* . sma_min_offset_x -> unsigned short
* . sma_max_offset_x -> unsigned short
* . data_offset_vector -> unsigned short * ddc_cnt
* . ...
* . data -> size of all strings + ddc_cnt (Nul termination)
*/
using BDCC_Block = typename std::array<uint8_t, gBlockSize>;
template<typename KeyType>
struct DataNode {
using KeyVector = std::array<KeyType, 8192>; // <KeyType, nvml::obj::allocator<KeyType>>;
using HistogramType = std::unordered_map<uint32_t,
std::size_t,
std::hash<uint32_t>,
std::equal_to<uint32_t>,
nvml::obj::allocator<uint32_t>>;
DataNode() : next(nullptr) {}
DataNode(BDCC_Block _block) : next(nullptr), block(_block) {}
persistent_ptr<struct DataNode> next;
p<BDCC_Block> block;
p<KeyVector> keys;
p<HistogramType> histogram;
const uint32_t calcAverageBDCC() const {
auto sum = 0u;
for(const auto &bdccValue : histogram.get_ro()) {
sum += bdccValue.first * bdccValue.second;
}
return sum / reinterpret_cast<const uint32_t &>(block.get_ro()[gCountPos]);
}
void clear() {
if (next) {
//delete_persistent<struct DataNode>(next);
next = nullptr;
}
delete_persistent<struct DataNode>(this);
}
};
} /* end namespace nvm */
} /* end namespace pfabric */
#endif /* DataNode_hpp_ */
This diff is collapsed.
/*
Taken from: https://pmem.io/2017/01/23/cpp-strings.html
*/
#ifndef PString_hpp_
#define PString_hpp_
#include "nvml/include/libpmemobj/tx_base.h"
#include "nvml/include/libpmemobj++/make_persistent.hpp"
#include "nvml/include/libpmemobj++/make_persistent_array.hpp"
#include "nvml/include/libpmemobj++/persistent_ptr.hpp"
using nvml::obj::delete_persistent;
using nvml::obj::make_persistent;
using nvml::obj::persistent_ptr;
namespace pfabric { namespace nvm {
#define SSO_CHARS 15
#define SSO_SIZE (SSO_CHARS + 1)
class PString {
public:
char *data() const { return str ? str.get() : const_cast<char *>(sso); }
void reset();
void set(std::string *value);
private:
char sso[SSO_SIZE];
persistent_ptr<char[]> str;
};
inline void PString::reset() {
pmemobj_tx_add_range_direct(sso, 1);
sso[0] = 0;
if (str) delete_persistent<char[]>(str, strlen(str.get()) + 1);
}
inline void PString::set(std::string *value) {
unsigned long length = value->length();
if (length <= SSO_CHARS) {
if (str) {
delete_persistent<char[]>(str, strlen(str.get()) + 1);
str = nullptr;
}
pmemobj_tx_add_range_direct(sso, SSO_SIZE);
strcpy(sso, value->c_str());
} else {
if (str) delete_persistent<char[]>(str, strlen(str.get()) + 1);
str = make_persistent<char[]>(length + 1);
strcpy(str.get(), value->c_str());
}
}
}} /* namespace pfabric::nvm */
#endif
This diff is collapsed.
#include "PTableInfo.hpp"
#include <sstream>
using namespace pfabric::nvm;
std::string PTableInfo::generateTypeDef() const {
std::ostringstream os;
bool first = true;
os << "TuplePtr<Tuple<";
for (auto& col : *mColumns) {
if (first)
first = false;
else
os << ", ";
os << col.getType();
}
os << ">>";
return os.str();
}
std::string PTableInfo::typeSignature() const {
std::ostringstream os;
os << "[";
for (auto& col : *mColumns) {
switch (col.getType()) {
case ColumnInfo::Void_Type:
os << "V";
break;
case ColumnInfo::Int_Type:
os << "i";
break;
case ColumnInfo::Double_Type:
os << "d";
break;
case ColumnInfo::String_Type:
os << "S";
break;
}
}
os << "]";
return os.str();
}
int PTableInfo::findColumnByName(const std::string& colName) const {
for (std::size_t i = 0; i < (*mColumns).size(); i++) {
if (mColumns->at(i).getName() == colName) return (int)i;
}
return -1;
}
\ No newline at end of file
#ifndef PTableInfo_hpp_
#define PTableInfo_hpp_
#include <cstddef>
#include <cstring>
#include <initializer_list>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include "table/TableInfo.hpp"
#include "nvm/PString.hpp"
#include "nvml/include/libpmemobj++/allocator.hpp"
#include "nvml/include/libpmemobj++/detail/persistent_ptr_base.hpp"
#include "nvml/include/libpmemobj++/make_persistent.hpp"
#include "nvml/include/libpmemobj++/make_persistent_array.hpp"
#include "nvml/include/libpmemobj++/p.hpp"
#include "nvml/include/libpmemobj++/pool.hpp"
#include "nvml/include/libpmemobj++/persistent_ptr.hpp"
#include "nvml/include/libpmemobj++/transaction.hpp"
#include "nvml/include/libpmemobj++/utils.hpp"
using nvml::obj::delete_persistent;
using nvml::obj::make_persistent;
using nvml::obj::p;
using nvml::obj::persistent_ptr;
using nvml::obj::pool_base;
using nvml::obj::pool_by_vptr;
using nvml::obj::transaction;
namespace pfabric { namespace nvm {
class PColumnInfo {
public:
PColumnInfo(pool_base pop) : PColumnInfo(pop, "", ColumnInfo::ColumnType::Void_Type) {}
PColumnInfo(pool_base pop, const std::string& n, ColumnInfo::ColumnType ct) : mColType(ct) {
transaction::exec_tx(pop, [&] {
mColName = make_persistent<char[]>(n.length() +1);
strcpy(mColName.get(), n.c_str());
});
}
const std::string getName() const { return mColName.get(); }
const ColumnInfo::ColumnType getType() const { return mColType.get_ro(); }
private:
persistent_ptr<char[]> mColName;
p<ColumnInfo::ColumnType> mColType;
};
using ColumnInitList = std::initializer_list<std::pair<std::string, ColumnInfo::ColumnType>>;
class PTableInfo {
public:
using PTableInfoPtr = persistent_ptr<PTableInfo>;
using ColumnVector = std::vector<PColumnInfo, nvml::obj::allocator<PColumnInfo>>;
using ColumnIterator = ColumnVector::const_iterator;
PTableInfo(){}
PTableInfo(const TableInfo& _tInfo, ColumnInfo::ColumnType keyType = ColumnInfo::Void_Type) : mKeyType(keyType){
auto pop = pool_by_vptr(this);
transaction::exec_tx(pop, [&] {
mName.set(const_cast<std::string*>(& _tInfo.tableName()));
mColumns = make_persistent<ColumnVector>();
for (const auto &c : _tInfo)
mColumns->push_back(PColumnInfo(pop, c.getName(), c.getType()));
});
}
PTableInfo(const std::string& name, ColumnInitList columns,
ColumnInfo::ColumnType keyType = ColumnInfo::Void_Type) : mKeyType(keyType) {
auto pop = pool_by_vptr(this);
transaction::exec_tx(pop, [&] {
mName.set(const_cast<std::string*>(&name));
mColumns = make_persistent<ColumnVector>();
for (const auto &c : columns)
mColumns->push_back(PColumnInfo(pop, c.first, c.second));
});
}
PTableInfo(const std::string& name, const ColumnVector& columns,
ColumnInfo::ColumnType keyType = ColumnInfo::Void_Type) : mKeyType(keyType) {
auto pop = pool_by_vptr(this);
transaction::exec_tx(pop, [&] {
mName.set(const_cast<std::string*>(&name));
mColumns = make_persistent<ColumnVector>(columns.begin(), columns.end());
});
}
const std::string tableName() const { return std::string(mName.data()); }
std::string typeSignature() const;
std::string generateTypeDef() const;
ColumnInfo::ColumnType typeOfKey() const { return mKeyType.get_ro(); }
int findColumnByName(const std::string& colName) const;
const PColumnInfo& columnInfo(int pos) const { return mColumns->at(pos); }
const std::size_t numColumns() const { return mColumns->size(); }
void setColumns(const ColumnVector vec) {
auto pop = pool_by_vptr(this);
transaction::exec_tx(pop, [&] {
delete_persistent<ColumnVector>(mColumns);
mColumns = make_persistent<ColumnVector>(vec.cbegin(), vec.cend());
});
}
PTableInfoPtr makeShared() const {
auto pop = pool_by_vptr(this);
PTableInfoPtr tInfo_ptr = nullptr;
transaction::exec_tx(pop, [&] {
tInfo_ptr = make_persistent<PTableInfo>(std::string(mName.data()), *mColumns, mKeyType.get_ro());
});
return tInfo_ptr;
}
ColumnIterator begin() const { return mColumns->begin(); }
ColumnIterator end() const { return mColumns->end(); }
// private:
PString mName;
persistent_ptr<ColumnVector> mColumns;
p<ColumnInfo::ColumnType> mKeyType;
};
}
using PTableInfoPtr = persistent_ptr<nvm::PTableInfo>;
} /* namespace pfabric::nvm */
namespace std {
template <>
struct hash<pfabric::nvm::PColumnInfo> {
std::size_t operator()(const pfabric::nvm::PColumnInfo& c) const {
return std::hash<std::string>()(c.getName());
}
};
}
#endif
/*
* Copyright (c) 2014-17 The PipeFabric team,
* All Rights Reserved.
*
* This file is part of the PipeFabric package.
*
* PipeFabric is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License (GPL) as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file LICENSE.
* If not you can find the GPL at http://www.gnu.org/copyleft/gpl.html
*/
#ifndef PTuple_hpp_
#define PTuple_hpp_
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <string>
#include "core/PFabricTypes.hpp"
#include "core/Tuple.hpp"
#include "nvm/DataNode.hpp"
#include "nvml/include/libpmemobj++/persistent_ptr.hpp"
using nvml::obj::persistent_ptr;
using nvml::obj::p;
namespace pfabric {
namespace nvm {
namespace detail {
/**************************************************************************//**
* \brief get_helper is a helper function to receive an attribute of a PTuple.
*
* \tparam T
* the type of the requested attribute
* \tparam ID
* the index of the requested attribute
*****************************************************************************/
template<typename T, std::size_t ID, typename KeyType>
struct get_helper;
/**************************************************************************//**
* \brief General overload for any type of attribute.
*
* \tparam T
* the type of the requested attribute
* \tparam ID
* the index of the requested attribute
*****************************************************************************/
template<typename T, std::size_t ID, typename KeyType>
struct get_helper {
static T apply(persistent_ptr<DataNode<KeyType>> node, const uint16_t *offsets) {
T val;
uint8_t* ptr = reinterpret_cast<uint8_t*>(&val);
std::copy(node->block.get_ro().begin() + offsets[ID], node->block.get_ro().begin() + offsets[ID] + sizeof(T), ptr);
return val;
}
};
/**************************************************************************//**
* \brief Specialization for retrieving an attribute of type string.
*
* \tparam T
* the type of the requested attribute
* \tparam ID
* the index of the requested attribute
*****************************************************************************/
template<std::size_t ID, typename KeyType>
struct get_helper<std::string, ID, KeyType> {
static std::string apply(persistent_ptr<DataNode<KeyType>> node, const uint16_t *offsets) {
return reinterpret_cast<const char (&)[]>(node->block.get_ro()[offsets[ID]]);
}
};
/**************************************************************************//**
* \brief Specialization for retrieving an attribute of type 32 byte integer.
*
* \tparam T
* the type of the requested attribute
* \tparam ID
* the index of the requested attribute
*****************************************************************************/
template<std::size_t ID, typename KeyType>
struct get_helper<int, ID, KeyType> {
static int apply(persistent_ptr<DataNode<KeyType>> node, const uint16_t *offsets) {