aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel/test/prim_file_SUITE.erl
diff options
context:
space:
mode:
authorFilipe David Manana <[email protected]>2010-04-22 23:40:26 +0100
committerRaimo Niskanen <[email protected]>2010-05-20 15:48:17 +0200
commit3f53a96a8bd0cd4a18f819b6857e6a764706ede5 (patch)
tree04841cd714a6e23ac664a05ff9219dd8e5da474e /lib/kernel/test/prim_file_SUITE.erl
parent80b231a0874aa5cd68c3d9f0dc7e13b6736a5dd3 (diff)
downloadotp-3f53a96a8bd0cd4a18f819b6857e6a764706ede5.tar.gz
otp-3f53a96a8bd0cd4a18f819b6857e6a764706ede5.tar.bz2
otp-3f53a96a8bd0cd4a18f819b6857e6a764706ede5.zip
Add file:datasync/1 for syncing file contents only
file:datasync/1 invokes the POSIX system call "int fdatasync(int fd)". This system call is similar to "fsync" but, unlike fsync, it does not update the metadata associated with the file (like the access time for example). It's used by many DBMSs (MySQL and SQLite of example) to increase disk IO performance, as it avoids disk seeks and disk write operations compared to fsync. More details on it at: http://linux.die.net/man/2/fdatasync An example, from the MySQL source: http://bazaar.launchpad.net/~mysql/mysql-server/mysql-5.1-telco-6.1/annotate/head%3A/mysys/my_sync.c#L61 This new function just calls fsync on systems not implementing fdatasync.
Diffstat (limited to 'lib/kernel/test/prim_file_SUITE.erl')
-rw-r--r--lib/kernel/test/prim_file_SUITE.erl22
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/kernel/test/prim_file_SUITE.erl b/lib/kernel/test/prim_file_SUITE.erl
index 6badbb5090..842945e83c 100644
--- a/lib/kernel/test/prim_file_SUITE.erl
+++ b/lib/kernel/test/prim_file_SUITE.erl
@@ -34,7 +34,7 @@
file_info_times_a/1, file_info_times_b/1,
file_write_file_info_a/1, file_write_file_info_b/1]).
-export([rename_a/1, rename_b/1,
- access/1, truncate/1, sync/1,
+ access/1, truncate/1, datasync/1, sync/1,
read_write/1, pread_write/1, append/1]).
-export([errors/1, e_delete/1, e_rename/1, e_make_dir/1, e_del_dir/1]).
@@ -380,7 +380,7 @@ win_cur_dir_1(_Config, Handle) ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-files(suite) -> [open,pos,file_info,truncate,sync].
+files(suite) -> [open,pos,file_info,truncate,sync,datasync].
open(suite) -> [open1,modes,close,access,read_write,
pread_write,append].
@@ -1064,6 +1064,24 @@ truncate(Config) when is_list(Config) ->
ok.
+datasync(suite) -> [];
+datasync(doc) -> "Tests that ?PRIM_FILE:datasync/1 at least doesn't crash.";
+datasync(Config) when is_list(Config) ->
+ ?line Dog = test_server:timetrap(test_server:seconds(5)),
+ ?line PrivDir = ?config(priv_dir, Config),
+ ?line Sync = filename:join(PrivDir,
+ atom_to_list(?MODULE)
+ ++"_sync.fil"),
+
+ %% Raw open.
+ ?line {ok, Fd} = ?PRIM_FILE:open(Sync, [write]),
+ ?line ok = ?PRIM_FILE:datasync(Fd),
+ ?line ok = ?PRIM_FILE:close(Fd),
+
+ ?line test_server:timetrap_cancel(Dog),
+ ok.
+
+
sync(suite) -> [];
sync(doc) -> "Tests that ?PRIM_FILE:sync/1 at least doesn't crash.";
sync(Config) when is_list(Config) ->