![]() This behaviour seems to be present all the way back to 4.0.6 from the little additional checking I made. I tried to trace this out between 4.1.2 and 4.2.2 (4.2.2 does not exhibit this behaviour) but I can find no obvious differances in the codepaths between versions. This becomes bad news because the ipc system on linux is a global resource and not based per user, so it's possible for a local user to DOS the box by running php -v test]$ ipcs > test]$ php -vĬontent-type: test]$ ipcs > test]$ diff l ll One record returned to any other thread attempting to get the record with locked = 'N'.I've been contacted by a php user in the wild who told me that by simply issuing 'php -v', a semaphore that php opens for session management is not closed on exit. Any other thread attempting to get the record with locked = 'N' gets no results. GDBM DATABASE AS A SEMAPHOR UPDATEUpdate job_locker set locked = 'N', update_time = sysdate where job_name = 'myjob' GDBM DATABASE AS A SEMAPHOR CODEYou could have code to pull for that job name and locked = 'Y' and if still zero results, add the record. Any other thread attempting to get the record with locked = 'N' gets zero results. Locks can be held shared or exclusive, and a request to take a lock, or to convert a lock from one mode to another, support a timeout. A gdbm database thus provides the same functionality as a hash. It furthermore allows a non-sorted traversal of all key-value pairs. Gdbm allows the user to store, retrieve, and delete data by key. ![]() A database is a file that stores key-value pairs. Any other thread attempting to get the record gets ORA-00054. Essentially, it allows for the enqueue locking mechanisms that Oracle uses internally, except that it allows you to define a lock type of 'UL' (user lock). GNU dbm is a library for simple databases. Update job_locker set locked = 'Y', update_time = sysdate where job_name = 'myjob' ![]() Any other thread attempting to get the record gets ORA-00054. Select * from job_locker where job_name='myjob' and locked = 'N' for update NOWAIT Insert into job_locker (job_name, locked) values ('myjob','N') datum content The data to be associated with the key. ret gdbmstore(dbf, key, content, flag) The parameters are: GDBMFILE dbf The pointer returned by gdbmopen. The function gdbmstore inserts or replaces records in the database. ![]() Here are what might be some workable SQL commands, but no timeout except through a cron job hack: -ĬREATE TABLE "JOB_LOCKER" ( "JOB_NAME" VARCHAR2(128 BYTE), "LOCKED" VARCHAR2(1 BYTE), "UPDATE_TIME" TIMESTAMP (6) ) ĬREATE UNIQUE INDEX "JOB_LOCKER_PK" ON "JOB_LOCKER" ("JOB_NAME") ĪLTER TABLE "JOB_LOCKER" ADD CONSTRAINT "JOB_LOCKER_PK" PRIMARY KEY ("JOB_NAME") ĪLTER TABLE "JOB_LOCKER" MODIFY ("JOB_NAME" NOT NULL ENABLE) ĪLTER TABLE "JOB_LOCKER" MODIFY ("LOCKED" NOT NULL ENABLE) Inserting and replacing records in the database. That would be a huge bonus to have a timeout! It would be cool, but I don't know if it's possible for a database-supported semaphore to have a time-out. Then at the end of my processing, I'd need to run another SQL transaction to release the semaphore. Years ago a developer that was a SQL wiz had a single SQL transaction that took the semaphore and returned true if it got it, and returned false if it didn't get it. I could probably come-up with some workable SQL commands that used Oracle transaction processing, latches, or whatever, but I'd rather find something that's been tried and true. If several instances of the same code are running on different servers, I would like to use a database to make sure a process doesn't start on one server if it's already running on another server. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |