Commit 8da32c15 authored by Philipp Götze's avatar Philipp Götze
Browse files

🐛 Fixed a bug (alignment was calculated wrong) +++ minor changes

parent 62d776be
...@@ -39,7 +39,7 @@ else() ...@@ -39,7 +39,7 @@ else()
endif() endif()
# C++ compiler flags # C++ compiler flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wno-deprecated -g -O2 -Wsign-compare") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -g -O2 -Wsign-compare")
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-local-typedefs -Wno-#pragma-messages") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-local-typedefs -Wno-#pragma-messages")
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
......
...@@ -74,7 +74,7 @@ class PTable<KeyType, std::tuple<Types...>> { ...@@ -74,7 +74,7 @@ class PTable<KeyType, std::tuple<Types...>> {
***************************************************************************/ ***************************************************************************/
class BlockIterator { class BlockIterator {
using DataNodeVector = std::vector<persistent_ptr<DataNode<KeyType>>>; using DataNodeVector = std::vector<persistent_ptr<DataNode<KeyType>>>;
const PTable<KeyType, Tuple> parent; const PTable<KeyType, Tuple>& parent;
const ColumnRangeMap predicates; const ColumnRangeMap predicates;
const DataNodeVector candidates; const DataNodeVector candidates;
typename DataNodeVector::const_iterator currentNode; typename DataNodeVector::const_iterator currentNode;
...@@ -82,16 +82,12 @@ class PTable<KeyType, std::tuple<Types...>> { ...@@ -82,16 +82,12 @@ class PTable<KeyType, std::tuple<Types...>> {
uint16_t currentPos = 0u; uint16_t currentPos = 0u;
public: public:
BlockIterator(const PTable<KeyType, Tuple> &_parent, const ColumnRangeMap &_predicates) : BlockIterator(const PTable<KeyType, Tuple> &_parent) :
parent(_parent), parent(_parent), currentNode(nullptr), currentPos(1) {}
predicates(_predicates),
candidates(parent.getCandidateBlocks(predicates)), BlockIterator(const PTable<KeyType, Tuple> &_parent,
currentNode(candidates.cbegin()), const ColumnRangeMap &_predicates) :
currentCnt( BlockIterator(_parent, _predicates, _parent.getCandidateBlocks(_predicates)) {}
candidates.size() > 0 ? reinterpret_cast<const uint32_t &>((*currentNode)->block.get_ro()[gCountPos]) : 0) {
if (candidates.size() > 0) ++(*this);
else currentPos = 1; // --> setting to end()
}
BlockIterator(const PTable<KeyType, Tuple> &_parent, BlockIterator(const PTable<KeyType, Tuple> &_parent,
const ColumnRangeMap &_predicates, const ColumnRangeMap &_predicates,
...@@ -100,14 +96,12 @@ class PTable<KeyType, std::tuple<Types...>> { ...@@ -100,14 +96,12 @@ class PTable<KeyType, std::tuple<Types...>> {
predicates(_predicates), predicates(_predicates),
candidates(_candidates), candidates(_candidates),
currentNode(candidates.cbegin()), currentNode(candidates.cbegin()),
currentCnt( currentCnt(candidates.size() > 0 ?
candidates.size() > 0 ? reinterpret_cast<const uint32_t &>((*currentNode)->block.get_ro()[gCountPos]) : 0) { reinterpret_cast<const uint32_t &>((*currentNode)->block.get_ro()[gCountPos]) : 0) {
if (candidates.size() > 0) ++(*this); if (candidates.size() > 0) ++(*this);
else currentPos = 1; // --> setting to end() else currentPos = 1; // --> setting to end()
} }
BlockIterator(const PTable<KeyType, Tuple> &_parent) :
parent(_parent), currentNode(nullptr), currentPos(1) {}
BlockIterator &operator++() { BlockIterator &operator++() {
if (++currentPos > currentCnt) { if (++currentPos > currentCnt) {
...@@ -150,8 +144,7 @@ class PTable<KeyType, std::tuple<Types...>> { ...@@ -150,8 +144,7 @@ class PTable<KeyType, std::tuple<Types...>> {
bool operator==(BlockIterator other) const { bool operator==(BlockIterator other) const {
return ( return (
// currentBlock == other.currentBlock && // This prevents the comparison with end() // currentBlock == other.currentBlock && // This prevents the comparison with end()
currentPos == other.currentPos && currentPos == other.currentPos && currentCnt == other.currentCnt);
currentCnt == other.currentCnt);
} }
bool operator!=(BlockIterator other) const { return !(*this == other); } bool operator!=(BlockIterator other) const { return !(*this == other); }
...@@ -1038,7 +1031,7 @@ class PTable<KeyType, std::tuple<Types...>> { ...@@ -1038,7 +1031,7 @@ class PTable<KeyType, std::tuple<Types...>> {
callForIndex(std::get<0>(dim), tp, [&dim, &xtr](auto &value) { callForIndex(std::get<0>(dim), tp, [&dim, &xtr](auto &value) {
const auto &nBits = std::get<1>(dim); const auto &nBits = std::get<1>(dim);
const auto &mapping = std::get<2>(dim); const auto &mapping = std::get<2>(dim);
const auto alignment = nBits - std::get<3>(dim); const auto alignment = std::get<3>(dim) - nBits;
const auto &mask = ((1L << nBits) - 1) << alignment; // based on maximum inserted value const auto &mask = ((1L << nBits) - 1) << alignment; // based on maximum inserted value
/* Calculate tuples bin for current dimension and realign bits */ /* Calculate tuples bin for current dimension and realign bits */
...@@ -1187,7 +1180,7 @@ class PTable<KeyType, std::tuple<Types...>> { ...@@ -1187,7 +1180,7 @@ class PTable<KeyType, std::tuple<Types...>> {
} }
} }
return true; return true;
*/ */
} }
const bool findInsertNodeOrSplit(DataNodePtr &node, const Tuple &tp) const { const bool findInsertNodeOrSplit(DataNodePtr &node, const Tuple &tp) const {
...@@ -1213,7 +1206,7 @@ class PTable<KeyType, std::tuple<Types...>> { ...@@ -1213,7 +1206,7 @@ class PTable<KeyType, std::tuple<Types...>> {
/* set results */ /* set results */
node = splitNode; node = splitNode;
return enoughSpace ? false : true; return enoughSpace ? false : true; // split or not
} }
const bool hasEnoughSpace(const DataNodePtr &node, const Tuple &tp) const { const bool hasEnoughSpace(const DataNodePtr &node, const Tuple &tp) const {
......
include(../../cmake/Testing.cmake.in) include(../../cmake/Testing.cmake.in)
if (BUILD_BENCHMARKS) if (BUILD_BENCHMARKS)
do_bench(insert)
do_bench(scan) do_bench(scan)
do_bench(point) do_bench(point)
endif() endif()
...@@ -36,7 +36,7 @@ using PTableType = ptable::PTable<MyKey, MyTuple>; ...@@ -36,7 +36,7 @@ using PTableType = ptable::PTable<MyKey, MyTuple>;
using Vector = std::vector<int>; using Vector = std::vector<int>;
using VectorVector = std::vector<Vector>; using VectorVector = std::vector<Vector>;
const int hibit(int n) noexcept; const int hibit_pos(int n) noexcept;
template <size_t SIZE> template <size_t SIZE>
static inline VectorVector *createPointVector(VectorVector *v); static inline VectorVector *createPointVector(VectorVector *v);
...@@ -47,9 +47,9 @@ struct root { ...@@ -47,9 +47,9 @@ struct root {
const std::string path = ptable::gPmemPath + "benchdb.db"; const std::string path = ptable::gPmemPath + "benchdb.db";
const auto NUM_TUPLES = 1000 * 1000; const auto NUM_TUPLES = 1000 * 1000;
const auto POOL_SIZE = 1024 * 1024 * 1024 * 1ull; // 1GB const auto POOL_SIZE = 1024 * 1024 * 1024 * 2ull; // 2GB
const auto ALIGNMENT = hibit(NUM_TUPLES) + 1; const auto ALIGNMENT = hibit_pos(NUM_TUPLES) + 1;
VectorVector pv; VectorVector pv;
const auto POINT_ACCESS = *createPointVector<NUM_TUPLES>(&pv); const auto POINT_ACCESS = *createPointVector<NUM_TUPLES>(&pv);
...@@ -76,13 +76,13 @@ const VectorVector NON_KEY_RANGES = { ...@@ -76,13 +76,13 @@ const VectorVector NON_KEY_RANGES = {
Vector{0, NUM_TUPLES - 1, 0, NUM_TUPLES - 1} //100,0% Vector{0, NUM_TUPLES - 1, 0, NUM_TUPLES - 1} //100,0%
}; };
const int hibit(int n) noexcept { const int hibit_pos(int n) noexcept {
n |= (n >> 1); int c = 0;
n |= (n >> 2); while (n>>1 != 0) {
n |= (n >> 4); c++;
n |= (n >> 8); n>>=1;
n |= (n >> 16); }
return n - (n >> 1); return c;
} }
template<size_t SIZE> template<size_t SIZE>
......
/*
* Copyright (C) 2017 DBIS Group - TU Ilmenau, All Rights Reserved.
*
* This file is part of PTable.
*
* PTable is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PTable 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 PTable. If not, see <http://www.gnu.org/licenses/>.
*/
#include <unistd.h>
#include "fmt/format.h"
#include "common.h"
using namespace ptable;
int main() {
pool<root> pop;
std::remove(path.c_str());
if (access(path.c_str(), F_OK) != 0) {
insert(pop, path, NUM_TUPLES);
} else {
std::cerr << "Table already exists" << std::endl;
}
auto pTable = pop.get_root()->pTable;
pop.close();
}
\ No newline at end of file
...@@ -30,10 +30,10 @@ static void BM_PointQuery(benchmark::State& state) { ...@@ -30,10 +30,10 @@ static void BM_PointQuery(benchmark::State& state) {
const std::string path = ptable::gPmemPath + "benchdb" + std::to_string(state.range(0)) + ".db"; const std::string path = ptable::gPmemPath + "benchdb" + std::to_string(state.range(0)) + ".db";
std::remove(path.c_str()); //std::remove(path.c_str());
if (access(path.c_str(), F_OK) != 0) { if (access(path.c_str(), F_OK) != 0) {
insert(pop, path, state.range(1)); insert(pop, path, state.range(0));
} else { } else {
std::cerr << "WARNING: Table already exists" << std::endl; std::cerr << "WARNING: Table already exists" << std::endl;
pop = pool<root>::open(path, LAYOUT); pop = pool<root>::open(path, LAYOUT);
......
...@@ -77,7 +77,7 @@ static void BM_NonKeyRangeScan(benchmark::State &state) { ...@@ -77,7 +77,7 @@ static void BM_NonKeyRangeScan(benchmark::State &state) {
static void NonKeyRangeArguments(benchmark::internal::Benchmark* b) { static void NonKeyRangeArguments(benchmark::internal::Benchmark* b) {
for (const auto &arg : NON_KEY_RANGES) b->Args(arg); for (const auto &arg : NON_KEY_RANGES) b->Args(arg);
} }
//BENCHMARK(BM_NonKeyRangeScan)->Apply(NonKeyRangeArguments); BENCHMARK(BM_NonKeyRangeScan)->Apply(NonKeyRangeArguments);
static void BM_PBPTreeKeyScan(benchmark::State &state) { static void BM_PBPTreeKeyScan(benchmark::State &state) {
...@@ -100,7 +100,7 @@ static void BM_PBPTreeKeyScan(benchmark::State &state) { ...@@ -100,7 +100,7 @@ static void BM_PBPTreeKeyScan(benchmark::State &state) {
pop.close(); pop.close();
//std::remove(path.c_str()); //std::remove(path.c_str());
} }
BENCHMARK(BM_PBPTreeKeyScan)->Apply(KeyRangeArguments); //BENCHMARK(BM_PBPTreeKeyScan)->Apply(KeyRangeArguments);
static void BM_PBPTreeScan(benchmark::State &state) { static void BM_PBPTreeScan(benchmark::State &state) {
...@@ -132,7 +132,7 @@ static void BM_PBPTreeScan(benchmark::State &state) { ...@@ -132,7 +132,7 @@ static void BM_PBPTreeScan(benchmark::State &state) {
pop.close(); pop.close();
//std::remove(path.c_str()); //std::remove(path.c_str());
} }
BENCHMARK(BM_PBPTreeScan)->Apply(NonKeyRangeArguments); //BENCHMARK(BM_PBPTreeScan)->Apply(NonKeyRangeArguments);
BENCHMARK_MAIN(); BENCHMARK_MAIN();
...@@ -37,8 +37,7 @@ using pmem::obj::p; ...@@ -37,8 +37,7 @@ using pmem::obj::p;
/**************************************************************************//** /**************************************************************************//**
* \brief This type is used for defining the dimensions for the table. * \brief This type is used for defining the dimensions for the table.
* *
* key: Column ID * entry: <ColumnID, number of BDCC bits , bit alignment when applying mask on value>
* value: <number of BDCC bits , bit alignment when applying mask on value>
*****************************************************************************/ *****************************************************************************/
using Dimensions = std::vector<std::tuple<uint16_t, uint16_t, uint16_t>>; using Dimensions = std::vector<std::tuple<uint16_t, uint16_t, uint16_t>>;
......
Supports Markdown
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