|
cluck 1.0.1
The cluster lock service.
|
Implementation of the inter-process lock mechanism. More...
#include "cluckd.h"#include <cluck/exception.h>#include <cluck/names.h>#include <cluck/version.h>#include <communicator/flags.h>#include <communicator/names.h>#include <as2js/json.h>#include <eventdispatcher/names.h>#include <snapdev/gethostname.h>#include <snapdev/hexadecimal_string.h>#include <snapdev/stringize.h>#include <snapdev/tokenize_string.h>#include <snapdev/to_string_literal.h>#include <snaplogger/logger.h>#include <snaplogger/options.h>#include <snaplogger/severity.h>#include <advgetopt/advgetopt.h>#include <advgetopt/exception.h>#include <algorithm>#include <iostream>#include <sstream>#include <openssl/rand.h>#include <snapdev/poison.h>
Go to the source code of this file.
Namespaces | |
| namespace | cluck_daemon |
| namespace | cluck_daemon::anonymous_namespace{cluckd.cpp} |
Variables | |
| constexpr char const *const | cluck_daemon::anonymous_namespace{cluckd.cpp}::g_configuration_files [] |
| constexpr std::string_view | cluck_daemon::anonymous_namespace{cluckd.cpp}::g_default_candidate_priority |
| advgetopt::group_description const | cluck_daemon::anonymous_namespace{cluckd.cpp}::g_group_descriptions [] |
| advgetopt::option const | cluck_daemon::anonymous_namespace{cluckd.cpp}::g_options [] |
| advgetopt::options_environment const | cluck_daemon::anonymous_namespace{cluckd.cpp}::g_options_environment |
This file implements an inter-process lock that functions between any number of machines. The basic algorithm used is the Bakery Algorithm by Lamport. The concept is simple: you get a waiting ticket and loop through the tickets until it yours is picked.
Contrary to a multi-processor environment thread synchronization, this lock system uses messages and arrays to know its current state. A user interested in obtaining a lock sends a LOCK message. The cluck daemon then waits until the lock is obtained and sends a LOCKED as a reply. Once done with the lock, the user sends UNLOCK to release the lock.
The implementation makes use of any number of cluck instances. The locking mechanism makes use of the QUORUM voting system to know that enough of the other cluck agree on a statement. This allows the cluck daemon to obtain/release locks in an unknown network environment (i.e. any one of the machines may be up or down and the locking mechanism still functions as expected).
The QUORUM is computed using the following formula:
![\[
{number of computers} over 2 + 1
\]](form_0.png)
Note that the lock mechanism itself only uses 3 computers (2 or 1 if your cluster is that small). So in a cluster of, say, 100 computers, you would still end up using just 3 for the locks. However, the elections still require you to have a quorum of all the computers (100 / 2 + 1 is at least 51 computers).
Definition in file cluckd.cpp.
This document is part of the Snap! Websites Project.
Copyright by Made to Order Software Corp.