LogCabin
|
This is an in-memory, hierarchical key-value store. More...
#include <Tree.h>
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 |
This is an in-memory, hierarchical key-value store.
TODO(ongaro): Document how this fits into the rest of the system.
void LogCabin::Tree::Tree::dumpSnapshot | ( | Core::ProtoBuf::OutputStream & | stream | ) | const |
void LogCabin::Tree::Tree::loadSnapshot | ( | Core::ProtoBuf::InputStream & | stream | ) |
Result LogCabin::Tree::Tree::checkCondition | ( | const std::string & | path, |
const std::string & | contents | ||
) | const |
Verify that the file at path has the given contents.
path | The path to the file that must have the contents specified in 'contents'. |
contents | The 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. |
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.
path | The path where there should be a directory after this call. |
Result LogCabin::Tree::Tree::listDirectory | ( | const std::string & | path, |
std::vector< std::string > & | children | ||
) | const |
List the contents of a directory.
path | The directory whose direct children to list. | |
[out] | children | This 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). |
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.
path | The path where there should not be a directory after this call. |
Result LogCabin::Tree::Tree::write | ( | const std::string & | path, |
const std::string & | contents | ||
) |
Set the value of a file.
path | The path where there should be a file with the given contents after this call. |
contents | The new value associated with the file. |
Result LogCabin::Tree::Tree::read | ( | const std::string & | path, |
std::string & | contents | ||
) | const |
Get the value of a file.
path | The path of the file whose contents to read. |
contents | The current value associated with the file. |
Result LogCabin::Tree::Tree::removeFile | ( | const std::string & | path | ) |
Make sure a file does not exist.
path | The path where there should not be a file after this call. |
void LogCabin::Tree::Tree::updateServerStats | ( | Protocol::ServerStats_Tree & | tstats | ) | const |
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).
[in] | path | The path whose parent directory to find. |
[out] | parent | Upon successful return, points to the target's parent directory. |
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.
[in] | path | The path whose parent directory to find. |
[out] | parent | Upon successful return, points to the target's parent directory. |
Result LogCabin::Tree::Tree::mkdirLookup | ( | const Internal::Path & | path, |
Internal::Directory ** | parent | ||
) | [private] |
Like normalLookup but creates parent directories as necessary.
[in] | path | The path whose parent directory to find. |
[out] | parent | Upon successful return, points to the target's parent directory. |
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.
uint64_t LogCabin::Tree::Tree::numConditionsChecked [mutable, private] |
uint64_t LogCabin::Tree::Tree::numConditionsFailed [mutable, private] |
uint64_t LogCabin::Tree::Tree::numMakeDirectoryAttempted [private] |
uint64_t LogCabin::Tree::Tree::numMakeDirectorySuccess [private] |
uint64_t LogCabin::Tree::Tree::numListDirectoryAttempted [mutable, private] |
uint64_t LogCabin::Tree::Tree::numListDirectorySuccess [mutable, private] |
uint64_t LogCabin::Tree::Tree::numRemoveDirectoryAttempted [private] |
uint64_t LogCabin::Tree::Tree::numRemoveDirectoryParentNotFound [private] |
uint64_t LogCabin::Tree::Tree::numRemoveDirectoryTargetNotFound [private] |
uint64_t LogCabin::Tree::Tree::numRemoveDirectoryDone [private] |
uint64_t LogCabin::Tree::Tree::numRemoveDirectorySuccess [private] |
uint64_t LogCabin::Tree::Tree::numWriteAttempted [private] |
uint64_t LogCabin::Tree::Tree::numWriteSuccess [private] |
uint64_t LogCabin::Tree::Tree::numReadAttempted [mutable, private] |
uint64_t LogCabin::Tree::Tree::numReadSuccess [mutable, private] |
uint64_t LogCabin::Tree::Tree::numRemoveFileAttempted [private] |
uint64_t LogCabin::Tree::Tree::numRemoveFileParentNotFound [private] |
uint64_t LogCabin::Tree::Tree::numRemoveFileTargetNotFound [private] |
uint64_t LogCabin::Tree::Tree::numRemoveFileDone [private] |
uint64_t LogCabin::Tree::Tree::numRemoveFileSuccess [private] |