Skip to content

Commit

Permalink
Add TXG timestamp database
Browse files Browse the repository at this point in the history
This feature enables tracking of when TXGs are committed to disk,
providing an estimated timestamp for each TXG.

With this information, it becomes possible to perform scrubs based
on specific date ranges, improving the granularity of
data management and recovery operations.

Signed-off-by: Mariusz Zaborski <[email protected]>
  • Loading branch information
oshogbo committed Jan 31, 2025
1 parent 1e32c57 commit 7797e3f
Show file tree
Hide file tree
Showing 21 changed files with 677 additions and 165 deletions.
49 changes: 47 additions & 2 deletions cmd/zpool/zpool_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8367,6 +8367,8 @@ zpool_do_reopen(int argc, char **argv)
typedef struct scrub_cbdata {
int cb_type;
pool_scrub_cmd_t cb_scrub_cmd;
time_t cb_date_start;
time_t cb_date_end;
} scrub_cbdata_t;

static boolean_t
Expand Down Expand Up @@ -8410,7 +8412,8 @@ scrub_callback(zpool_handle_t *zhp, void *data)
return (1);
}

err = zpool_scan(zhp, cb->cb_type, cb->cb_scrub_cmd);
err = zpool_scan(zhp, cb->cb_type, cb->cb_scrub_cmd, cb->cb_date_start,
cb->cb_date_end);

if (err == 0 && zpool_has_checkpoint(zhp) &&
cb->cb_type == POOL_SCAN_SCRUB) {
Expand All @@ -8429,10 +8432,32 @@ wait_callback(zpool_handle_t *zhp, void *data)
return (zpool_wait(zhp, *act));
}

static time_t
date_string_to_sec(const char *timestr)
{
int ret;
struct tm tm = {0};

ret = sscanf(timestr, "%4d-%2d-%2d %2d:%2d", &tm.tm_year, &tm.tm_mon,
&tm.tm_mday, &tm.tm_hour, &tm.tm_min);
if (ret < 3) {
fprintf(stderr, gettext("Failed to parse the date.\n"));
usage(B_FALSE);
}

// Adjust struct
tm.tm_year -= 1900;
tm.tm_mon -= 1;

return (timegm(&tm));
}

/*
* zpool scrub [-e | -s | -p | -C] [-w] <pool> ...
*
* -e Only scrub blocks in the error log.
* -E End date of scrub.
* -S Start date of scrub.
* -s Stop. Stops any in-progress scrub.
* -p Pause. Pause in-progress scrub.
* -w Wait. Blocks until scrub has completed.
Expand All @@ -8448,21 +8473,28 @@ zpool_do_scrub(int argc, char **argv)

cb.cb_type = POOL_SCAN_SCRUB;
cb.cb_scrub_cmd = POOL_SCRUB_NORMAL;
cb.cb_date_start = cb.cb_date_end = 0;

boolean_t is_error_scrub = B_FALSE;
boolean_t is_pause = B_FALSE;
boolean_t is_stop = B_FALSE;
boolean_t is_txg_continue = B_FALSE;

/* check options */
while ((c = getopt(argc, argv, "spweC")) != -1) {
while ((c = getopt(argc, argv, "spweCE:S:")) != -1) {
switch (c) {
case 'e':
is_error_scrub = B_TRUE;
break;
case 'E':
cb.cb_date_end = date_string_to_sec(optarg);
break;
case 's':
is_stop = B_TRUE;
break;
case 'S':
cb.cb_date_start = date_string_to_sec(optarg);
break;
case 'p':
is_pause = B_TRUE;
break;
Expand Down Expand Up @@ -8510,6 +8542,19 @@ zpool_do_scrub(int argc, char **argv)
}
}

if ((cb.cb_date_start != 0 || cb.cb_date_end != 0) &&
cb.cb_scrub_cmd != POOL_SCRUB_NORMAL) {
(void) fprintf(stderr, gettext("invalid option combination: "
"start/end date is available only with normal scrub\n"));
usage(B_FALSE);
}
if (cb.cb_date_start != 0 && cb.cb_date_end != 0 &&
cb.cb_date_start > cb.cb_date_end) {
(void) fprintf(stderr, gettext("invalid arguments: "
"end date has to be later than start date\n"));
usage(B_FALSE);
}

if (wait && (cb.cb_type == POOL_SCAN_NONE ||
cb.cb_scrub_cmd == POOL_SCRUB_PAUSE)) {
(void) fprintf(stderr, gettext("invalid option combination: "
Expand Down
1 change: 1 addition & 0 deletions include/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ COMMON_H = \
cityhash.h \
zfeature_common.h \
zfs_comutil.h \
zfs_crrd.h \
zfs_deleg.h \
zfs_fletcher.h \
zfs_namecheck.h \
Expand Down
3 changes: 2 additions & 1 deletion include/libzfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ typedef struct trimflags {
/*
* Functions to manipulate pool and vdev state
*/
_LIBZFS_H int zpool_scan(zpool_handle_t *, pool_scan_func_t, pool_scrub_cmd_t);
_LIBZFS_H int zpool_scan(zpool_handle_t *, pool_scan_func_t, pool_scrub_cmd_t,
time_t, time_t);
_LIBZFS_H int zpool_initialize(zpool_handle_t *, pool_initialize_func_t,
nvlist_t *);
_LIBZFS_H int zpool_initialize_wait(zpool_handle_t *, pool_initialize_func_t,
Expand Down
3 changes: 3 additions & 0 deletions include/sys/dmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,9 @@ typedef struct dmu_buf {
#define DMU_POOL_ZPOOL_CHECKPOINT "com.delphix:zpool_checkpoint"
#define DMU_POOL_LOG_SPACEMAP_ZAP "com.delphix:log_spacemap_zap"
#define DMU_POOL_DELETED_CLONES "com.delphix:deleted_clones"
#define DMU_POOL_TXG_LOG_TIME_MINUTES "com.klaraystems:txg_log_time:minutes"
#define DMU_POOL_TXG_LOG_TIME_DAYS "com.klaraystems:txg_log_time:days"
#define DMU_POOL_TXG_LOG_TIME_MONTHS "com.klaraystems:txg_log_time:months"

/*
* Allocate an object from this objset. The range of object numbers
Expand Down
8 changes: 8 additions & 0 deletions include/sys/spa_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
#include <sys/dsl_deadlist.h>
#include <zfeature_common.h>

#include "zfs_crrd.h"

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -353,6 +355,12 @@ struct spa {
spa_checkpoint_info_t spa_checkpoint_info; /* checkpoint accounting */
zthr_t *spa_checkpoint_discard_zthr;

kmutex_t spa_txg_log_time_lock; /* for spa_txg_log_time */
dbrrd_t spa_txg_log_time;
uint64_t spa_last_noted_txg;
uint64_t spa_last_noted_txg_time;
uint64_t spa_last_flush_txg_time;

space_map_t *spa_syncing_log_sm; /* current log space map */
avl_tree_t spa_sm_logs_by_txg;
kmutex_t spa_flushed_ms_lock; /* for metaslabs_by_flushed */
Expand Down
73 changes: 73 additions & 0 deletions include/zfs_crrd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2024 Klara Inc.
*
* This software was developed by
* Fred Weigel <[email protected]>
* Mariusz Zaborski <[email protected]>
* under sponsorship from Wasabi Technology, Inc. and Klara Inc.
*/

#ifndef _CRRD_H_
#define _CRRD_H_

#define RRD_MAX_ENTRIES 256

typedef enum {
DBRRD_FLOOR,
DBRRD_CEILING
} dbrrd_rounding_t;

typedef struct {
hrtime_t rrdd_time;
uint64_t rrdd_txg;
} rrd_data_t;

typedef struct {
uint64_t rrd_head; /* head (beginning) */
uint64_t rrd_tail; /* tail (end) */
uint64_t rrd_length;

rrd_data_t rrd_entries[RRD_MAX_ENTRIES];
} rrd_t;

typedef struct {
rrd_t dbr_minutes;
rrd_t dbr_days;
rrd_t dbr_months;
} dbrrd_t;

size_t rrd_len(rrd_t *rrd);

const rrd_data_t *rrd_entry(rrd_t *r, size_t i);
const rrd_data_t *rrd_tail_entry(rrd_t *rrd);
uint64_t rrd_tail(rrd_t *rrd);
uint64_t rrd_get(rrd_t *rrd, size_t i);

void rrd_add(rrd_t *rrd, hrtime_t time, uint64_t txg);
void rrd_pack(rrd_t *rrd, uint8_t *buffer);
void rrd_ntoh(rrd_t *rrd);

void dbrrd_add(dbrrd_t *db, hrtime_t time, uint64_t txg);
uint64_t dbrrd_query(dbrrd_t *r, hrtime_t tv, dbrrd_rounding_t rouding);

#endif
5 changes: 5 additions & 0 deletions lib/libnvpair/libnvpair.abi
Original file line number Diff line number Diff line change
Expand Up @@ -2194,6 +2194,7 @@
</data-member>
</class-decl>
<typedef-decl name='stack_t' type-id='380f9954' id='ac5e685f'/>
<typedef-decl name='unw_regnum_t' type-id='95e97e5e' id='c53620f0'/>
<class-decl name='unw_cursor' size-in-bits='8128' is-struct='yes' visibility='default' id='384a1f22'>
<data-member access='public' layout-offset-in-bits='0'>
<var-decl name='opaque' type-id='dc70ec0b' visibility='default'/>
Expand Down Expand Up @@ -2306,6 +2307,10 @@
<parameter type-id='b59d7dce'/>
<return type-id='79a0948f'/>
</function-decl>
<function-decl name='_Ux86_64_regname' visibility='default' binding='global' size-in-bits='64'>
<parameter type-id='c53620f0'/>
<return type-id='80f4b756'/>
</function-decl>
<function-decl name='_ULx86_64_init_local' visibility='default' binding='global' size-in-bits='64'>
<parameter type-id='3946e4d1'/>
<parameter type-id='2e408b96'/>
Expand Down
45 changes: 6 additions & 39 deletions lib/libuutil/libuutil.abi
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,7 @@
</data-member>
</class-decl>
<typedef-decl name='stack_t' type-id='380f9954' id='ac5e685f'/>
<typedef-decl name='unw_regnum_t' type-id='95e97e5e' id='c53620f0'/>
<class-decl name='unw_cursor' size-in-bits='8128' is-struct='yes' visibility='default' id='384a1f22'>
<data-member access='public' layout-offset-in-bits='0'>
<var-decl name='opaque' type-id='dc70ec0b' visibility='default'/>
Expand Down Expand Up @@ -763,6 +764,10 @@
<parameter type-id='b59d7dce'/>
<return type-id='79a0948f'/>
</function-decl>
<function-decl name='_Ux86_64_regname' visibility='default' binding='global' size-in-bits='64'>
<parameter type-id='c53620f0'/>
<return type-id='80f4b756'/>
</function-decl>
<function-decl name='_ULx86_64_init_local' visibility='default' binding='global' size-in-bits='64'>
<parameter type-id='3946e4d1'/>
<parameter type-id='2e408b96'/>
Expand Down Expand Up @@ -1011,16 +1016,9 @@
</function-decl>
</abi-instr>
<abi-instr address-size='64' path='lib/libspl/os/linux/getmntany.c' language='LANG_C99'>
<array-type-def dimensions='1' type-id='38b51b3c' size-in-bits='832' id='02b72c00'>
<subrange length='13' type-id='7359adad' id='487fded1'/>
</array-type-def>
<array-type-def dimensions='1' type-id='03085adc' size-in-bits='192' id='083f8d58'>
<subrange length='3' type-id='7359adad' id='56f209d2'/>
</array-type-def>
<class-decl name='__locale_data' is-struct='yes' visibility='default' is-declaration-only='yes' id='23de8b96'/>
<array-type-def dimensions='1' type-id='80f4b756' size-in-bits='832' id='39e6f84a'>
<subrange length='13' type-id='7359adad' id='487fded1'/>
</array-type-def>
<class-decl name='mnttab' size-in-bits='256' is-struct='yes' visibility='default' id='1b055409'>
<data-member access='public' layout-offset-in-bits='0'>
<var-decl name='mnt_special' type-id='26a90f95' visibility='default'/>
Expand Down Expand Up @@ -1130,25 +1128,6 @@
<typedef-decl name='__blksize_t' type-id='bd54fe1a' id='d3f10a7f'/>
<typedef-decl name='__blkcnt64_t' type-id='bd54fe1a' id='4e711bf1'/>
<typedef-decl name='__syscall_slong_t' type-id='bd54fe1a' id='03085adc'/>
<class-decl name='__locale_struct' size-in-bits='1856' is-struct='yes' visibility='default' id='90cc1ce3'>
<data-member access='public' layout-offset-in-bits='0'>
<var-decl name='__locales' type-id='02b72c00' visibility='default'/>
</data-member>
<data-member access='public' layout-offset-in-bits='832'>
<var-decl name='__ctype_b' type-id='31347b7a' visibility='default'/>
</data-member>
<data-member access='public' layout-offset-in-bits='896'>
<var-decl name='__ctype_tolower' type-id='6d60f45d' visibility='default'/>
</data-member>
<data-member access='public' layout-offset-in-bits='960'>
<var-decl name='__ctype_toupper' type-id='6d60f45d' visibility='default'/>
</data-member>
<data-member access='public' layout-offset-in-bits='1024'>
<var-decl name='__names' type-id='39e6f84a' visibility='default'/>
</data-member>
</class-decl>
<typedef-decl name='__locale_t' type-id='f01e1813' id='b7ac9b5f'/>
<typedef-decl name='locale_t' type-id='b7ac9b5f' id='973a4f8d'/>
<class-decl name='timespec' size-in-bits='128' is-struct='yes' visibility='default' id='a9c79a1f'>
<data-member access='public' layout-offset-in-bits='0'>
<var-decl name='tv_sec' type-id='65eda9c0' visibility='default'/>
Expand All @@ -1157,23 +1136,12 @@
<var-decl name='tv_nsec' type-id='03085adc' visibility='default'/>
</data-member>
</class-decl>
<pointer-type-def type-id='23de8b96' size-in-bits='64' id='38b51b3c'/>
<pointer-type-def type-id='90cc1ce3' size-in-bits='64' id='f01e1813'/>
<qualified-type-def type-id='95e97e5e' const='yes' id='2448a865'/>
<pointer-type-def type-id='2448a865' size-in-bits='64' id='6d60f45d'/>
<qualified-type-def type-id='8efea9e5' const='yes' id='3beb2af4'/>
<pointer-type-def type-id='3beb2af4' size-in-bits='64' id='31347b7a'/>
<pointer-type-def type-id='0c544dc0' size-in-bits='64' id='394fc496'/>
<pointer-type-def type-id='56fe4a37' size-in-bits='64' id='b6b61d2f'/>
<qualified-type-def type-id='b6b61d2f' restrict='yes' id='3cad23cd'/>
<pointer-type-def type-id='1b055409' size-in-bits='64' id='9d424d31'/>
<pointer-type-def type-id='0bbec9cd' size-in-bits='64' id='62f7a03d'/>
<qualified-type-def type-id='62f7a03d' restrict='yes' id='f1cadedf'/>
<class-decl name='__locale_data' is-struct='yes' visibility='default' is-declaration-only='yes' id='23de8b96'/>
<function-decl name='uselocale' visibility='default' binding='global' size-in-bits='64'>
<parameter type-id='973a4f8d'/>
<return type-id='973a4f8d'/>
</function-decl>
<function-decl name='getmntent_r' visibility='default' binding='global' size-in-bits='64'>
<parameter type-id='e75a27e9'/>
<parameter type-id='3cad23cd'/>
Expand All @@ -1185,9 +1153,8 @@
<parameter type-id='822cd80b'/>
<return type-id='95e97e5e'/>
</function-decl>
<function-decl name='strerror_l' visibility='default' binding='global' size-in-bits='64'>
<function-decl name='strerror' visibility='default' binding='global' size-in-bits='64'>
<parameter type-id='95e97e5e'/>
<parameter type-id='973a4f8d'/>
<return type-id='26a90f95'/>
</function-decl>
<function-decl name='__fprintf_chk' visibility='default' binding='global' size-in-bits='64'>
Expand Down
Loading

0 comments on commit 7797e3f

Please sign in to comment.