跳到主要内容

Sequencer API component

Configuration file structure

The json configuration file has the following structure:

"sequencer": {
"<Component A Name>": {
"type": "Component A Name",
"biggerThan": {
"<KEY>": "<VALUE>",
"<KEY>": "<VALUE>"
},
"metadata": {
"<KEY>": "<VALUE>",
"<KEY>": "<VALUE>"
}
},
"<Component B Name>": {
"type": "Component B Name",
"biggerThan": {
"<KEY>": "<VALUE>",
"<KEY>": "<VALUE>"
},
"metadata": {
"<KEY>": "<VALUE>",
"<KEY>": "<VALUE>"
}
}
}

You can configure the key/value configuration items that the component cares about in the metadata. For example, Etcd component configuration is as follows:

"sequencer": {
"sequencer_demo": {
"type": "etcd",
"biggerThan": {
"key1": 1,
"key2": 111
},
"metadata": {
"endpoints": "localhost:2379",
"segmentCacheEnable": "false",
"segmentStep": "1",
"username": "",
"password": "",
"dialTimeout": "5"
}
}
},

Common configuration item description

FieldRequiredDescription
biggerThanNAll IDs generated by components are required to be larger than "biggerThan". This configuration item is designed to make apps portable. For example, the system originally used mysql as the id generating service and the id has been generated to 1000. If you want to migrate your system to PostgreSQL, you need to configure biggerThan to 1000, so that the PostgreSQL component will be set when it is initialized, and the id will be forced to be above 1000, or an error will be returned during startup if the requirements cannot be met.
segmentCacheEnableNWhether to enable number segment caching. The default value is true
segmentStepNThe size of each number segment cache, the default value is 50
  • What is segment cache?

The original solution was to read and write the database every time the ID was obtained, which caused great pressure on the database. The design purpose of segment mode is to cache some ids in the sidecar in advance (cache all ids in a range) to reduce the database pressure.

Specifically, Layotto obtains ids in batches from the sequencer component each time. After the cache runs out, Layotto invokes the component again, and the component goes to the database to obtain a new number segment, which can greatly reduce the pressure on the database.

This design refers to Meituan Leaf's design

Other configuration items

In addition to the above general configuration items, each component has its own special configuration items. Please refer to the documentation for each component.