Out of all the support calls one might get, the "system is completely frozen" problem is a fairly easy one to solve: just restart all the servers involved. Of course, when you have a competent systems operations team that watches over the application and knows how to do all this stuff, this is one of the last calls you want to get: something is probably seriously wrong with the application.

Jeff Moss was the unlucky recipient of the latter type of call. In his case, both the database and web servers would completely freeze up within minutes of the popular, publicly-available web-application coming back online. After a bit of hunting, Jeff found they were simply running out of ID's ...

sub GetNewTransactionId
{ # AFAIK, Sybase does not have a sequence. This
  # should work just fine, and give the added
  # benefit of being a random order 

  # params
  my($db, $type) = @_;
  
  # keep trying to create a new id
  my $newTranId;
  while (!$newTranId)
  {
    # generate random id
    my $possibleTranId;
    while (length($possibleTranId) < 6) 
    { # ensure length is correct
      $possibleTranId .= int(rand 9) + 1;
    }
    
    # check if id exists already
    if !(executeScalarQuery($db, "SELECT TransactionId FROM OpTransactions WHERE TransactionId = '$possibleTranId'"))
    { # row not found, the id can be used
      $newTranId = $possibleTranId ;
    }
  }

  return($newTranId);
}

Time was of the essence, so Jeff didn't go to the trouble of re-implementing this with Sybase's sequence functions ("AUTO_INCREMENT"). Instead, he left the same hack for the next poor maintainer a few magnitudes down the line ...

    while (length($possibleTranId) < 9) 
    { # ensure length is correct
      $possibleTranId .= int(rand 9) + 1;
    }
[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!