Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 227511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:36:17+00:00 2026-05-11T19:36:17+00:00

is there an easy way to timeout an SQL statement so that it will

  • 0

is there an easy way to timeout an SQL statement so that it will fail instead of waiting (e.g. deliver an empty result set or an error message or whatever else) so I can let a job’s ressource reservation fail and give another one a chance? I’m looking for some DBI option I’ve overlooked so far; sending SIGALRMs to myself to commit suicide is rather not what I have in mind (although I might have to resort to that if I had to).

The code snipped is pseudo-ized and shortened to the extreme, but I hope you’ll catch the drift.

my $sql = "SELECT one, two, three FROM sometable WHERE this = ? AND that = ?";
my $sth = $self->make_handle( $sql );
eval {
    foreach my $this ( sort keys %needed_ressources ) {
        # vvv This is where the idle time is spent vvv
        $sth->execute( $this, $that ) or die( "DB connection gone?!" );
        # ^^^ This is where the idle time is spent ^^^
        my ( $one, $two, $three ) = $sth->fetchrow_array();
        unless( $one ) { # undefined record set == not found
            $self->{DB_HANDLE}->rollback();
            die( "$this not defined for $that!" );
        }
    }
    # If we haven't died so far, we can move on
    foreach... #similar loop here doing the actual update statement
    $self->{DB_HANDLE}->commit();
};
return( 1 ) unless $@;
return( undef );

Here are the gory details for the interested:

In an application that does massively parallel numbercrunching there is a ressource locking mechanism implemented that uses an oracle table. Each job needs to lock a number of ressources for reading and/or a number of ressources to write to, and can only start if all the locks have been acquired successfully. Instead of patiently waiting for ressources to be freed, jobs should just fail and be re-run later by their master (this keeps the number of open transactions low while boosting performance by having more jobs around that actually crunch).

Of course, before actually updating the table, each row is being reserved using a “SELECT … FOR UPDATE” statement so Oracle uses row level locking and concurrent transactions can happen on the table. In order to further reduce possible race conditions and deadlocks all jobs first select their ressource rows and then row lock them using the same ordering before performing the update.

As of the current implementation this works fine in most of the cases. But, because the “Select for update” blocks until Oracle actually grants the row lock, it may still happen that a job is idle waiting for its ressources, and I’m after those to better utilize the available CPU power. It’s OK to wait a second or two, but not ten or more just for the locking. For unlocking later, waiting is required of course, so setting the whole DB connection to only accept immediate results will not work.

I’m always grateful for RTFM answers as long as they point to the location in the M that I should TF have R ;-))

Thanks a lot in advance,
Olfan

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T19:36:17+00:00Added an answer on May 11, 2026 at 7:36 pm

    I think you want the NOWAIT parameter on the FOR UPDATE clause. If the record cannot be locked, the select will fail (“ORA-00054: resource busy and acquire with NOWAIT specified”)
    and you can handle the exception however you need to. Check out the SQL Reference manual. It’s for 11g, but the syntax hasn’t changed for several versions now.

    Another option is to give a time to wait: “FOR UPDATE WAIT 3” to wait 3 seconds for the lock to be acquired rather than failing immediately.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 205k
  • Answers 205k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You have to have your template definitions available at the… May 12, 2026 at 8:55 pm
  • Editorial Team
    Editorial Team added an answer Nacho, let me suggest you watch http://railscasts.com/episodes/160-authlogic It should answer… May 12, 2026 at 8:55 pm
  • Editorial Team
    Editorial Team added an answer Sorry guys this seems to have been caused by a… May 12, 2026 at 8:55 pm

Related Questions

I'm creating 3 events with the following function: HANDLE WINAPI CreateEvent(...); I'm waiting on
Let's consider the two following lines in C# (using framework .NET 3.5) Regex regex
Is there an easy way to iterate over an associative array of this structure
Is there an easy way to produce MSDN-style documentation from the Visual Studio XML

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.