20 #include <glog/logging.h>
41 std::memset(control_block_->buffer_, 0,
sizeof(control_block_->buffer_));
49 &control_block_->oldest_offset_,
50 &control_block_->durable_offset_);
58 stop_requested_ =
false;
59 logger_thread_ = std::move(std::thread(&MetaLogger::meta_logger_main,
this));
80 LOG(WARNING) <<
"Found a meta log that is not in durable epoch (" << durable_epoch
81 <<
"). Probably the last run didn't invoke wait_for_commit(). The operation is discarded."
82 <<
" Log content:" << std::endl << ss.str();
85 ErrorStack MetaLogger::truncate_non_durable(
Epoch saved_durable_epoch) {
90 LOG(INFO) <<
"Truncating non-durable meta logs, if any. Right now meta logger's"
91 <<
" oldest_offset_=" << from_offset
92 <<
", (meta logger's local) durable_offset_=" << to_offset
93 <<
", global saved_durable_epoch=" << saved_durable_epoch;
99 const uint64_t read_size = to_offset - from_offset;
106 char* buf =
reinterpret_cast<char*
>(buffer.
get_block());
108 uint64_t first_non_durable_at = read_size;
109 while (cur < read_size) {
119 if (epoch <= saved_durable_epoch) {
123 const uint64_t raw_offset = from_offset + cur;
125 ASSERT_ND(first_non_durable_at == read_size || first_non_durable_at < cur);
126 first_non_durable_at = std::min(first_non_durable_at, cur);
133 if (first_non_durable_at < read_size) {
138 LOG(WARNING) <<
"Found some meta logs that are not in durable epoch (" << saved_durable_epoch
139 <<
"). We will truncate non-durable regions. new durable_offset=" << first_non_durable_at;
148 LOG(ERROR) <<
"Meta log file has a non-durable region. Probably there"
149 <<
" was a crash. Will truncate";
154 if (new_offset < current_file_->get_current_offset()) {
155 LOG(WARNING) <<
"Truncating meta log file to " << new_offset
166 if (logger_thread_.joinable()) {
168 stop_requested_ =
true;
171 logger_thread_.join();
175 current_file_->
close();
176 delete current_file_;
177 current_file_ =
nullptr;
182 void MetaLogger::meta_logger_main() {
183 LOG(INFO) <<
"Meta-logger started";
184 while (!stop_requested_) {
188 VLOG(0) <<
"Meta-logger going to sleep";
192 VLOG(0) <<
"Meta-logger woke up";
193 if (stop_requested_) {
202 uint32_t write_size =
sizeof(control_block_->
buffer_);
204 LOG(INFO) <<
"Meta-logger got a log (" << control_block_->
buffer_used_ <<
" b) to write out";
205 FillerLogType* filler =
reinterpret_cast<FillerLogType*
>(
207 filler->populate(write_size - control_block_->
buffer_used_);
210 LOG(FATAL) <<
"Meta-logger couldn't write a log. error=" <<
get_error_message(er)
225 LOG(INFO) <<
"Meta-logger terminated";
230 <<
"<current_file_>";
231 if (v.current_file_) {
232 o << *v.current_file_;
236 o <<
"</current_file_>"
LogCode
A unique identifier of all log types.
ErrorCode truncate(uint64_t new_length, bool sync=false)
Discard the content of the file after the given offset.
numa_alloc_onnode() and numa_free().
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
GlobalMemoryAnchors * get_global_memory_anchors()
Epoch::EpochInteger get_epoch_int() const __attribute__((always_inline))
bool close()
Close the file if not yet closed.
Brings error stacktrace information as return value of functions.
uint32_t get_ordinal() const __attribute__((always_inline))
void alloc(uint64_t size, uint64_t alignment, AllocType alloc_type, int numa_node) noexcept
Allocate a memory, releasing the current memory if exists.
ErrorCode open(bool read, bool write, bool append, bool create)
Tries to open the file for the specified volume.
uint64_t get_current_offset() const
log::MetaLogControlBlock * meta_logger_memory_
Tiny memory for metadata logger.
Declares common log types used in all packages.
void change_meta_logger_durable_offset(uint64_t durable_offset)
Rewrites meta logger's durable_offset.
void on_non_durable_meta_log_found(const log::LogHeader *entry, Epoch durable_epoch, uint64_t offset)
const EngineOptions & get_options() const
ErrorCode read_raw(uint64_t desired_bytes, void *buffer)
A version that receives a raw pointer that has to be aligned (be careful to use this ver)...
bool is_master() const
Returns if this engine object is a master instance.
savepoint::SavepointManager * get_savepoint_manager() const
See Savepoint Manager.
uint64_t acquire_ticket() const
Gives the ticket to.
Analogue of boost::filesystem::path.
bool is_opened() const
Whether the file is already and successfully opened.
Epoch get_epoch() const __attribute__((always_inline))
ErrorCode seek(uint64_t offset, SeekType seek_type)
Sets the position of the next byte to be written/extracted from/to the stream.
bool create_directories(const Path &p, bool sync=false)
Recursive mkdir (mkdirs).
bool exists(const Path &p)
Returns if the file exists.
void * get_block() const
Returns the memory block.
ErrorCode write_raw(uint64_t desired_bytes, const void *buffer)
A version that receives a raw pointer that has to be aligned (be careful to use this ver)...
std::ostream & operator<<(std::ostream &o, const LogHeader &v)
std::string construct_meta_log_path() const
metadata log file is placed in node-0/logger-0 folder
std::string os_error()
Thread-safe strerror(errno).
#define CHECK_ERROR(x)
This macro calls x and checks its returned value.
Represents an I/O stream on one file without filesystem caching.
Represents one memory block aligned to actual OS/hardware pages.
foedus::fs::DeviceEmulationOptions emulation_
Settings to emulate slower logging device.
const ErrorStack kRetOk
Normal return value for no-error case.
0 is reserved as a non-existing log type.
soc::SocManager * get_soc_manager() const
See SOC and IPC.
void invoke_ostream(const void *buffer, std::ostream *ptr)
Invokes the ostream operator for the given log type defined in log_type.xmacro.
const char * get_error_message(ErrorCode code)
Returns the error messages corresponding to ErrorCode enum defined in error_code.xmacro.
Convenient way of writing hex integers to stream.
0x3001 : foedus::log::FillerLogType .
void get_meta_logger_offsets(uint64_t *oldest_offset, uint64_t *durable_offset) const
Returns the saved information of metadata logger in lateset savepoint.
Epoch get_saved_durable_epoch() const
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
#define WRAP_ERROR_CODE(x)
Same as CHECK_ERROR(x) except it receives only an error code, thus more efficient.
void memory_fence_release()
Equivalent to std::atomic_thread_fence(std::memory_order_release).
bool fsync(const Path &path, bool sync_parent_directory=false)
Makes the content and metadata of the file durable all the way up to devices.
The offset is set to offset bytes.
ErrorCode
Enum of error codes defined in error_code.xmacro.
bool timedwait(uint64_t demanded_ticket, uint64_t timeout_microsec, uint64_t polling_spins=kDefaultPollingSpins, uint64_t max_interval_us=kDefaultPollingMaxIntervalUs) const
Wait for signal up to the given timeout.
void signal()
Signal it to let waiters exit.
SharedMemoryRepo * get_shared_memory_repo()
Returns the shared memories maintained across SOCs.
0x3002 : foedus::log::EpochMarkerLogType .
void memory_fence_acq_rel()
Equivalent to std::atomic_thread_fence(std::memory_order_acq_rel).