You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: skills/cosid-manual-integration/SKILL.md
+57-18Lines changed: 57 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,21 +1,21 @@
1
1
---
2
2
name: cosid-manual-integration
3
-
description: Guide for manually integrating CosId into Java/Kotlin projects without Spring Boot auto-configuration. Use this skill when the user wants to configure CosId programmatically, set up custom ID generators, integrate CosId in non-Spring environments, asks about CosId core API usage (SnowflakeId, SegmentId, CosIdGenerator), needs to configure machine ID allocation manually, or mentions "manual integration", "programmatic configuration", "without Spring Boot", "non-Spring environment", or "library integration".
3
+
description: Manually integrate CosId into Java or Kotlin applications without Spring Boot auto-configuration. Use when the user needs programmatic setup for SnowflakeId, SegmentId, SegmentChainId, CosIdGenerator, machine ID distribution, custom IdConverter wiring, non-Spring environments, library/framework integration, or production-safe generator lifecycle management.
4
4
---
5
5
6
6
# CosId Manual Integration Skill
7
7
8
-
## Instructions
8
+
Use this skill when CosId must be configured with code instead of `cosid-spring-boot-starter`.
9
9
10
-
### When to Use
10
+
##Workflow
11
11
12
-
- User wants to integrate CosId without Spring Boot
13
-
- User needs custom programmatic configuration of ID generators
14
-
- User is building a library or framework that needs ID generation
15
-
- User asks about CosId core API usage (SnowflakeId, SegmentId, CosIdGenerator)
16
-
- User needs to configure machine ID allocation manually
12
+
1. Identify the generator strategy. Use `$cosid-strategy-guide` first if the user has not chosen one.
13
+
2. Identify the coordination mechanism: manual machine ID, StatefulSet ordinal, Redis, JDBC, MongoDB, ZooKeeper, or proxy.
14
+
3. Show the minimal constructor/wiring path for the chosen generator.
15
+
4. Include lifecycle handling for distributors, guard/heartbeat, prefetch workers, and state storage when relevant.
16
+
5. Add a small verification example: uniqueness, monotonicity, parser behavior, or restart behavior.
17
17
18
-
###Core Architecture
18
+
## Core APIs
19
19
20
20
CosId provides three main ID generation strategies:
21
21
@@ -33,22 +33,24 @@ CosId provides three main ID generation strategies:
33
33
- Requires `MachineIdDistributor` for machine ID allocation (same as SnowflakeId)
34
34
- Supports much larger instance counts than SnowflakeId (not constrained by 63-bit long format)
35
35
36
-
###Machine ID Allocation
36
+
## Machine ID Allocation
37
37
38
38
For SnowflakeId, each instance needs a unique machineId. Options:
39
39
40
40
-**Manual**: Set machineId directly (0-1023 for default 10-bit)
41
-
-**Redis**: `RedisMachineIdDistributor` - uses Redis for coordination
41
+
-**Redis**: `SpringRedisMachineIdDistributor` - uses Redis for coordination
-**StatefulSet**: Kubernetes StatefulSet ordinal as machineId
46
46
47
-
### Manual Configuration Pattern
47
+
Always define the namespace and instance identity deliberately. For production, prefer a distributor that can guard ownership and reclaim expired machine IDs.
int machineId = distributor.distribute("my-namespace", instanceId, Duration.ofSeconds(10));
@@ -63,7 +65,34 @@ SnowflakeId safeId = new ClockSyncSnowflakeId(snowflakeId);
63
65
long id = safeId.generate();
64
66
```
65
67
66
-
### Key Configuration Parameters
68
+
If the user has fixed deployment slots, use `ManualMachineIdDistributor` or directly provide the machine ID, but warn that duplicate machine IDs can create duplicate IDs.
69
+
70
+
## Segment Configuration Pattern
71
+
72
+
Use `SegmentId` or `SegmentChainId` when monotonic IDs and batch allocation are more important than time-encoded IDs.
For `SegmentChainId`, ensure the prefetch worker lifecycle is owned by the application and is closed during shutdown if the concrete setup exposes close/shutdown behavior.
83
+
84
+
## CosIdGenerator Pattern
85
+
86
+
Use `CosIdGenerator` when callers need compact string IDs rather than `long` IDs.
Copy file name to clipboardExpand all lines: skills/cosid-sharding/SKILL.md
+35-5Lines changed: 35 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,19 @@
1
1
---
2
2
name: cosid-sharding
3
-
description: Guide for using CosId sharding algorithms for database sharding with ShardingSphere. Use this skill whenever the user mentions database sharding, table sharding, ShardingSphere, interval sharding, modulo sharding, date-based sharding, range sharding, or needs to distribute data across multiple database tables or nodes. Also use when the user asks about ModCycle, IntervalTimeline, CachedSharding, PreciseSharding, RangeSharding, or SnowflakeLocalDateTimeConvertor.
3
+
description: Design and configure CosId sharding algorithms for database sharding and ShardingSphere. Use when the user mentions table or database sharding, ShardingSphere COSID_MOD or COSID_INTERVAL rules, modulo sharding, date/time interval sharding, range routing, SnowflakeId timestamp extraction, ModCycle, IntervalTimeline, CachedSharding, PreciseSharding, RangeSharding, or SnowflakeLocalDateTimeConvertor.
4
4
---
5
5
6
6
# CosId Sharding Algorithms
7
7
8
-
CosId provides sharding algorithms designed for database sharding, compatible with Apache ShardingSphere. All algorithms implement both precise sharding (single key lookup) and range sharding (key range lookup).
8
+
Use this skill to choose, configure, and validate CosId sharding behavior.
9
+
10
+
## Workflow
11
+
12
+
1. Identify the sharding key type: numeric ID, SnowflakeId, `LocalDateTime`, or an existing timestamp column.
13
+
2. Choose the algorithm: `ModCycle` for uniform numeric distribution, `IntervalTimeline` for time ranges, or `CachedSharding` to cache repeated range routing.
14
+
3. Confirm both precise and range queries. ShardingSphere routes `=`, `IN`, and range predicates differently.
15
+
4. Define effective nodes and bounds explicitly. For interval sharding, include lower/upper datetime bounds and suffix format.
16
+
5. Provide a minimal Java or ShardingSphere YAML example and a routing test.
9
17
10
18
## Sharding Algorithm Types
11
19
@@ -34,6 +42,8 @@ Implementations:
34
42
35
43
Distributes numeric IDs across nodes using `value % divisor`. Best for uniform distribution when using SnowflakeId or SegmentId.
36
44
45
+
Use `ModCycle` when the sharding key is already numeric and the desired distribution is even across a fixed number of tables or databases.
46
+
37
47
### Usage
38
48
39
49
```java
@@ -75,6 +85,8 @@ rules:
75
85
76
86
Distributes data across time-based intervals. Each interval maps to a specific node named with a formatted date suffix.
77
87
88
+
Use `IntervalTimeline` when table names encode time periods such as day, month, or hour. It is also appropriate when a SnowflakeId can be converted back into event time.
89
+
78
90
### Usage
79
91
80
92
```java
@@ -213,12 +225,30 @@ Range queries are often repeated (e.g., querying "last 7 days" across many reque
213
225
| High QPS range queries | CachedSharding + any | Cache avoids recomputation |
214
226
| Auto-increment / SegmentId as key | ModCycle | Even distribution of monotonic IDs |
215
227
228
+
## Validation Checklist
229
+
230
+
Use a small routing matrix before finalizing a rule:
231
+
232
+
- One exact key routes to exactly one expected node.
233
+
- An `IN` query routes to the union of expected nodes.
234
+
- A range query covers all boundary nodes and no unrelated nodes when possible.
235
+
- Values outside an `IntervalTimeline` effective range fail intentionally.
236
+
- Snowflake timestamp extraction uses the same epoch and timestamp bits as the generator.
237
+
- The ShardingSphere `actualDataNodes` expression matches every possible CosId effective node.
238
+
216
239
## Key Design Principles
217
240
218
241
1. **Precise + Range**: Every algorithm supports both single-value and range sharding. ShardingSphere uses precise for `=` and `IN`, and range for `BETWEEN`, `>`, `<`.
219
-
220
242
2. **Effective nodes**: `getEffectiveNodes()`returns all possible target nodes. This is used by ShardingSphere for routing optimization.
221
-
222
243
3. **Thread safety**: All sharding implementations are thread-safe (`@ThreadSafe`).
244
+
4. **Interval bounds**: `IntervalTimeline`requires an explicit effective time range. Values outside this range throw `IllegalArgumentException`.
245
+
5. **Generator alignment**: When the sharding key is a CosId-generated ID, keep the generator epoch, timestamp unit, and converter settings aligned with the sharding rule.
246
+
247
+
## Response Template
248
+
249
+
When answering a sharding request, include:
223
250
224
-
4.**Interval bounds**: IntervalTimeline requires an explicit effective time range. Values outside this range throw `IllegalArgumentException`.
251
+
1. The selected algorithm and why it fits the sharding key.
252
+
2. The expected table/database naming pattern.
253
+
3. A concise Java or ShardingSphere YAML example.
254
+
4. A routing test matrix for exact, `IN`, and range queries.
Copy file name to clipboardExpand all lines: skills/cosid-spring-boot/SKILL.md
+33-3Lines changed: 33 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,21 @@
1
1
---
2
2
name: cosid-spring-boot
3
-
description: Guide for integrating CosId distributed ID generator with Spring Boot. Use this skill whenever the user mentions CosId, distributed ID generation, SnowflakeId, SegmentId, SegmentChainId, CosIdGenerator, machine ID allocation, or needs help configuring ID generation in a Spring Boot application. Also use when the user asks about ID conversion (Radix62, Radix36, SnowflakeFriendly), sharding with CosId, or configuring machine ID distributors (Redis, JDBC, MongoDB, ZooKeeper) for Spring Boot. Triggers on cosid YAML configuration, application.yml ID setup, or any CosId Spring Boot starter questions.
3
+
description: Configure CosId in Spring Boot applications with cosid-spring-boot-starter. Use when the user works with application.yml, Gradle or Maven dependencies, starter feature variants, Redis/JDBC/MongoDB/ZooKeeper/proxy distributors, SnowflakeId, SegmentId, SegmentChainId, CosIdGenerator, @CosId, IdGeneratorProvider, ID converters, machine guarder settings, clock-backwards synchronization, or Actuator endpoints in a Spring Boot service.
4
4
---
5
5
6
6
# CosId Spring Boot Integration
7
7
8
8
CosId is a universal, flexible, high-performance distributed ID generator for Java 17+. The Spring Boot starter (`cosid-spring-boot-starter`) provides auto-configuration for all ID generation strategies.
9
9
10
+
## Workflow
11
+
12
+
1. Confirm the user's Spring Boot and CosId major versions. CosId 2.x targets Spring Boot 3.x and Java 17; CosId 3.x targets Spring Boot 4.x and Java 17.
13
+
2. Choose the ID strategy. Use `$cosid-strategy-guide` first when the user has not chosen between SnowflakeId, SegmentId, SegmentChainId, and CosIdGenerator.
14
+
3. Select the distributor and starter capability needed by the deployment: Redis, JDBC, MongoDB, ZooKeeper, proxy, manual, or StatefulSet.
15
+
4. Provide the smallest working YAML for the selected strategy and backend.
16
+
5. Show how the application consumes the generator: shared bean, named provider, or `@CosId`.
17
+
6. Add validation guidance for uniqueness, ordering, machine ID ownership, segment allocation, and Actuator visibility.
0 commit comments