-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
config: move snapshot related code into utils
Config's box.cfg applier scans snapshot_dir in order to find out, whether recovery is going to be done. It's needed in order to determine, whether the instance should be started into ro mode firstly. Let's move info about snapshot into separate file in utils. The commit also introduces snapshot_path, which will be used in the following commits in order to validate names. Needed for #8978 NO_DOC=refactoring NO_TEST=refactoring NO_CHANGELOG=refactoring
- Loading branch information
1 parent
e72e57b
commit 21e9ef4
Showing
4 changed files
with
77 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
local fio = require('fio') | ||
local instance_config = require('internal.config.instance_config') | ||
|
||
local snapshot_path = nil | ||
|
||
-- Determine where snapshot should reside based on the given | ||
-- configuration. | ||
-- | ||
-- To be called before first box.cfg(). | ||
local function effective_snapshot_dir(iconfig) | ||
assert(iconfig ~= nil) | ||
-- The snapshot directory has a default value in the schema | ||
-- (it is a string). So, it can't be nil or box.NULL. | ||
local snap_dir = instance_config:get(iconfig, 'snapshot.dir') | ||
assert(snap_dir ~= nil) | ||
|
||
-- If the path is absolute, just return it. | ||
-- | ||
-- This check is necessary due to fio.pathjoin() peculiars, | ||
-- see gh-8816. | ||
if snap_dir:startswith('/') then | ||
return snap_dir | ||
end | ||
|
||
-- We assume that the startup working directory is the current | ||
-- working directory. IOW, that this function is called before | ||
-- first box.cfg() call. Let's verify it. | ||
assert(type(box.cfg) == 'function') | ||
|
||
-- If the snapshot directory is not absolute, it is relative | ||
-- to the working directory. | ||
-- | ||
-- Determine an absolute path to the configured working | ||
-- directory considering that it may be relative to the | ||
-- working directory at the startup moment. | ||
local work_dir = instance_config:get(iconfig, 'process.work_dir') | ||
if work_dir == nil then | ||
work_dir = '.' | ||
end | ||
work_dir = fio.abspath(work_dir) | ||
|
||
-- Now we know the absolute path to the configured working | ||
-- directory. Let's determine the snapshot directory path. | ||
return fio.abspath(fio.pathjoin(work_dir, snap_dir)) | ||
end | ||
|
||
-- Determine whether the instance will be recovered from an existing | ||
-- snapshot and return its path. Should be called before box.cfg. | ||
-- | ||
-- To be called before first box.cfg(). | ||
local function get_snapshot_path(iconfig) | ||
assert(type(box.cfg) == 'function') | ||
if snapshot_path == nil then | ||
local snap_dir = effective_snapshot_dir(iconfig) | ||
local glob = fio.glob(fio.pathjoin(snap_dir, '*.snap')) | ||
if #glob > 0 then | ||
table.sort(glob) | ||
snapshot_path = glob[#glob] | ||
end | ||
end | ||
|
||
return snapshot_path | ||
end | ||
|
||
return { | ||
get_path = get_snapshot_path, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters