Qlock()

Read(1191) Label: qvs, global lock,

Description:

Implement global lock through QVS.

Syntax:

Qlock(n,s)

Note:

When Qlock() function is executed in a script, global lock named n will be created in the controller QVS. Execute Qlock@u to open the lock.

 

If there is locking check about lock n before the script code, the script can be executed only when the global lock is open. If there isn’t such a check on lock n, the script can be directly executed without considering the lock; in this case, if we perform operations on the same file from multiple script files at the same time, file update collision will occur.

 

Will be parsed as lock() function if no controller QVS is configured.

Parameter:

n

Global lock name

s

Locking time-out (Unit: second)

Option:

@u

Open the global lock

Return value:

Boolean value

Example:

Create script file p1.splx, save it and upload it to the cloud storage:

 

A

B

 

1

=Qlock("lock1")

 

Implement global lock named lock1.

2

if(A1)

 

Check if the locking succeeds; execute B3, B4 and B5 if it succeeds, otherwise the system will execute B7.

3

 

=Qfile("qtc01/Employees.txt")

Get Employees.txt from cloud storage

4

 

=B3.import@t()

Import data from B3’s file.

5

 

return B4

Return B4’s result.

6

else

 

 

7

 

return "Getting lock failed"

 

8

=Qlock@u("lock1")

 

Open the lock.

 

Create script file p2.splx, save it and upload it to storage bucket qtc01 in the cloud storage:

 

A

B

 

1

=Qlock("lock1",10)

 

Implement global lock named lock1;the locking fails if it takes over 10 seconds.

2

if(A1)

 

Check if the locking succeeds; execute B3 and B4 if it succeeds, otherwise the system will execute B6

3

 

=Qmove("qtc01/Employees.txt","emp_new.txt")

Rename Employees.txt in the cloud storage platform emp_new.txt.

4

 

return "Rename file successfully"

Return result.

5

else

 

 

6

 

return " Getting lock failed "

 

7

=Qlock@u("lock1")

 

Open the lock.

 

Create script file p3.splx, save it and upload it to the cloud storage:

 

A

 

1

=Qmove("qtc01/Employees.txt ")

Delete Employees.txt from the cloud storage

 

When executing p1.splx, p2.splx and p3.splx at the same time:

 

Suppose p1 is executed first. A global lock named lock1 will be created and then p1’s retrieval query on txt data will be executed. During the process if p2 also begins to execute while p1 is under execution, that is to say, p1 is still locked, then p2’s execution of Qlock is put to the waiting list. After 10 seconds if the execution of p1 is unfinished, execution of p2 will be abandoned and “Getting lock failed” is returned. If p1 finishes execution, then p2 begins to perform locking and file naming operations;

 

Suppose p3 begins to execution during the execution of p2. As p3 does not check lock1, it will directly execute deletion of txt file. This will result in collision between p2 and p3 as both are trying to modify the txt file.