473,763 Members | 1,333 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2338
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 "opportunis tic 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 "opportunis tic 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
"ReallyReallyFl ushThisDataToTh eNetworkDiskAnd EnsureAllTheDis kCachesGotFlush edAndThe
ToDiskAndTheWri teSuceededAndTh eFileCloseWentO kayAndNeverGive MeAPrematureAnd OverlyOptimisti cAllIsOkay(
"\\\\Server\\Pa th\\FileName.Ex t" );

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************ *********@d34g2 000cwd.googlegr oups.com>
Ancient_Hacker <gr**@comcast.n etwrote:
>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 "transactionali zed". 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
4391
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 *ipAddress = S""; IDictionary *server_config = dynamic_cast<IDictionary*>(ConfigurationSettings::GetConfig("ServerAddress") ); ipAddress = dynamic_cast<String*>(server_config->get_Item(S"IP"));
0
2934
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 compile. Did a few other code things to take advantage of .Net features not available in VB6. When I start the application on my PC I get the error shown below. It seems to me that the app initiation is failing before any app code is executed. My...
0
1945
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"; return (SCS.SR.IDAL.IUser) Assembly.Load(path).CreateInstance(className); ( This line iam getting Error)
7
13406
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 every thing else from windows update. ..NET 1.0 and 1.1 installed on the server. Actually .NET was installed before the server was made a DC.
2
2315
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 dependencies, was not found. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
1
5105
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 is not missing nor is it misspelled or on a different path) Is it permissions? (ASP.NET account is given full access to E:\DNN dir)
1
6508
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" setting to be "E_ALL", notices are still not getting reported. The perms on my file are 664, with owner root and group root. The php.ini file is located at /usr/local/lib/php/php.ini. Any ideas why the setting does not seem to be having an effect? ...
1
2087
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 computers for a long, long time, but VB/.NET/ etc. is not my specialty.
4
3346
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 . rt now im not sure where the problem is . is it something to do with any dll file which i need to include. if yes could u suggest me which dll files are involved in the open file dialog? thank u in advance See the end of this message for...
0
9563
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9998
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8822
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3523
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.