troubleshooting Question

How do I flush a FileStream to disk in Lazarus on Linux

Avatar of zakiwi
zakiwiFlag for New Zealand asked on
Pascal
7 Comments1 Solution2048 ViewsLast Modified:
Hi there,

I am processing a lot of data (100GB) and I need to write results into client files.  The resulting program itterates through the source data and for each itteration, opens the correct results file (using TFileStream) and writes the results to the file and then free's the stream.

The program works for a while, but then starts giving errors like:

Loading /old-data/2008-09-26-151035588-AC06CAC4-4C91-4FC6-B11B-B49BDDC04BF6.DAT
Processing /old-data/2008-09-26-151035588-AC06CAC4-4C91-4FC6-B11B-B49BDDC04BF6.DAT
Master: *-
Hash  : *-
Client: *Unable to open file "/new-data/client1.idx"
Unable to open file "/new-data/client1.idx"
Unable to open file "/new-data/client1.idx"
Unable to open file "/new-data/client1.idx"
Unable to open file "/new-data/client1.idx"
Unable to open file "/new-data/client1.idx"
Unable to open file "/new-data/client1.idx"

PLEASE NOTE:
- The output file does exist, and I can open it with other applcations.
- The error only happens after the program has been running for a while
- Disk activity is high during the process, which leads me to beleive that this is a flushing issue.
- If I kill the application and start again, it works for a while.
- I am running the application as root so there shouldn't be a permissions problem

I am running debian lenny.

Any help will be appreciated

Zakiwi
This is the code that is raising the error:
 
lbIndexOpen := False;
while not lbIndexOpen do
  begin
    try
      if FileExists(FileName) then
        fStream := TFileStream.Create(FileName, fmOpenReadWrite)
      else
        fStream := TFileStream.Create(FileName, fmCreate);
      lbIndexOpen := True;
    except
      on e: Exception do
        begin
          WriteLn(E.Message);
          Sleep(500);
        end;
      end;
  end;             

Open in new window

ASKER CERTIFIED SOLUTION
Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 7 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 7 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004