Skip to content

Commit f02cc6f

Browse files
pcd1193182Paul Dagnelie
authored andcommitted
Fix time database update calculations
The time database update math assumed that the timestamps were in nanoseconds, but at some point in the development or review process they changed to seconds. This PR fixes the math to use seconds instead. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Alexander Motin <alexander.motin@TrueNAS.com> Signed-off-by: Paul Dagnelie <paul.dagnelie@klarasystems.com> Sponsored-by: Klara, Inc. Sponsored-by: Wasabi Technology, Inc. Closes openzfs#17735
1 parent 02312f4 commit f02cc6f

File tree

5 files changed

+81
-3
lines changed

5 files changed

+81
-3
lines changed

module/zfs/zfs_crrd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ dbrrd_add(dbrrd_t *db, hrtime_t time, uint64_t txg)
162162
daydiff = time - rrd_tail(&db->dbr_days);
163163
monthdiff = time - rrd_tail(&db->dbr_months);
164164

165-
if (monthdiff >= 0 && monthdiff >= SEC2NSEC(30 * 24 * 60 * 60))
165+
if (monthdiff >= 0 && monthdiff >= 30 * 24 * 60 * 60)
166166
rrd_add(&db->dbr_months, time, txg);
167-
else if (daydiff >= 0 && daydiff >= SEC2NSEC(24 * 60 * 60))
167+
else if (daydiff >= 0 && daydiff >= 24 * 60 * 60)
168168
rrd_add(&db->dbr_days, time, txg);
169169
else if (minutedif >= 0)
170170
rrd_add(&db->dbr_minutes, time, txg);

tests/runfiles/common.run

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ tests = ['zpool_scrub_001_neg', 'zpool_scrub_002_pos', 'zpool_scrub_003_pos',
538538
'zpool_scrub_offline_device', 'zpool_scrub_multiple_copies',
539539
'zpool_error_scrub_001_pos', 'zpool_error_scrub_002_pos',
540540
'zpool_error_scrub_003_pos', 'zpool_error_scrub_004_pos',
541-
'zpool_scrub_date_range_001']
541+
'zpool_scrub_date_range_001', 'zpool_scrub_date_range_002']
542542
tags = ['functional', 'cli_root', 'zpool_scrub']
543543

544544
[tests/functional/cli_root/zpool_set]

tests/zfs-tests/include/tunables.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ SPA_DISCARD_MEMORY_LIMIT spa.discard_memory_limit zfs_spa_discard_memory_limit
8888
SPA_LOAD_VERIFY_DATA spa.load_verify_data spa_load_verify_data
8989
SPA_LOAD_VERIFY_METADATA spa.load_verify_metadata spa_load_verify_metadata
9090
SPA_NOTE_TXG_TIME spa.note_txg_time spa_note_txg_time
91+
SPA_FLUSH_TXG_TIME spa.flush_txg_time spa_flush_txg_time
9192
TRIM_EXTENT_BYTES_MIN trim.extent_bytes_min zfs_trim_extent_bytes_min
9293
TRIM_METASLAB_SKIP trim.metaslab_skip zfs_trim_metaslab_skip
9394
TRIM_TXG_BATCH trim.txg_batch zfs_trim_txg_batch

tests/zfs-tests/tests/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,7 @@ nobase_dist_datadir_zfs_tests_tests_SCRIPTS += \
12341234
functional/cli_root/zpool_scrub/zpool_scrub_print_repairing.ksh \
12351235
functional/cli_root/zpool_scrub/zpool_scrub_txg_continue_from_last.ksh \
12361236
functional/cli_root/zpool_scrub/zpool_scrub_date_range_001.ksh \
1237+
functional/cli_root/zpool_scrub/zpool_scrub_date_range_002.ksh \
12371238
functional/cli_root/zpool_scrub/zpool_error_scrub_001_pos.ksh \
12381239
functional/cli_root/zpool_scrub/zpool_error_scrub_002_pos.ksh \
12391240
functional/cli_root/zpool_scrub/zpool_error_scrub_003_pos.ksh \
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/ksh -p
2+
# SPDX-License-Identifier: CDDL-1.0
3+
#
4+
# CDDL HEADER START
5+
#
6+
# The contents of this file are subject to the terms of the
7+
# Common Development and Distribution License (the "License").
8+
# You may not use this file except in compliance with the License.
9+
#
10+
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11+
# or https://opensource.org/licenses/CDDL-1.0.
12+
# See the License for the specific language governing permissions
13+
# and limitations under the License.
14+
#
15+
# When distributing Covered Code, include this CDDL HEADER in each
16+
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17+
# If applicable, add the following below this CDDL HEADER, with the
18+
# fields enclosed by brackets "[]" replaced with your own identifying
19+
# information: Portions Copyright [yyyy] [name of copyright owner]
20+
#
21+
# CDDL HEADER END
22+
#
23+
# Copyright 2025 Klara, Inc.
24+
#
25+
26+
. $STF_SUITE/include/libtest.shlib
27+
. $STF_SUITE/tests/functional/cli_root/zpool_scrub/zpool_scrub.cfg
28+
29+
#
30+
# DESCRIPTION:
31+
# Verify that the timestamp database updates all the tables as expected.
32+
#
33+
# STRATEGY:
34+
# 1. Decrease the note and flush frequency of the txg database.
35+
# 2. Force the pool to sync several txgs
36+
# 3. Verify that there are entries in each of the "month", "day", and
37+
# "minute" tables.
38+
#
39+
40+
verify_runnable "global"
41+
42+
function cleanup
43+
{
44+
log_must restore_tunable SPA_NOTE_TXG_TIME
45+
log_must restore_tunable SPA_FLUSH_TXG_TIME
46+
rm /$TESTPOOL/f1
47+
}
48+
49+
log_onexit cleanup
50+
51+
log_assert "Verifiy timestamp databases all update as expected."
52+
53+
log_must save_tunable SPA_NOTE_TXG_TIME
54+
log_must set_tunable64 SPA_NOTE_TXG_TIME 1
55+
log_must save_tunable SPA_FLUSH_TXG_TIME
56+
log_must set_tunable64 SPA_FLUSH_TXG_TIME 1
57+
58+
log_must touch /$TESTPOOL/f1
59+
log_must zpool sync $TESTPOOL
60+
sleep 1
61+
log_must touch /$TESTPOOL/f1
62+
log_must zpool sync $TESTPOOL
63+
sleep 1
64+
log_must touch /$TESTPOOL/f1
65+
log_must zpool sync $TESTPOOL
66+
67+
mos_zap="$(zdb -dddd $TESTPOOL 1)"
68+
minutes_entries=$(echo "$mos_zap" | grep "txg_log_time:minutes" | awk '{print $5}')
69+
days_entries=$(echo "$mos_zap" | grep "txg_log_time:days" | awk '{print $5}')
70+
months_entries=$(echo "$mos_zap" | grep "txg_log_time:months" | awk '{print $5}')
71+
72+
[[ "$minutes_entries" -ne "0" ]] || log_fail "0 entries in the minutes table"
73+
[[ "$days_entries" -ne "0" ]] || log_fail "0 entries in the days table"
74+
[[ "$months_entries" -ne "0" ]] || log_fail "0 entries in the months table"
75+
76+
log_pass "Verified all timestamp databases had entries as expected."

0 commit comments

Comments
 (0)