Skip to content

Commit

Permalink
reformat index related code
Browse files Browse the repository at this point in the history
  • Loading branch information
kuron99 committed Dec 3, 2023
1 parent 464fd1d commit 0354599
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 95 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ file(GLOB SOURCES
"jogasaki/memory/*.cpp"
"jogasaki/memory/details/*.cpp"
"jogasaki/meta/*.cpp"
"jogasaki/meta/impl/*.cpp"
"jogasaki/model/*.cpp"
"jogasaki/plan/*.cpp"
"jogasaki/recovery/*.cpp"
Expand Down
18 changes: 16 additions & 2 deletions src/jogasaki/index/index_accessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@

namespace jogasaki::index {

status decode_fields(std::vector<index::field_info> const& fields,
status decode_fields(
std::vector<index::field_info> const& fields,
kvs::readable_stream& stream,
accessor::record_ref target,
memory::lifo_paged_memory_resource* resource
Expand Down Expand Up @@ -65,6 +66,19 @@ status decode_fields(std::vector<index::field_info> const& fields,
return status::ok;
}

}
mapper::mapper(std::vector<field_info> key_fields, std::vector<field_info> value_fields) :
key_fields_(std::move(key_fields)),
value_fields_(std::move(value_fields))
{}

bool mapper::read(
bool key,
kvs::readable_stream& stream,
accessor::record_ref target,
memory::lifo_paged_memory_resource* resource
) {
auto& flds = key ? key_fields_ : value_fields_;
return decode_fields(flds, stream, target, resource) == status::ok;
}

} // namespace jogasaki::index
10 changes: 2 additions & 8 deletions src/jogasaki/index/index_accessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,14 @@ class mapper {
mapper(
std::vector<field_info> key_fields,
std::vector<field_info> value_fields
) :
key_fields_(std::move(key_fields)),
value_fields_(std::move(value_fields))
{}
);

bool read(
bool key,
kvs::readable_stream& stream,
accessor::record_ref target,
memory::lifo_paged_memory_resource* resource
) {
auto& flds = key ? key_fields_ : value_fields_;
return decode_fields(flds, stream, target, resource) == status::ok;
}
);

private:
std::vector<field_info> key_fields_{};
Expand Down
38 changes: 0 additions & 38 deletions src/jogasaki/index/index_searcher.h

This file was deleted.

73 changes: 73 additions & 0 deletions src/jogasaki/meta/impl/record_layout_creator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright 2018-2023 Project Tsurugi.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "record_layout_creator.h"

#include <jogasaki/meta/record_meta.h>
#include <jogasaki/utils/round.h>

namespace jogasaki::meta::impl {

record_layout_creator::record_layout_creator(
record_layout_creator::fields_type const& fields,
record_layout_creator::nullability_type const& nullability
) {
std::size_t nullity_offset = 0;
auto field_count = fields.size();
BOOST_ASSERT(field_count == nullability.size()); // NOLINT
for(std::size_t i = 0; i < field_count; ++i) {
std::size_t pos = record_meta::npos;
if (nullability[i]) {
pos = nullity_offset;
++nullity_offset;
}
nullity_offset_table_.emplace_back(pos);
}
auto nullity_bytes = utils::round_up_to_power_of_two(
(nullability.count() + bits_per_byte - 1) / bits_per_byte
);
std::size_t record_max_align = 1UL;
std::size_t cur = nullity_bytes;
for(std::size_t i = 0; i < field_count; ++i) {
auto&& field = fields[i];
auto alignment = field.runtime_type_alignment();
record_max_align = std::max(record_max_align, alignment);
cur = (cur + alignment - 1) / alignment * alignment;
value_offset_table_.emplace_back(cur);
cur += field.runtime_type_size();
}
record_alignment_ = record_max_align;
record_size_ = (cur + record_alignment_ - 1) / record_alignment_ * record_alignment_;
BOOST_ASSERT(record_max_align <= record_meta::max_alignment); //NOLINT
BOOST_ASSERT(record_meta::max_alignment % record_max_align == 0); //NOLINT
}

record_layout_creator::value_offset_table_type& record_layout_creator::value_offset_table() noexcept {
return value_offset_table_;
}

record_layout_creator::nullity_offset_table_type& record_layout_creator::nullity_offset_table() noexcept {
return nullity_offset_table_;
}

size_t record_layout_creator::record_alignment() const noexcept {
return record_alignment_;
}

size_t record_layout_creator::record_size() const noexcept {
return record_size_;
}
} // namespace

53 changes: 6 additions & 47 deletions src/jogasaki/meta/impl/record_layout_creator.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,55 +35,15 @@ class record_layout_creator {
using value_offset_table_type = record_meta::value_offset_table_type;
using nullity_offset_table_type = record_meta::nullity_offset_table_type;

record_layout_creator(
fields_type const& fields,
nullability_type const& nullability
) {
std::size_t nullity_offset = 0;
auto field_count = fields.size();
BOOST_ASSERT(field_count == nullability.size()); // NOLINT
for(std::size_t i = 0; i < field_count; ++i) {
std::size_t pos = record_meta::npos;
if (nullability[i]) {
pos = nullity_offset;
++nullity_offset;
}
nullity_offset_table_.emplace_back(pos);
}
auto nullity_bytes = utils::round_up_to_power_of_two(
(nullability.count() + bits_per_byte - 1) / bits_per_byte
);
std::size_t record_max_align = 1UL;
std::size_t cur = nullity_bytes;
for(std::size_t i = 0; i < field_count; ++i) {
auto&& field = fields[i];
auto alignment = field.runtime_type_alignment();
record_max_align = std::max(record_max_align, alignment);
cur = (cur + alignment - 1) / alignment * alignment;
value_offset_table_.emplace_back(cur);
cur += field.runtime_type_size();
}
record_alignment_ = record_max_align;
record_size_ = (cur + record_alignment_ - 1) / record_alignment_ * record_alignment_;
BOOST_ASSERT(record_max_align <= record_meta::max_alignment); //NOLINT
BOOST_ASSERT(record_meta::max_alignment % record_max_align == 0); //NOLINT
}
record_layout_creator(fields_type const& fields, nullability_type const& nullability);

[[nodiscard]] value_offset_table_type& value_offset_table() noexcept {
return value_offset_table_;
}
[[nodiscard]] value_offset_table_type& value_offset_table() noexcept;

[[nodiscard]] nullity_offset_table_type& nullity_offset_table() noexcept {
return nullity_offset_table_;
}
[[nodiscard]] nullity_offset_table_type& nullity_offset_table() noexcept;

[[nodiscard]] size_t record_alignment() const noexcept {
return record_alignment_;
}
[[nodiscard]] size_t record_alignment() const noexcept;

[[nodiscard]] size_t record_size() const noexcept {
return record_size_;
}
[[nodiscard]] size_t record_size() const noexcept;

private:
value_offset_table_type value_offset_table_{};
Expand All @@ -92,5 +52,4 @@ class record_layout_creator {
std::size_t record_size_{};
};

} // namespace

} // namespace jogasaki::meta::impl

0 comments on commit 0354599

Please sign in to comment.