473,323 Members | 1,547 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

File read error win9x winNT

I have been having a very peculiar issue from a long time.

I have an application where multiple clients read from a shared set of
files. When a record is changed, sometimes the win9x clients still read
the old data (if it was read earlier) and this is causing data
corruption. WinNT clients inlcuding windows2000 & XP do not have this
issue. The program is complied in VC++, console mode.

I am unable to understand the cause. I flush the files before the read
and still have this issue. The problem is aggrevated if the write was
from another win9x client and subsequent read if from another win9x
client: this results in a dirty read.

Sep 22 '06 #1
8 2306
dosworldguy wrote:
I have been having a very peculiar issue from a long time.

I have an application where multiple clients read from a shared set of
files. When a record is changed, sometimes the win9x clients still read
the old data (if it was read earlier) and this is causing data
corruption. WinNT clients inlcuding windows2000 & XP do not have this
issue. The program is complied in VC++, console mode.

I am unable to understand the cause. I flush the files before the read
and still have this issue. The problem is aggrevated if the write was
from another win9x client and subsequent read if from another win9x
client: this results in a dirty read.
fread can cache data.
That means if you fread one record, the system might actually read 3 and
a half records, caching the remaining 2.5 records.

flushing input streams is undefined behavior.

Your question anyway sounds windows specific, ask in
a windows related programming channel.

Sep 22 '06 #2

dosworldguy wrote:
I have been having a very peculiar issue from a long time.

I have an application where multiple clients read from a shared set of
files. When a record is changed, sometimes the win9x clients still read
the old data (if it was read earlier) and this is causing data
corruption.

This will never work reliably. What if the app writes a record, but
the reader happens to read that area in the middle of the write? No
OS that I know of guarantees that disk I/O is "atomic". The OS is free
to reorder disk writes as it sees fit. For example, if a file is
spread out over disparate areas of the disk, many OS's have an
"elevator" algorithm-- they reorder read/write operations to minimize
the distance the disk heads have to travel. It's called the "elevator"
algorithm as the intent is to reorder the operations so the disk head
sweeps back and forth with a minimum number of changes direction.

Also if yo're accessing the file across the network, the disk blocks
may arrive out of order due to typical network protocols.

You need to implement some kind of record or file locking. For a C
program, see the "flock" or "lockf" library routines. If you're
doing this jsut for Windows, there are some non-portable WIndows file
locking API's that probably will give better granularity and
performance than the C lib functions.

Sep 22 '06 #3
Ancient_Hacker wrote:
dosworldguy wrote:
>I have been having a very peculiar issue from a long time.

I have an application where multiple clients read from a shared set of
files. When a record is changed, sometimes the win9x clients still read
the old data (if it was read earlier) and this is causing data
corruption.


This will never work reliably. What if the app writes a record, but
the reader happens to read that area in the middle of the write? No
OS that I know of guarantees that disk I/O is "atomic". The OS is free
to reorder disk writes as it sees fit. For example, if a file is
spread out over disparate areas of the disk, many OS's have an
"elevator" algorithm-- they reorder read/write operations to minimize
the distance the disk heads have to travel. It's called the "elevator"
algorithm as the intent is to reorder the operations so the disk head
sweeps back and forth with a minimum number of changes direction.
An OS can have all the knowledge of all read /writes by all
applications, and often have a cache aiding in keeping
things consistent even though the actual disk IO might be reordered.
Thus it can syncronize read/writes to the same file.

You do ofcourse need to synchronize readers and writes anyway, but
usually not for reasons that have to do with the actual IO gynmastics
of the platform.
Sep 22 '06 #4

Nils O. Selåsdal wrote:
An OS can have all the knowledge of all read /writes by all
applications, and often have a cache aiding in keeping
things consistent even though the actual disk IO might be reordered.
Thus it can syncronize read/writes to the same file.
I realize this would be a Good Thing, but do we know for sure all the
major OS's do in fact guarantee this? Your use of the word "can"
leaves a lot of wiggle-room. I'm pretty sure this isnt guaranteed by
some very popular remote-disk protocols, like NFS. The poor OP is
probably looking for something dependable and standard.

Sep 22 '06 #5
dosworldguy wrote:
>
I have been having a very peculiar issue from a long time.

I have an application where multiple clients read from a shared set of
files. When a record is changed, sometimes the win9x clients still read
the old data (if it was read earlier) and this is causing data
corruption. WinNT clients inlcuding windows2000 & XP do not have this
issue. The program is complied in VC++, console mode.

I am unable to understand the cause. I flush the files before the read
and still have this issue. The problem is aggrevated if the write was
from another win9x client and subsequent read if from another win9x
client: this results in a dirty read.
If you're using stream I/O (ie: fopen/fread/fwrite/fclose, which are
the only ones discussed here) then you have the problem that the other
processes may have already read, and buffered, the old data before you
write the new data. (And flushing input streams is not defined.)

If you're using the POSIX open/read/write/close functions (which are
not discussed here), then you may need to ask a Windows group about
something called "opportunistic locking", which can cause the O/S
itself to locally cache data from a file on another server, causing
updates to be missed. (BTDTGTTS)

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>
Sep 22 '06 #6
Thank you all for your thoughts.

To add:

Locking is implemented via "co-operative" means: when a client wants to
write, it requests a server for permission, gets the "go ahead",
performs write and hands back the flag to the server. No other client
can write during that time.

After one write, another client askes for the write token. Now when
this client reads a record written earlier, it gets to read 'dirty
data'.

This is not consistent. Also, open, read & write have been used, not
fopen & etc.

I am looking for 'C' help. Instead of Flush, will it help to close the
files and re-open?
Kenneth Brody wrote:
dosworldguy wrote:

I have been having a very peculiar issue from a long time.

I have an application where multiple clients read from a shared set of
files. When a record is changed, sometimes the win9x clients still read
the old data (if it was read earlier) and this is causing data
corruption. WinNT clients inlcuding windows2000 & XP do not have this
issue. The program is complied in VC++, console mode.

I am unable to understand the cause. I flush the files before the read
and still have this issue. The problem is aggrevated if the write was
from another win9x client and subsequent read if from another win9x
client: this results in a dirty read.

If you're using stream I/O (ie: fopen/fread/fwrite/fclose, which are
the only ones discussed here) then you have the problem that the other
processes may have already read, and buffered, the old data before you
write the new data. (And flushing input streams is not defined.)

If you're using the POSIX open/read/write/close functions (which are
not discussed here), then you may need to ask a Windows group about
something called "opportunistic locking", which can cause the O/S
itself to locally cache data from a file on another server, causing
updates to be missed. (BTDTGTTS)

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>
Sep 23 '06 #7

dosworldguy wrote:
Thank you all for your thoughts.

To add:

Locking is implemented via "co-operative" means: when a client wants to
write, it requests a server for permission, gets the "go ahead",
performs write and hands back the flag to the server.
How do you ensure that the client write has happened and completed and
flushed to the server disk? OS's, particularly on network
connections, do extensive file buffering. the client program may have
done a write(), but that just puts the data in a kernel buffer. Even
doing an explicit C close() on the file descriptor does not guarantee
the data is at the server and consistent to other readers or writers.
And file packets can arrive out of order, so even an explicit close
might have to wait until allpackets have arrived and been acknowledged
and reverse acknowledged by the client.

There's nothing in standard C to help with this... You're going to have
to pore thru the OS's network file server API, there's almost certainly
a
"ReallyReallyFlushThisDataToTheNetworkDiskAndEnsur eAllTheDiskCachesGotFlushedAndThe
ToDiskAndTheWriteSuceededAndTheFileCloseWentOkayAn dNeverGiveMeAPrematureAndOverlyOptimisticAllIsOkay (
"\\\\Server\\Path\\FileName.Ext" );

Sep 23 '06 #8
>dosworldguy wrote:
>I have an application where multiple clients read from a shared set of
files. When a record is changed, sometimes the win9x clients still read
the old data (if it was read earlier) and this is causing data
corruption.
In article <11*********************@d34g2000cwd.googlegroups. com>
Ancient_Hacker <gr**@comcast.netwrote:
>This will never work reliably.
Not in general, no.
>What if the app writes a record, but the reader happens to read
that area in the middle of the write? No OS that I know of
guarantees that disk I/O is "atomic".
HRFS, in vxWorks 6.x, does. (Well, the on-disk writes are not
atomic, but at the file I/O level, they *appear* to be, as they
are "transactionalized". The file system guarantees that, even if
the power fails in the middle of a write() call, the write() is
either not-started-at-all or completely-done when the file is
examined later. This does depend on certain [common] disk drive
characteristics; in particular the disk itself must not fail due
to the power-off.)
>You need to implement some kind of record or file locking.
Or some other OS-specific method, certainly. So the solution is
off-topic in comp.lang.c, alas. :-)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Sep 24 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chris | last post by:
I have seen the posts on various places on the internet about .NET framework mismatch issues and I don't think that is my problem. ; ) When I execute the following C++.NET code: String...
0
by: Bill Burwell | last post by:
I am converting a VB6 WebClass application to VB.Net. Used the VB upgrade tool to do the conversion - and it left me a lot of little code things to do. Did those code things and got my app to...
0
by: karunakar | last post by:
Hi All I am not able to read the class name I want read the particular class name string path = System.Configuration.ConfigurationSettings.AppSettings; string className = path + ".User";...
7
by: Mark | last post by:
Hello, I have researched and tried every thing I have found on the web, in groups and MS KB articles. Here is what I have. I have a Windows 2000 Domain Controller all service packs and...
2
by: aallee83 | last post by:
i'm new in asp.net after develop my solution i copied it on the server where I want it to run but something cares... WHAT?!?! thank you in advance File or assembly name System, or one of its...
1
by: Dan | last post by:
Environment: Win2k Server, ASP.NET(v1.1.4322) Everything seemed to work fine till this morning...and than this happened What could this possibly mean? Is it the file? (The file in the error...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
1
by: mrpetegroups | last post by:
Hi - Problem: The file below has become zero length \winnt\assembly\GAC_MSIL\system.deployment\2.0.0.0_b03f5f7f11d50a3a \system.deployment.dll Details follow ... I've been programming...
4
by: nightscorpion | last post by:
Hello Gurus, i implemented the OpenFileDialog in my Windows Form Applications and it worked perfectly fine.However when it was run on a remote desktop i got the below error . ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.