1、Anno brief introduction

  Anno It's a microservice framework engine . Easy entry Security Stable High availability The whole platform can monitor 、 Less reliance on third-party frameworks . Bottom layer communication RPC(Remote Procedure Call) Using stable, reliable, cross lingual... Proven by numerous successful projects thrift grpc.  Self service registration found health check ( Don't depend on Etcd、Consul、Zookeeper)、 Call chain tracing 、Cron Dispatch 、 Current limiting 、 Event bus . Plug in development , Business module to CQRS 、DDD As a guiding ideology .

   One It can't be monitored Its micro service platform is terrible , Something went wrong.   It's hard to pinpoint the root cause of the problem , Anno It provides a complete monitoring system , Include Link tracking System resources occupied by services 、 System itself  CPU、 Memory 、 Hard disk usage Real time monitoring and so on .

github Anno:https://github.com/duyanming/Anno.Core  

gitee      :https://gitee.com/duyanming/anno.core

Experience address :

2、Anno How to implement the distributed lock server

   In the last chapter, we learned what problems distributed locks are designed to solve and how clients use them , Today, let's take a look at how the distributed lock coordination center is implemented . I hope you can correct the shortcomings . If you don't know how to use it, check out the previous chapter 《.netcore Microservice rapid development framework Anno&Viper - What the hell is distributed lock

First, we need an entry class for the distributed lock server  DLockCenter

Pseudo code :

 public static class DLockCenter
private static List<LockerQueue> _lockerQueues = new List<LockerQueue>();
private static readonly object Lock = new object();
     // Enter the distributed lock
     public static EngineData.ActionResult Enter(LockInfo info)
var locker = _lockerQueues.Find(l => l.MLoker.Key == info.Key);
return locker.Enter(info);
    // Release distributed lock
public static void Free(LockInfo info)
_lockerQueues.Find(l => l.MLoker.Owner == info.Owner)?.Free();
/// <summary>
/// The timed task detects whether the distributed lock has timed out , Just throw it away
/// </summary>
public static void Detection()
if (_lockerQueues.Count > 0)
} }

 _lockerQueues: Maintains a list of distributed locks .

  Release timeout lock :

The distributed lock plug-in starts a timed task to detect the timeout of the distributed lock when it is loaded .

public class DLockBootstrap: IPlugsConfigurationBootstrap
private static readonly CronDaemon CronDaemon = new CronDaemon();
public void ConfigurationBootstrap()
// Distributed lock startup configuration
* Every period of time to detect whether there is a lock timeout , Time out releases the lock
CronDaemon.AddJob("* * * * * ? *", DLockCenter.Detection);
if (CronDaemon.Status == DaemonStatus.Stop)
} public void PreConfigurationBootstrap()
//throw new NotImplementedException();

Distributed lock service Module:

 /// <summary>
/// Distributed lock service
/// </summary>
public class DLockModule : BaseModule
[AnnoInfo(Desc = " Distributed lock service Get the lock [DLKey][TimeOut:5000][Owner]")]
public ActionResult EnterLock()
var dlKey = RequestString("DLKey");
var timeOut = RequestInt32("TimeOut")??5000;
var owner = RequestString("Owner");
var locker=new LockInfo()
Key = dlKey,
Time = timeOut,
var rlt = DLockCenter.Enter(locker);
return rlt;
[AnnoInfo(Desc = " Distributed lock service Release the lock [DLKey][Owner]")]
public ActionResult DisposeLock()
var dlKey = RequestString("DLKey");
var owner = RequestString("Owner");
var locker = new LockInfo();
locker.Key = dlKey;
locker.Owner = owner;
return new ActionResult(true, null, null, "DisposeLock Message");

For detailed source code of distributed lock, please see :https://github.com/duyanming/Anno.Core/tree/master/samples/Packages/Anno.Plugs.DLockService

Anno Core source code :https://github.com/duyanming/Anno.Core  

Viper The sample project :https://github.com/duyanming/Viper  

Experience address :

QQ Communication group :478399354 


Anno&Viper - Distributed lock server how to achieve more related articles

  1. Reading Google Distributed lock service

    Reading Google Distributed lock service   Background introduction stay 2010 year 4 month ,Google Web page index update realizes real-time update , In this year's OSDI At the conference ,Google For the first time, a paper on this technology has been published . Before that ,Google The index is more ...

  2. [ Reprint ] zookeeper Distributed lock service

    Reprinted from http://www.cnblogs.com/shanyou/archive/2012/09/22/2697818.html Distributed lock services may not be used much in your projects , Because everyone puts exclusivity in the database ...

  3. Redis Distributed lock service ( 8、 ... and )

    Read the directory : summary Distributed lock Multi instance distributed lock summary summary In multithreaded environment , Lock is usually used to ensure that there is only one thread to operate the shared resource . such as : object obj = new object(); lock (ob ...

  4. Redis Distributed lock service ( turn )

    original text :http://www.cnblogs.com/mushroom/p/4752499.html summary In multithreaded environment , Lock is usually used to ensure that there is only one thread to operate the shared resource . such as : object obj ...

  5. redis Implement distributed lock service

    translation Redis Official documents In the scenario of multithreading sharing critical resources , Distributed lock is a very important component . Many libraries are used in different ways redis Implement a distributed lock management . There is a part of the simple implementation of the lack of reliability , With a few simple modifications ...

  6. DIOCP Open source project - Using queues +0MQ+ Multi process logic processing , Build stability , Efficient , Distributed server

    Recently, I've been thinking about how to make people based on DIOCP Write stable server program on . Many friends ask me , you DIOCP Is it stable , Can I use it as a three tier server ? That's what I said at the time , I can only promise DIOCP The stability of the underlying communication . To tell the truth ...

  7. Redis Distributed lock service

    Read the directory : summary Distributed lock Multi instance distributed lock summary summary In multithreaded environment , Lock is usually used to ensure that there is only one thread to operate the shared resource . such as : object obj = new object(); lock (ob ...

  8. Zookeeper Implement distributed lock service (Chubby)

    In distributed systems , If different systems or different hosts of the same system share one or a group of resources , So when you visit these resources , We often need mutual exclusion to prevent interference , To ensure consistency , under these circumstances , You need to use distributed locks, such as N Two servers at the same time ...

  9. zookeeper Implement distributed lock service

    A distributed lock base on zookeeper. zookeeper yes hadoop One of the following sub projects , To coordinate with hadoop Related distributed frameworks , Such as hadoop, hiv ...

  10. DIOCP Open source project - Efficient and stable server solution (DIOCP + Lockless queue + ZeroMQ + QWorkers) It's out

    [ summary ] Since the last release [DIOCP Open source project - Using queues +0MQ+ Multi process logic processing , Build stability , Efficient , Distributed server ] After the article , Got a lot of friends' support and affirmation . This has increased my motivation for development , After several nights of staying up , Finally yesterday ...

Random recommendation

  1. Li Hongqiang iOS Classic interview questions 140-UI

    Li Hongqiang iOS Classic interview questions 140-UI   UI viewcontroller Description of some methods of viewDidLoad,viewWillDisappear, viewWillAppear Methodical Sequence and function ? ...

  2. C Language bit operation ( turn )


  3. 【golang】go Language , Making concurrent requests wrap Variable parameter encapsulation

    package main import ( "fmt" "sync" "time" ) type WaitGroupWrapper stru ...

  4. [Javascript] Ex: concatAll, map and filter

    concatAll: Array.prototype.concatAll = function() { var results = []; this.forEach(function(subArray ...

  5. Stripies(POJ 1862 greedy )

    Stripies Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 14151   Accepted: 6628 Descrip ...

  6. Mybatis Basic usage -- On

    Mybatis Basic usage -- On This article is just to fill in the gaps . For a comprehensive look at the official documents , Support Chinese and English Principle reference :http://blog.csdn.net/luanlouis/article/details/40422 ...

  7. Java Explain execution and compile execution

    There used to be a saying that :“Java It's the interpretation of execution  ” . It doesn't seem very accurate now , As for the reason , Here is a brief explanation : First , Let's first explain what happened in the Java Explain the difference between execution and compilation execution in . Explain to perform : Translate the compiled bytecode line by line into a machine ...

  8. shell Common test commands

    Predefined variables : The predefined variables are created by Bash A class of special variables pre-defined by a program , Users can only use predefined variables , You cannot create a new predefined variable , You can't assign values to predefined variables directly . Predefined variables use "$" Match with another symbol ...

  9. Django Template language combination search

    url.py from django.conf.urls import url from django.contrib import admin from app01 import views url ...

  10. TypeError: cannot perform reduce with flexible type

    To solve this mistake , Better understand first numpy Data type dtype transformation Generate a floating point array a=np.random.random(4) Output a array([0.0945377,0.52199916,0.62 ...