Skip to content

Commit

Permalink
PXB-3381 : Implement check to fail early if number of open file handl…
Browse files Browse the repository at this point in the history
…es is not same as number of files in datadir

1. Verifies the ulimit -Sn , ulimit -Hn, current --open-files-limit
   parameter and increases the limit if possible, else throws an error
   early.

2. Despite the limit increase, backup may still fail because if there
   are new files that appear, we may need more handles than we first
   calculated.
  • Loading branch information
satya-bodapati committed Oct 4, 2024
1 parent 335c7d5 commit bb3e06a
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
7 changes: 7 additions & 0 deletions storage/innobase/fil/fil0fil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12146,6 +12146,13 @@ dberr_t Tablespace_dirs::scan(bool populate_fil_cache IF_XB(, bool only_undo)) {
<< undo_files.size() << " undo files";
}

size_t total_files =
ibd_files.size() + undo_files.size() + 50 /*buffer for ibdata, redo */;

if (!xb_check_and_set_open_files_limit(total_files)) {
return DB_FAIL;
}

Space_id_set unique;
Space_id_set duplicates;

Expand Down
3 changes: 3 additions & 0 deletions storage/innobase/include/xb0xb.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,7 @@ extern char *xtrabackup_debug_sync;
/** @return true if xtrabackup has locked Server with LOCK INSTANCE FOR BACKP or
LOCK TABLES FOR BACKUP */
bool is_server_locked();

bool xb_check_and_set_open_files_limit(size_t num_files);

#endif
74 changes: 74 additions & 0 deletions storage/innobase/xtrabackup/src/xtrabackup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4080,6 +4080,80 @@ static uint xb_set_max_open_files(
#endif
}

/* true on success, false on failure */
bool xb_check_and_set_open_files_limit(size_t num_files) {
if (opt_lock_ddl != LOCK_DDL_REDUCED) {
return true;
}

#if defined(RLIMIT_NOFILE)
xb::info() << "xb_check_and_set_open_files_limit is verifying the open_files "
"limit for --lock-ddl=reduced";

struct rlimit rlimit;
uint old_cur;

if (getrlimit(RLIMIT_NOFILE, &rlimit)) {
xb::info() << "getrlimit() failed with error: " << strerror(errno);
return true;
}

old_cur = (uint)rlimit.rlim_cur;

xb::info() << "Current open file limits:";
xb::info() << "Desired file_handles: " << num_files;
xb::info() << "ulimit -Sn: " << rlimit.rlim_cur;
xb::info() << "ulimit -Hn: " << rlimit.rlim_max;
xb::info() << "--open-files-limit: " << xb_open_files_limit;

if (rlimit.rlim_cur == RLIM_INFINITY) {
// current open files limit is inifinity. All good. nothing do
return true;
}

if (num_files < old_cur) {
// all good nothing to do. Num of files we have is less than
// the open files limit.
return true;
}

if (xb_open_files_limit != 0) {
if (num_files > xb_open_files_limit) {
xb::error() << "Reduced lock mode needs open file handles: " << num_files
<< " but --open-files-limit parameter is set to "
<< xb_open_files_limit;
xb::error() << "Please retry with --open-files-limit=" << num_files;
return false; // ERROR
}
}

if (num_files <= rlimit.rlim_max) {
// We are allowed to go up to rlimit.rlim_max. Lets try.
ulint result_files = xb_set_max_open_files(num_files);
if (result_files < num_files) {
xb::error() << "Reduced lock mode requested open file handles: "
<< num_files << " but only got " << result_files
<< " open file handles";
return false; // ERROR
} else {
xb::info() << "Reduced lock mode successfully raised open files limit to "
<< result_files;
}
} else {
// we are below xb_open_limit but above the max allowed open files
xb::error() << "Reduced lock mode requires open file handles " << num_files
<< " but the max limit (ulimit -Hn) is " << rlimit.rlim_max;
return false;
}

#else
xb::info() << "setrlimit() is not available on this platform";
return true;
#endif

return true;
}

/**************************************************************************
Prints a warning for every table that uses unsupported engine and
hence will not be backed up. */
Expand Down

0 comments on commit bb3e06a

Please sign in to comment.