Wednesday, April 16, 2025

The new File system feature: Atomic Writes

 Большинство БД Oracle созданы с размером блока 8К и  16К. Размер блока файловых систем в Линукс =4К. Размер сектора на шпиндельном диске = 512 байт.

В результате, возможна ситуация когда БД отправляет на запись 8К, а на диск записывается только часть блока БД (например, при отключении электропитания).

Для такого случая в СУБД Оракл есть свои механизмы контроля: SCN, который записывается в заголовке и в хвосте блока БД, db_block_checksum.

В этот раз помощь пришла откуда не ждали: atomic commit для файловых систем EXT4, XFS, BTRFS и блочных устройств. 

Реализуется путём добавления "атомного" флага в syscall:  
a new "atomic" flag to each of pwritev2().  When set, these indicate that we want the write issued "atomically".  

Only direct IO is supported and for block devices. Atomic write HW is required, like SCSI ATOMIC WRITE (16).



Появились "атомные" опции монтирования (atomic-writes=1), пример для XFS (https://lwn.net/Articles/971754/):

XFS can be formatted for atomic writes as follows:
mkfs.xfs -i forcealign=1 -d extsize=16384 -d atomic-writes=1  /dev/sda

atomic-writes=1 just enables atomic writes in the SB, but does not auto-
enable atomic writes for each file.

Support can be enabled through xfs_io command:
$xfs_io -c "lsattr -v" filename
[extsize, force-align]
$xfs_io -c "extsize" filename
[16384] filename
$xfs_io -c "chattr +W" filename
$xfs_io -c "lsattr -v" filename
[extsize, force-align, atomic-writes] filename
$xfs_io -c statx filename
..
stat.stx_atomic_write_unit_min = 4096
stat.stx_atomic_write_unit_max = 16384
stat.stx_atomic_write_segments_max = 1



Статья с картинками на эту тему:
https://transactional.blog/blog/2025-torn-writes



ASM: How much time the rebalance will continue?

When planning  ASM  changes/downtimes every DBA need to answer the query  "how much time the rebalance will continue ?". It turns...