Skip to content

The concurrency pattern produces a globally unique ID

Notifications You must be signed in to change notification settings

themoonstone/get_uid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

Get_uid is a distributed unique ID generator in this package two methods is provided the first method inspired by Twitter's Snowflake: A Sonyflake ID is composed of

39 bits for time in units of 10 msec
 8 bits for a sequence number
16 bits for a machine id

the second methos is to take advantage of the key-value and strong consistency of etcd to dynamically generate a globally unique id Build

The project could be build into a Dockerized server with 'make docker-build'. An local image named 'get_uid' is available after that.

$make
$docker build -t get_uid .

Run

About the mysql database:

If you just call the get_uid package, you should install the mysql service on a master server to provide the auto_increment data.

but if what you want is obtain the global id through the interface ,you can  run the get_uid program directly.

Start Mysql

The machine ID is generated by the self-incrementing of the mysql database,so we should start a Mysql server at first and create a 'guid' database:

$ docker run -e MYSQL_ROOT_PASSWORD=123456 -p 3306:3306 -d --rm --name mysql mysql/mysql-server

$ docker exec -ti mysql mysql -hlocalhost -uroot -p123456 -e "create database guid" 
mysql: [Warning] Using a password on the command line interface can be insecure.

$ docker exec -ti mysql mysql -hlocalhost -uroot -p123456 -e "show databases" 
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------------------+
| Database           |
+--------------------+
| information_schema |
| guid               |
| mysql              |
| performance_schema |
| sys                |
+--------------------+

Run get_uid

$docker run --name container_name -p 8080:8080 get_uid
or in detached:
$docker run --name container_name -p 8080:8080 -d get_uid
You can start multiple services at the same time, by using different ports
$docker run --name container_name1 -p 8080:8080 -d get_uid
$docker run --name container_name2 -p 8081:8080 -d get_uid
$docker run --name container_name3 -p 8082:8080 -d get_uid

Send curl command

$curl 192.168.1.175:8080/user/getuid

About

The concurrency pattern produces a globally unique ID

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published