cluck 1.0.1
The cluster lock service.
Namespaces | Classes | Typedefs | Enumerations | Functions | Variables
cluck Namespace Reference

Namespaces

namespace  anonymous_namespace{cluck.cpp}
 
namespace  anonymous_namespace{cluck_status.cpp}
 

Classes

class  cluck
 Cluster lock. More...
 

Typedefs

typedef snapdev::timespec_ex timeout_t
 A timeout delay.
 

Enumerations

enum class  mode_t { CLUCK_MODE_SIMPLE , CLUCK_MODE_EXTENDED }
 
enum class  reason_t {
  CLUCK_REASON_NONE , CLUCK_REASON_LOCAL_TIMEOUT , CLUCK_REASON_REMOTE_TIMEOUT , CLUCK_REASON_DEADLOCK ,
  CLUCK_REASON_TRANSMISSION_ERROR , CLUCK_REASON_INVALID
}
 
enum class  state_t {
  CLUCK_STATE_IDLE , CLUCK_STATE_LOCKING , CLUCK_STATE_LOCKED , CLUCK_STATE_UNLOCKING ,
  CLUCK_STATE_FAILED
}
 
enum class  type_t { CLUCK_TYPE_READ_WRITE , CLUCK_TYPE_READ_ONLY , CLUCK_TYPE_READ_WRITE_PRIORITY }
 

Functions

 DECLARE_EXCEPTION (cluck_exception, busy)
 
 DECLARE_EXCEPTION (cluck_exception, invalid_message)
 
 DECLARE_EXCEPTION (cluck_exception, invalid_parameter)
 
 DECLARE_EXCEPTION (cluck_exception, timeout)
 
 DECLARE_LOGIC_ERROR (logic_error)
 
 DECLARE_LOGIC_ERROR (unexpected_case)
 
 DECLARE_MAIN_EXCEPTION (cluck_exception)
 
 DECLARE_OUT_OF_RANGE (out_of_range)
 
timeout_t get_lock_duration_timeout ()
 
timeout_t get_lock_obtention_timeout ()
 
int get_major_version ()
 Get the major version of the library.
 
int get_patch_version ()
 Get the patch version of the library.
 
int get_release_version ()
 Get the minor version of the library.
 
timeout_t get_unlock_timeout ()
 
char const * get_version_string ()
 Get the full version of the library as a string.
 
bool is_lock_ready ()
 Check the current status of the cluck daemon.
 
void listen_to_cluck_status (ed::connection_with_send_message::pointer_t messenger, ed::dispatcher::pointer_t dispatcher, typename ed::dispatcher_match::execute_callback_t callback)
 Start listening to changes in the cluck status.
 
void set_lock_duration_timeout (timeout_t timeout)
 
void set_lock_obtention_timeout (timeout_t timeout)
 
void set_unlock_timeout (timeout_t timeout)
 

Variables

timeout_t CLUCK_DEFAULT_TIMEOUT = timeout_t(-1, 0)
 
timeout_t CLUCK_LOCK_DURATION_DEFAULT_TIMEOUT = timeout_t(5, 0)
 
timeout_t CLUCK_LOCK_OBTENTION_DEFAULT_TIMEOUT = timeout_t(5, 0)
 
timeout_t CLUCK_LOCK_OBTENTION_MAXIMUM_TIMEOUT = timeout_t(60 * 60, 0)
 
std::size_t CLUCK_MAXIMUM_ENTERING_LOCKS = 100
 
timeout_t CLUCK_MAXIMUM_TIMEOUT = timeout_t(7 * 24 * 60 * 60, 0)
 
timeout_t CLUCK_MINIMUM_TIMEOUT = timeout_t(3, 0)
 
timeout_t CLUCK_UNLOCK_DEFAULT_TIMEOUT = timeout_t(5, 0)
 
timeout_t CLUCK_UNLOCK_MINIMUM_TIMEOUT = timeout_t(3, 0)
 

Typedef Documentation

◆ timeout_t

typedef snapdev::timespec_ex cluck::timeout_t

This type is used to defined a timeout delay between an event and its reply. The value represents microseconds.

The special value, CLUCK_DEFAULT_TIMEOUT (-1), is used to indicate that the default is to be used.

Definition at line 80 of file cluck.h.

Enumeration Type Documentation

◆ mode_t

enum class cluck::mode_t
strong
Enumerator
CLUCK_MODE_SIMPLE 
CLUCK_MODE_EXTENDED 

Definition at line 36 of file cluck.h.

◆ reason_t

enum class cluck::reason_t
strong
Enumerator
CLUCK_REASON_NONE 
CLUCK_REASON_LOCAL_TIMEOUT 
CLUCK_REASON_REMOTE_TIMEOUT 
CLUCK_REASON_DEADLOCK 
CLUCK_REASON_TRANSMISSION_ERROR 
CLUCK_REASON_INVALID 

Definition at line 43 of file cluck.h.

◆ state_t

enum class cluck::state_t
strong
Enumerator
CLUCK_STATE_IDLE 
CLUCK_STATE_LOCKING 
CLUCK_STATE_LOCKED 
CLUCK_STATE_UNLOCKING 
CLUCK_STATE_FAILED 

Definition at line 62 of file cluck.h.

◆ type_t

enum class cluck::type_t
strong
Enumerator
CLUCK_TYPE_READ_WRITE 
CLUCK_TYPE_READ_ONLY 
CLUCK_TYPE_READ_WRITE_PRIORITY 

Definition at line 54 of file cluck.h.

Function Documentation

◆ DECLARE_EXCEPTION() [1/4]

cluck::DECLARE_EXCEPTION ( cluck_exception  ,
busy   
)

◆ DECLARE_EXCEPTION() [2/4]

cluck::DECLARE_EXCEPTION ( cluck_exception  ,
invalid_message   
)

◆ DECLARE_EXCEPTION() [3/4]

cluck::DECLARE_EXCEPTION ( cluck_exception  ,
invalid_parameter   
)

◆ DECLARE_EXCEPTION() [4/4]

cluck::DECLARE_EXCEPTION ( cluck_exception  ,
timeout   
)

◆ DECLARE_LOGIC_ERROR() [1/2]

cluck::DECLARE_LOGIC_ERROR ( logic_error  )

◆ DECLARE_LOGIC_ERROR() [2/2]

cluck::DECLARE_LOGIC_ERROR ( unexpected_case  )

◆ DECLARE_MAIN_EXCEPTION()

cluck::DECLARE_MAIN_EXCEPTION ( cluck_exception  )

◆ DECLARE_OUT_OF_RANGE()

cluck::DECLARE_OUT_OF_RANGE ( out_of_range  )

◆ get_lock_duration_timeout()

timeout_t cluck::get_lock_duration_timeout ( )

Definition at line 159 of file cluck.cpp.

◆ get_lock_obtention_timeout()

timeout_t cluck::get_lock_obtention_timeout ( )

Definition at line 136 of file cluck.cpp.

Referenced by cluck_daemon::cluckd::get_parameters().

◆ get_major_version()

int cluck::cluck::get_major_version ( )

This function returns the major version of the running library (the one you are linked against at runtime).

Returns
The major version.

Definition at line 53 of file version.cpp.

References CLUCK_VERSION_MAJOR.

◆ get_patch_version()

int cluck::cluck::get_patch_version ( )

This function returns the patch version of the running library (the one you are linked against at runtime).

Returns
The patch version.

Definition at line 79 of file version.cpp.

References CLUCK_VERSION_PATCH.

◆ get_release_version()

int cluck::cluck::get_release_version ( )

This function returns the minor version of the running library (the one you are linked against at runtime).

Returns
The release version.

Definition at line 66 of file version.cpp.

References CLUCK_VERSION_MINOR.

◆ get_unlock_timeout()

timeout_t cluck::get_unlock_timeout ( )

Definition at line 182 of file cluck.cpp.

◆ get_version_string()

char const * cluck::cluck::get_version_string ( )

This function returns the major, minor, and patch versions of the running library (the one you are linked against at runtime) in the form of a string.

The build version is not made available. In most cases we change the build version only to run a new build, so not code will have changed (some documentation and non-code files may changed between build versions; but the code will work exactly the same way.)

Returns
The library version.

Definition at line 98 of file version.cpp.

References CLUCK_VERSION_STRING.

◆ is_lock_ready()

bool cluck::is_lock_ready ( )

This function returns true if the cluck daemon is up and ready to receive LOCK messages. The function returns false if the cluck daemon is not yet ready.

Note that sending a LOCK message to a cluck daemon which is not ready results in the LOCK message getting cached. If the cluck daemon does not get ready before the lock times out, then a LOCK_FAILED reply is sent to the client.

A better way is for the client to wait for this flag to become true before requesting a LOCK. In effect, the initialization process of your service should take this flag in account. Until the callback passed to the listen_to_cluck_status() function is called and the is_lock_ready() function returns true, your own service is not quite fully ready.

Note
It is possible that the cluck daemon stops being ready. This happens if 2 or more leaders go down and your local system losses its connections to remote communicator daemons. In particular, this happens when a system is about to be rebooted or the network goes down.
Returns
true if the LOCK_READY message was last received.

Definition at line 259 of file cluck_status.cpp.

◆ listen_to_cluck_status()

void cluck::listen_to_cluck_status ( ed::connection_with_send_message::pointer_t  messenger,
ed::dispatcher::pointer_t  dispatcher,
typename ed::dispatcher_match::execute_callback_t  callback 
)

This function adds two commands to the dispatcher:

  • LOCK_READY – the cluck daemon is ready to receive LOCK messages
  • NO_LOCK – the cluck daemon is no ready, LOCK messages are cached and may timeout before the daemon becomes ready

When called, the function also emits a LOCK_STATUS command to the local cluck daemon. This ensures that we receive a status from the cluck daemon (i.e. if we missed the last change, it could take a very long time before the status of the cluck daemon changes again).

Parameters
[in]messengerYour messenger to send and receive commands.
[in]dispatcherYour dispatcher to listen to the LOCK_READY and NO_LOCK messages.
[in]callbackA callback that gets called each time the cluck daemon status changes.

Definition at line 201 of file cluck_status.cpp.

◆ set_lock_duration_timeout()

void cluck::set_lock_duration_timeout ( timeout_t  timeout)

◆ set_lock_obtention_timeout()

void cluck::set_lock_obtention_timeout ( timeout_t  timeout)

◆ set_unlock_timeout()

void cluck::set_unlock_timeout ( timeout_t  timeout)

Variable Documentation

◆ CLUCK_DEFAULT_TIMEOUT

timeout_t cluck::CLUCK_DEFAULT_TIMEOUT = timeout_t(-1, 0)
inline

◆ CLUCK_LOCK_DURATION_DEFAULT_TIMEOUT

timeout_t cluck::CLUCK_LOCK_DURATION_DEFAULT_TIMEOUT = timeout_t(5, 0)
inline

Definition at line 87 of file cluck.h.

Referenced by set_lock_duration_timeout().

◆ CLUCK_LOCK_OBTENTION_DEFAULT_TIMEOUT

timeout_t cluck::CLUCK_LOCK_OBTENTION_DEFAULT_TIMEOUT = timeout_t(5, 0)
inline

Definition at line 85 of file cluck.h.

Referenced by set_lock_obtention_timeout().

◆ CLUCK_LOCK_OBTENTION_MAXIMUM_TIMEOUT

timeout_t cluck::CLUCK_LOCK_OBTENTION_MAXIMUM_TIMEOUT = timeout_t(60 * 60, 0)
inline

Definition at line 86 of file cluck.h.

Referenced by set_lock_obtention_timeout(), and cluck::cluck::set_lock_obtention_timeout().

◆ CLUCK_MAXIMUM_ENTERING_LOCKS

std::size_t cluck::CLUCK_MAXIMUM_ENTERING_LOCKS = 100
inline

Definition at line 92 of file cluck.h.

Referenced by cluck_daemon::cluckd::msg_lock().

◆ CLUCK_MAXIMUM_TIMEOUT

timeout_t cluck::CLUCK_MAXIMUM_TIMEOUT = timeout_t(7 * 24 * 60 * 60, 0)
inline

◆ CLUCK_MINIMUM_TIMEOUT

timeout_t cluck::CLUCK_MINIMUM_TIMEOUT = timeout_t(3, 0)
inline

◆ CLUCK_UNLOCK_DEFAULT_TIMEOUT

timeout_t cluck::CLUCK_UNLOCK_DEFAULT_TIMEOUT = timeout_t(5, 0)
inline

Definition at line 88 of file cluck.h.

Referenced by set_unlock_timeout().

◆ CLUCK_UNLOCK_MINIMUM_TIMEOUT

timeout_t cluck::CLUCK_UNLOCK_MINIMUM_TIMEOUT = timeout_t(3, 0)
inline

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.