Skip to content

Commit d8cf089

Browse files
committed
snapshots: do not create temp files when download is disabled
1 parent af15cb0 commit d8cf089

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

src/discof/restore/fd_snapct_tile.c

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
/* FIXME: Implement max_retry_abort and retry logic in general */
2828
/* FIXME: Add more timeout config options and have consistent behavior */
2929
/* FIXME: Do a finishing pass over the default.toml config options / comments */
30+
/* FIXME: Improve behavior when using incremental_snapshots = false */
3031

3132
#define GOSSIP_PEERS_MAX (FD_CONTACT_INFO_TABLE_SIZE)
3233
#define SERVER_PEERS_MAX (FD_TOPO_SNAPSHOTS_SERVERS_MAX)
@@ -333,11 +334,18 @@ rename_snapshots( fd_snapct_tile_t * ctx ) {
333334
static ulong
334335
rlimit_file_cnt( fd_topo_t const * topo FD_PARAM_UNUSED,
335336
fd_topo_tile_t const * tile ) {
336-
return 1UL + /* stderr */
337-
1UL + /* logfile */
338-
3UL + /* dirfd + 2 snapshot file fds in the worst case */
339-
!!download_enabled( tile ) + /* ssping socket */
340-
2UL*tile->snapct.sources.servers_cnt; /* http resolver peer sockets (full + incr) */
337+
ulong cnt = 1UL + /* stderr */
338+
1UL; /* logfile */
339+
if( download_enabled( tile ) ) {
340+
cnt += 1UL + /* ssping socket */
341+
2UL + /* dirfd + full snapshot download temp fd */
342+
tile->snapct.sources.servers_cnt; /* http resolver peer full sockets */
343+
if( tile->snapct.incremental_snapshots ) {
344+
cnt += 1UL + /* incr snapshot download temp fd */
345+
tile->snapct.sources.servers_cnt; /* http resolver peer incr sockets */
346+
}
347+
}
348+
return cnt;
341349
}
342350

343351
static ulong
@@ -1110,31 +1118,20 @@ privileged_init( fd_topo_t * topo,
11101118
}
11111119
}
11121120

1113-
/* FIXME: Do not create the temporary files if downloading is not
1114-
enabled by the configuration. Account for this in rlimit. */
1115-
11161121
ctx->local_out.dir_fd = -1;
11171122
ctx->local_out.full_snapshot_fd = -1;
11181123
ctx->local_out.incremental_snapshot_fd = -1;
1124+
if( FD_LIKELY( download_enabled( tile ) ) ) {
1125+
ctx->local_out.dir_fd = open( tile->snapct.snapshots_path, O_DIRECTORY|O_CLOEXEC );
1126+
if( FD_UNLIKELY( -1==ctx->local_out.dir_fd ) ) FD_LOG_ERR(( "open(%s) failed (%i-%s)", tile->snapct.snapshots_path, errno, fd_io_strerror( errno ) ));
11191127

1120-
/* Set up download descriptors because even if we have local
1121-
snapshots, we may need to download new snapshots if the local
1122-
snapshots are too old. */
1123-
ctx->local_out.dir_fd = open( tile->snapct.snapshots_path, O_DIRECTORY|O_CLOEXEC );
1124-
if( FD_UNLIKELY( -1==ctx->local_out.dir_fd ) ) FD_LOG_ERR(( "open() failed `%s` (%i-%s)", tile->snapct.snapshots_path, errno, fd_io_strerror( errno ) ));
1125-
1126-
char full_snapshot_path[ PATH_MAX ];
1127-
FD_TEST( fd_cstr_printf_check( full_snapshot_path, PATH_MAX, NULL, "%s/" TEMP_FULL_SNAP_NAME, tile->snapct.snapshots_path ) );
1128-
ctx->local_out.full_snapshot_fd = openat( ctx->local_out.dir_fd, TEMP_FULL_SNAP_NAME, O_WRONLY|O_CREAT|O_TRUNC|O_NONBLOCK, S_IRUSR|S_IWUSR );
1129-
if( FD_UNLIKELY( -1==ctx->local_out.full_snapshot_fd ) ) FD_LOG_ERR(( "open() failed `%s` (%i-%s)", full_snapshot_path, errno, fd_io_strerror( errno ) ));
1130-
1131-
if( FD_LIKELY( tile->snapct.incremental_snapshots ) ) {
1132-
char incremental_snapshot_path[ PATH_MAX ];
1133-
FD_TEST( fd_cstr_printf_check( incremental_snapshot_path, PATH_MAX, NULL, "%s/" TEMP_INCR_SNAP_NAME, tile->snapct.snapshots_path ) );
1134-
ctx->local_out.incremental_snapshot_fd = openat( ctx->local_out.dir_fd, TEMP_INCR_SNAP_NAME, O_WRONLY|O_CREAT|O_TRUNC|O_NONBLOCK, S_IRUSR|S_IWUSR );
1135-
if( FD_UNLIKELY( -1==ctx->local_out.incremental_snapshot_fd ) ) FD_LOG_ERR(( "open() failed `%s` (%i-%s)", incremental_snapshot_path, errno, fd_io_strerror( errno ) ));
1136-
} else {
1137-
ctx->local_out.incremental_snapshot_fd = -1;
1128+
ctx->local_out.full_snapshot_fd = openat( ctx->local_out.dir_fd, TEMP_FULL_SNAP_NAME, O_WRONLY|O_CREAT|O_TRUNC|O_NONBLOCK, S_IRUSR|S_IWUSR );
1129+
if( FD_UNLIKELY( -1==ctx->local_out.full_snapshot_fd ) ) FD_LOG_ERR(( "open(%s/%s) failed (%i-%s)", tile->snapct.snapshots_path, TEMP_FULL_SNAP_NAME, errno, fd_io_strerror( errno ) ));
1130+
1131+
if( FD_LIKELY( tile->snapct.incremental_snapshots ) ) {
1132+
ctx->local_out.incremental_snapshot_fd = openat( ctx->local_out.dir_fd, TEMP_INCR_SNAP_NAME, O_WRONLY|O_CREAT|O_TRUNC|O_NONBLOCK, S_IRUSR|S_IWUSR );
1133+
if( FD_UNLIKELY( -1==ctx->local_out.incremental_snapshot_fd ) ) FD_LOG_ERR(( "open(%s/%s) failed (%i-%s)", tile->snapct.snapshots_path, TEMP_INCR_SNAP_NAME, errno, fd_io_strerror( errno ) ));
1134+
}
11381135
}
11391136
}
11401137

src/discof/restore/utils/fd_http_resolver.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
#define PEER_DEADLINE_NANOS_RESOLVE (1L*1000L*1000L*1000L) /* 1 second */
2121
#define PEER_DEADLINE_NANOS_INVALID (5L*1000L*1000L*1000L) /* 5 seconds */
2222

23+
/* FIXME: The fds/fds_len/idx logic is fragile, replace with something
24+
that duplicates less state / etc. */
25+
2326
struct fd_ssresolve_peer {
2427
fd_ip4_port_t addr;
2528
fd_ssinfo_t ssinfo;
@@ -263,9 +266,9 @@ remove_peer( fd_http_resolver_t * resolver,
263266
ulong idx ) {
264267
FD_TEST( idx<resolver->fds_len );
265268

266-
/* FIXME... */
269+
/* FIXME: These sockets should be closed at the correct location */
267270
close( resolver->fds[ idx ].fd );
268-
close( resolver->fds[ idx+1UL ].fd );
271+
if( FD_LIKELY( -1!=resolver->fds[ idx+1UL ].fd ) ) close( resolver->fds[ idx+1UL ].fd );
269272

270273
if( FD_UNLIKELY( resolver->fds_len==2UL ) ) {
271274
resolver->fds_len = 0UL;

0 commit comments

Comments
 (0)