@@ -587,88 +587,123 @@ void log_t::create()
587
587
}
588
588
}
589
589
590
+ log_file_t ::log_file_t (log_file_t &&rhs)
591
+ {
592
+ m_fd= std::move (rhs.m_fd );
593
+ rhs.m_fd = OS_FILE_CLOSED;
594
+ m_path= std::move (rhs.m_path );
595
+ }
596
+ log_file_t &log_file_t ::operator =(log_file_t &&rhs)
597
+ {
598
+ std::swap (m_fd, rhs.m_fd );
599
+ std::swap (m_path, rhs.m_path );
600
+ return *this ;
601
+ }
602
+
603
+ log_file_t ::~log_file_t ()
604
+ {
605
+ if (is_opened ())
606
+ os_file_close (m_fd);
607
+ }
608
+
609
+ bool log_file_t::open ()
610
+ {
611
+ ut_a (!is_opened ());
612
+
613
+ bool success;
614
+ m_fd= os_file_create (innodb_log_file_key, m_path.c_str (),
615
+ OS_FILE_OPEN | OS_FILE_ON_ERROR_NO_EXIT, OS_FILE_NORMAL,
616
+ OS_LOG_FILE, srv_read_only_mode, &success);
617
+ if (!success)
618
+ m_fd= OS_FILE_CLOSED;
619
+
620
+ return success;
621
+ }
622
+
623
+ bool log_file_t::close ()
624
+ {
625
+ ut_a (is_opened ());
626
+ bool result= os_file_close (m_fd);
627
+ m_fd= OS_FILE_CLOSED;
628
+ return result;
629
+ }
630
+
631
+ dberr_t log_file_t::read (size_t offset, span<byte> buf)
632
+ {
633
+ ut_ad (is_opened ());
634
+ return os_file_read (IORequestRead, m_fd, buf.data (), offset, buf.size ());
635
+ }
636
+
637
+ dberr_t log_file_t::write (size_t offset, span<const byte> buf)
638
+ {
639
+ ut_ad (is_opened ());
640
+ return os_file_write (IORequestWrite, m_path.c_str (), m_fd, buf.data (),
641
+ offset, buf.size ());
642
+ }
643
+
644
+ bool log_file_t::flush_data_only ()
645
+ {
646
+ ut_ad (is_opened ());
647
+ return os_file_flush_data (m_fd);
648
+ }
649
+
590
650
void log_t::files::set_file_names (std::vector<std::string> names)
591
651
{
592
- file_names= std::move (names);
652
+ files.clear ();
653
+
654
+ for (auto &&name : names)
655
+ files.emplace_back (std::move (name));
593
656
}
594
657
595
658
void log_t::files::open_files ()
596
659
{
597
- ut_ad (files.empty ());
598
- files.reserve (file_names.size ());
599
- for (const auto &name : file_names)
660
+ for (auto &file : files)
600
661
{
601
- bool success;
602
- files.push_back (os_file_create (innodb_log_file_key, name.c_str (),
603
- OS_FILE_OPEN | OS_FILE_ON_ERROR_NO_EXIT,
604
- OS_FILE_NORMAL, OS_LOG_FILE,
605
- srv_read_only_mode, &success));
606
- if (!success)
607
- {
608
- ib::fatal () << " os_file_create(" << name << " ) failed" ;
609
- }
662
+ if (!file.open ())
663
+ ib::fatal () << " os_file_create(" << file.get_path () << " ) failed" ;
610
664
}
611
665
}
612
666
613
667
void log_t::files::read (size_t total_offset, span<byte> buf)
614
668
{
615
- ut_ad (files.size () == file_names.size ());
616
-
617
- const size_t file_idx= total_offset / static_cast <size_t >(file_size);
669
+ auto &file= files[total_offset / static_cast <size_t >(file_size)];
618
670
const size_t offset= total_offset % static_cast <size_t >(file_size);
619
671
620
- if (const dberr_t err= os_file_read (IORequestRead, files[file_idx],
621
- buf.data (), offset, buf.size ()))
622
- {
623
- ib::fatal () << " os_file_read(" << file_names[file_idx] << " ) returned "
672
+ if (const dberr_t err= file.read (offset, buf))
673
+ ib::fatal () << " log_file_t::read(" << file.get_path () << " ) returned "
624
674
<< err;
625
- }
626
675
}
627
676
628
677
void log_t::files::write (size_t total_offset, span<byte> buf)
629
678
{
630
- ut_ad (files.size () == file_names.size ());
631
-
632
- const size_t file_idx= total_offset / static_cast <size_t >(file_size);
679
+ auto &file= files[total_offset / static_cast <size_t >(file_size)];
633
680
const size_t offset= total_offset % static_cast <size_t >(file_size);
634
681
635
- if (const dberr_t err=
636
- os_file_write (IORequestWrite, file_names[file_idx].c_str (),
637
- files[file_idx], buf.data (), offset, buf.size ()))
638
- {
639
- ib::fatal () << " os_file_write(" << file_names[file_idx] << " ) returned "
682
+ if (const dberr_t err= file.write (offset, buf))
683
+ ib::fatal () << " log_file_t::d_write(" << file.get_path () << " ) returned "
640
684
<< err;
641
- }
642
685
}
643
686
644
687
void log_t::files::flush_data_only ()
645
688
{
646
- ut_ad (files.size () == file_names.size ());
647
-
648
689
log_sys.pending_flushes .fetch_add (1 , std::memory_order_acquire);
649
- for (auto it= files. begin (), end= files. end (); it != end; ++it )
690
+ for (auto &file : files)
650
691
{
651
- if (!os_file_flush_data (*it))
652
- {
653
- const auto idx= std::distance (files.begin (), it);
654
- ib::fatal () << " os_file_flush_data(" << file_names[idx] << " ) failed" ;
655
- }
692
+ if (!file.flush_data_only ())
693
+ ib::fatal () << " log_file_t::flush_data_only(" << file.get_path ()
694
+ << " ) failed" ;
656
695
}
657
696
log_sys.pending_flushes .fetch_sub (1 , std::memory_order_release);
658
697
log_sys.flushes .fetch_add (1 , std::memory_order_release);
659
698
}
660
699
661
700
void log_t::files::close_files ()
662
701
{
663
- for (auto it= files. begin (), end= files. end (); it != end; ++it )
702
+ for (auto &file : files)
664
703
{
665
- if (!os_file_close (*it))
666
- {
667
- const auto idx= std::distance (files.begin (), it);
668
- ib::fatal () << " os_file_close(" << file_names[idx] << " ) failed" ;
669
- }
704
+ if (file.is_opened () && !file.close ())
705
+ ib::fatal () << " log_file_t::close(" << file.get_path () << " ) failed" ;
670
706
}
671
- files.clear ();
672
707
}
673
708
674
709
/* * Initialize the redo log.
0 commit comments