473,471 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Transactions with files?

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

Nov 15 '05 #1
4 1694
On 20 Jul 2005 06:37:37 -0700, "Toni" <to**@toni.to> wrote:
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.

--
Al Balmer
Balmer Consulting
re************************@att.net
Nov 15 '05 #2
Toni wrote:

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.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!

Nov 15 '05 #3

"Toni" <to**@toni.to> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
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
Nov 15 '05 #4
Toni wrote:
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.

Nov 15 '05 #5

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

Similar topics

1
by: Arthur Dent | last post by:
I have a log file in this format: YYYYMMDD HHMMSS DATADATADATADATADATA RESULTCODE and I want to be able to parse the log and gleen information about gaps in time between transactions. For...
7
by: Richard Maher | last post by:
Hi, I am seeking the help of volunteers to test some software that I've developed which facilitates distributed two-phase commit transactions, encompassing any resource manager (e.g. SQL/Server...
3
by: Iain Mcleod | last post by:
I wish to do a series of inserts on a sql server database in the context of a transaction. The inserts will be done as a series of stored procedure calls. I wish to be able to rollback any...
1
by: Evan Nelson | last post by:
We are running a website on 3 W2K servers running IIS 5.0 as the webservers and using a server running under Windows Server 2003 for the database servers. All of our ASP pages are written using...
6
by: Terri | last post by:
I have a table called Transactions with 3 fields: ID, Date, and Amount. Each ID can have multiple transactions in one particular year. An ID might not have had any transactions in recent years. ...
3
by: Ace Calhoon | last post by:
Hello, I have a VBA/Database application which reads files, analyzes them, updates a database, and then moves them to an archive. I would like to make this an atomic transaction -- that is, if...
11
by: Mike P | last post by:
I've been using C# transactions for a while and had no problems with them. Using try catch blocks I can trap basically all possible errors and rollback all necessary data. Over the last few...
2
by: Sridhar | last post by:
Hi, I am trying to implement sql transactions. But I am not knowing how to do that. I created a data access layer which contains methods to select/insert/update tables in a database. I have also...
12
by: Rami | last post by:
I have some requirement for an automated payment system. The system has four machines setup as follows: 1- Two machines have a clustered database. 2- Two machines have a .net business logic...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.