Transactions with files?

T

Toni

Hi,

I'm writing a C program that should do something like transactions on
files.
I have several reader processes and one writer, and I have to make sure
that the writer either writes everything or nothing to (part of) a
file.
So I thought of COW (copy-on-write), but how to do that?
mmap() with MAP_PRIVATE can give me a copy of the (part of the) file to
work with. But how can I write the changes back to the original file so
that other processes would see those changes? MAP_PRIVATE prevents
writing changes to the original file, so I can't use msync().
AIX has deferred write capability (open() with O_DEFER flag)- changes
are written to a file only when fsync() is called. Linux doesn't seem
to have such a capability.

Any ideas?

Cheers, Toni
 
A

Alan Balmer

Hi,

I'm writing a C program that should do something like transactions on
files.
I have several reader processes and one writer, and I have to make sure
that the writer either writes everything or nothing to (part of) a
file.
So I thought of COW (copy-on-write), but how to do that?
mmap() with MAP_PRIVATE can give me a copy of the (part of the) file to
work with. But how can I write the changes back to the original file so
that other processes would see those changes? MAP_PRIVATE prevents
writing changes to the original file, so I can't use msync().
AIX has deferred write capability (open() with O_DEFER flag)- changes
are written to a file only when fsync() is called. Linux doesn't seem
to have such a capability.
Standard C, the subject of this newsgroup, definitely doesn't have
such a capability. I suggest you post your question on
comp.unix.programmer, or perhaps on comp.programming.
 
C

CBFalconer

Toni said:
I'm writing a C program that should do something like transactions
on files.

I have several reader processes and one writer, and I have to make
sure that the writer either writes everything or nothing to (part
of) a file.

So I thought of COW (copy-on-write), but how to do that?
mmap() with MAP_PRIVATE can give me a copy of the (part of the)
file to work with. But how can I write the changes back to the
original file so that other processes would see those changes?
MAP_PRIVATE prevents writing changes to the original file, so I
can't use msync(). AIX has deferred write capability (open() with
O_DEFER flag)- changes are written to a file only when fsync() is
called. Linux doesn't seem to have such a capability.

This has nothing to do with the C language, and everything to do
with the actual system you are using. Try newsgroups with
'threads' or 'unix' in their names.
 
D

David Schwartz

I'm writing a C program that should do something like transactions on
files.
I have several reader processes and one writer, and I have to make sure
that the writer either writes everything or nothing to (part of) a
file.
So I thought of COW (copy-on-write), but how to do that?
mmap() with MAP_PRIVATE can give me a copy of the (part of the) file to
work with. But how can I write the changes back to the original file so
that other processes would see those changes? MAP_PRIVATE prevents
writing changes to the original file, so I can't use msync().
AIX has deferred write capability (open() with O_DEFER flag)- changes
are written to a file only when fsync() is called. Linux doesn't seem
to have such a capability.

There is no good way to do what you are asking for. I can think of any
number of reasonable ways. They all rely on more complex coordination
between the writers and the readers. For example, you could copy the file,
modify it, move it over the original, and then tell the readers to reopen
the file.

DS
 
R

Rob Thorpe

Toni said:
Hi,

I'm writing a C program that should do something like transactions on
files.
I have several reader processes and one writer, and I have to make sure
that the writer either writes everything or nothing to (part of) a
file.
So I thought of COW (copy-on-write), but how to do that?
mmap() with MAP_PRIVATE can give me a copy of the (part of the) file to
work with. But how can I write the changes back to the original file so
that other processes would see those changes? MAP_PRIVATE prevents
writing changes to the original file, so I can't use msync().
AIX has deferred write capability (open() with O_DEFER flag)- changes
are written to a file only when fsync() is called. Linux doesn't seem
to have such a capability.

Any ideas?

It is a very good idea to avoid doing this kind of stuff with files
completely.
Instead of using parts of one large file trying using one file for each
part. That will solve many of the problems.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,167
Messages
2,570,911
Members
47,453
Latest member
MadelinePh

Latest Threads

Top