LogCabin
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Classes | Public Member Functions | Public Attributes | Private Attributes
LogCabin::Storage::SnapshotFile::Writer Class Reference

Assists in writing snapshot files to the local filesystem. More...

#include <SnapshotFile.h>

Inheritance diagram for LogCabin::Storage::SnapshotFile::Writer:
LogCabin::Core::ProtoBuf::OutputStream

List of all members.

Classes

struct  SharedMMap
 Allocates an object that is shared across processes. More...

Public Member Functions

 Writer (const Storage::Layout &storageLayout)
 Constructor.
 ~Writer ()
 Destructor.
void discard ()
 Throw away the file.
void flushToOS ()
 Flush changes just down to the operating system's buffer cache.
void seekToEnd ()
 Seek to the end of the file, in case another process has written to it.
uint64_t save ()
 Flush changes all the way down to the disk and close the file.
uint64_t getBytesWritten () const
 Return the number of bytes written so far.
void writeMessage (const google::protobuf::Message &message)
 Write the given ProtoBuf message to the stream.
void writeRaw (const void *data, uint64_t length)
 Write some raw bytes to the stream.

Public Attributes

SharedMMap< std::atomic
< uint64_t > > 
sharedBytesWritten
 This value is incremented every time bytes are written to the Writer from any process holding this Writer.

Private Attributes

Storage::FilesystemUtil::File parentDir
 A handle to the directory containing the snapshot.
std::string stagingName
 The temporary name of 'file' before it is closed.
Storage::FilesystemUtil::File file
 Wraps the raw file descriptor; in charge of closing it when done.
uint64_t bytesWritten
 The number of bytes accumulated in the file so far.

Detailed Description

Assists in writing snapshot files to the local filesystem.

Definition at line 78 of file SnapshotFile.h.


Constructor & Destructor Documentation

Constructor.

Parameters:
storageLayoutThe directories in which to create the snapshot (in a file called "snapshot" in the snapshotDir). TODO(ongaro): what if it can't be written?

Definition at line 163 of file SnapshotFile.cc.

Destructor.

If the file hasn't been explicitly saved or discarded, prints a warning and discards the file.

Definition at line 178 of file SnapshotFile.cc.


Member Function Documentation

Throw away the file.

If you call this after the file has been closed, it will PANIC.

Definition at line 187 of file SnapshotFile.cc.

Flush changes just down to the operating system's buffer cache.

Leave the file open for additional writes.

This is useful when forking child processes to write to the file. The correct procedure for that is: 0. write stuff 1. call flushToOS() 2. fork 3. child process: write stuff 4. child process: call flushToOS() 5. child process: call _exit() 6. parent process: call seekToEnd() 7. parent process: write stuff 8. parent process: call save()

Definition at line 196 of file SnapshotFile.cc.

Seek to the end of the file, in case another process has written to it.

Subsequent calls to getBytesWritten() will include data written by other processes.

Definition at line 202 of file SnapshotFile.cc.

Flush changes all the way down to the disk and close the file.

If you call this after the file has been closed, it will PANIC.

Returns:
Size in bytes of the file

Definition at line 211 of file SnapshotFile.cc.

Return the number of bytes written so far.

Implements LogCabin::Core::ProtoBuf::OutputStream.

Definition at line 225 of file SnapshotFile.cc.

void LogCabin::Storage::SnapshotFile::Writer::writeMessage ( const google::protobuf::Message &  message) [virtual]

Write the given ProtoBuf message to the stream.

Implements LogCabin::Core::ProtoBuf::OutputStream.

Definition at line 231 of file SnapshotFile.cc.

void LogCabin::Storage::SnapshotFile::Writer::writeRaw ( const void *  data,
uint64_t  length 
) [virtual]

Write some raw bytes to the stream.

Implements LogCabin::Core::ProtoBuf::OutputStream.

Definition at line 250 of file SnapshotFile.cc.


Member Data Documentation

A handle to the directory containing the snapshot.

Used for renameat on close.

Definition at line 153 of file SnapshotFile.h.

The temporary name of 'file' before it is closed.

Definition at line 155 of file SnapshotFile.h.

Wraps the raw file descriptor; in charge of closing it when done.

Definition at line 157 of file SnapshotFile.h.

The number of bytes accumulated in the file so far.

Definition at line 159 of file SnapshotFile.h.

This value is incremented every time bytes are written to the Writer from any process holding this Writer.

Used by Server/StateMachine to implement a watchdog that checks progress of a snapshotting process.

Definition at line 166 of file SnapshotFile.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines