snaplock: snaplock.cpp File Reference

snaplock  1.7.14
The multi-computer lock service.
snaplock.cpp File Reference

Implementation of the snap inter-process lock mechanism. More...

#include "snaplock.h"
#include "version.h"
#include <snapwebsites/log.h>
#include <snapwebsites/qstring_stream.h>
#include <snapwebsites/dbutils.h>
#include <snapwebsites/process.h>
#include <snapwebsites/snap_string_list.h>
#include <snapdev/tokenize_string.h>
#include <advgetopt/advgetopt.h>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <openssl/rand.h>
#include <snapdev/poison.h>
Include dependency graph for snaplock.cpp:

Go to the source code of this file.

Namespaces  snaplock    snaplock::anonymous_namespace{snaplock.cpp}   Variables advgetopt::option const snaplock::anonymous_namespace{snaplock.cpp}::g_options []   advgetopt::options_environment const snaplock::anonymous_namespace{snaplock.cpp}::g_options_environment   Detailed Description

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 into it is your turn.

Contrary to a multi-processor environment thread synchronization, this lock system uses messages and arrays to know its current status. A user interested in obtaining a lock sends a LOCK message. The snaplock daemon then waits until the lock is obtained and sends a LOCKED as a reply. Once done with the lock, the user sends UNLOCK.

The implementation makes use of any number of snaplock instances. The locking mechanism makes use of the QUORUM voting system to know that enough of the other snaplock agree on a statement. This allows the snaplock 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 snaplock implementation checks parameters and throws away messages that are definitely not going to be understood. However, it is, like most Snap! daemons, very trustworthy of other snaplock daemons and does not expect other daemons to mess around with its sequence of lock message used to ensure that everything worked as expected.

Definition in file snaplock.cpp.

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.

Syndicate content

Snap! Websites
An Open Source CMS System in C++

Contact Us Directly