This is an automated email from the ASF dual-hosted git repository.

yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git

commit beac4003edb38c180b3ebc8bc4b2a3bdabed710d
Author: sruthip2 <sruth...@vmware.com>
AuthorDate: Wed Aug 2 19:42:20 2023 +0530

    Add logic for checking the process holding the lock file exists
    
    Issue:
    Some utilities (gprecoverseg, gpstop, etc...) use a lock directory to 
prevent customers from running
    multiple instances of the program simultaneously. The lock directory is 
created inside the
    COORDINATOR_DATA_DIRECTORY at the start of program execution and should be 
removed when the execution completes.
    However, the lock directory is not always removed if the user abruptly 
kills the program
    during execution. Consequently, the next run of the same utility encounters 
an error, stating
    that the lock directory already exists and asks the user to manually delete 
it, even if
    the process holding the lock is already terminated.
    
    Solution:
    To address this issue, this commit introduces a modification in 
mainUtils.py.
    When attempting to acquire the lock, the code now checks if the process ID 
in the PID file,
    present in the lock directory, still exists. If the process has been 
killed, the script
    automatically removes the lock directory and proceeds to acquire a new lock 
for the current run.
    This ensures that the utility can continue its execution without being 
hindered by
    orphaned lock files from previous runs.
---
 gpMgmt/bin/gppylib/mainUtils.py | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/gpMgmt/bin/gppylib/mainUtils.py b/gpMgmt/bin/gppylib/mainUtils.py
index 98d42bddad..b191c88156 100644
--- a/gpMgmt/bin/gppylib/mainUtils.py
+++ b/gpMgmt/bin/gppylib/mainUtils.py
@@ -173,6 +173,11 @@ class SimpleMainLock:
             if self.pidfilepid == self.parentpid:
                 return None
 
+            # Check if the process that holds the lock exists.
+            # If the process is already killed, remove the lock directory.
+            if not unix.check_pid(self.pidfilepid):
+                shutil.rmtree(self.ppath)
+
         # try and acquire the lock
         try:
             self.pidlockfile.acquire()


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cloudberry.apache.org
For additional commands, e-mail: commits-h...@cloudberry.apache.org

Reply via email to