Databases 7 min read

Using Distributed Timestamp Global Sequence in Dble: Environment Setup and Verification

This article explains the distributed‑timestamp global sequence in Dble, detailing its 63‑bit ID structure, the required Zookeeper and configuration file settings, schema and server adjustments, and step‑by‑step commands to create a table, insert data, and verify that the generated IDs correctly encode instance, cluster, and timestamp information.

Aikesheng Open Source Community
Aikesheng Open Source Community
Aikesheng Open Source Community
Using Distributed Timestamp Global Sequence in Dble: Environment Setup and Verification

Dble provides four global sequence modes; this guide focuses on the distributed‑timestamp method, which generates a globally unique 63‑bit binary ID using Zookeeper as a distributed ID generator.

The 63‑bit ID consists of fields a‑e: a (9‑bit thread ID), b (5‑bit instance ID from INSTANCEID ), c (4‑bit data‑center ID from CLUSTERID ), d (6‑bit auto‑increment), and e (39‑bit low part of the current timestamp).

Environment setup includes deploying a Zookeeper cluster that manages three Dble nodes (dble‑1, dble‑2, dble‑3) and configuring each node’s sequence_distributed_conf.properties :

INSTANCEID=zk
CLUSTERID=01   // for dble‑1
START_TIME=2010-11-04 09:42:54
INSTANCEID=zk
CLUSTERID=02   // for dble‑2
START_TIME=2010-11-04 09:42:54
INSTANCEID=zk
CLUSTERID=03   // for dble‑3
START_TIME=2010-11-04 09:42:54

Update schema.xml to define a table using the distributed sequence and set sequenceHandlerType to 3 in server.xml :

<schema name="schema1" dataNode="dn1">
    <table name="tb_autoIncre" dataNode="dn1,dn2,dn3,dn4" rule="hash-four" cacheKey="id" incrementColumn="id"/>
</schema>
<system>
    <property name="sequenceHandlerType">3</property>
</system>

After editing, execute reload @@config_all on the management port and restart all three Dble instances so the configuration takes effect.

Operation and verification :

mysql -p111111 -utest -P8066 -Dschema1 -e "create table tb_autoIncre(id bigint,time char(120));"
datestr=`date +%Y%m%d`
mysql -p111111 -utest -P8066 -Dschema1 -e "insert tb_autoIncre values('${datestr}');"
mysql -p111111 -utest -P8066 -Dschema1 -e "select * from tb_autoIncre;"

Retrieve the generated id , convert it to binary with select conv(id,10,2) , and dissect the bits to confirm that the cluster ID, instance ID, and timestamp portions match the configured values. Converting the 39‑bit timestamp back to a date (using set @unixtime=.../1000; select from_unixtime(@unixtime); ) yields a time close to the original START_TIME plus the calculated offset, proving the ID generation is correct.

Conclusion: the distributed‑timestamp global sequence in Dble reliably produces positive, globally unique IDs whose components correspond to the configured instance, cluster, and timestamp fields.

Zookeeperdatabase middlewareID GenerationDBLEDistributed Timestampglobal sequence
Aikesheng Open Source Community
Written by

Aikesheng Open Source Community

The Aikesheng Open Source Community provides stable, enterprise‑grade MySQL open‑source tools and services, releases a premium open‑source component each year (1024), and continuously operates and maintains them.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.