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;             
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros