Skip to content

Commit

Permalink
[PLAT-15273]Remote files download bug fix
Browse files Browse the repository at this point in the history
Summary:
This diff has the fix for a bug where we assume the same tmp directory for the YBA and the db nodes.
As a result support bundle creation fails when we set `yb.filepaths.TmpDirectory` to any path which is absent on the db nodes.

Fix for both the python script and the node agent flow.

Test Plan: Manually verified that support bundle creation succeeds when the tmp directory is changed on either YBA or the db nodes via gflags.

Reviewers: nsingh, skurapati

Reviewed By: nsingh

Subscribers: yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D39722
  • Loading branch information
asharma-yb committed Nov 6, 2024
1 parent 316cda5 commit 7ece035
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
7 changes: 5 additions & 2 deletions managed/devops/bin/run_node_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ def add_download_file_subparser(subparsers, command, parent):
parser.add_argument('--source_node_files_path', type=str,
help='File containing source files to download (separated by new line)',
required=True)
parser.add_argument('--remote_node_files_path', type=str,
help='File containing source files to download on the remote server',
required=True)
parser.add_argument('--target_local_file', type=str,
help='Target file to save source to',
required=True)
Expand All @@ -171,11 +174,11 @@ def add_download_file_subparser(subparsers, command, parent):
def download_file_node(args, client):
# Name is irrelevant as long as it doesn't already exist
tar_file_name = args.node_name + "-" + str(uuid.uuid4()) + ".tar.gz"
target_node_files_path = args.source_node_files_path
target_node_files_path = args.remote_node_files_path

# "node_utils.sh/create_tar_file" file takes parameters:
# [home_dir, tar_file_name, file_list_text_path]
cmd = [args.source_node_files_path]
cmd = [target_node_files_path]
client.put_file(args.source_node_files_path, target_node_files_path)
cmd.insert(0, tar_file_name)
cmd.insert(0, args.yb_home_dir)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ public void downloadFile(
NodeDetails node,
String ybHomeDir,
String fileListFilepath,
String targetNodeFilesPath,
String targetLocalFile,
ShellProcessContext context) {
String user = context.getSshUser();
Duration timeout = context.getTimeout();
String tarFilename = String.format("%s-%s.tar.gz", node.getNodeName(), UUID.randomUUID());
String targetNodeFilesPath = fileListFilepath;
// Upload the files to be downloaded.
nodeAgentClient.uploadFile(nodeAgent, fileListFilepath, targetNodeFilesPath, user, 0, timeout);
Path scriptPath =
Expand All @@ -150,7 +150,7 @@ public void downloadFile(
scriptParams.add("create_tar_file");
scriptParams.add(ybHomeDir);
scriptParams.add(tarFilename);
scriptParams.add(fileListFilepath);
scriptParams.add(targetNodeFilesPath);
String scriptOutput =
nodeAgentClient
.executeScript(nodeAgent, scriptPath, scriptParams, context)
Expand Down Expand Up @@ -189,11 +189,6 @@ public void downloadFile(
*/
public void copyFile(
NodeAgent nodeAgent, String remoteFile, String localFile, ShellProcessContext context) {
Path localFilepath = Paths.get(localFile);
Path localFileDir = localFilepath.getParent().toAbsolutePath();
nodeAgentClient
.executeCommand(nodeAgent, Arrays.asList("mkdir", "-p", localFileDir.toString()), context)
.processErrors();
nodeAgentClient.downloadFile(nodeAgent, remoteFile, localFile);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,28 @@ public void downloadNodeFile(
List<String> sourceNodeFiles,
String targetLocalFile) {
universeLock.acquireLock(universe.getUniverseUUID());
String filesListFilePath = "";
String filesListFilePath = "", remoteFilesListPath = "";
try {
filesListFilePath = createTempFileWithSourceFiles(sourceNodeFiles);
if (filesListFilePath == null) {
throw new RuntimeException(
"Could not create temp file while downloading node file for universe "
+ universe.getUniverseUUID());
}
remoteFilesListPath =
getRemoteTmpDir(node, universe)
+ "/"
+ Paths.get(filesListFilePath).getFileName().toString();
Optional<NodeAgent> optional = maybeGetNodeAgent(universe, node, true /*check feature flag*/);
if (optional.isPresent()) {
nodeActionRunner.downloadFile(
optional.get(), node, ybHomeDir, filesListFilePath, targetLocalFile, DEFAULT_CONTEXT);
optional.get(),
node,
ybHomeDir,
filesListFilePath,
remoteFilesListPath,
targetLocalFile,
DEFAULT_CONTEXT);
} else {
List<String> actionArgs = new ArrayList<>();
// yb_home_dir denotes a custom starting directory for the remote file. (Eg: ~/, /mnt/d0,
Expand All @@ -159,6 +169,8 @@ public void downloadNodeFile(
actionArgs.add(ybHomeDir);
actionArgs.add("--source_node_files_path");
actionArgs.add(filesListFilePath);
actionArgs.add("--remote_node_files_path");
actionArgs.add(remoteFilesListPath);
actionArgs.add("--target_local_file");
actionArgs.add(targetLocalFile);
executeNodeAction(
Expand Down

0 comments on commit 7ece035

Please sign in to comment.