Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/dbzero/core/collections/vector/VLimitedMatrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ DB0_PACKED_END
m_sparse_matrix.commit();
super_t::commit();
}

template <typename ItemT, unsigned int Dim2, typename PtrT>
void VLimitedMatrix<ItemT, Dim2, PtrT>::push_back(const ItemT &value, std::uint32_t dim2_key)
{
Expand Down Expand Up @@ -286,7 +286,7 @@ DB0_PACKED_END
<< "Index (" << index.first << "," << index.second << ") not found" << THROWF_END;
}
}

template <typename ItemT, unsigned int Dim2, typename PtrT>
void VLimitedMatrix<ItemT, Dim2, PtrT>::set(std::pair<std::uint32_t, std::uint32_t> index, const ItemT &value)
{
Expand Down
44 changes: 17 additions & 27 deletions src/dbzero/core/collections/vector/v_bdata_block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,42 +21,38 @@ DB0_PACKED_BEGIN
protected:
using super_t = o_base<o_block_data<ItemT, b_class>, 0, false >;
friend super_t;

o_block_data(std::uint32_t)
{

o_block_data(std::uint32_t page_size_hint) {
auto count = 0x1u << shift(page_size_hint);
// initialize with default values
std::uninitialized_fill(this->getData(), this->getData() + count, ItemT());
}

public:
using iterator = ItemT*;
using const_iterator = const ItemT*;

ItemT *getData()
{
ItemT *getData() {
return reinterpret_cast<ItemT *>(this);
}

const ItemT *getData() const
{
const ItemT *getData() const {
return reinterpret_cast<const ItemT *>(this);
}

static std::size_t measure(std::uint32_t page_size_hint)
{
static std::size_t measure(std::uint32_t page_size_hint) {
return sizeof(ItemT) << shift(page_size_hint);
}

template <class buf_t> static std::size_t safeSizeOf(buf_t buf)
{
template <class buf_t> static std::size_t safeSizeOf(buf_t buf) {
throw std::runtime_error("o_block_data::safeSizeOf member not available");
}

inline const ItemT &getItem(std::size_t index) const
{
inline const ItemT &getItem(std::size_t index) const {
return getData()[index];
}

ItemT &modifyItem(std::size_t index)
{
ItemT &modifyItem(std::size_t index) {
return getData()[index];
}

Expand Down Expand Up @@ -84,20 +80,14 @@ DB0_PACKED_BEGIN
}
return result;
}

/**
* Pull begin (first item) iterator for write
*/
iterator begin()
{

// Pull begin (first item) iterator for write
iterator begin() {
return getData();
}

/**
* Pull begin (first item) iterator for read
*/
const_iterator begin() const
{

// Pull begin (first item) iterator for read
const_iterator begin() const {
return getData();
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/dbzero/core/crdt/CRDT_Allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ namespace db0
std::uint32_t CRDT_Allocator::Alloc::getAllocSize(std::uint32_t address) const
{
// Get allocation size under a specific address or throw exception
if (!isAllocated(address)) {
if (!isAllocated(address)) {
THROWF(db0::BadAddressException) << "Invalid address: " << address << THROWF_END;
}
return m_stride;
Expand Down
8 changes: 4 additions & 4 deletions src/dbzero/object_model/class/Class.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ namespace db0::object_model

{

DB0_PACKED_BEGIN

using namespace db0;
using namespace db0::pools;
using Fixture = db0::Fixture;
Expand All @@ -54,6 +52,8 @@ DB0_PACKED_BEGIN

// fidelity + slot index
using VFidelityVector = db0::v_bvector<std::pair<std::uint8_t, unsigned int> >;

DB0_PACKED_BEGIN

struct DB0_PACKED_ATTR o_class: public db0::o_fixed<o_class>
{
Expand Down Expand Up @@ -83,6 +83,8 @@ DB0_PACKED_BEGIN
);
};

DB0_PACKED_END

// address <-> class_ref conversion functions
// @param type_slot_addr_range the address of the types-specific slot
std::uint32_t classRef(const Class &, std::pair<std::uint64_t, std::uint64_t> type_slot_addr_range);
Expand Down Expand Up @@ -327,6 +329,4 @@ DB0_PACKED_BEGIN

std::optional<std::string> getNameVariant(const Class &, int variant_id);

DB0_PACKED_END

}
2 changes: 1 addition & 1 deletion src/dbzero/object_model/class/Field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace db0::object_model

{

o_field::o_field(RC_LimitedStringPool &string_pool, const char *name)
: m_name(string_pool.addRef(name))
{
Expand Down
10 changes: 5 additions & 5 deletions src/dbzero/object_model/class/Field.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
namespace db0::object_model

{

DB0_PACKED_BEGIN

class Class;
using namespace db0;
using namespace db0::pools;
using ClassPtr = db0::db0_ptr<Class>;

DB0_PACKED_BEGIN

struct DB0_PACKED_ATTR o_field: public db0::o_fixed<o_field>
{
Expand All @@ -29,10 +29,10 @@ DB0_PACKED_BEGIN
o_field() = default;
o_field(RC_LimitedStringPool &, const char *name);
};


DB0_PACKED_END

// NOTE: we use lofi_store<2> since it's the lowest supported type fidelity
using VFieldMatrix = db0::VLimitedMatrix<o_field, lofi_store<2>::size()>;

DB0_PACKED_END

}
33 changes: 20 additions & 13 deletions src/dbzero/object_model/class/Schema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ namespace db0::object_model
return result;
}

void o_schema::initTypeVector(Memspace &memspace, TypeVector &type_vector)
{
if (!type_vector) {
if (!m_type_vector_ptr) {
type_vector = TypeVector(memspace);
m_type_vector_ptr = db0::db0_ptr<TypeVector>(type_vector);
} else {
type_vector = m_type_vector_ptr(memspace);
}
}
}

void o_schema::update(Memspace &memspace,
std::vector<std::tuple<FieldLoc, SchemaTypeId, int> >::const_iterator begin,
std::vector<std::tuple<FieldLoc, SchemaTypeId, int> >::const_iterator end,
Expand All @@ -117,13 +129,7 @@ namespace db0::object_model
m_secondary_type = o_type_item();
}
} else {
if (!type_vector) {
if (m_type_vector_ptr) {
type_vector = m_type_vector_ptr(memspace);
} else {
type_vector = TypeVector(memspace);
}
}
initTypeVector(memspace, type_vector);
auto it = type_vector.find(o_type_item{std::get<1>(*begin), 0});
if (it == type_vector.end()) {
// add new type ID
Expand Down Expand Up @@ -160,7 +166,7 @@ namespace db0::object_model
TypeVector type_vector;
update(memspace, type_vector, collection_size);
}

void o_schema::update(Memspace &memspace, TypeVector &type_vector, std::uint32_t collection_size)
{
// try swapping primary / secondary and extra types
Expand All @@ -183,9 +189,8 @@ namespace db0::object_model
return;
}

if (!type_vector) {
type_vector = m_type_vector_ptr(memspace);
}
initTypeVector(memspace, type_vector);
assert(type_vector);

o_type_item max_item, second_max_item;
for (auto &type_item : type_vector) {
Expand Down Expand Up @@ -440,14 +445,16 @@ namespace db0::object_model
return *m_builder;
}

void Schema::add(FieldID field_id, SchemaTypeId type_id) {
void Schema::add(FieldID field_id, SchemaTypeId type_id)
{
if (type_id == SchemaTypeId::UNDEFINED || type_id == SchemaTypeId::DELETED) {
return;
}
getBuilder().collect(field_id, type_id, 1);
}

void Schema::remove(FieldID field_id, SchemaTypeId type_id) {
void Schema::remove(FieldID field_id, SchemaTypeId type_id)
{
if (type_id == SchemaTypeId::UNDEFINED || type_id == SchemaTypeId::DELETED) {
return;
}
Expand Down
5 changes: 3 additions & 2 deletions src/dbzero/object_model/class/Schema.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,11 @@ DB0_PACKED_BEGIN

private:
void update(Memspace &, TypeVector &, std::uint32_t collection_size);
void initTypeVector(Memspace &, TypeVector &);
};

DB0_PACKED_END

class Schema: protected db0::VLimitedMatrix<o_schema, lofi_store<2>::size()>
{
public:
Expand Down Expand Up @@ -199,7 +202,5 @@ DB0_PACKED_BEGIN
// Update to reflect the collection size change only
void update(std::uint32_t collection_size);
};

DB0_PACKED_END

}
8 changes: 6 additions & 2 deletions src/dbzero/object_model/enum/EnumValue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
namespace db0::object_model

{

DB0_PACKED_BEGIN

using LP_String = db0::LP_String;
using ObjectSharedPtr = db0::object_model::LangConfig::ObjectSharedPtr;
Expand All @@ -29,6 +27,8 @@ DB0_PACKED_BEGIN
std::uint64_t asULong() const;
};

DB0_PACKED_BEGIN

class DB0_PACKED_ATTR o_enum_value_repr: public db0::o_base<o_enum_value_repr, 0, false>
{
protected:
Expand All @@ -54,6 +54,8 @@ DB0_PACKED_BEGIN
}
};

DB0_PACKED_END

// EnumValue placeholder when EnumValue could not be created
// e.g. due to read-only access
struct EnumValueRepr
Expand Down Expand Up @@ -123,6 +125,8 @@ DB0_PACKED_BEGIN
db0::swine_ptr<Fixture> getFixture() const;
};

DB0_PACKED_BEGIN

class DB0_PACKED_ATTR o_enum_value: public db0::o_base<o_enum_value, 0, false>
{
protected:
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/ObjectTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ namespace tests
data.m_types = std::vector<StorageClass> { StorageClass::INT64, StorageClass::POOLED_STRING };
data.m_values = std::vector<Value> { Value(0), Value(0) };

ASSERT_EQ ( 47u, o_object::measure(0, {0, 0}, 0, data, 0) );
ASSERT_EQ ( 44u, o_object::measure(0, {0, 0}, 0, data, 0) );
}

TEST_F( ObjectTest , testObjectInitializerCanBeFoundIfAdded )
{
Workspace workspace("", {}, {}, {}, {}, db0::object_model::initializer());
Expand Down