imthekrish Respected Contributor.
Respected Contributor.
1386 views

access same file - multi instance

Jump to solution

I have operations that should be performed parallely. These operations write logs to .log file. I'm using multi-instance to perform parallel operation, while first process is writting log to x.log file, the other parallel process is unable to write/access that file. Is there anyway for me to access that file while its being used by another process ?

Labels (1)
0 Likes
1 Solution

Accepted Solutions
Micro Focus Expert
Micro Focus Expert

Re: access same file - multi instance

Jump to solution

Hi,

From what i understand you run a batch file on a remote host that performs the switchover and writs to a log file the output of the switchover. In order not to be confused i will call this log file the remote.log.  Then you want to write the contents from the remote.log to a local file on the oo worker which i will call local.log. If this is the case then the flow should look something like the screenshot https://ibb.co/fprKo5 .

If however you want to write the local file directly from remote batch that performs the failover then you need to perform a full instance lock (which would look something like this https://ibb.co/nA8Avk ), however if you do the full instance lock than you might as well just iterate throught he servers, as it is pretty much the same thing now. 

You may have noticed that i use wait for lock to acquire the locks, this is because wait for lock flow tries to acquire the lock and if it fails it waits for a number of seconds then tries again. 

 

PS: because of a bug with hpln forum that does not recognize the extensions of screenshots correctly i had to upload the screenshots to a free online image sharing site.

Regards,

Vlad

0 Likes
11 Replies
Established Member.. TerrySummers
Established Member..

Re: access same file - multi instance

Jump to solution

As a general rule there is no way to do this.
2 processes writing to the same file will lead to corruption and OS's protect against this exact thing by locking the file.

Try adding something variable like the date/time (dd-mm-yy-hh-mm-ss) to the log name and you will overcome this.

0 Likes
imthekrish Respected Contributor.
Respected Contributor.

Re: access same file - multi instance

Jump to solution

Thanks you are right. I had a databse name appended at the end of file name

0 Likes
Micro Focus Expert
Micro Focus Expert

Re: access same file - multi instance

Jump to solution

Hi,

Using write to file operation on local host makes it somewhat possible to write to the same text file from within a multi-instance, however what then happens is that data is unreadable in the file (there are going to be empty lines, there is no specific order in which the lines are going to be in the file and there may even be missing lines). 

If there is something else happening in the MI before the loggin then you colud put an aquire lock step (hpe solutions : library\integrations\HP\Operations Orchestration\10.x\locks) and have the write to file operations proceed based on the lock.

 

Regards,

Vlad

0 Likes
AndreiTruta Outstanding Contributor.
Outstanding Contributor.

Re: access same file - multi instance

Jump to solution

If you are ok with certain delays, as Vlad mentioned you could contruct a lock based mechanism to check for locks/wait for and aquire locks. In this way every mi instance will be able to write at a certain time, hence you do not care about the line each lane writes data to.

Andrei Vasile Truta
imthekrish Respected Contributor.
Respected Contributor.

Re: access same file - multi instance

Jump to solution

@Vlad / @AndreiTruta Thank you so much .... I'm creating different files. I wanted to test locking as well, but not sure how to use those operations. I got the cp,. Could you please attach any samples to use locking if you have one

0 Likes
Micro Focus Expert
Micro Focus Expert

Re: access same file - multi instance

Jump to solution

Hi,

HPLN forum only allows images as attachments, therefore we cannot provide you with a sample flow via the forum.

The way you want to do it is like this:

Before the write to file place a step to wait for lock (there is a flow in the lock folder for this). This step will acquire the lock if it is available if it is not it will keep retrying until it is either available or you set up an exit condition. This flow has 2 responses and if you want to have it keep trying no matter what just drag the failure response back to the step.  After writing to file place a step with release lock operation and you are done.

The lock itself is a string you enter (it can be anything). Make sure to enter the same string in the wait for lock and release lock steps.  This string is locked only for the purpose of aquire/wait for/release lock context, it can still be used in regular operations without incident. 

Regards,

Vlad

0 Likes
AndreiTruta Outstanding Contributor.
Outstanding Contributor.

Re: access same file - multi instance

Jump to solution

you can consider one of the below files.

whatever link will work for you.

It is a rather old explanation but accurate and helpful.

https://lnast01pcache.saas.hpe.com/asset/resources/pd/oo/1qo1459950507/Semaphores_in_HPOO_0.pdf

/t5/Grounded-in-the-Cloud/Semaphores-in-HP-Operations-Orchestration/ba-p/6260929#.WO3E7Yh963Y

 

Andrei Vasile Truta
0 Likes
imthekrish Respected Contributor.
Respected Contributor.

Re: access same file - multi instance

Jump to solution

This is my scenario:

I have x databases which has to swtichover

I've a batch file that runs switchover command and type output to a zzz.log. Both the commands are in same batch file.

So now, on all x databases i run this batch file using Remote command Execution operation. the switchover operation is performed as expected on all DBs and i've issue writing log into zzz.log file which is on HPOO server since one of the DBs log is being written to zzz.log while other one is trying to access this.

I somehow figured out how to use lock aquire in a sample where i'm only having type command but not switch. What this lock thing is doing on a failure to write to .log i have aquire lock step where lock id is process id and output of aquire lock is code. Next i have wait for lock 1 second, 60 seconds timeout and code as lockid and then release lock, lockid is code again. on success of release lock it will go to remote command execution and run that file. In my test scenario I have only type command so its not a problem for me to retry this operation several time until the files gets free but in my real scenario I can retry/run switchover command again. What can i do in this scenario ?

0 Likes
imthekrish Respected Contributor.
Respected Contributor.

Re: access same file - multi instance

Jump to solution

@Vlad and @AndreiTruta Do you guys have solition for this scenario below 

 

I have x databases which has to swtichover

I've a batch file that runs switchover command and type output to a zzz.log. Both the commands are in same batch file.

So now, on all x databases i run this batch file using Remote command Execution operation. the switchover operation is performed as expected on all DBs and i've issue writing log into zzz.log file which is on HPOO server since one of the DBs log is being written to zzz.log while other one is trying to access this.

I somehow figured out how to use lock aquire in a sample where i'm only having type command but not switch. What this lock thing is doing on a failure to write to .log i have aquire lock step where lock id is process id and output of aquire lock is code. Next i have wait for lock 1 second, 60 seconds timeout and code as lockid and then release lock, lockid is code again. on success of release lock it will go to remote command execution and run that file. In my test scenario I have only type command so its not a problem for me to retry this operation several time until the files gets free but in my real scenario I can retry/run switchover command again. What can i do in this scenario ?

0 Likes
Micro Focus Expert
Micro Focus Expert

Re: access same file - multi instance

Jump to solution

Hi,

From what i understand you run a batch file on a remote host that performs the switchover and writs to a log file the output of the switchover. In order not to be confused i will call this log file the remote.log.  Then you want to write the contents from the remote.log to a local file on the oo worker which i will call local.log. If this is the case then the flow should look something like the screenshot https://ibb.co/fprKo5 .

If however you want to write the local file directly from remote batch that performs the failover then you need to perform a full instance lock (which would look something like this https://ibb.co/nA8Avk ), however if you do the full instance lock than you might as well just iterate throught he servers, as it is pretty much the same thing now. 

You may have noticed that i use wait for lock to acquire the locks, this is because wait for lock flow tries to acquire the lock and if it fails it waits for a number of seconds then tries again. 

 

PS: because of a bug with hpln forum that does not recognize the extensions of screenshots correctly i had to upload the screenshots to a free online image sharing site.

Regards,

Vlad

0 Likes
imthekrish Respected Contributor.
Respected Contributor.

Re: access same file - multi instance

Jump to solution

Amazing! Thank you!

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.