Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
L
loit-build-common
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
loit-Infrastructure
loit-build-common
Commits
2c5a891e
提交
2c5a891e
authored
2月 25, 2020
作者:
陈世营
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Id leaf
上级
8525974d
显示空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
1076 行增加
和
0 行删除
+1076
-0
pom.xml
loit-build-component/pom.xml
+2
-0
README.md
loit-build-component/sharding-keygen-leaf/README.md
+45
-0
pom.xml
loit-build-component/sharding-keygen-leaf/pom.xml
+726
-0
LeafPropertiesConstant.java
...a/io/opensharding/keygen/leaf/LeafPropertiesConstant.java
+12
-0
LeafSegmentKeyGenerator.java
.../io/opensharding/keygen/leaf/LeafSegmentKeyGenerator.java
+83
-0
LeafSnowflakeKeyGenerator.java
...o/opensharding/keygen/leaf/LeafSnowflakeKeyGenerator.java
+51
-0
org.apache.shardingsphere.spi.keygen.ShardingKeyGenerator
...org.apache.shardingsphere.spi.keygen.ShardingKeyGenerator
+2
-0
LeafSegmentKeyGeneratorTest.java
...opensharding/keygen/leaf/LeafSegmentKeyGeneratorTest.java
+44
-0
LeafSnowflakeKeyGeneratorTest.java
...ensharding/keygen/leaf/LeafSnowflakeKeyGeneratorTest.java
+44
-0
UniqueLeafKeyGeneratorTest.java
.../opensharding/keygen/leaf/UniqueLeafKeyGeneratorTest.java
+56
-0
leaf.properties
...t/sharding-keygen-leaf/src/test/resources/leaf.properties
+11
-0
没有找到文件。
loit-build-component/pom.xml
浏览文件 @
2c5a891e
...
...
@@ -14,6 +14,7 @@
<modules>
<module>
loit-seata-mybatis-mysql-suport
</module>
<module>
loit-component-jetcache-client
</module>
<module>
sharding-keygen-leaf
</module>
</modules>
</project>
\ No newline at end of file
loit-build-component/sharding-keygen-leaf/README.md
0 → 100644
浏览文件 @
2c5a891e
## Build & Test
For using Leaf-Segment key generator, this SQL should executed in MySQL first:
```
$mysql
CREATE DATABASE leaf;
CREATE TABLE `leaf_alloc` (
`biz_tag` varchar(128) NOT NULL DEFAULT '', -- your biz unique name
`max_id` bigint(20) NOT NULL DEFAULT '1',
`step` int(11) NOT NULL,
`description` varchar(256) DEFAULT NULL,
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`biz_tag`)
) ENGINE=InnoDB;
insert into leaf_alloc(biz_tag, max_id, step, description) values('sstest', 1, 2000, 'Test leaf Segment Mode Get Id');
```
## Examples
In tests of this project, you can see:
1.
Configuration parameters in
`leaf.properties`
;
2.
Example codes in test classes.
## Using in ShardingSphere config file
Step1: You just need refer dependency in you pom.xml:
```
$xml
<dependency>
<groupId>io.opensharding</groupId>
<artifactId>sharding-keygen-leaf</artifactId>
<version>5.0.0-RC1-SNAPSHOT</version>
</dependency>
```
Step2: And then config this parameter in your rule,
Using Leaf Segment via Database:
```
$yaml
keyGenerator: LEAF_SEGMENT
```
Or using Leaf Snowflake via zookeeper:
```
$yaml
keyGenerator: LEAF_SNOWFLAKE
```
loit-build-component/sharding-keygen-leaf/pom.xml
0 → 100644
浏览文件 @
2c5a891e
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
loit-build-component
</artifactId>
<groupId>
com.timeloit.project
</groupId>
<version>
1.0-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
sharding-keygen-leaf
</artifactId>
<name>
sharding-keygen-leaf
</name>
<packaging>
jar
</packaging>
<properties>
<sharding-orchestration-core.version>
5.0.0-RC1-SNAPSHOT
</sharding-orchestration-core.version>
<java.version>
1.8
</java.version>
<maven.version.range>
[3.0.4,)
</maven.version.range>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<project.build.locale>
zh_CN
</project.build.locale>
<guava.version>
18.0
</guava.version>
<slf4j.version>
1.7.7
</slf4j.version>
<zookeeper.version>
3.4.14
</zookeeper.version>
<curator.version>
2.10.0
</curator.version>
<jackson.version>
2.9.10
</jackson.version>
<meituan.leaf.version>
1.0.1
</meituan.leaf.version>
<mybatis.version>
3.3.0
</mybatis.version>
<springframework.version>
[4.3.6.RELEASE,5.0.0.M1)
</springframework.version>
<spring-boot.version>
[1.5.0.RELEASE,2.0.0.M1)
</spring-boot.version>
<aspectjweaver.version>
1.8.9
</aspectjweaver.version>
<lombok.version>
1.16.4
</lombok.version>
<junit.version>
4.12
</junit.version>
<hamcrest.version>
1.3
</hamcrest.version>
<mockito.version>
2.7.21
</mockito.version>
<logback.version>
1.2.0
</logback.version>
<hikari-cp.version>
2.4.11
</hikari-cp.version>
<alibaba.druid.version>
1.1.12
</alibaba.druid.version>
<commons-dbcp2.version>
2.2.0
</commons-dbcp2.version>
<tomcat-dbcp.version>
9.0.14
</tomcat-dbcp.version>
<commons-pool.version>
1.6
</commons-pool.version>
<commons-io.version>
2.6
</commons-io.version>
<h2.version>
1.4.196
</h2.version>
<mysql-connector-java.version>
5.1.46
</mysql-connector-java.version>
<postgresql.version>
42.2.5
</postgresql.version>
<mssql.version>
6.1.7.jre7-preview
</mssql.version>
<perf4j.version>
0.9.16
</perf4j.version>
<maven-compiler-plugin.version>
3.3
</maven-compiler-plugin.version>
<maven-assembly-plugin.version>
3.1.0
</maven-assembly-plugin.version>
<maven-resources-plugin.version>
2.7
</maven-resources-plugin.version>
<maven-jar-plugin.version>
2.6
</maven-jar-plugin.version>
<maven-surefire-plugin.version>
2.18.1
</maven-surefire-plugin.version>
<maven-site-plugin.version>
3.4
</maven-site-plugin.version>
<maven-enforcer-plugin.version>
1.4
</maven-enforcer-plugin.version>
<maven-project-info-reports-plugin.version>
2.8
</maven-project-info-reports-plugin.version>
<maven-plugin-plugin.version>
3.4
</maven-plugin-plugin.version>
<maven-javadoc-plugin.version>
2.10.3
</maven-javadoc-plugin.version>
<maven-source-plugin.version>
2.4
</maven-source-plugin.version>
<maven-jxr-plugin.version>
2.5
</maven-jxr-plugin.version>
<lifecycle-mapping.version>
1.0.0
</lifecycle-mapping.version>
<coveralls-maven-plugin.version>
4.3.0
</coveralls-maven-plugin.version>
<cobertura-maven-plugin.version>
2.7
</cobertura-maven-plugin.version>
<jacoco.version>
0.7.9
</jacoco.version>
<findbugs-maven-plugin.version>
3.0.2
</findbugs-maven-plugin.version>
<maven-checkstyle-plugin.version>
2.16
</maven-checkstyle-plugin.version>
<maven-pmd-plugin.version>
3.5
</maven-pmd-plugin.version>
<jdepend-maven-plugin.version>
2.0
</jdepend-maven-plugin.version>
<taglist-maven-plugin.version>
2.4
</taglist-maven-plugin.version>
<maven-gpg-plugin.version>
1.6
</maven-gpg-plugin.version>
<protobuf-maven-plugin.version>
0.5.0
</protobuf-maven-plugin.version>
<os-maven-plugin.version>
1.5.0.Final
</os-maven-plugin.version>
<docker-maven-plugin.version>
0.4.14
</docker-maven-plugin.version>
<javadocExecutable>
${java.home}/../bin/javadoc
</javadocExecutable>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>
org.apache.shardingsphere
</groupId>
<artifactId>
sharding-orchestration-core
</artifactId>
<version>
${sharding-orchestration-core.version}
</version>
</dependency>
<!-- dependency>
<groupId>com.sankuai.inf.leaf</groupId>
<artifactId>leaf-core</artifactId>
<version>${meituan.leaf.version}</version>
</dependency -->
<dependency>
<groupId>
com.google.guava
</groupId>
<artifactId>
guava
</artifactId>
<version>
${guava.version}
</version>
</dependency>
<dependency>
<groupId>
org.slf4j
</groupId>
<artifactId>
slf4j-api
</artifactId>
<version>
${slf4j.version}
</version>
</dependency>
<dependency>
<groupId>
org.slf4j
</groupId>
<artifactId>
jcl-over-slf4j
</artifactId>
<version>
${slf4j.version}
</version>
</dependency>
<dependency>
<groupId>
org.apache.zookeeper
</groupId>
<artifactId>
zookeeper
</artifactId>
<version>
${zookeeper.version}
</version>
</dependency>
<dependency>
<groupId>
org.aspectj
</groupId>
<artifactId>
aspectjweaver
</artifactId>
<version>
${aspectjweaver.version}
</version>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-context-support
</artifactId>
<version>
${springframework.version}
</version>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-jdbc
</artifactId>
<version>
${springframework.version}
</version>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter
</artifactId>
<version>
${spring-boot.version}
</version>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-aop
</artifactId>
<version>
${spring-boot.version}
</version>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-jdbc
</artifactId>
<version>
${spring-boot.version}
</version>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
<version>
${lombok.version}
</version>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
<version>
${junit.version}
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.hamcrest
</groupId>
<artifactId>
hamcrest-library
</artifactId>
<version>
${hamcrest.version}
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.mockito
</groupId>
<artifactId>
mockito-core
</artifactId>
<version>
${mockito.version}
</version>
<scope>
test
</scope>
<exclusions>
<exclusion>
<groupId>
org.hamcrest
</groupId>
<artifactId>
hamcrest-core
</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>
org.mockito
</groupId>
<artifactId>
mockito-inline
</artifactId>
<version>
${mockito.version}
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
ch.qos.logback
</groupId>
<artifactId>
logback-classic
</artifactId>
<version>
${logback.version}
</version>
<exclusions>
<exclusion>
<groupId>
org.slf4j
</groupId>
<artifactId>
slf4j-api
</artifactId>
</exclusion>
</exclusions>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.apache.curator
</groupId>
<artifactId>
curator-client
</artifactId>
<version>
${curator.version}
</version>
</dependency>
<dependency>
<groupId>
org.apache.curator
</groupId>
<artifactId>
curator-framework
</artifactId>
<version>
${curator.version}
</version>
</dependency>
<dependency>
<groupId>
com.fasterxml.jackson.core
</groupId>
<artifactId>
jackson-core
</artifactId>
<version>
${jackson.version}
</version>
</dependency>
<dependency>
<groupId>
com.fasterxml.jackson.core
</groupId>
<artifactId>
jackson-annotations
</artifactId>
<version>
${jackson.version}
</version>
</dependency>
<dependency>
<groupId>
com.fasterxml.jackson.core
</groupId>
<artifactId>
jackson-databind
</artifactId>
<version>
${jackson.version}
</version>
</dependency>
<dependency>
<groupId>
commons-io
</groupId>
<artifactId>
commons-io
</artifactId>
<version>
${commons-io.version}
</version>
</dependency>
<dependency>
<groupId>
org.apache.curator
</groupId>
<artifactId>
curator-test
</artifactId>
<version>
${curator.version}
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
com.zaxxer
</groupId>
<artifactId>
HikariCP-java7
</artifactId>
<version>
${hikari-cp.version}
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
druid
</artifactId>
<version>
${alibaba.druid.version}
</version>
</dependency>
<dependency>
<groupId>
commons-pool
</groupId>
<artifactId>
commons-pool
</artifactId>
<version>
${commons-pool.version}
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-dbcp2
</artifactId>
<version>
${commons-dbcp2.version}
</version>
<exclusions>
<exclusion>
<groupId>
commons-pool
</groupId>
<artifactId>
commons-pool
</artifactId>
</exclusion>
</exclusions>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.apache.tomcat
</groupId>
<artifactId>
tomcat-dbcp
</artifactId>
<version>
${tomcat-dbcp.version}
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
com.h2database
</groupId>
<artifactId>
h2
</artifactId>
<version>
${h2.version}
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
<version>
${mysql-connector-java.version}
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.postgresql
</groupId>
<artifactId>
postgresql
</artifactId>
<version>
${postgresql.version}
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
com.microsoft.sqlserver
</groupId>
<artifactId>
mssql-jdbc
</artifactId>
<version>
${mssql.version}
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-test
</artifactId>
<version>
${springframework.version}
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<version>
${spring-boot.version}
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.mybatis
</groupId>
<artifactId>
mybatis
</artifactId>
<version>
${mybatis.version}
</version>
</dependency>
<dependency>
<groupId>
org.perf4j
</groupId>
<artifactId>
perf4j
</artifactId>
<version>
${perf4j.version}
</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>
org.apache.shardingsphere
</groupId>
<artifactId>
sharding-orchestration-core
</artifactId>
</dependency>
<!--TODO-->
<dependency>
<groupId>
com.sankuai.inf.leaf
</groupId>
<artifactId>
leaf-core
</artifactId>
<version>
1.0.1
</version>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
druid
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.curator
</groupId>
<artifactId>
curator-client
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.curator
</groupId>
<artifactId>
curator-framework
</artifactId>
</dependency>
<dependency>
<groupId>
com.fasterxml.jackson.core
</groupId>
<artifactId>
jackson-core
</artifactId>
</dependency>
<dependency>
<groupId>
com.fasterxml.jackson.core
</groupId>
<artifactId>
jackson-annotations
</artifactId>
</dependency>
<dependency>
<groupId>
com.fasterxml.jackson.core
</groupId>
<artifactId>
jackson-databind
</artifactId>
</dependency>
<dependency>
<groupId>
com.google.guava
</groupId>
<artifactId>
guava
</artifactId>
</dependency>
<dependency>
<groupId>
org.slf4j
</groupId>
<artifactId>
slf4j-api
</artifactId>
</dependency>
<dependency>
<groupId>
org.slf4j
</groupId>
<artifactId>
jcl-over-slf4j
</artifactId>
</dependency>
<dependency>
<groupId>
commons-io
</groupId>
<artifactId>
commons-io
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
</dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
</dependency>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
</dependency>
<dependency>
<groupId>
org.hamcrest
</groupId>
<artifactId>
hamcrest-library
</artifactId>
</dependency>
<dependency>
<groupId>
org.mockito
</groupId>
<artifactId>
mockito-core
</artifactId>
</dependency>
<dependency>
<groupId>
org.mockito
</groupId>
<artifactId>
mockito-inline
</artifactId>
</dependency>
<dependency>
<groupId>
ch.qos.logback
</groupId>
<artifactId>
logback-classic
</artifactId>
</dependency>
<dependency>
<groupId>
org.mybatis
</groupId>
<artifactId>
mybatis
</artifactId>
</dependency>
<dependency>
<groupId>
org.perf4j
</groupId>
<artifactId>
perf4j
</artifactId>
</dependency>
</dependencies>
<build>
<extensions>
<extension>
<groupId>
kr.motd.maven
</groupId>
<artifactId>
os-maven-plugin
</artifactId>
<version>
${os-maven-plugin.version}
</version>
</extension>
</extensions>
<pluginManagement>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-compiler-plugin
</artifactId>
<configuration>
<source>
${java.version}
</source>
<target>
${java.version}
</target>
<testSource>
${java.version}
</testSource>
<testTarget>
${java.version}
</testTarget>
<compilerArguments>
<extdirs>
${project.basedir}/Leaf/leaf-core/target
</extdirs>
</compilerArguments>
</configuration>
<version>
${maven-compiler-plugin.version}
</version>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-resources-plugin
</artifactId>
<version>
${maven-resources-plugin.version}
</version>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-jar-plugin
</artifactId>
<version>
${maven-jar-plugin.version}
</version>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-surefire-plugin
</artifactId>
<configuration>
<argLine>
-Xmx1024m -XX:MaxPermSize=256m
</argLine>
</configuration>
</plugin>
<plugin>
<artifactId>
maven-assembly-plugin
</artifactId>
<version>
${maven-assembly-plugin.version}
</version>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-site-plugin
</artifactId>
<version>
${maven-site-plugin.version}
</version>
<configuration>
<locales>
${project.build.locale}
</locales>
</configuration>
</plugin>
<plugin>
<groupId>
org.eclipse.m2e
</groupId>
<artifactId>
lifecycle-mapping
</artifactId>
<version>
${lifecycle-mapping.version}
</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-enforcer-plugin
</artifactId>
<versionRange>
[1.0.0,)
</versionRange>
<goals>
<goal>
enforce
</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore/>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-plugin-plugin
</artifactId>
<versionRange>
[1.0.0,)
</versionRange>
<goals>
<goal>
descriptor
</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore/>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-plugin-plugin
</artifactId>
<version>
${maven-plugin-plugin.version}
</version>
<configuration>
<skipErrorNoDescriptorsFound>
true
</skipErrorNoDescriptorsFound>
</configuration>
<executions>
<execution>
<id>
default-descriptor
</id>
<phase>
process-classes
</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-javadoc-plugin
</artifactId>
<version>
${maven-javadoc-plugin.version}
</version>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-source-plugin
</artifactId>
<version>
${maven-source-plugin.version}
</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<!-- wanna use this config to resolve travis, but no effect. <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<executions>
<execution>
<id>install-external</id>
<phase>clean</phase>
<configuration>
<file>${project.basedir}/Leaf/leaf-core/target/leaf.jar</file>
<repositoryLayout>default</repositoryLayout>
<groupId>com.sankuai.inf.leaf</groupId>
<artifactId>leaf-core</artifactId>
<version>${meituan.leaf.version}</version>
<packaging>jar</packaging>
<generatePom>true</generatePom>
</configuration>
<goals>
<goal>install-file</goal>
</goals>
</execution>
</executions>
</plugin -->
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-source-plugin
</artifactId>
<executions>
<execution>
<id>
attach-sources
</id>
<phase>
verify
</phase>
<goals>
<goal>
jar-no-fork
</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-surefire-plugin
</artifactId>
<version>
3.0.0-M1
</version>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>
${project.basedir}/Leaf/leaf-core/target/leaf.jar
</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
<dependencies>
<dependency>
<groupId>
org.apache.maven.surefire
</groupId>
<artifactId>
surefire-junit47
</artifactId>
<version>
3.0.0-M1
</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-javadoc-plugin
</artifactId>
<executions>
<execution>
<id>
attach-javadocs
</id>
<goals>
<goal>
jar
</goal>
</goals>
</execution>
</executions>
<configuration>
<aggregate>
true
</aggregate>
<charset>
${project.build.sourceEncoding}
</charset>
<encoding>
${project.build.sourceEncoding}
</encoding>
<docencoding>
${project.build.sourceEncoding}
</docencoding>
</configuration>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-enforcer-plugin
</artifactId>
<version>
${maven-enforcer-plugin.version}
</version>
<executions>
<execution>
<id>
enforce-banned-dependencies
</id>
<goals>
<goal>
enforce
</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>
${maven.version.range}
</version>
</requireMavenVersion>
<requireJavaVersion>
<version>
${java.version}
</version>
</requireJavaVersion>
</rules>
<fail>
true
</fail>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>
org.eluder.coveralls
</groupId>
<artifactId>
coveralls-maven-plugin
</artifactId>
<version>
${coveralls-maven-plugin.version}
</version>
</plugin>
<plugin>
<groupId>
org.codehaus.mojo
</groupId>
<artifactId>
cobertura-maven-plugin
</artifactId>
<version>
${cobertura-maven-plugin.version}
</version>
<configuration>
<check>
<!--<branchRate>85</branchRate>-->
<!--<lineRate>85</lineRate>-->
<!--<haltOnFailure>true</haltOnFailure>-->
<!--<totalBranchRate>85</totalBranchRate>-->
<!--<totalLineRate>85</totalLineRate>-->
<!--<packageLineRate>85</packageLineRate>-->
<!--<packageBranchRate>85</packageBranchRate>-->
</check>
<aggregate>
true
</aggregate>
<encoding>
${project.build.sourceEncoding}
</encoding>
<quiet>
true
</quiet>
<format>
xml
</format>
<instrumentation>
<ignoreTrivial>
true
</ignoreTrivial>
<ignoreMethodAnnotations>
<ignoreMethodAnnotation>
lombok.Generated
</ignoreMethodAnnotation>
</ignoreMethodAnnotations>
<excludes>
<exclude>
io/shardingsphere/**/*Test.class
</exclude>
<exclude>
io/shardingsphere/**/Test*.class
</exclude>
<exclude>
authpb/*.class
</exclude>
<exclude>
mvccpb/*.class
</exclude>
<exclude>
etcdserverpb/*.class
</exclude>
</excludes>
</instrumentation>
</configuration>
</plugin>
<plugin>
<groupId>
org.jacoco
</groupId>
<artifactId>
jacoco-maven-plugin
</artifactId>
<version>
${jacoco.version}
</version>
<executions>
<execution>
<goals>
<goal>
prepare-agent
</goal>
</goals>
</execution>
<execution>
<id>
report
</id>
<phase>
test
</phase>
<goals>
<goal>
report
</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>
com.spotify
</groupId>
<artifactId>
docker-maven-plugin
</artifactId>
<version>
${docker-maven-plugin.version}
</version>
</plugin>
<!--
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>${maven-gpg-plugin.version}</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
-->
</plugins>
</build>
</project>
\ No newline at end of file
loit-build-component/sharding-keygen-leaf/src/main/java/io/opensharding/keygen/leaf/LeafPropertiesConstant.java
0 → 100644
浏览文件 @
2c5a891e
package
io
.
opensharding
.
keygen
.
leaf
;
public
final
class
LeafPropertiesConstant
{
// for keyGenerator
public
final
static
String
LEAF_KEY
=
"leaf.key"
;
// for LeafSegment
public
final
static
String
LEAF_JDBC_URL
=
"leaf.jdbc.url"
;
public
final
static
String
LEAF_JDBC_USERNAME
=
"leaf.jdbc.username"
;
public
final
static
String
LEAF_JDBC_PASSWORD
=
"leaf.jdbc.password"
;
// for LeafSnowflake
public
final
static
String
LEAF_ZK_LIST
=
"leaf.zk.list"
;
}
loit-build-component/sharding-keygen-leaf/src/main/java/io/opensharding/keygen/leaf/LeafSegmentKeyGenerator.java
0 → 100644
浏览文件 @
2c5a891e
package
io
.
opensharding
.
keygen
.
leaf
;
import
com.alibaba.druid.pool.DruidDataSource
;
import
com.sankuai.inf.leaf.IDGen
;
import
com.sankuai.inf.leaf.common.Result
;
import
com.sankuai.inf.leaf.segment.SegmentIDGenImpl
;
import
com.sankuai.inf.leaf.segment.dao.IDAllocDao
;
import
com.sankuai.inf.leaf.segment.dao.impl.IDAllocDaoImpl
;
import
lombok.Getter
;
import
lombok.Setter
;
import
lombok.SneakyThrows
;
import
org.apache.shardingsphere.spi.keygen.ShardingKeyGenerator
;
import
java.util.Properties
;
/**
* Key generator implemented by leaf segment algorithms.
*/
public
final
class
LeafSegmentKeyGenerator
implements
ShardingKeyGenerator
{
public
final
static
String
TYPE
=
"LEAF_SEGMENT"
;
@Getter
@Setter
private
Properties
properties
;
private
IDGen
idGen
;
private
DruidDataSource
dataSource
;
@Override
public
Comparable
<?>
generateKey
()
{
if
(
this
.
dataSource
==
null
){
initDataSourceAndIDGen
(
this
.
properties
);
}
Result
result
=
this
.
idGen
.
get
(
properties
.
getProperty
(
LeafPropertiesConstant
.
LEAF_KEY
));
return
result
.
getId
();
}
@SneakyThrows
public
synchronized
void
initDataSourceAndIDGen
(
Properties
properties
){
if
(
this
.
properties
==
null
){
this
.
setProperties
(
properties
);
}
synchronized
(
this
){
if
(
this
.
dataSource
==
null
)
{
DruidDataSource
dataSource
=
new
DruidDataSource
();
dataSource
.
setUrl
(
properties
.
getProperty
(
LeafPropertiesConstant
.
LEAF_JDBC_URL
));
dataSource
.
setUsername
(
properties
.
getProperty
(
LeafPropertiesConstant
.
LEAF_JDBC_USERNAME
));
dataSource
.
setPassword
(
properties
.
getProperty
(
LeafPropertiesConstant
.
LEAF_JDBC_PASSWORD
));
dataSource
.
init
();
IDAllocDao
dao
=
new
IDAllocDaoImpl
(
dataSource
);
this
.
idGen
=
new
SegmentIDGenImpl
();
((
SegmentIDGenImpl
)
this
.
idGen
).
setDao
(
dao
);
this
.
idGen
.
init
();
this
.
dataSource
=
dataSource
;
}
}
}
@Override
public
String
getType
()
{
return
TYPE
;
}
@Override
public
Properties
getProperties
()
{
return
this
.
properties
;
}
@Override
public
void
setProperties
(
Properties
properties
)
{
this
.
properties
=
properties
;
}
@Override
protected
void
finalize
()
throws
Throwable
{
super
.
finalize
();
if
(
this
.
dataSource
!=
null
)
{
this
.
dataSource
.
close
();
}
}
}
\ No newline at end of file
loit-build-component/sharding-keygen-leaf/src/main/java/io/opensharding/keygen/leaf/LeafSnowflakeKeyGenerator.java
0 → 100644
浏览文件 @
2c5a891e
package
io
.
opensharding
.
keygen
.
leaf
;
import
com.sankuai.inf.leaf.IDGen
;
import
com.sankuai.inf.leaf.snowflake.SnowflakeIDGenImpl
;
import
lombok.Getter
;
import
lombok.Setter
;
import
org.apache.shardingsphere.spi.keygen.ShardingKeyGenerator
;
import
java.util.Properties
;
/**
* Key generator implemented by leaf snowflake algorithms.
*/
public
final
class
LeafSnowflakeKeyGenerator
implements
ShardingKeyGenerator
{
public
final
static
String
TYPE
=
"LEAF_SNOWFLAKE"
;
@Getter
@Setter
private
Properties
properties
;
private
IDGen
idGen
;
@Override
public
Comparable
<?>
generateKey
()
{
if
(
this
.
idGen
==
null
)
{
synchronized
(
this
)
{
if
(
this
.
idGen
==
null
)
{
IDGen
idGen
=
new
SnowflakeIDGenImpl
(
properties
.
getProperty
(
LeafPropertiesConstant
.
LEAF_ZK_LIST
),
8089
);
this
.
idGen
=
idGen
;
}
}
}
return
this
.
idGen
.
get
(
properties
.
getProperty
(
LeafPropertiesConstant
.
LEAF_KEY
)).
getId
();
}
@Override
public
String
getType
()
{
return
TYPE
;
}
@Override
public
Properties
getProperties
()
{
return
this
.
properties
;
}
@Override
public
void
setProperties
(
Properties
properties
)
{
this
.
properties
=
properties
;
}
}
loit-build-component/sharding-keygen-leaf/src/main/resources/META-INF/services/org.apache.shardingsphere.spi.keygen.ShardingKeyGenerator
0 → 100644
浏览文件 @
2c5a891e
io.opensharding.keygen.leaf.LeafSegmentKeyGenerator
io.opensharding.keygen.leaf.LeafSnowflakeKeyGenerator
loit-build-component/sharding-keygen-leaf/src/test/java/io/opensharding/keygen/leaf/LeafSegmentKeyGeneratorTest.java
0 → 100644
浏览文件 @
2c5a891e
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
io
.
opensharding
.
keygen
.
leaf
;
import
org.junit.Before
;
import
org.junit.Test
;
import
java.io.IOException
;
import
java.sql.SQLException
;
public
class
LeafSegmentKeyGeneratorTest
extends
UniqueLeafKeyGeneratorTest
{
@Override
public
String
getLeafType
()
{
return
LeafSegmentKeyGenerator
.
TYPE
;
}
@Before
@Override
public
void
before
()
throws
IOException
,
SQLException
{
super
.
before
();
}
@Test
@Override
public
void
testGetId
()
{
super
.
testGetId
();
}
}
loit-build-component/sharding-keygen-leaf/src/test/java/io/opensharding/keygen/leaf/LeafSnowflakeKeyGeneratorTest.java
0 → 100644
浏览文件 @
2c5a891e
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
io
.
opensharding
.
keygen
.
leaf
;
import
org.junit.Before
;
import
org.junit.Test
;
import
java.io.IOException
;
import
java.sql.SQLException
;
public
class
LeafSnowflakeKeyGeneratorTest
extends
UniqueLeafKeyGeneratorTest
{
@Override
public
String
getLeafType
()
{
return
LeafSnowflakeKeyGenerator
.
TYPE
;
}
@Before
@Override
public
void
before
()
throws
IOException
,
SQLException
{
super
.
before
();
}
@Test
@Override
public
void
testGetId
()
{
super
.
testGetId
();
}
}
loit-build-component/sharding-keygen-leaf/src/test/java/io/opensharding/keygen/leaf/UniqueLeafKeyGeneratorTest.java
0 → 100644
浏览文件 @
2c5a891e
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
io
.
opensharding
.
keygen
.
leaf
;
import
com.sankuai.inf.leaf.common.PropertyFactory
;
import
org.apache.shardingsphere.spi.algorithm.keygen.ShardingKeyGeneratorServiceLoader
;
import
org.apache.shardingsphere.spi.keygen.ShardingKeyGenerator
;
import
org.junit.Assert
;
import
java.io.IOException
;
import
java.sql.SQLException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Properties
;
public
abstract
class
UniqueLeafKeyGeneratorTest
{
ShardingKeyGenerator
keyGenerator
;
public
abstract
String
getLeafType
();
public
void
before
()
throws
IOException
,
SQLException
{
if
(
this
.
getLeafType
()
!=
null
)
{
Properties
properties
=
PropertyFactory
.
getProperties
();
keyGenerator
=
new
ShardingKeyGeneratorServiceLoader
().
newService
(
this
.
getLeafType
(),
properties
);
}
}
public
void
testGetId
()
{
if
(
this
.
getLeafType
()
!=
null
)
{
List
<
Object
>
list
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
100
;
++
i
)
{
Object
r
=
keyGenerator
.
generateKey
();
System
.
out
.
println
(
r
);
if
(((
Long
)
r
).
longValue
()
>
0
)
list
.
add
(
r
);
}
Assert
.
assertEquals
(
100
,
list
.
size
());
}
}
}
loit-build-component/sharding-keygen-leaf/src/test/resources/leaf.properties
0 → 100644
浏览文件 @
2c5a891e
# for keyGenerator key
leaf.key
=
loittest
# for LeafSegment
leaf.jdbc.url
=
jdbc:mysql://39.98.202.173:3306/leaf?serverTimezone=UTC&useSSL=false
leaf.jdbc.username
=
root
leaf.jdbc.password
=
abcd1234A!
# for LeafSnowflake
leaf.zk.list
=
localhost:2181
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论