@@ -11,7 +11,7 @@ use trans::{TxHandle, TxMgr};
11
11
12
12
/// A reader for a specific vesion of file content.
13
13
///
14
- /// This reader can be obtained by [`version_reader`] function , and it
14
+ /// This reader can be obtained by [`version_reader`] method , and it
15
15
/// implements [`Read`] trait.
16
16
///
17
17
/// [`version_reader`]: struct.File.html#method.version_reader
@@ -130,7 +130,7 @@ impl Seek for VersionReader {
130
130
/// File content is cached internally for deduplication and will be handled
131
131
/// automatically, thus calling [`flush`] is **not** recommended.
132
132
///
133
- /// `File` can be sent to multiple threads, but only thread can modify it at
133
+ /// `File` can be sent to multiple threads, but only one thread can modify it at
134
134
/// a time, which is similar to a `RwLock`.
135
135
///
136
136
/// `File` is multi-versioned, each time updating its content will create a new
@@ -143,9 +143,10 @@ impl Seek for VersionReader {
143
143
/// version. Unless [`finish`] was successfully returned, no data will be
144
144
/// written to the file.
145
145
///
146
- /// Internally, a transaction is created when writing to the file and calling
147
- /// [`finish`] will commit that transaction. Thus, you should not call
148
- /// [`finish`] in case of any writing failure.
146
+ /// Internally, a transaction is created when writing to the file first time
147
+ /// and calling [`finish`] will commit that transaction. If any errors
148
+ /// happened during [`write`], that transaction will be aborted. Thus, you
149
+ /// should not call [`finish`] after any failed [`write`].
149
150
///
150
151
/// ## Examples
151
152
///
@@ -207,6 +208,20 @@ impl Seek for VersionReader {
207
208
/// # foo().unwrap();
208
209
/// ```
209
210
///
211
+ /// To gurantee atomicity, ZboxFS uses transaction when updating file so the
212
+ /// data either be wholly persisted or nothing has been written.
213
+ ///
214
+ /// - For multi-part write, the transaction begins in the first-time [`write`]
215
+ /// and will be committed in [`finish`]. Any failure in [`write`] will abort
216
+ /// the transaction, thus [`finish`] should not be called after that. If error
217
+ /// happened during [`finish`], the transaction will also be aborted.
218
+ /// - For single-part write, [`write_once`] itself is transactional. The
219
+ /// transaction begins and will be committed inside this method.
220
+ ///
221
+ /// Keep in mind of those characteristics, especially when writing a large
222
+ /// amount of data to file, because any uncomitted transactions will abort
223
+ /// and data in those transactions won't be persisted.
224
+ ///
210
225
/// # Reading
211
226
///
212
227
/// As `File` can contain multiple versions, [`Read`] operation can be
@@ -450,11 +465,16 @@ impl File {
450
465
451
466
/// Complete multi-part write to file and create a new version.
452
467
///
468
+ /// This method will try to commit the transaction internally, no data will
469
+ /// be persisted if it failed. Do not call this method if any previous
470
+ /// [`write`] failed.
471
+ ///
453
472
/// # Errors
454
473
///
455
- /// Calling this function without writing data before will return
474
+ /// Calling this method without writing data before will return
456
475
/// [`Error::NotWrite`] error.
457
476
///
477
+ /// [`Write`]: https://doc.rust-lang.org/std/io/trait.Write.html
458
478
/// [`Error::NotWrite`]: enum.Error.html
459
479
pub fn finish ( & mut self ) -> Result < ( ) > {
460
480
self . check_closed ( ) ?;
@@ -486,9 +506,11 @@ impl File {
486
506
487
507
/// Single-part write to file and create a new version.
488
508
///
489
- /// This function provides a convenient way of combining [`Write`] and
509
+ /// This method provides a convenient way of combining [`Write`] and
490
510
/// [`finish`].
491
511
///
512
+ /// This method is atomic.
513
+ ///
492
514
/// [`Write`]: https://doc.rust-lang.org/std/io/trait.Write.html
493
515
/// [`finish`]: struct.File.html#method.finish
494
516
pub fn write_once ( & mut self , buf : & [ u8 ] ) -> Result < ( ) > {
@@ -522,10 +544,12 @@ impl File {
522
544
/// then the content will be extended to `size` and have all of the
523
545
/// intermediate data filled in with 0s.
524
546
///
547
+ /// This method is atomic.
548
+ ///
525
549
/// # Errors
526
550
///
527
- /// This function will return an error if the file is not opened for
528
- /// writing or not finished writing.
551
+ /// This method will return an error if the file is not opened for writing
552
+ /// or not finished writing.
529
553
pub fn set_len ( & mut self , len : usize ) -> Result < ( ) > {
530
554
self . check_closed ( ) ?;
531
555
if self . wtr . is_some ( ) {
0 commit comments