Avoid locking between two files:

Hi frnz,

I have requirement as follows..

There are two Modules say A and B...n both have few set of files..we have one script which read these files and load into database(vertica) table..while running script smtimes i encounter an error like one table is getting loaded from A module file also and module B file also..and due to this licking my script fails.

Now A & B run parellely so when A's file getting loaded into table it locks the table and B files fails to load..

so i want to add a piece of code where my script will wait till A file completley load into table and stop the file of B..n once A file loaded it will start loading B file into B..

Overall i need to Develop table update dependency tracking to avoid query failure due to table lock.
I knw its very confusing but if anyone can provide some input , i wud be very grateful..

Thanx:b:

Your scripts should use a flag to avoid conflict.

This flag should be created using an atomic operation (like mkdir or using clobber stuff).

Atomic means that if your both script tries to setup the flag at the same time, only one of them will pass and the second will fail.

But you will then have to check against the successful creation of the flag before your script run and erase the flag when it ends.

well thanks for the idea..i wud be grateful if u can provide sm unix script for that or atleast sm kind of pseudo code...

Thanks again

If you can tell us your OS, please.

Why don't you use DB locking mechanisms? Sth like "select * from table for update"?

@jim_mcnamara::--i am using Windows OS but connected to LINUX server to write n execute my shell scripts...so i guess i need a code corresponds to LINUX OS...

---------- Post updated at 07:02 AM ---------- Previous update was at 06:57 AM ----------

@RudiC::
well i am using cron jobs to run my script.. i have one load_cdr script which loads all files in diff modules to table...actually i dont want to put lock on table rather i need something like if A module file and B module File are interdependent then my script should run first A file and wait till it completes and then B file should execute...

So as per my understanding if i put some lock while reading module A file and if B module File comes into the picture my script will go in sleep mode till the lock on Module A file gets remove...smthin like that..but i am not getting how to write this into unix script..

TIA

The second script using select ... for update will automatically go to sleep.

If always script A runs first to completion, then script B, why don't you just run them sequentially?

Hi RudiC
there is only one script but we have multiple source feeds..so every feed has 10 set of files..so there is some interdependency on two files and these files exist in diff source feeds..so i run that main script and all feed's files loaded parallely but when ever those two inter dependent files come together it gets lock and i get an error..so i am not getting any problem loading two files together in db rather i am getting prob while reading those files simultaneously from my main script..