Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
JPewterschmidt committed May 12, 2024
2 parents 975c9aa + a26099a commit 017c602
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 22 deletions.
16 changes: 8 additions & 8 deletions example/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ koios::eager_task<> db_test()
co_await db->init();

// #1
spdlog::debug("db_test: start insert");
for (size_t i{}; i < scale; ++i)
{
auto k = ::std::to_string(i);
co_await db->insert(k, "test value abcdefg abcdefg");
}
spdlog::debug("db_test: insert complete");
//spdlog::debug("db_test: start insert");
//for (size_t i{}; i < scale; ++i)
//{
// auto k = ::std::to_string(i);
// co_await db->insert(k, "test value abcdefg abcdefg");
//}
//spdlog::debug("db_test: insert complete");

//#2
// #2
//spdlog::debug("db_test: start insert");
//for (size_t i{}; i < scale; ++i)
//{
Expand Down
6 changes: 5 additions & 1 deletion include/frenzykv/io/in_mem_rw.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class in_mem_rw final

in_mem_rw(in_mem_rw&& other) noexcept
: m_blocks{ ::std::move(other.m_blocks) },
m_block_size{ other.m_block_size }
m_block_size{ other.m_block_size },
m_id{ ::std::move(other.m_id) }
{
}

Expand All @@ -38,6 +39,7 @@ class in_mem_rw final
{
m_blocks = ::std::move(other.m_blocks);
m_block_size = other.m_block_size;
m_id = ::std::move(other.m_id);
return *this;
}

Expand Down Expand Up @@ -70,6 +72,7 @@ class in_mem_rw final
}

koios::task<size_t> dump_to(seq_writable& file);
::std::string_view filename() const noexcept override { return m_id.to_string(); }

private:
koios::generator<::std::span<const ::std::byte>>
Expand All @@ -79,6 +82,7 @@ class in_mem_rw final
private:
::std::vector<buffer<>> m_blocks;
size_t m_block_size;
uuid m_id{};
};

} // namespace frenzykv
Expand Down
12 changes: 5 additions & 7 deletions include/frenzykv/io/iouring_readable.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#define FRENZYKV_IOURING_READABLE_H

#include <filesystem>
#include <string>
#include <string_view>

#include "frenzykv/io/readable.h"
#include "frenzykv/io/inner_buffer.h"
Expand All @@ -19,13 +21,6 @@ class iouring_readable : public posix_base, public random_readable
iouring_readable(const ::std::filesystem::path& p,
const options& opt);

iouring_readable(toolpex::unique_posix_fd fd,
const options& opt)
: posix_base{ ::std::move(fd) },
m_opt{ &opt }
{
}

~iouring_readable() noexcept = default;

koios::task<size_t>
Expand All @@ -40,10 +35,13 @@ class iouring_readable : public posix_base, public random_readable

uintmax_t file_size() const override { return m_filesize; }

::std::string_view filename() const noexcept override { return m_filename; }

private:
const options* m_opt;
seq_readable_context m_fdctx;
uintmax_t m_filesize{};
::std::string m_filename;
};

}
Expand Down
3 changes: 3 additions & 0 deletions include/frenzykv/io/readable.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <span>
#include <memory>
#include <cstddef>
#include <filesystem>

#include "frenzykv/io/file.h"

Expand All @@ -23,6 +24,8 @@ class seq_readable : virtual public file
read(::std::span<::std::byte> dest) = 0;

virtual ~seq_readable() noexcept {}

virtual ::std::string_view filename() const = 0;
};

class random_readable : public seq_readable
Expand Down
58 changes: 55 additions & 3 deletions include/frenzykv/persistent/sstable.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <vector>
#include <utility>
#include <list>
#include <functional>

#include "koios/task.h"

Expand Down Expand Up @@ -60,18 +61,37 @@ struct block_with_storage
* Magic Number See the sstable.cc source file.
*/

/*! \brief SSTable parser and accesser
*
* This class could parse a SSTable from a `random_readable` object,
* provides several useful async API.
*
* \attention Before call to any of those non-async member function,
* except those has clear information that informs you no need to parse meta data,
* you have to `co_await sst.parse_meta_data()` first.
* Or there suppose to be a assertion terminates the program
* if you compile it with debug mode.
*/
class sstable
{
public:
/* \param file A raw pointer pointed to a `random_readable` object,
* without life time management, it could equals to nullptr, means the sstable is empty.
* But before use a `sstable` object with a nullptr file still need to `parse_meta_data()` first.
*/
sstable(const kvdb_deps& deps,
filter_policy* filter,
random_readable* file);

/* \param file A unique pointer pointed to a `random_readable` object.
* it could equals to nullptr, means the sstable is empty.
* But before use a `sstable` object with a nullptr file still need to `parse_meta_data()` first.
*/
sstable(const kvdb_deps& deps,
filter_policy* filter,
::std::unique_ptr<random_readable> file);

/*! \brief Searching specific user key from this memtable
/*! \brief Searching specific user key from this sstable
*
* \return A ::std::optional<block_segment>
* represents a block segment that all elements
Expand All @@ -81,14 +101,23 @@ class sstable
* from some RAII object that actually hold the memory.
* So after a call of this function,
* any access to the previously returned
* `block_segment` object are XXX undefined behaviour.
* `block_segment` object is undefined behaviour.
* \param user_key_ignore_seq Only take the serialized user key part, ignore the seq part
*/
koios::task<::std::optional<::std::pair<block_segment, block_with_storage>>>
get_segment(const sequenced_key& user_key_ignore_seq);

/*! \brief Searching specific sequenced key from this sstable
*
* \return A ::std::optional<kv_entry>
* represents the kv_entry object that metch the sequenced key
* which sequence number also involved in the searching process.
*
* \param seq_key A typical sequenced key which sequence number also
* get involved in the searching process unlike the member function `get_segment()`
*/
koios::task<::std::optional<kv_entry>>
get_kv_entry(const sequenced_key& user_key);
get_kv_entry(const sequenced_key& seq_key);

sequenced_key last_user_key_without_seq() const noexcept;
sequenced_key first_user_key_without_seq() const noexcept;
Expand All @@ -115,6 +144,18 @@ class sstable
koios::generator<::std::pair<uintmax_t, btl_t>> block_offsets() const noexcept;
koios::task<bool> parse_meta_data();

/*! \brief A function to get the hash value of the current sstable.
*
* Since a SSTable getting ready to be read, menas it's a immutable object.
* so the hash value could be evaluate at the very beginning of the usage.
* The current implementation uses the hash value of
* the corresponding file name as the argument of hash function.
* So you can use this function without `parse_meta_data()`
*
* \return The hash value.
*/
size_t hash() const noexcept { return m_hash_value; }

private:
koios::task<btl_t> btl_value(uintmax_t offset); // Required by `generate_block_offsets()`
koios::task<bool> generate_block_offsets(mbo_t mbo); // Required by `parse_meta_data()`
Expand All @@ -132,11 +173,22 @@ class sstable
::std::vector<::std::pair<uintmax_t, btl_t>> m_block_offsets;
buffer<> m_buffer{};
size_t m_get_call_count{};
size_t m_hash_value{};
};

koios::task<::std::list<kv_entry>>
get_entries_from_sstable(sstable& table);

} // namespace frenzykv

template<>
class std::hash<frenzykv::sstable>
{
public:
::std::size_t operator()(const frenzykv::sstable& tab) const noexcept
{
return tab.hash();
}
};

#endif
2 changes: 1 addition & 1 deletion io/iouring_readable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ static toolpex::errret_thrower et;

iouring_readable::iouring_readable(const ::std::filesystem::path& p, const options& opt)
: posix_base{ et << ::open(p.c_str(), O_CREAT | O_RDONLY | O_CLOEXEC, file::default_create_mode()) },
m_opt{ &opt }
m_opt{ &opt }, m_filename{ p.filename().string() }
{
typename ::stat st{};
et << ::fstat(fd(), &st);
Expand Down
6 changes: 4 additions & 2 deletions persistent/sstable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ sstable::sstable(const kvdb_deps& deps,
: m_deps{ &deps },
m_file{ file },
m_filter{ filter },
m_compressor{ get_compressor(*m_deps->opt(), m_deps->opt()->compressor_name) }
m_compressor{ get_compressor(*m_deps->opt(), m_deps->opt()->compressor_name) },
m_hash_value{ ::std::hash<::std::string_view>{}(m_file->filename()) }
{
assert(m_compressor);
assert(m_filter);
Expand All @@ -34,7 +35,8 @@ sstable::sstable(const kvdb_deps& deps,
m_deps{ &deps },
m_file{ m_self_managed_file.get() },
m_filter{ filter },
m_compressor{ get_compressor(*m_deps->opt(), m_deps->opt()->compressor_name) }
m_compressor{ get_compressor(*m_deps->opt(), m_deps->opt()->compressor_name) },
m_hash_value{ ::std::hash<::std::string_view>{}(m_file->filename()) }
{
assert(m_compressor);
assert(m_filter);
Expand Down

0 comments on commit 017c602

Please sign in to comment.