473,836 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

crash during file writing, how to recover ?

Hi
I'm writing a commercial program which must be reliable. It has to do
some basic reading and writing to and from files on the hard disk,
and also to a floppy.
I have foreseen a potential problem. The program may crash
unexpectedly while writing to the file. If so, my program should
detect this during startup, and then (during startup) probably delete the
data added to the file and redo the writing operation.

Are file writing operations atomic ? ie when you write to a file,
will it either do it succesfully, OR say half fail (eg write a few letters
and not finish), OR not commit any changes to the file if a crash at
this point occurs?

My next question is how is this handled in commercial programming? I
plan on writing a flag (say, a simple char) to another file (this
would signal that a file write is about to begin), and then
removing this char after the file writing operation is completed.
Then on startup i just check the flags. if flag hasn't been removed a
crash occurred, so have to open file and get rid of any garbage.

Has anyone done anything similar b4? if so how did you handle this
crash scenario. My application could totally stuff up if i don't
handle this right.

by the way, i'm using the java language and api. this might effect
how files are written to, so i thought i should mention this.
MANY THANKS
Joseph

Jul 17 '05
48 8521
Nick Landsberg wrote:
The bean counters get apoplectic when they lose track
of a few cents here of there. To me, this was
an extreme case of overkill, but the customer
was willing to pay for it.


Personally, this is a level of overkill I'm glad my bank and
CC companies indulge in.

Maybe YOU don't mind if a few cents disappear from your accounts,
but it makes ME apoplectic! (-:

--
|_ CJSonnack <Ch***@Sonnack. com> _____________| How's my programming? |
|_ http://www.Sonnack.com/ _______________ ____| Call: 1-800-DEV-NULL |
|______________ _______________ _______________ _|_____________ __________|
Jul 17 '05 #31
Chris Sonnack wrote:
Nick Landsberg wrote:

The bean counters get apoplectic when they lose track
of a few cents here of there. To me, this was
an extreme case of overkill, but the customer
was willing to pay for it.

Personally, this is a level of overkill I'm glad my bank and
CC companies indulge in.

Maybe YOU don't mind if a few cents disappear from your accounts,
but it makes ME apoplectic! (-:


I was referring to the triple mirroring when
I used the word overkill. :) I would
agree with you that I, too, would get upset
if my bank balance was wrong. The triple
mirroring was /their/ preconcieved solution
to the problem which could have been solved
more cheaply.

--
"It is impossible to make anything foolproof
because fools are so ingenious"
- A. Bloch
Jul 17 '05 #32
Nick Landsberg wrote:

I was referring to the triple mirroring when
I used the word overkill. :) I would
agree with you that I, too, would get upset
if my bank balance was wrong. The triple
mirroring was /their/ preconcieved solution
to the problem which could have been solved
more cheaply.


Actually a bank in Denmark recently introduced a system
with three mirrors. That happened after IBM screwed up
their system with only two copies of the data. IIRC the
bank had to pay around 10 million dollars in expenses to
their customers.

--
Kasper Dupont -- der bruger for meget tid paa usenet.
For sending spam use ab***@mk.lir.dk and ka*****@mk.lir. dk
I'd rather be a hammer than a nail.
Jul 17 '05 #33
On Mon, 03 May 2004 22:42:47 +0200, Kasper Dupont
<ka*****@daimi. au.dk> wrote or quoted :
Actually a bank in Denmark recently introduced a system
with three mirrors. That happened after IBM screwed up
their system with only two copies of the data. IIRC the
bank had to pay around 10 million dollars in expenses to
their customers.


If you really wanted to be safe, you have three teams running it and
three programming teams working to the same spec.

I was watching a Sun video the other day where the Sun guy was saying
with a flick of his mouse he could install software on 1000 servers.

On the other hand, he could bring 1000 servers to their knees with a
flick of his mouse.

Must feel like Bush toying with the big red button.
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Jul 17 '05 #34
Chris Sonnack wrote:
Nick Landsberg wrote:
The bean counters get apoplectic when they lose track
of a few cents here of there. To me, this was
an extreme case of overkill, but the customer
was willing to pay for it.


Personally, this is a level of overkill I'm glad my bank and
CC companies indulge in.

Maybe YOU don't mind if a few cents disappear from your accounts,
but it makes ME apoplectic! (-:


Actually, I have no objection whatsoever to a few cents
disappearing from your accounts, with the sole proviso that they
reappear in mine.

--
"I'm a war president. I make decisions here in the Oval Office
in foreign policy matters with war on my mind." - Bush.
"Churchill and Bush can both be considered wartime leaders, just
as Secretariat and Mr Ed were both horses." - James Rhodes.
Jul 17 '05 #35
Kasper Dupont wrote:
Nick Landsberg wrote:
I was referring to the triple mirroring when
I used the word overkill. :) I would
agree with you that I, too, would get upset
if my bank balance was wrong. The triple
mirroring was /their/ preconcieved solution
to the problem which could have been solved
more cheaply.

Actually a bank in Denmark recently introduced a system
with three mirrors. That happened after IBM screwed up
their system with only two copies of the data. IIRC the
bank had to pay around 10 million dollars in expenses to
their customers.


Three mirrors implies four copies.

There are two situations which could
have cause the problem, one of which is
*probably* not IBM's fault. For example,
a disk goes off-line because of a hardware
failure. Diagnostics are issued, but the
customer does not immediately take steps
to replace that disk. If the customer
waits a week or more to replace it, they
are "at risk" of another disk failure
during that time period, all the more so
if all the disks were from the same
batch. I am no apologist for IBM, and
I do not know all the details of this situation
so this is just conjecture on my part.
(But I have seen it happen in the past.)

The other situation is when a software bug
scribbles all over the data. In this case,
it will scribble over *all* copies of the
data. Adding additional disks does not
solve this problem. :)
--
"It is impossible to make anything foolproof
because fools are so ingenious"
- A. Bloch
Jul 17 '05 #36
CBFalconer wrote:
Chris Sonnack wrote:
Nick Landsberg wrote:

The bean counters get apoplectic when they lose track
of a few cents here of there. To me, this was
an extreme case of overkill, but the customer
was willing to pay for it.


Personally, this is a level of overkill I'm glad my bank and
CC companies indulge in.

Maybe YOU don't mind if a few cents disappear from your accounts,
but it makes ME apoplectic! (-:

Actually, I have no objection whatsoever to a few cents
disappearing from your accounts, with the sole proviso that they
reappear in mine.


Wasn't this the case in one of the "urban legends"
of the early days of computers?

What I remember (and memory is the second thing
to go) is that there was a story about some bank
customer who computed what his compound interest
should have been and found it to be a few pennies
off. (This was in the days before calculators.)
He went to his local bank branch and confronted
them with the data. After checking his data,
they confirmed that he was right. They subsequently
found that the person who had programmed their
system had taken the "breakage" (fractions of cents)
and had it credited to his account. This
amounted to quite a bundle!

I do not know if this story is true, just
relating it as a piece of trivia/memorobilia.

Were you that person, Chuck? :)

--
"It is impossible to make anything foolproof
because fools are so ingenious"
- A. Bloch
Jul 17 '05 #37
Nick Landsberg wrote:
CBFalconer wrote:
Chris Sonnack wrote:
Nick Landsberg wrote:

The bean counters get apoplectic when they lose track
of a few cents here of there. To me, this was
an extreme case of overkill, but the customer
was willing to pay for it.

Personally, this is a level of overkill I'm glad my bank and
CC companies indulge in.

Maybe YOU don't mind if a few cents disappear from your accounts,
but it makes ME apoplectic! (-:


Actually, I have no objection whatsoever to a few cents
disappearing from your accounts, with the sole proviso that they
reappear in mine.


Wasn't this the case in one of the "urban legends"
of the early days of computers?

What I remember (and memory is the second thing
to go) is that there was a story about some bank
customer who computed what his compound interest
should have been and found it to be a few pennies
off. (This was in the days before calculators.)
He went to his local bank branch and confronted
them with the data. After checking his data,
they confirmed that he was right. They subsequently
found that the person who had programmed their
system had taken the "breakage" (fractions of cents)
and had it credited to his account. This
amounted to quite a bundle!

I do not know if this story is true, just
relating it as a piece of trivia/memorobilia.

Were you that person, Chuck? :)


Unfortunately, no. However it goes on today, and is known as
'float'. When some bill handling firm receives your payment to
JoesFancyGrocer y, they age it for some period of time, collecting
the interest (which may be only one day) and then forward the
original amount.

A better technique (for your tale) would be to have taken
advantage of the bias in rounding. In the US we round 0.50..0 of
anything up to 1.0, which produces a bias of some size. If the
perpetrator had been satisfied with this he might still be
collecting. Rounding down also produces a bias, while round to
even is (normally) unbiased.

--
"I'm a war president. I make decisions here in the Oval Office
in foreign policy matters with war on my mind." - Bush.
"Churchill and Bush can both be considered wartime leaders, just
as Secretariat and Mr Ed were both horses." - James Rhodes.

Jul 17 '05 #38
On Mon, 03 May 2004 22:05:22 GMT, Nick Landsberg
<hu*****@NOSPAM .att.net> wrote or quoted :
The other situation is when a software bug
scribbles all over the data. In this case,
it will scribble over *all* copies of the
data. Adding additional disks does not
solve this problem. :)


The scariest sort of software bug is one that corrupts data just a
tiny bit so that problem may not be noticed for a long time. By the
all the back ups are corrupt too.

All you could is find a very old database and play transactions
against it, or write some one-shot program to compensate for the
trouble.

In banking it would be catastrophic since you have already sent out
erroneous statements.

The RZ-1000 DMA controller hardware bug was horrible for this same
reason. The corruption was sporadic and minor.
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Jul 17 '05 #39
On Mon, 03 May 2004 22:13:32 GMT, Nick Landsberg
<hu*****@NOSPAM .att.net> wrote or quoted :
I do not know if this story is true, just
relating it as a piece of trivia/memorobilia.


Everybody heard the story if you were around in computing circa 1962.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Jul 17 '05 #40

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

Similar topics

110
10654
by: alf | last post by:
Hi, is it possible that due to OS crash or mysql itself crash or some e.g. SCSI failure to lose all the data stored in the table (let's say million of 1KB rows). In other words what is the worst case scenario for MyISAM backend? Also is it possible to not to lose data but get them corrupted?
0
9810
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
10821
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10527
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
9358
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
6973
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
5642
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
5812
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4001
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3102
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.