Skip to content

Commit d3b111e

Browse files
committed
Add option to specify segment size in blocks
The tests don't have much coverage of segment related code, as we don't create large enough tables. To make it easier to test these paths, add a new option specifying the segment size in blocks. Set the new option to 6 blocks in one of the CI tasks. Smaller numbers currently fail one of the tests, for understandable reasons. While at it, fix some segment size related issues in the meson build. Author: Andres Freund <[email protected]> Discussion: https://postgr.es/m/[email protected]
1 parent bf07ab4 commit d3b111e

File tree

6 files changed

+132
-24
lines changed

6 files changed

+132
-24
lines changed

.cirrus.yml

+2
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ task:
323323
./configure \
324324
--enable-cassert --enable-debug --enable-tap-tests \
325325
--enable-nls \
326+
--with-segsize-blocks=8 \
326327
\
327328
${LINUX_CONFIGURE_FEATURES} \
328329
\
@@ -491,6 +492,7 @@ task:
491492
-Dextra_lib_dirs=${brewpath}/lib \
492493
-Dcassert=true \
493494
-Dssl=openssl -Duuid=e2fs -Ddtrace=auto \
495+
-Dsegsize_blocks=6 \
494496
-DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
495497
build
496498

configure

+53-10
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,7 @@ enable_dtrace
842842
enable_tap_tests
843843
with_blocksize
844844
with_segsize
845+
with_segsize_blocks
845846
with_wal_blocksize
846847
with_CC
847848
with_llvm
@@ -1551,6 +1552,8 @@ Optional Packages:
15511552
--with-blocksize=BLOCKSIZE
15521553
set table block size in kB [8]
15531554
--with-segsize=SEGSIZE set table segment size in GB [1]
1555+
--with-segsize-blocks=SEGSIZE_BLOCKS
1556+
set table segment size in blocks [0]
15541557
--with-wal-blocksize=BLOCKSIZE
15551558
set WAL block size in kB [8]
15561559
--with-CC=CMD set compiler (deprecated)
@@ -3731,8 +3734,6 @@ _ACEOF
37313734
#
37323735
# Relation segment size
37333736
#
3734-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for segment size" >&5
3735-
$as_echo_n "checking for segment size... " >&6; }
37363737

37373738

37383739

@@ -3756,12 +3757,52 @@ else
37563757
fi
37573758

37583759

3759-
# this expression is set up to avoid unnecessary integer overflow
3760-
# blocksize is already guaranteed to be a factor of 1024
3761-
RELSEG_SIZE=`expr '(' 1024 / ${blocksize} ')' '*' ${segsize} '*' 1024`
3762-
test $? -eq 0 || exit 1
3763-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ${segsize}GB" >&5
3760+
3761+
3762+
3763+
# Check whether --with-segsize-blocks was given.
3764+
if test "${with_segsize_blocks+set}" = set; then :
3765+
withval=$with_segsize_blocks;
3766+
case $withval in
3767+
yes)
3768+
as_fn_error $? "argument required for --with-segsize-blocks option" "$LINENO" 5
3769+
;;
3770+
no)
3771+
as_fn_error $? "argument required for --with-segsize-blocks option" "$LINENO" 5
3772+
;;
3773+
*)
3774+
segsize_blocks=$withval
3775+
;;
3776+
esac
3777+
3778+
else
3779+
segsize_blocks=0
3780+
fi
3781+
3782+
3783+
3784+
# If --with-segsize-blocks is non-zero, it is used, --with-segsize
3785+
# otherwise. segsize-blocks is only really useful for developers wanting to
3786+
# test segment related code. Warn if both are used.
3787+
if test $segsize_blocks -ne 0 -a $segsize -ne 1; then
3788+
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: both --with-segsize and --with-segsize-blocks specified, --with-segsize-blocks wins" >&5
3789+
$as_echo "$as_me: WARNING: both --with-segsize and --with-segsize-blocks specified, --with-segsize-blocks wins" >&2;}
3790+
fi
3791+
3792+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for segment size" >&5
3793+
$as_echo_n "checking for segment size... " >&6; }
3794+
if test $segsize_blocks -eq 0; then
3795+
# this expression is set up to avoid unnecessary integer overflow
3796+
# blocksize is already guaranteed to be a factor of 1024
3797+
RELSEG_SIZE=`expr '(' 1024 / ${blocksize} ')' '*' ${segsize} '*' 1024`
3798+
test $? -eq 0 || exit 1
3799+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ${segsize}GB" >&5
37643800
$as_echo "${segsize}GB" >&6; }
3801+
else
3802+
RELSEG_SIZE=$segsize_blocks
3803+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ${RELSEG_SIZE} blocks" >&5
3804+
$as_echo "${RELSEG_SIZE} blocks" >&6; }
3805+
fi
37653806

37663807

37673808
cat >>confdefs.h <<_ACEOF
@@ -15450,9 +15491,11 @@ _ACEOF
1545015491

1545115492

1545215493

15453-
# If we don't have largefile support, can't handle segsize >= 2GB.
15454-
if test "$ac_cv_sizeof_off_t" -lt 8 -a "$segsize" != "1"; then
15455-
as_fn_error $? "Large file support is not enabled. Segment size cannot be larger than 1GB." "$LINENO" 5
15494+
# If we don't have largefile support, can't handle segment size >= 2GB.
15495+
if test "$ac_cv_sizeof_off_t" -lt 8; then
15496+
if expr $RELSEG_SIZE '*' $blocksize '>=' 2 '*' 1024 '*' 1024; then
15497+
as_fn_error $? "Large file support is not enabled. Segment size cannot be larger than 1GB." "$LINENO" 5
15498+
fi
1545615499
fi
1545715500

1545815501
# The cast to long int works around a bug in the HP C Compiler

configure.ac

+27-9
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,31 @@ AC_DEFINE_UNQUOTED([BLCKSZ], ${BLCKSZ}, [
285285
#
286286
# Relation segment size
287287
#
288-
AC_MSG_CHECKING([for segment size])
289288
PGAC_ARG_REQ(with, segsize, [SEGSIZE], [set table segment size in GB [1]],
290289
[segsize=$withval],
291290
[segsize=1])
292-
# this expression is set up to avoid unnecessary integer overflow
293-
# blocksize is already guaranteed to be a factor of 1024
294-
RELSEG_SIZE=`expr '(' 1024 / ${blocksize} ')' '*' ${segsize} '*' 1024`
295-
test $? -eq 0 || exit 1
296-
AC_MSG_RESULT([${segsize}GB])
291+
PGAC_ARG_REQ(with, segsize-blocks, [SEGSIZE_BLOCKS], [set table segment size in blocks [0]],
292+
[segsize_blocks=$withval],
293+
[segsize_blocks=0])
294+
295+
# If --with-segsize-blocks is non-zero, it is used, --with-segsize
296+
# otherwise. segsize-blocks is only really useful for developers wanting to
297+
# test segment related code. Warn if both are used.
298+
if test $segsize_blocks -ne 0 -a $segsize -ne 1; then
299+
AC_MSG_WARN([both --with-segsize and --with-segsize-blocks specified, --with-segsize-blocks wins])
300+
fi
301+
302+
AC_MSG_CHECKING([for segment size])
303+
if test $segsize_blocks -eq 0; then
304+
# this expression is set up to avoid unnecessary integer overflow
305+
# blocksize is already guaranteed to be a factor of 1024
306+
RELSEG_SIZE=`expr '(' 1024 / ${blocksize} ')' '*' ${segsize} '*' 1024`
307+
test $? -eq 0 || exit 1
308+
AC_MSG_RESULT([${segsize}GB])
309+
else
310+
RELSEG_SIZE=$segsize_blocks
311+
AC_MSG_RESULT([${RELSEG_SIZE} blocks])
312+
fi
297313

298314
AC_DEFINE_UNQUOTED([RELSEG_SIZE], ${RELSEG_SIZE}, [
299315
RELSEG_SIZE is the maximum number of blocks allowed in one disk file.
@@ -1733,9 +1749,11 @@ fi
17331749
dnl Check for largefile support (must be after AC_SYS_LARGEFILE)
17341750
AC_CHECK_SIZEOF([off_t])
17351751

1736-
# If we don't have largefile support, can't handle segsize >= 2GB.
1737-
if test "$ac_cv_sizeof_off_t" -lt 8 -a "$segsize" != "1"; then
1738-
AC_MSG_ERROR([Large file support is not enabled. Segment size cannot be larger than 1GB.])
1752+
# If we don't have largefile support, can't handle segment size >= 2GB.
1753+
if test "$ac_cv_sizeof_off_t" -lt 8; then
1754+
if expr $RELSEG_SIZE '*' $blocksize '>=' 2 '*' 1024 '*' 1024; then
1755+
AC_MSG_ERROR([Large file support is not enabled. Segment size cannot be larger than 1GB.])
1756+
fi
17391757
fi
17401758

17411759
AC_CHECK_SIZEOF([bool], [],

doc/src/sgml/installation.sgml

+28
Original file line numberDiff line numberDiff line change
@@ -1681,6 +1681,20 @@ build-postgresql:
16811681
</para>
16821682
</listitem>
16831683
</varlistentry>
1684+
1685+
<varlistentry>
1686+
<term><option>--with-segsize-blocks=SEGSIZE_BLOCKS</option></term>
1687+
<listitem>
1688+
<para>
1689+
Specify the segment size in blocks. If both
1690+
<option>--with-segsize</option> and this option are specified, this
1691+
option wins.
1692+
1693+
This option is only for developers, to test segment related code.
1694+
</para>
1695+
</listitem>
1696+
</varlistentry>
1697+
16841698
</variablelist>
16851699

16861700
</sect3>
@@ -3097,6 +3111,20 @@ ninja install
30973111
</para>
30983112
</listitem>
30993113
</varlistentry>
3114+
3115+
<varlistentry>
3116+
<term><option>-Dsegsize_blocks=SEGSIZE_BLOCKS</option></term>
3117+
<listitem>
3118+
<para>
3119+
Specify the segment size in blocks. If both
3120+
<option>-Dsegsize</option> and this option are specified, this option
3121+
wins.
3122+
3123+
This option is only for developers, to test segment related code.
3124+
</para>
3125+
</listitem>
3126+
</varlistentry>
3127+
31003128
</variablelist>
31013129
</sect3>
31023130
</sect2>

meson.build

+19-5
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,19 @@ meson_bin = find_program(meson_binpath, native: true)
419419

420420
cdata.set('USE_ASSERT_CHECKING', get_option('cassert') ? 1 : false)
421421

422-
cdata.set('BLCKSZ', get_option('blocksize').to_int() * 1024, description:
422+
blocksize = get_option('blocksize').to_int() * 1024
423+
424+
if get_option('segsize_blocks') != 0
425+
if get_option('segsize') != 1
426+
warning('both segsize and segsize_blocks specified, segsize_blocks wins')
427+
endif
428+
429+
segsize = get_option('segsize_blocks')
430+
else
431+
segsize = (get_option('segsize') * 1024 * 1024 * 1024) / blocksize
432+
endif
433+
434+
cdata.set('BLCKSZ', blocksize, description:
423435
'''Size of a disk block --- this also limits the size of a tuple. You can set
424436
it bigger if you need bigger tuples (although TOAST should reduce the need
425437
to have large tuples, since fields can be spread across multiple tuples).
@@ -429,7 +441,7 @@ cdata.set('BLCKSZ', get_option('blocksize').to_int() * 1024, description:
429441
Changing BLCKSZ requires an initdb.''')
430442

431443
cdata.set('XLOG_BLCKSZ', get_option('wal_blocksize').to_int() * 1024)
432-
cdata.set('RELSEG_SIZE', get_option('segsize') * 131072)
444+
cdata.set('RELSEG_SIZE', segsize)
433445
cdata.set('DEF_PGPORT', get_option('pgport'))
434446
cdata.set_quoted('DEF_PGPORT_STR', get_option('pgport').to_string())
435447
cdata.set_quoted('PG_KRB_SRVNAM', get_option('krb_srvnam'))
@@ -3132,9 +3144,11 @@ if meson.version().version_compare('>=0.57')
31323144

31333145
summary(
31343146
{
3135-
'data block size': cdata.get('BLCKSZ'),
3136-
'WAL block size': cdata.get('XLOG_BLCKSZ') / 1024,
3137-
'segment size': cdata.get('RELSEG_SIZE') / 131072,
3147+
'data block size': '@0@ kB'.format(cdata.get('BLCKSZ') / 1024),
3148+
'WAL block size': '@0@ kB'.format(cdata.get('XLOG_BLCKSZ') / 1024),
3149+
'segment size': get_option('segsize_blocks') != 0 ?
3150+
'@0@ blocks'.format(cdata.get('RELSEG_SIZE')) :
3151+
'@0@ GB'.format(get_option('segsize')),
31383152
},
31393153
section: 'Data layout',
31403154
)

meson_options.txt

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ option('wal_blocksize', type : 'combo',
1313
option('segsize', type : 'integer', value : 1,
1414
description : '''Segment size, in gigabytes''')
1515

16+
option('segsize_blocks', type : 'integer', value: 0,
17+
description : '''Segment size, in blocks''')
18+
1619

1720
# Miscellaneous options
1821

0 commit comments

Comments
 (0)