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

This is an in-memory, hierarchical key-value store. More...

#include <Tree.h>

List of all members.

Public Member Functions

 Tree ()
 Constructor.
void dumpSnapshot (Core::ProtoBuf::OutputStream &stream) const
 Write the tree to the given stream.
void loadSnapshot (Core::ProtoBuf::InputStream &stream)
 Load the tree from the given stream.
Result checkCondition (const std::string &path, const std::string &contents) const
 Verify that the file at path has the given contents.
Result makeDirectory (const std::string &path)
 Make sure a directory exists at the given path.
Result listDirectory (const std::string &path, std::vector< std::string > &children) const
 List the contents of a directory.
Result removeDirectory (const std::string &path)
 Make sure a directory does not exist.
Result write (const std::string &path, const std::string &contents)
 Set the value of a file.
Result read (const std::string &path, std::string &contents) const
 Get the value of a file.
Result removeFile (const std::string &path)
 Make sure a file does not exist.
void updateServerStats (Protocol::ServerStats_Tree &tstats) const
 Add metrics about the tree to the given structure.

Private Member Functions

Result normalLookup (const Internal::Path &path, Internal::Directory **parent)
 Resolve the final next-to-last component of the given path (the target's parent).
Result normalLookup (const Internal::Path &path, const Internal::Directory **parent) const
 Resolve the final next-to-last component of the given path (the target's parent) -- const version.
Result mkdirLookup (const Internal::Path &path, Internal::Directory **parent)
 Like normalLookup but creates parent directories as necessary.

Private Attributes

Internal::Directory superRoot
 This directory contains the root directory.
uint64_t numConditionsChecked
uint64_t numConditionsFailed
uint64_t numMakeDirectoryAttempted
uint64_t numMakeDirectorySuccess
uint64_t numListDirectoryAttempted
uint64_t numListDirectorySuccess
uint64_t numRemoveDirectoryAttempted
uint64_t numRemoveDirectoryParentNotFound
uint64_t numRemoveDirectoryTargetNotFound
uint64_t numRemoveDirectoryDone
uint64_t numRemoveDirectorySuccess
uint64_t numWriteAttempted
uint64_t numWriteSuccess
uint64_t numReadAttempted
uint64_t numReadSuccess
uint64_t numRemoveFileAttempted
uint64_t numRemoveFileParentNotFound
uint64_t numRemoveFileTargetNotFound
uint64_t numRemoveFileDone
uint64_t numRemoveFileSuccess

Detailed Description

This is an in-memory, hierarchical key-value store.

TODO(ongaro): Document how this fits into the rest of the system.

Definition at line 287 of file Tree.h.


Constructor & Destructor Documentation

Constructor.

Definition at line 280 of file Tree.cc.


Member Function Documentation

Write the tree to the given stream.

Definition at line 365 of file Tree.cc.

Load the tree from the given stream.

Warning:
This will blow away any existing files and directories.

Definition at line 374 of file Tree.cc.

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

Verify that the file at path has the given contents.

Parameters:
pathThe path to the file that must have the contents specified in 'contents'.
contentsThe contents that the file specified by 'path' should have for an OK response. An OK response is also returned if 'contents' is the empty string and the file specified by 'path' does not exist.
Returns:
Status and error message. Possible errors are:
  • CONDITION_NOT_MET upon any error.

Definition at line 382 of file Tree.cc.

Result LogCabin::Tree::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.

Definition at line 415 of file Tree.cc.

Result LogCabin::Tree::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.

Definition at line 436 of file Tree.cc.

Result LogCabin::Tree::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.

Definition at line 467 of file Tree.cc.

Result LogCabin::Tree::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.

Definition at line 510 of file Tree.cc.

Result LogCabin::Tree::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.

Definition at line 533 of file Tree.cc.

Result LogCabin::Tree::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.

Definition at line 563 of file Tree.cc.

void LogCabin::Tree::Tree::updateServerStats ( Protocol::ServerStats_Tree &  tstats) const

Add metrics about the tree to the given structure.

Definition at line 594 of file Tree.cc.

Result LogCabin::Tree::Tree::normalLookup ( const Internal::Path path,
Internal::Directory **  parent 
) [private]

Resolve the final next-to-last component of the given path (the target's parent).

Parameters:
[in]pathThe path whose parent directory to find.
[out]parentUpon successful return, points to the target's parent directory.
Returns:
Status and error message. Possible errors are:
  • LOOKUP_ERROR if a parent of path does not exist.
  • TYPE_ERROR if a parent of path is a file.

Definition at line 309 of file Tree.cc.

Result LogCabin::Tree::Tree::normalLookup ( const Internal::Path path,
const Internal::Directory **  parent 
) const [private]

Resolve the final next-to-last component of the given path (the target's parent) -- const version.

Parameters:
[in]pathThe path whose parent directory to find.
[out]parentUpon successful return, points to the target's parent directory.
Returns:
Status and error message. Possible errors are:
  • LOOKUP_ERROR if a parent of path does not exist.
  • TYPE_ERROR if a parent of path is a file.

Definition at line 316 of file Tree.cc.

Result LogCabin::Tree::Tree::mkdirLookup ( const Internal::Path path,
Internal::Directory **  parent 
) [private]

Like normalLookup but creates parent directories as necessary.

Parameters:
[in]pathThe path whose parent directory to find.
[out]parentUpon successful return, points to the target's parent directory.
Returns:
Status and error message. Possible errors are:
  • TYPE_ERROR if a parent of path is a file.

Definition at line 344 of file Tree.cc.


Member Data Documentation

This directory contains the root directory.

The super root has a single child directory named "root", and the rest of the tree lies below "root". This is just an implementation detail; this class prepends "/root" to every path provided by the caller.

This removes a lot of special-case branches because every operation now has a name of a target within a parent directory -- even those operating on the root directory.

Definition at line 480 of file Tree.h.

uint64_t LogCabin::Tree::Tree::numConditionsChecked [mutable, private]

Definition at line 485 of file Tree.h.

uint64_t LogCabin::Tree::Tree::numConditionsFailed [mutable, private]

Definition at line 486 of file Tree.h.

Definition at line 487 of file Tree.h.

Definition at line 488 of file Tree.h.

Definition at line 489 of file Tree.h.

uint64_t LogCabin::Tree::Tree::numListDirectorySuccess [mutable, private]

Definition at line 490 of file Tree.h.

Definition at line 491 of file Tree.h.

Definition at line 492 of file Tree.h.

Definition at line 493 of file Tree.h.

Definition at line 494 of file Tree.h.

Definition at line 495 of file Tree.h.

Definition at line 496 of file Tree.h.

Definition at line 497 of file Tree.h.

uint64_t LogCabin::Tree::Tree::numReadAttempted [mutable, private]

Definition at line 498 of file Tree.h.

uint64_t LogCabin::Tree::Tree::numReadSuccess [mutable, private]

Definition at line 499 of file Tree.h.

Definition at line 500 of file Tree.h.

Definition at line 501 of file Tree.h.

Definition at line 502 of file Tree.h.

Definition at line 503 of file Tree.h.

Definition at line 504 of file Tree.h.


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