Comment On This Should Work Just Fine

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. [expand full text]
« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Re: This Should Work Just Fine

2006-03-02 14:22 • by uncool
future planning...

Re: This Should Work Just Fine

2006-03-02 14:25 • by lucky luke
brilliant.

(in best cave man voice): ugh, me no like round wheel, me like square wheel.

Re: This Should Work Just Fine

2006-03-02 14:26 • by nyetter
Truly, the mind boggles.

In tech it's usually the case that if something feels stupid, it probably is, and if it seems like there ought to be a better way, there probably is.  Failure to realize these situations, or failure to be able to find the solution (come on, a DB without a sequence? wtf) is the sign of a bad technologist.

Re: This Should Work Just Fine

2006-03-02 14:27 • by BlackTigerX
62556 in reply to 62554
tercero!

Re: This Should Work Just Fine

2006-03-02 14:27 • by connected
Some people should be legally barred from using computer technology.

Re: This Should Work Just Fine

2006-03-02 14:28 • by Anonymous Schlep
I'm beginning to think all registered users need an auto-reply to all post feature that reposts the same thing over and over on every thread.

Re: This Should Work Just Fine

2006-03-02 14:28 • by Jeff S
Very nice.  A good, solid, old-school WTF. 

Re: This Should Work Just Fine

2006-03-02 14:33 • by Krudt
62560 in reply to 62553
 haha nice one :D

Re: This Should Work Just Fine

2006-03-02 14:34 • by Robert
62561 in reply to 62559

Ok, I have an honest question.


I use a method like this because I need to know the ID number before I write something to the database (like, to create a link to the new object in several tables).  So I generate a random ID, check to make sure it isn't already in use, and return it.


I know MSSQL has an auto-increment option, but how would I implement a non-WTF solution that returns the ID so I can use it?

Re: This Should Work Just Fine

2006-03-02 14:37 • by JohnO
62562 in reply to 62561
Anonymous:

Ok, I have an honest question.


I use a method like this because I need to know the ID number before I write something to the database (like, to create a link to the new object in several tables).  So I generate a random ID, check to make sure it isn't already in use, and return it.


I know MSSQL has an auto-increment option, but how would I implement a non-WTF solution that returns the ID so I can use it?



Use UUID/GUID.

Re: This Should Work Just Fine

2006-03-02 14:38 • by BH

There's so many OTHER WTFs too...


1) why just build up 1 digit at a time?  Why not all 6 (or 9) at once?


2) What's stopping someone else from getting the same random number(s) before the new ID is used?


3) Why not do this in the DB using RAND or it's equivalent and thus only use one DB call


 


*brain imploding*

Re: This Should Work Just Fine

2006-03-02 14:38 • by JohnO
62564 in reply to 62562

To be clear, you don't need the SELECT ahead of time to test for availability.  So you can construct the entire object graph in memory and pump it all down to the DB without having to get back what the ID is actually going to be like you do with IDENTITY, SEQUENCE, etc.

Re: This Should Work Just Fine

2006-03-02 14:38 • by marvin_rabbit
I admit that I did have to invent a method of assigning transaction ID's before.  (Older versions of FoxPro didn't have any autoinc fields.)

But when I did it, I made it so that there were around 14 quintillion possible id's.  And I only expected a few hundred new ones per day.

(Yes, yes, everyone can start in with the "FoxPro is the *real* WTF" comments.  I'm sure that Nostradamus even had a quatrain predicting those.)

Re: This Should Work Just Fine

2006-03-02 14:41 • by You buy, I sell
If he starts running out of Guids I can sell him some... special price, $15 for 10!

Re: This Should Work Just Fine

2006-03-02 14:41 • by TheGuy
62567 in reply to 62561
Anonymous:

Ok, I have an honest question.


I use a method like this because I need to know the ID number before I write something to the database (like, to create a link to the new object in several tables).  So I generate a random ID, check to make sure it isn't already in use, and return it.


I know MSSQL has an auto-increment option, but how would I implement a non-WTF solution that returns the ID so I can use it?



SELECT @output= @@IDENTITY


or


SELECT @output = SCOPE_IDENTITY()

Re: This Should Work Just Fine

2006-03-02 14:41 • by BH
62568 in reply to 62561
Identity columns and @@Identity

Re: This Should Work Just Fine

2006-03-02 14:41 • by Koen
62569 in reply to 62561
You could try to get the highest ID (with MAX()) and simply and 1 to that number and use it as your ID.

Re: This Should Work Just Fine

2006-03-02 14:43 • by singalongawtf
62570 in reply to 62561
DECLARE @CustID integer
INSERT Customer(Name,Age) VALUES('WTF', 42)
SELECT @CustID = @@IDENTITY
INSERT Orders(CustomerID,Amount) VALUES( @CustID, 69 )

Re: This Should Work Just Fine

2006-03-02 14:45 • by Misthop
62571 in reply to 62569
Anonymous:
You could try to get the highest ID (with MAX()) and simply and 1 to that number and use it as your ID.


Not threadsafe.  The WTF isn't either, but not a good solution

Re: This Should Work Just Fine

2006-03-02 14:46 • by boohiss
62572 in reply to 62561
Here's the solution for MS-SQL:

sql = "SET NOCOUNT ON;
INSERT INTO foo (bar) VALUES ('whatever');
SELECT @@IDENTITY FROM foo;"

your recordset will contain the ID of the record you just inserted

Re: This Should Work Just Fine

2006-03-02 14:47 • by maht
 
# and give the added
# benefit of being a random order

perhaps he should have added a b_tree balancer

Re: This Should Work Just Fine

2006-03-02 14:49 • by mlathe
62574 in reply to 62561
Anonymous:

Ok, I have an honest question.


I use a method like this because I need to know the ID number before I write something to the database (like, to create a link to the new object in several tables).  So I generate a random ID, check to make sure it isn't already in use, and return it.


I know MSSQL has an auto-increment option, but how would I implement a non-WTF solution that returns the ID so I can use it?



you should do
select my_seq.nextval
into :foo
from dual;

then do all your inserts into the child tables using the :foo var


then do the final insert into the parent table using the :foo var

Re: This Should Work Just Fine

2006-03-02 14:50 • by Justin Miller
REMEMBER FOLKS:

Every time you program like that God kills a kitten.

Re: This Should Work Just Fine

2006-03-02 14:53 • by Gene Wirchenko
62576 in reply to 62566
Anonymous:
If he starts running out of Guids I can sell him some... special price, $15 for 10!


Is that ten factorial GUIDs for $10, or are you just excited about selling GUIDs for $1.50 each?

Sincerely,

Gene Wirchenko

Re: This Should Work Just Fine

2006-03-02 14:54 • by mlathe
62577 in reply to 62571

Anonymous:
Anonymous:
You could try to get the highest ID (with MAX()) and simply and 1 to that number and use it as your ID.


Not threadsafe.  The WTF isn't either, but not a good solution


question: is it thread safe if you do a nested SQL? something like


insert into foo (
  select (max(id)+1), 'first name', 'last name', '12345'
  from foo
)


i think it is.

Re: This Should Work Just Fine

2006-03-02 14:55 • by tatsu
62578 in reply to 62561
Anonymous:

Ok, I have an honest question.


I use a method like this because I need to know the ID number before I write something to the database (like, to create a link to the new object in several tables).  So I generate a random ID, check to make sure it isn't already in use, and return it.


I know MSSQL has an auto-increment option, but how would I implement a non-WTF solution that returns the ID so I can use it?



Use a transaction. You can insert the row, then should be able to read out the used id and create more inserts with that id and they will all happen at once from an onlooker.

Re: This Should Work Just Fine

2006-03-02 14:57 • by Joe
62579 in reply to 62569
Anonymous:
You could try to get the highest ID (with MAX()) and simply and 1 to that number and use it as your ID.




Really bad if you delete some rows. MAX ID will be 10 and auto_increment will be 15.

Re: This Should Work Just Fine

2006-03-02 14:59 • by lamborghini
62580 in reply to 62569
Anonymous:
You could try to get the highest ID (with MAX()) and simply and 1 to that number and use it as your ID.


That's another WTF :D:D:D

Re: This Should Work Just Fine

2006-03-02 14:59 • by wintermyute
Awesome.  I like that the guy didn't actually solve the underlying
problem, just kind of swept it a little further under the rug.



I hope he bragged later about fixing the whole app with "1 keystroke!".



Waiting for someone to say that the Real WTF is that the system was written in Perl...

Re: This Should Work Just Fine

2006-03-02 15:04 • by Charlie Marlow
62584 in reply to 62571
What I did on a system we were converting from Interbase to MSSQL was create a generators table, and then I wrote a stored procedure to first update the value in the generators table and then return it to the caller. I don't have the code in front of me, but it was something like:

update generators
set @NewID = genvalue = genvalue + 1

Where NewID was an output variable. We tested this with multiple people concurrently pulling values, and did not get any duplicates.

Of course, where possible, I used MSSQL's native identity stuff.

Re: This Should Work Just Fine

2006-03-02 15:07 • by Omnifarious
62585 in reply to 62558
Anonymous:
I'm beginning to think all registered users need an auto-reply to all post feature that reposts the same thing over and over on every thread.

I have noticed a similarly distressing lack of originality in the replies. Yes, we all know that some of you think others should be barred from programming. Yes, we all know that the goggles do nothing and that the WTF is brillant. Please, tell us something we don't know. Those posts are about as stupid as the 'fist' posts.


Re: This Should Work Just Fine

2006-03-02 15:08 • by JohnO
62586 in reply to 62582

wintermyute:
Waiting for someone to say that the Real WTF is that the system was written in Perl...


I was wondering what that was.  What the hell is My?  Local variable declaration?

Re: This Should Work Just Fine

2006-03-02 15:10 • by Omnifarious
62587 in reply to 62582
wintermyute:
Awesome.  I like that the guy didn't actually solve the underlying
problem, just kind of swept it a little further under the rug.



I hope he bragged later about fixing the whole app with "1 keystroke!".



Waiting for someone to say that the Real WTF is that the system was written in Perl...

IMHO, as an emergency, fix it in the middle of the night so stuff runs again solution, it's not so bad. Now, if it wasn't brought up with someone and stuck in a "We need to fix this ASAP" list as soon as he got into work the next morning, then its definitely a WTF.


Re: This Should Work Just Fine

2006-03-02 15:17 • by anon
Why on earth would this cause the database AND web servers to freeze? Shouldn't it just log an error everytime it tried to add a new transaction? Surely the web servers should still be able to serve pages even though they can't start a new transaction. . .

Re: This Should Work Just Fine

2006-03-02 15:18 • by Bubba
62589 in reply to 62561
Have a field somewhere that is a long value.  Select from this field and use that number.  Update the field by adding 1.  Put everything in a transaction and use the correct locking for your database to keep everything thread safe.

Re: This Should Work Just Fine

2006-03-02 15:18 • by versatilia
62590 in reply to 62585
Omnifarious:
Anonymous:
I'm beginning to
think all registered users need an auto-reply to all post feature that
reposts the same thing over and over on every thread.

I have noticed a similarly distressing lack of originality in the
replies. Yes, we all know that some of you think others should be
barred from programming. Yes, we all know that the goggles do nothing
and that the WTF is brillant. Please, tell us something we don't know.
Those posts are about as stupid as the 'fist' posts.





So here's the plan... someone create a bot which monitors the RSS feed
for new WTFs, and as soon as it's there post something like:



fist my useless goggles, this is brillant but I don't see the brillant wtf... etc



Or better, an 'auto troll' to block any post containing 'brillant' and other old jokes!

Re: This Should Work Just Fine

2006-03-02 15:19 • by Bubba
62591 in reply to 62589
Anonymous:
Have a field somewhere that is a long value.  Select from this field and use that number.  Update the field by adding 1.  Put everything in a transaction and use the correct locking for your database to keep everything thread safe.


Opps.. meant to quote tthis guy:

Anonymous:

Ok, I have an honest question.


I use a method like this because I need to know the ID number before
I write something to the database (like, to create a link to the new
object in several tables).  So I generate a random ID, check to make
sure it isn't already in use, and return it.


I know MSSQL has an auto-increment option, but how would I implement a non-WTF solution that returns the ID so I can use it?


Re: This Should Work Just Fine

2006-03-02 15:20 • by Hugo
62592 in reply to 62561
Anonymous:

I know MSSQL has an auto-increment option, but how would I implement a non-WTF solution that returns the ID so I can use it?



If:


a) the auto-increment MUST be an identity, and


b) you MUST know the new value before actually inserting,


then:


1) Restart reading from the beginning of the specs. You have already read past the WTF, you just didn't realise yet.


2) If you still want this, use IDENT_CURRENT('tablename') and add 1. Make sure to use a transaction and force a table lock before calling the function. Don't forget to send your code to Alex when you're done, then we can all have a laugh at it.


Best, Hugo

Re: This Should Work Just Fine

2006-03-02 15:23 • by Ann Coulter
62593 in reply to 62575
Then it's God's fault, is it not?

Re: This Should Work Just Fine

2006-03-02 15:25 • by Anonymous Cupboard
62594 in reply to 62587
Omnifarious:
wintermyute:
Awesome.  I like that the guy didn't actually solve the underlying
problem, just kind of swept it a little further under the rug.



I hope he bragged later about fixing the whole app with "1 keystroke!".



Waiting for someone to say that the Real WTF is that the system was written in Perl...

IMHO, as an emergency, fix it in the middle of the night so stuff runs again solution, it's not so bad. Now, if it wasn't brought up with someone and stuck in a "We need to fix this ASAP" list as soon as he got into work the next morning, then its definitely a WTF.



See, all you think that it would be easy for the guy to just put in a fix that uses autoincrement/sequences/etc, but guess what...  What will you do about all the keys in the database already, randomly distributed over the number space, and one can only guess how many other tables and rows are joined using those keys!  It's kinda hard to start assigning them sequentially once there are thousands of randomly generated keys already there.

The solution that he used was the only way to fix it quickly, and perhaps even the only fix even given a moderate amount of time.  A real long term fix would require not only rewriting the id generator, but rekeying the whole database.

Re: This Should Work Just Fine

2006-03-02 15:29 • by osp70
62595 in reply to 62582

wintermyute:
Awesome.  I like that the guy didn't actually solve the underlying problem, just kind of swept it a little further under the rug.

I hope he bragged later about fixing the whole app with "1 keystroke!".

Waiting for someone to say that the Real WTF is that the system was written in Perl...


No comment on Perl, as we all know, you can create a wtf with any language.  What I contest is that he didn't solve the underlying problem.  The website app was freezing up, that was the problem and he solved that. 

Re: This Should Work Just Fine

2006-03-02 15:30 • by Some guy
62596 in reply to 62594
Anonymous:
Omnifarious:
wintermyute:
Awesome.  I like that the guy didn't actually solve the underlying
problem, just kind of swept it a little further under the rug.



I hope he bragged later about fixing the whole app with "1 keystroke!".



Waiting for someone to say that the Real WTF is that the system was written in Perl...

IMHO, as an emergency, fix it in the middle of the night so stuff runs again solution, it's not so bad. Now, if it wasn't brought up with someone and stuck in a "We need to fix this ASAP" list as soon as he got into work the next morning, then its definitely a WTF.



See, all you think that it would be easy for the guy to just put in a fix that uses autoincrement/sequences/etc, but guess what...  What will you do about all the keys in the database already, randomly distributed over the number space, and one can only guess how many other tables and rows are joined using those keys!  It's kinda hard to start assigning them sequentially once there are thousands of randomly generated keys already there.

The solution that he used was the only way to fix it quickly, and perhaps even the only fix even given a moderate amount of time.  A real long term fix would require not only rewriting the id generator, but rekeying the whole database.



Since the original value had a length of 6, just start your new sequence id at 1000000.........bingo.

Re: This Should Work Just Fine

2006-03-02 15:31 • by Charlie Marlow
62597 in reply to 62594
He could convert to an identity by changing the identity seed to something larger than anything in the database.

Re: This Should Work Just Fine

2006-03-02 15:34 • by Djinn
62598 in reply to 62594
Rekeying the db isn't as hard as you make it sound.


id = 0
for each borked row
    update row set table.id = ++id where table.id = row.id


of course, updating the FKs is a PITA, but the same logic can be applied. 30min - 1hr job.

Re: This Should Work Just Fine

2006-03-02 15:35 • by Djinn
62599 in reply to 62594
Anonymous:
Omnifarious:
wintermyute:
Awesome.  I like that the guy didn't actually solve the underlying
problem, just kind of swept it a little further under the rug.



I hope he bragged later about fixing the whole app with "1 keystroke!".



Waiting for someone to say that the Real WTF is that the system was written in Perl...

IMHO, as an emergency, fix it in the middle of the night so stuff runs again solution, it's not so bad. Now, if it wasn't brought up with someone and stuck in a "We need to fix this ASAP" list as soon as he got into work the next morning, then its definitely a WTF.



See, all you think that it would be easy for the guy to just put in a fix that uses autoincrement/sequences/etc, but guess what...  What will you do about all the keys in the database already, randomly distributed over the number space, and one can only guess how many other tables and rows are joined using those keys!  It's kinda hard to start assigning them sequentially once there are thousands of randomly generated keys already there.

The solution that he used was the only way to fix it quickly, and perhaps even the only fix even given a moderate amount of time.  A real long term fix would require not only rewriting the id generator, but rekeying the whole database.



Meant to quote that.

Re: This Should Work Just Fine

2006-03-02 15:36 • by Zlodo
62600 in reply to 62575
Anonymous:
REMEMBER FOLKS:

Every time you program like that God kills a kitten.


Are you implying that writing crappy code is akin to self-pleasuring ? Are you a closet WTFer or what ?

Re: This Should Work Just Fine

2006-03-02 15:38 • by pete
62601 in reply to 62594
Anonymous:
Omnifarious:
wintermyute:
Awesome.  I like that the guy didn't actually
solve the underlying
problem, just kind of swept it a little further under the rug.



I hope he bragged later about fixing the whole app with "1 keystroke!".



Waiting for someone to say that the Real WTF is that the system was written in Perl...

IMHO, as an emergency, fix it in the middle of the night so stuff
runs again solution, it's not so bad. Now, if it wasn't brought up with
someone and stuck in a "We need to fix this ASAP" list as soon as he
got into work the next morning, then its definitely a WTF.



See,
all you think that it would be easy for the guy to just put in a fix
that uses autoincrement/sequences/etc, but guess what...  What
will you do about all the keys in the database already, randomly
distributed over the number space, and one can only guess how many
other tables and rows are joined using those keys!  It's kinda
hard to start assigning them sequentially once there are thousands of
randomly generated keys already there.

The solution that he used
was the only way to fix it quickly, and perhaps even the only fix even
given a moderate amount of time.  A real long term fix would
require not only rewriting the id generator, but rekeying the whole
database.





He could start using an autoincrement but add 1000000 (Or set it to
start at 1000000 if that was possible with his db).  This gets
past all the possible keys that have already been used.

Re: This Should Work Just Fine

2006-03-02 15:40 • by Whiskey Tango Foxtrot? Over.
62602 in reply to 62594

Anonymous:
A real long term fix would require not only rewriting the id generator, but rekeying the whole database.


Re-keying the whole database would be a snap if they'd used the ultimate address book...

Re: This Should Work Just Fine

2006-03-02 15:40 • by Charlie Marlow
62603 in reply to 62598
From looking at the original code, it does not seem that there were any duplicate keys, but that the key size had exceeded the anticipated length, and that was throwing the system into an infinate loop. I think it would take more than half an hour to fully explore what ramifications changing a primary key would have on a system.

Re: This Should Work Just Fine

2006-03-02 15:41 • by Jeff Moss
62604 in reply to 62582
No, I just argued with people on slashdot for a few hours, occasionally
letting out a sigh of frustration to make it sound like I was working
hard on the problem.

« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Add Comment