Jump to content
  • Advertisement
Sign in to follow this  
graveyard filla

How is this possible?

This topic is 4747 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I need to scan an FTP for files,download any files which don't begin with "PROCESSED_", parse the file, and then put the data into a database, and then rename the file on the FTP as "PROCESSED_*", so that I don't process it again. Anyway, the code I wrote (C#) basically looks like this:
files = scan ftp

foreach (file in files)
{
   if(file.StartsWith("PROCESSED_"))
      continue

   try
   {
     download file
     parse file
     begin SQL transaction
     put data in database
     rename to "PROCESSED_*"
     commit transaction
   }
   catch
   {
     rollback transaction
   }
}
When I test it with just a few files or even do a few hundred and randomly check, everything seems fine... but when I let it run and do around 1-2k files, I catch one or two inconsistancies, e.g. a file is renamed as PROCESSED_ but the data isn't in the DB, or vice versa. The latter should not be possible because I don't commit the tranny untill after I rename the file... the former I think is possible but highly unlikely (and im not sure how to make it impossible...). I know this isn't exactly a question or bug you can just solve with all the vagueness, but I just dont understand how this is possible the way SQL transactions work.. I'm using C# w/ MSSQL. Thanks for any help.

Share this post


Link to post
Share on other sites
Advertisement
SQL Transactions won't protect the file rename operation, even if it's contained between the BeginTran and EndTran stuff.

Try rethrowing the error, or at least logging the error to a log or something. rather than just leaving it at "rollback tran"

Share this post


Link to post
Share on other sites
hi !

a quick and maybe stupid question: why don't you check the DB if you already processed the file ??? having all files renamed doesn't look very nice to me. and using the DB for checking you are save to process very file just once.

cu

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!