-
Notifications
You must be signed in to change notification settings - Fork 6
Introduce log writer thread #1146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
mihirj1993
wants to merge
21
commits into
main
Choose a base branch
from
logwriter_thread
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
e4d426b
Introduce log writer APIs (log_io.cpp, log_io.hpp)
mihirj1993 64325c4
Introduce persistent log writer thread
mihirj1993 e9407d9
fixes
mihirj1993 b72466a
Introduce log writer APIs (log_io.cpp, log_io.hpp)
mihirj1993 0508152
fixes
mihirj1993 cbdad1d
Merge branch 'log_writer_apis' of https://github.com/gaia-platform/Ga…
mihirj1993 5fe5efa
fixes 2
mihirj1993 f0d039c
Merge branch 'master' of https://github.com/gaia-platform/GaiaPlatfor…
mihirj1993 baa1012
Merge branch 'log_writer_apis' of https://github.com/gaia-platform/Ga…
mihirj1993 82306c9
Merge branch 'log_writer_apis' of https://github.com/gaia-platform/Ga…
mihirj1993 d76c1f8
fixes
mihirj1993 9a709e6
remove session decision eventfd
mihirj1993 033e3dd
futex fix
mihirj1993 dc0fdb8
Fix persist_pending_writes
mihirj1993 9e68c3b
more fixes
mihirj1993 58fafe3
Introduce max_txn_memory_size. Track txn size in client tls and throw…
mihirj1993 9d4ffc5
topsort impl
mihirj1993 a7de946
use top sort to find chunk order
mihirj1993 34a9454
Refactoring
mihirj1993 59914ad
refactor #2
mihirj1993 c80c6cb
nit
mihirj1993 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| ///////////////////////////////////////////// | ||
| // Copyright (c) Gaia Platform LLC | ||
| // All rights reserved. | ||
| ///////////////////////////////////////////// | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <fcntl.h> | ||
| #include <unistd.h> | ||
|
|
||
| #include <cstddef> | ||
|
|
||
| #include <atomic> | ||
| #include <functional> | ||
| #include <memory> | ||
| #include <string> | ||
| #include <unordered_map> | ||
|
|
||
| #include "gaia/common.hpp" | ||
| #include <gaia_internal/common/topological_sort.hpp> | ||
|
|
||
| #include "gaia_internal/db/db_object.hpp" | ||
|
|
||
| #include "async_disk_writer.hpp" | ||
| #include "db_internal_types.hpp" | ||
| #include "log_file.hpp" | ||
| #include "memory_manager.hpp" | ||
|
|
||
| namespace gaia | ||
| { | ||
| namespace db | ||
| { | ||
| namespace persistence | ||
| { | ||
|
|
||
| /* | ||
| * Fill the record_header.crc field with CRC_INITIAL_VALUE when | ||
| * computing the checksum: crc32c is vulnerable to 0-prefixing, | ||
| * so we make sure the initial bytes are non-zero. | ||
| * | ||
| * https://stackoverflow.com/questions/2321676/data-length-vs-crc-length | ||
| * "From the wikipedia article: "maximal total blocklength is equal to 2r − 1". That's in bits. | ||
| * You don't need to do much research to see that 29 - 1 is 511 bits. Using CRC-8, | ||
| * multiple messages longer than 64 bytes will have the same CRC checksum value." | ||
| * So CRC-16 would have max message size 2^17-1 bits or about 2^14 bytes = 16KB, | ||
| * and CRC-32 would have max message size 2^33-1 bits or about 2^30 bytes = 1GB | ||
| */ | ||
| static constexpr crc32_t c_crc_initial_value = ((uint32_t)-1); | ||
|
|
||
| class log_handler_t | ||
| { | ||
| public: | ||
| explicit log_handler_t(const std::string& directory_path); | ||
| ~log_handler_t(); | ||
| void open_for_writes(int validate_flushed_batch_eventfd, int signal_checkpoint_eventfd); | ||
|
|
||
| /** | ||
| * Allocate space in the log file and return starting offset of allocation. | ||
| */ | ||
| file_offset_t allocate_log_space(size_t payload_size); | ||
|
|
||
| /** | ||
| * Create a log record which stores txn information. | ||
| */ | ||
| void create_txn_record( | ||
| gaia_txn_id_t commit_ts, | ||
| record_type_t type, | ||
| std::vector<contiguous_offsets_t>& object_offsets, | ||
| std::vector<gaia::common::gaia_id_t>& deleted_ids); | ||
|
|
||
| /** | ||
| * Process the in memory txn_log and submit the processed writes (generated log records) to the async_disk_writer. | ||
| */ | ||
| void process_txn_log_and_write(int txn_log_fd, gaia_txn_id_t commit_ts); | ||
|
|
||
| /** | ||
| * Create a log record which stores decisions for one or more txns. | ||
| */ | ||
| void create_decision_record(const decision_list_t& txn_decisions); | ||
|
|
||
| /** | ||
| * Submit async_disk_writer's internal I/O request queue to the kernel for processing. | ||
| */ | ||
| void submit_writes(bool should_wait_for_completion); | ||
|
|
||
| /** | ||
| * Validate the result of I/O calls submitted to the kernel for processing. | ||
| */ | ||
| void check_flushed_batch_results_and_do_maintenance(); | ||
|
|
||
| private: | ||
| static constexpr char c_gaia_wal_dir_name[] = "/wal_dir"; | ||
| static constexpr int c_gaia_wal_dir_permissions = S_IRWXU | (S_IRGRP | S_IROTH | S_IXGRP | S_IXOTH); | ||
| static inline std::string s_wal_dir_path{}; | ||
| static inline int s_dir_fd = -1; | ||
|
|
||
| // Log file sequence starts from 1. | ||
| static inline std::atomic<file_sequence_t::value_type> s_file_num = 1; | ||
|
|
||
| // Keep track of the current log file. | ||
| std::unique_ptr<log_file_t> m_current_file; | ||
|
|
||
| std::unique_ptr<async_disk_writer_t> m_async_disk_writer; | ||
| }; | ||
|
|
||
| } // namespace persistence | ||
| } // namespace db | ||
| } // namespace gaia |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding all these pieces to db_server, can you instead create a separate abstraction for handling log writing and just have the server keep track of an instance of it? That should separate the main server code from the log writing component.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this is tracked in https://gaiaplatform.atlassian.net/browse/GAIAPLAT-1818.