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

Provides access to the hierarchical key-value store. More...

#include <Client.h>

List of all members.

Public Member Functions

 Tree (const Tree &other)
 Copy constructor.
Treeoperator= (const Tree &other)
 Assignment operator.
Result setWorkingDirectory (const std::string &workingDirectory)
 Set the working directory for this object.
void setWorkingDirectoryEx (const std::string &workingDirectory)
 Like setWorkingDirectory but throws exceptions upon errors.
std::string getWorkingDirectory () const
 Return the working directory for this object.
std::pair< std::string,
std::string > 
getCondition () const
 Return the condition set by a previous call to setCondition().
Result setCondition (const std::string &path, const std::string &value)
 Set a predicate on all future operations.
void setConditionEx (const std::string &path, const std::string &value)
 Like setCondition but throws exceptions upon errors.
uint64_t getTimeout () const
 Return the timeout set by a previous call to setTimeout().
void setTimeout (uint64_t nanoseconds)
 Abort each future operation if it may not have completed within the specified period of time.
Result makeDirectory (const std::string &path)
 Make sure a directory exists at the given path.
void makeDirectoryEx (const std::string &path)
 Like makeDirectory but throws exceptions upon errors.
Result listDirectory (const std::string &path, std::vector< std::string > &children) const
 List the contents of a directory.
std::vector< std::string > listDirectoryEx (const std::string &path) const
 Like listDirectory but throws exceptions upon errors.
Result removeDirectory (const std::string &path)
 Make sure a directory does not exist.
void removeDirectoryEx (const std::string &path)
 Like removeDirectory but throws exceptions upon errors.
Result write (const std::string &path, const std::string &contents)
 Set the value of a file.
void writeEx (const std::string &path, const std::string &contents)
 Like write but throws exceptions upon errors.
Result read (const std::string &path, std::string &contents) const
 Get the value of a file.
std::string readEx (const std::string &path) const
 Like read but throws exceptions upon errors.
Result removeFile (const std::string &path)
 Make sure a file does not exist.
void removeFileEx (const std::string &path)
 Like removeFile but throws exceptions upon errors.

Private Member Functions

 Tree (std::shared_ptr< ClientImpl > clientImpl, const std::string &workingDirectory)
 Constructor.
std::shared_ptr< const
TreeDetails
getTreeDetails () const
 Get a reference to the implementation-specific members of this class.

Private Attributes

std::mutex mutex
 Provides mutual exclusion to treeDetails pointer.
std::shared_ptr< const
TreeDetails
treeDetails
 Reference-counted pointer to implementation-specific members.

Friends

class Cluster

Detailed Description

Provides access to the hierarchical key-value store.

You can get an instance of Tree through Cluster::getTree() or by copying an existing Tree.

A Tree has a working directory from which all relative paths (those that do not begin with a '/' are resolved). This allows different applications and modules to conveniently access their own subtrees -- they can have their own Tree instances and set their working directories accordingly.

Methods that can fail come in two flavors. The first flavor returns Result values with error codes and messages; the second throws exceptions upon errors. These can be distinguished by the "Ex" suffix in the names of methods that throw exceptions.

Definition at line 321 of file Client.h.


Constructor & Destructor Documentation

LogCabin::Client::Tree::Tree ( std::shared_ptr< ClientImpl clientImpl,
const std::string &  workingDirectory 
) [private]

Constructor.

Definition at line 227 of file Client.cc.

LogCabin::Client::Tree::Tree ( const Tree other)

Copy constructor.

Definition at line 234 of file Client.cc.


Member Function Documentation

Tree & LogCabin::Client::Tree::operator= ( const Tree other)

Assignment operator.

Definition at line 241 of file Client.cc.

Result LogCabin::Client::Tree::setWorkingDirectory ( const std::string &  workingDirectory)

Set the working directory for this object.

This directory will be created if it does not exist.

Parameters:
workingDirectoryThe new working directory, which may be relative to the current working directory.
Returns:
Status and error message. Possible errors are:
  • INVALID_ARGUMENT if workingDirectory is malformed.
  • TYPE_ERROR if parent of workingDirectory is a file.
  • TYPE_ERROR if workingDirectory exists but is a file.
  • CONDITION_NOT_MET if predicate from setCondition() was false.
  • TIMEOUT if timeout elapsed before the operation completed. If this returns an error, future operations on this tree using relative paths will fail until a valid working directory is set.

Definition at line 252 of file Client.cc.

void LogCabin::Client::Tree::setWorkingDirectoryEx ( const std::string &  workingDirectory)

Like setWorkingDirectory but throws exceptions upon errors.

Definition at line 286 of file Client.cc.

Return the working directory for this object.

Returns:
An absolute path that is the prefix for relative paths used with this Tree object.

Definition at line 293 of file Client.cc.

std::pair< std::string, std::string > LogCabin::Client::Tree::getCondition ( ) const

Return the condition set by a previous call to setCondition().

Returns:
First component: the absolute path corresponding to the 'path' argument of setCondition(). Second component: the file contents given as the 'value' argument of setCondition().

Definition at line 341 of file Client.cc.

Result LogCabin::Client::Tree::setCondition ( const std::string &  path,
const std::string &  value 
)

Set a predicate on all future operations.

Future operations will return Status::CONDITION_NOT_MET and have no effect unless the file at 'path' has the contents 'value'. To remove the predicate, pass an empty string as 'path'.

Parameters:
pathThe relative or absolute path to the file that must have the contents specified in value, or an empty string to clear the condition.
valueThe contents that the file specified by 'path' must have for future operations to succeed. If 'value' is the empty string and the file does not exist, the condition will also be satisfied.
Returns:
Status and error message. Possible errors are:
  • INVALID_ARGUMENT if path is malformed. If this returns an error, future operations on this tree will fail until a new condition is set or the condition is cleared.

Definition at line 300 of file Client.cc.

void LogCabin::Client::Tree::setConditionEx ( const std::string &  path,
const std::string &  value 
)

Like setCondition but throws exceptions upon errors.

Definition at line 335 of file Client.cc.

Return the timeout set by a previous call to setTimeout().

Returns:
The maximum duration of each operation (in nanoseconds), or 0 for no timeout.

Definition at line 348 of file Client.cc.

void LogCabin::Client::Tree::setTimeout ( uint64_t  nanoseconds)

Abort each future operation if it may not have completed within the specified period of time.

Warning:
The client library does not currently implement timeouts for DNS lookups. See https://github.com/logcabin/logcabin/issues/75
Parameters:
nanosecondsThe maximum duration of each operation (in nanoseconds). Set to 0 for no timeout.

Definition at line 355 of file Client.cc.

Result LogCabin::Client::Tree::makeDirectory ( const std::string &  path)

Make sure a directory exists at the given path.

Create parent directories listed in path as necessary.

Parameters:
pathThe path where there should be a directory after this call.
Returns:
Status and error message. Possible errors are:
  • INVALID_ARGUMENT if path is malformed.
  • TYPE_ERROR if a parent of path is a file.
  • TYPE_ERROR if path exists but is a file.
  • CONDITION_NOT_MET if predicate from setCondition() was false.
  • TIMEOUT if timeout elapsed before the operation completed.

Definition at line 364 of file Client.cc.

void LogCabin::Client::Tree::makeDirectoryEx ( const std::string &  path)

Like makeDirectory but throws exceptions upon errors.

Definition at line 375 of file Client.cc.

Result LogCabin::Client::Tree::listDirectory ( const std::string &  path,
std::vector< std::string > &  children 
) const

List the contents of a directory.

Parameters:
pathThe directory whose direct children to list.
[out]childrenThis will be replaced by a listing of the names of the directories and files that the directory at 'path' immediately contains. The names of directories in this listing will have a trailing slash. The order is first directories (sorted lexicographically), then files (sorted lexicographically).
Returns:
Status and error message. Possible errors are:
  • INVALID_ARGUMENT if path is malformed.
  • LOOKUP_ERROR if a parent of path does not exist.
  • LOOKUP_ERROR if path does not exist.
  • TYPE_ERROR if a parent of path is a file.
  • TYPE_ERROR if path exists but is a file.
  • CONDITION_NOT_MET if predicate from setCondition() was false.
  • TIMEOUT if timeout elapsed before the operation completed.

Definition at line 381 of file Client.cc.

std::vector< std::string > LogCabin::Client::Tree::listDirectoryEx ( const std::string &  path) const

Like listDirectory but throws exceptions upon errors.

Definition at line 394 of file Client.cc.

Result LogCabin::Client::Tree::removeDirectory ( const std::string &  path)

Make sure a directory does not exist.

Also removes all direct and indirect children of the directory.

If called with the root directory, this will remove all descendants but not actually remove the root directory; it will still return status OK.

Parameters:
pathThe path where there should not be a directory after this call.
Returns:
Status and error message. Possible errors are:
  • INVALID_ARGUMENT if path is malformed.
  • TYPE_ERROR if a parent of path is a file.
  • TYPE_ERROR if path exists but is a file.
  • CONDITION_NOT_MET if predicate from setCondition() was false.
  • TIMEOUT if timeout elapsed before the operation completed.

Definition at line 402 of file Client.cc.

void LogCabin::Client::Tree::removeDirectoryEx ( const std::string &  path)

Like removeDirectory but throws exceptions upon errors.

Definition at line 413 of file Client.cc.

Result LogCabin::Client::Tree::write ( const std::string &  path,
const std::string &  contents 
)

Set the value of a file.

Parameters:
pathThe path where there should be a file with the given contents after this call.
contentsThe new value associated with the file.
Returns:
Status and error message. Possible errors are:
  • INVALID_ARGUMENT if path is malformed.
  • INVALID_ARGUMENT if contents are too large to fit in a file.
  • LOOKUP_ERROR if a parent of path does not exist.
  • TYPE_ERROR if a parent of path is a file.
  • TYPE_ERROR if path exists but is a directory.
  • CONDITION_NOT_MET if predicate from setCondition() was false.
  • TIMEOUT if timeout elapsed before the operation completed.

Definition at line 419 of file Client.cc.

void LogCabin::Client::Tree::writeEx ( const std::string &  path,
const std::string &  contents 
)

Like write but throws exceptions upon errors.

Definition at line 431 of file Client.cc.

Result LogCabin::Client::Tree::read ( const std::string &  path,
std::string &  contents 
) const

Get the value of a file.

Parameters:
pathThe path of the file whose contents to read.
contentsThe current value associated with the file.
Returns:
Status and error message. Possible errors are:
  • INVALID_ARGUMENT if path is malformed.
  • LOOKUP_ERROR if a parent of path does not exist.
  • LOOKUP_ERROR if path does not exist.
  • TYPE_ERROR if a parent of path is a file.
  • TYPE_ERROR if path is a directory.
  • CONDITION_NOT_MET if predicate from setCondition() was false.
  • TIMEOUT if timeout elapsed before the operation completed.

Definition at line 437 of file Client.cc.

std::string LogCabin::Client::Tree::readEx ( const std::string &  path) const

Like read but throws exceptions upon errors.

Definition at line 449 of file Client.cc.

Result LogCabin::Client::Tree::removeFile ( const std::string &  path)

Make sure a file does not exist.

Parameters:
pathThe path where there should not be a file after this call.
Returns:
Status and error message. Possible errors are:
  • INVALID_ARGUMENT if path is malformed.
  • TYPE_ERROR if a parent of path is a file.
  • TYPE_ERROR if path exists but is a directory.
  • CONDITION_NOT_MET if predicate from setCondition() was false.
  • TIMEOUT if timeout elapsed before the operation completed.

Definition at line 457 of file Client.cc.

void LogCabin::Client::Tree::removeFileEx ( const std::string &  path)

Like removeFile but throws exceptions upon errors.

Definition at line 468 of file Client.cc.

std::shared_ptr< const TreeDetails > LogCabin::Client::Tree::getTreeDetails ( ) const [private]

Get a reference to the implementation-specific members of this class.

Definition at line 474 of file Client.cc.


Friends And Related Function Documentation

friend class Cluster [friend]

Definition at line 582 of file Client.h.


Member Data Documentation

std::mutex LogCabin::Client::Tree::mutex [mutable, private]

Provides mutual exclusion to treeDetails pointer.

Definition at line 575 of file Client.h.

std::shared_ptr<const TreeDetails> LogCabin::Client::Tree::treeDetails [private]

Reference-counted pointer to implementation-specific members.

This is copy-on-write, so 'mutex' need not be held after taking a reference to treeDetails.

Definition at line 581 of file Client.h.


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