6767 pending = [] :: iolist ()
6868 }).
6969
70- -type wal_write_strategy () ::
71- % writes all pending in one write(2) call then calls fsync(1)
72- default |
73- % like default but tries to open the file using synchronous io
74- % (O_SYNC) rather than a write(2) followed by an fsync.
75- o_sync |
76- % % low latency mode where writers are notifies _before_ syncing
77- % % but after writing.
78- sync_after_notify .
79-
8070-type writer_name_cache () :: {NextIntId :: non_neg_integer (),
8171 #{writer_id () => binary ()}}.
8272
8676 max_size_bytes :: non_neg_integer (),
8777 max_entries :: undefined | non_neg_integer (),
8878 recovery_chunk_size = ? WAL_RECOVERY_CHUNK_SIZE :: non_neg_integer (),
89- write_strategy = default :: wal_write_strategy (),
9079 sync_method = datasync :: sync | datasync | none ,
9180 counter :: counters :counters_ref (),
9281 mem_tables_tid :: ets :tid (),
139128 segment_writer => atom () | pid (),
140129 compute_checksums => boolean (),
141130 pre_allocate => boolean (),
142- write_strategy => wal_write_strategy (),
143131 sync_method => sync | datasync ,
144132 recovery_chunk_size => non_neg_integer (),
145133 hibernate_after => non_neg_integer (),
149137 min_bin_vheap_size => non_neg_integer ()
150138 }.
151139
152- -export_type ([wal_conf / 0 ,
153- wal_write_strategy / 0 ]).
140+ -export_type ([wal_conf / 0 ]).
154141
155142-type wal_command () ::
156143 {append | truncate , writer_id (), ra_index (), ra_term (), term ()}.
@@ -261,7 +248,6 @@ init(#{dir := Dir} = Conf0) ->
261248 segment_writer := SegWriter ,
262249 compute_checksums := ComputeChecksums ,
263250 pre_allocate := PreAllocate ,
264- write_strategy := WriteStrategy ,
265251 sync_method := SyncMethod ,
266252 garbage_collect := Gc ,
267253 min_heap_size := MinHeapSize ,
@@ -285,7 +271,6 @@ init(#{dir := Dir} = Conf0) ->
285271 max_size_bytes = max (? WAL_MIN_SIZE , MaxWalSize ),
286272 max_entries = MaxEntries ,
287273 recovery_chunk_size = RecoveryChunkSize ,
288- write_strategy = WriteStrategy ,
289274 sync_method = SyncMethod ,
290275 counter = CRef ,
291276 mem_tables_tid = ets :whereis (MemTablesName ),
@@ -299,7 +284,9 @@ init(#{dir := Dir} = Conf0) ->
299284 % generated during recovery
300285 ok = ra_log_segment_writer :await (SegWriter ),
301286 {ok , Result }
302- catch _ :Err :_Stack ->
287+ catch _ :Err :Stack ->
288+ ? ERROR (" WAL: failed to initialise with ~p , stack ~p " ,
289+ [Err , Stack ]),
303290 {stop , Err }
304291 end .
305292
@@ -322,16 +309,14 @@ terminate(Reason, State) ->
322309 _ = cleanup (State ),
323310 ok .
324311
325- format_status (# state {conf = # conf {write_strategy = Strat ,
326- sync_method = SyncMeth ,
312+ format_status (# state {conf = # conf {sync_method = SyncMeth ,
327313 compute_checksums = Cs ,
328314 names = #{wal := WalName },
329315 max_size_bytes = MaxSize },
330316 writers = Writers ,
331317 wal = # wal {file_size = FSize ,
332318 filename = Fn }}) ->
333- #{write_strategy => Strat ,
334- sync_method => SyncMeth ,
319+ #{sync_method => SyncMeth ,
335320 compute_checksums => Cs ,
336321 writers => maps :size (Writers ),
337322 filename => filename :basename (Fn ),
@@ -595,20 +580,6 @@ roll_over(#state{wal = Wal0, file_num = Num0,
595580 wal = Wal ,
596581 file_num = Num }.
597582
598- open_wal (File , Max , # conf {write_strategy = o_sync } = Conf ) ->
599- Modes = [sync | ? FILE_MODES ],
600- case prepare_file (File , Modes ) of
601- {ok , Fd } ->
602- % many platforms implement O_SYNC a bit like O_DSYNC
603- % perform a manual sync here to ensure metadata is flushed
604- {Conf , # wal {fd = Fd ,
605- max_size = Max ,
606- filename = File }};
607- {error , enotsup } ->
608- ? WARN (" wal: o_sync write strategy not supported. "
609- " Reverting back to default strategy." , []),
610- open_wal (File , Max , Conf # conf {write_strategy = default })
611- end ;
612583open_wal (File , Max , # conf {} = Conf0 ) ->
613584 {ok , Fd } = prepare_file (File , ? FILE_MODES ),
614585 Conf = maybe_pre_allocate (Conf0 , Fd , Max ),
@@ -637,9 +608,7 @@ make_tmp(File) ->
637608 ok = file :close (Fd ),
638609 Tmp .
639610
640- maybe_pre_allocate (# conf {pre_allocate = true ,
641- write_strategy = Strat } = Conf , Fd , Max0 )
642- when Strat /= o_sync ->
611+ maybe_pre_allocate (# conf {pre_allocate = true } = Conf , Fd , Max0 ) ->
643612 Max = Max0 - ? HEADER_SIZE ,
644613 case file :allocate (Fd , ? HEADER_SIZE , Max ) of
645614 ok ->
@@ -654,7 +623,7 @@ maybe_pre_allocate(#conf{pre_allocate = true,
654623 " falling back to fsync instead of fdatasync" , []),
655624 Conf # conf {pre_allocate = false }
656625 end ;
657- maybe_pre_allocate (Conf , _Fd , _Max ) ->
626+ maybe_pre_allocate (Conf , _Fd , _Max0 ) ->
658627 Conf .
659628
660629close_file (undefined ) ->
@@ -666,26 +635,11 @@ start_batch(#state{conf = #conf{counter = CRef}} = State) ->
666635 ok = counters :add (CRef , ? C_BATCHES , 1 ),
667636 State # state {batch = # batch {}}.
668637
669-
670- post_notify_flush (# state {wal = # wal {fd = Fd },
671- conf = # conf {write_strategy = sync_after_notify ,
672- sync_method = SyncMeth }}) ->
673- sync (Fd , SyncMeth );
674- post_notify_flush (_State ) ->
675- ok .
676-
677638flush_pending (# state {wal = # wal {fd = Fd },
678639 batch = # batch {pending = Pend },
679- conf = # conf {write_strategy = WriteStrategy ,
680- sync_method = SyncMeth }} = State0 ) ->
681-
682- case WriteStrategy of
683- default ->
684- ok = file :write (Fd , Pend ),
685- sync (Fd , SyncMeth );
686- _ ->
687- ok = file :write (Fd , Pend )
688- end ,
640+ conf = # conf {sync_method = SyncMeth }} = State0 ) ->
641+ ok = file :write (Fd , Pend ),
642+ sync (Fd , SyncMeth ),
689643 State0 # state {batch = undefined }.
690644
691645sync (_Fd , none ) ->
@@ -709,7 +663,6 @@ complete_batch(#state{batch = #batch{waiting = Waiting,
709663 Ranges = maps :fold (fun (Pid , BatchWriter , Acc ) ->
710664 complete_batch_writer (Pid , BatchWriter , Acc )
711665 end , Wal # wal .ranges , Waiting ),
712- ok = post_notify_flush (State ),
713666 State # state {wal = Wal # wal {ranges = Ranges }}.
714667
715668complete_batch_writer (Pid , # batch_writer {snap_idx = SnapIdx ,
@@ -955,7 +908,6 @@ merge_conf_defaults(Conf) ->
955908 recovery_chunk_size => ? WAL_RECOVERY_CHUNK_SIZE ,
956909 compute_checksums => true ,
957910 pre_allocate => false ,
958- write_strategy => default ,
959911 garbage_collect => false ,
960912 sync_method => datasync ,
961913 min_bin_vheap_size => ? MIN_BIN_VHEAP_SIZE ,
0 commit comments