Skip to content

Commit

Permalink
1. fix the bug that the historical version configuration is overwritt…
Browse files Browse the repository at this point in the history
…en when the new configuration is recreated after deleting the configuration.

2. optimize the readability of lua scripts
3. optimize Default Jvm Args of Deployment(Kubernetes)
  • Loading branch information
Ahoo-Wang committed Jun 2, 2021
1 parent 2465c77 commit 67ca974
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 86 deletions.
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ between process cache and Redis.
> Kotlin DSL
``` kotlin
val coskyVersion = "1.1.2";
val coskyVersion = "1.1.3";
implementation("me.ahoo.cosky:spring-cloud-starter-cosky-config:${coskyVersion}")
implementation("me.ahoo.cosky:spring-cloud-starter-cosky-discovery:${coskyVersion}")
```
Expand All @@ -52,7 +52,7 @@ between process cache and Redis.
<modelVersion>4.0.0</modelVersion>
<artifactId>demo</artifactId>
<properties>
<cosky.version>1.1.2</cosky.version>
<cosky.version>1.1.3</cosky.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -96,30 +96,30 @@ logging:
#### Option 1:Download the executable file
> Download [cosky-rest-api-server](https://github.com/Ahoo-Wang/cosky/releases/download/1.1.2/cosky-rest-api-1.1.2.tar)
> Download [cosky-rest-api-server](https://github.com/Ahoo-Wang/cosky/releases/download/1.1.3/cosky-rest-api-1.1.3.tar)
> tar *cosky-rest-api-1.1.2.tar*
> tar *cosky-rest-api-1.1.3.tar*
```shell
cd cosky-rest-api-1.1.2
# Working directory: cosky-rest-api-1.1.2
cd cosky-rest-api-1.1.3
# Working directory: cosky-rest-api-1.1.3
bin/cosky-rest-api --server.port=8080 --cosky.redis.uri=redis://localhost:6379
```

#### Option 2:Run On Docker

```shell
docker pull ahoowang/cosky-rest-api:1.1.2
docker run --name cosky-rest-api -d -p 8080:8080 --link redis -e COSKY_REDIS_URI=redis://redis:6379 ahoowang/cosky-rest-api:1.1.2
docker pull ahoowang/cosky-rest-api:1.1.3
docker run --name cosky-rest-api -d -p 8080:8080 --link redis -e COSKY_REDIS_URI=redis://redis:6379 ahoowang/cosky-rest-api:1.1.3
```

##### MacBook Pro (M1)

> Please use *ahoowang/cosky-rest-api:1.1.2-armv7*
> Please use *ahoowang/cosky-rest-api:1.1.3-armv7*
```shell
docker pull ahoowang/cosky-rest-api:1.1.2-armv7
docker run --name cosky-rest-api -d -p 8080:8080 --link redis -e COSKY_REDIS_URI=redis://redis:6379 ahoowang/cosky-rest-api:1.1.2-armv7
docker pull ahoowang/cosky-rest-api:1.1.3-armv7
docker run --name cosky-rest-api -d -p 8080:8080 --link redis -e COSKY_REDIS_URI=redis://redis:6379 ahoowang/cosky-rest-api:1.1.3-armv7
```

#### Option 3:Run On Kubernetes
Expand All @@ -145,7 +145,7 @@ spec:
value: standalone
- name: COSKY_REDIS_URI
value: redis://redis-uri:6379
image: ahoowang/cosky-rest-api:1.1.2
image: ahoowang/cosky-rest-api:1.1.3
name: cosky-rest-api
resources:
limits:
Expand Down Expand Up @@ -276,12 +276,12 @@ spec:
``` shell
gradle cosky-config:jmh
# or
java -jar cosky-config/build/libs/cosky-config-1.1.2-jmh.jar -bm thrpt -t 25 -wi 1 -rf json -f 1
java -jar cosky-config/build/libs/cosky-config-1.1.3-jmh.jar -bm thrpt -t 25 -wi 1 -rf json -f 1
```

```
# JMH version: 1.29
# VM version: JDK 11.1.21, OpenJDK 64-Bit Server VM, 11.1.21+9-LTS
# VM version: JDK 11.1.31, OpenJDK 64-Bit Server VM, 11.1.31+9-LTS
# VM invoker: /Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home/bin/java
# VM options: -Dfile.encoding=UTF-8 -Djava.io.tmpdir=/Users/ahoo/cosky/cosky-config/build/tmp/jmh -Duser.country=CN -Duser.language=zh -Duser.variant
# Blackhole mode: full + dont-inline hint
Expand All @@ -302,12 +302,12 @@ RedisConfigServiceBenchmark.setConfig thrpt 103659.132
``` shell
gradle cosky-discovery:jmh
# or
java -jar cosky-discovery/build/libs/cosky-discovery-1.1.2-jmh.jar -bm thrpt -t 25 -wi 1 -rf json -f 1
java -jar cosky-discovery/build/libs/cosky-discovery-1.1.3-jmh.jar -bm thrpt -t 25 -wi 1 -rf json -f 1
```

```
# JMH version: 1.29
# VM version: JDK 11.1.21, OpenJDK 64-Bit Server VM, 11.1.21+9-LTS
# VM version: JDK 11.1.31, OpenJDK 64-Bit Server VM, 11.1.31+9-LTS
# VM invoker: /Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home/bin/java
# VM options: -Dfile.encoding=UTF-8 -Djava.io.tmpdir=/Users/ahoo/cosky/cosky-discovery/build/tmp/jmh -Duser.country=CN -Duser.language=zh -Duser.variant
# Blackhole mode: full + dont-inline hint
Expand Down
32 changes: 16 additions & 16 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
> Kotlin DSL
``` kotlin
val coskyVersion = "1.1.2";
val coskyVersion = "1.1.3";
implementation("me.ahoo.cosky:spring-cloud-starter-cosky-config:${coskyVersion}")
implementation("me.ahoo.cosky:spring-cloud-starter-cosky-discovery:${coskyVersion}")
```
Expand All @@ -46,7 +46,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>demo</artifactId>
<properties>
<cosky.version>1.1.2</cosky.version>
<cosky.version>1.1.3</cosky.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -90,30 +90,30 @@ logging:
#### 方式一:下载可执行文件
> 下载 [rest-api-server](https://github.com/Ahoo-Wang/cosky/releases/download/1.1.2/cosky-rest-api-1.1.2.tar)
> 下载 [rest-api-server](https://github.com/Ahoo-Wang/cosky/releases/download/1.1.3/cosky-rest-api-1.1.3.tar)
> 解压 *cosky-rest-api-1.1.2.tar*
> 解压 *cosky-rest-api-1.1.3.tar*
```shell
cd cosky-rest-api-1.1.2
# 工作目录: cosky-rest-api-1.1.2
cd cosky-rest-api-1.1.3
# 工作目录: cosky-rest-api-1.1.3
bin/cosky-rest-api --server.port=8080 --cosky.redis.uri=redis://localhost:6379
```

#### 方式二:在 Docker 中运行

```shell
docker pull ahoowang/cosky-rest-api:1.1.2
docker run --name cosky-rest-api -d -p 8080:8080 --link redis -e COSKY_REDIS_URI=redis://redis:6379 ahoowang/cosky-rest-api:1.1.2
docker pull ahoowang/cosky-rest-api:1.1.3
docker run --name cosky-rest-api -d -p 8080:8080 --link redis -e COSKY_REDIS_URI=redis://redis:6379 ahoowang/cosky-rest-api:1.1.3
```

##### MacBook Pro (M1)

> 请使用 *ahoowang/cosky-rest-api:1.1.2-armv7*
> 请使用 *ahoowang/cosky-rest-api:1.1.3-armv7*
```shell
docker pull ahoowang/cosky-rest-api:1.1.2-armv7
docker run --name cosky-rest-api -d -p 8080:8080 --link redis -e COSKY_REDIS_URI=redis://redis:6379 ahoowang/cosky-rest-api:1.1.2-armv7
docker pull ahoowang/cosky-rest-api:1.1.3-armv7
docker run --name cosky-rest-api -d -p 8080:8080 --link redis -e COSKY_REDIS_URI=redis://redis:6379 ahoowang/cosky-rest-api:1.1.3-armv7
```

#### 方式三:在 Kubernetes 中运行
Expand All @@ -139,7 +139,7 @@ spec:
value: standalone
- name: COSKY_REDIS_URI
value: redis://redis-uri:6379
image: ahoowang/cosky-rest-api:1.1.2
image: ahoowang/cosky-rest-api:1.1.3
name: cosky-rest-api
resources:
limits:
Expand Down Expand Up @@ -270,12 +270,12 @@ spec:
``` shell
gradle cosky-config:jmh
# or
java -jar cosky-config/build/libs/cosky-config-1.1.2-jmh.jar -bm thrpt -t 25 -wi 1 -rf json -f 1
java -jar cosky-config/build/libs/cosky-config-1.1.3-jmh.jar -bm thrpt -t 25 -wi 1 -rf json -f 1
```

```
# JMH version: 1.29
# VM version: JDK 11.1.21, OpenJDK 64-Bit Server VM, 11.1.21+9-LTS
# VM version: JDK 11.1.31, OpenJDK 64-Bit Server VM, 11.1.31+9-LTS
# VM invoker: /Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home/bin/java
# VM options: -Dfile.encoding=UTF-8 -Djava.io.tmpdir=/Users/ahoo/cosky/config/build/tmp/jmh -Duser.country=CN -Duser.language=zh -Duser.variant
# Blackhole mode: full + dont-inline hint
Expand All @@ -296,12 +296,12 @@ RedisConfigServiceBenchmark.setConfig thrpt 103659.132
``` shell
gradle cosky-discovery:jmh
# or
java -jar cosky-discovery/build/libs/cosky-discovery-1.1.2-jmh.jar -bm thrpt -t 25 -wi 1 -rf json -f 1
java -jar cosky-discovery/build/libs/cosky-discovery-1.1.3-jmh.jar -bm thrpt -t 25 -wi 1 -rf json -f 1
```

```
# JMH version: 1.29
# VM version: JDK 11.1.21, OpenJDK 64-Bit Server VM, 11.1.21+9-LTS
# VM version: JDK 11.1.31, OpenJDK 64-Bit Server VM, 11.1.31+9-LTS
# VM invoker: /Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home/bin/java
# VM options: -Dfile.encoding=UTF-8 -Djava.io.tmpdir=/Users/ahoo/cosky/discovery/build/tmp/jmh -Duser.country=CN -Duser.language=zh -Duser.variant
# Blackhole mode: full + dont-inline hint
Expand Down
19 changes: 9 additions & 10 deletions cosky-config/src/main/resources/config_remove.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
local namespace = KEYS[1];
local configId = ARGV[1];
local op = 'remove';
local versionField = "version";

local configIdxKey = namespace .. ":cfg_idx";
local configHistoryIdxKey = namespace .. ":cfg_htr_idx:" .. configId;
local configKey = namespace .. ":cfg:" .. configId;

local removed = redis.call("srem", configIdxKey, configKey);
if removed == 0 then
return 0;
Expand All @@ -15,18 +14,18 @@ local function getConfigHistoryKey(version)
return namespace .. ":cfg_htr:" .. configId .. ":" .. tostring(version);
end

local function addHistory(preVersion, configKey)
local configHistoryKey = getConfigHistoryKey(preVersion);
redis.call("zadd", configHistoryIdxKey, preVersion, configHistoryKey);
local function addHistory(currentVersion, configKey, op)
local configHistoryKey = getConfigHistoryKey(currentVersion);
redis.call("zadd", configHistoryIdxKey, currentVersion, configHistoryKey);
redis.call("rename", configKey, configHistoryKey);
local opTime = redis.call('time')[1];
return redis.call("hmset", configHistoryKey, "op", "remove", "opTime", opTime);
return redis.call("hmset", configHistoryKey, 'op', op, "opTime", opTime);
end

local preVersion = redis.call("hget", configKey, versionField)
if preVersion then
local result = addHistory(preVersion, configKey);
redis.call("publish", configKey, "remove");
local currentVersion = redis.call("hget", configKey, versionField)
if currentVersion then
local result = addHistory(currentVersion, configKey, op);
redis.call("publish", configKey, op);
return result;
else
return 0;
Expand Down
27 changes: 14 additions & 13 deletions cosky-config/src/main/resources/config_rollback.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local namespace = KEYS[1];
local configId = ARGV[1];
local targetVersion = ARGV[2];
local op = 'rollback';
local versionField = "version";
local hashField = "hash";
local configIdxKey = namespace .. ":cfg_idx";
Expand All @@ -27,30 +28,30 @@ local function arrayToDictionary(arrayTable)
return dicTable;
end

local function addHistory(preVersion, configKey)
local configHistoryKey = getConfigHistoryKey(preVersion);
redis.call("zadd", configHistoryIdxKey, preVersion, configHistoryKey);
local function addHistory(currentVersion, configKey, op)
local configHistoryKey = getConfigHistoryKey(currentVersion);
redis.call("zadd", configHistoryIdxKey, currentVersion, configHistoryKey);
redis.call("rename", configKey, configHistoryKey);
local opTime = redis.call('time')[1];
return redis.call("hmset", configHistoryKey, "op", "rollback", "opTime", opTime);
return redis.call("hmset", configHistoryKey, 'op', op, "opTime", opTime);
end

local targetHistoryConfig = arrayToDictionary(targetHistoryConfigArray);

local hash = targetHistoryConfig[hashField];
local targetHash = targetHistoryConfig[hashField];

local preHash = redis.call("hget", configKey, hashField)
if (preHash ~= nil) and (preHash == hash) then
local currentHash = redis.call("hget", configKey, hashField)
if (currentHash ~= nil) and (currentHash == targetHash) then
return 0;
end
redis.call("sadd", configIdxKey, configKey)
redis.call("sadd", configIdxKey, configKey, configKey)

local preVersion = redis.call("hget", configKey, versionField)
local version = preVersion + 1;
addHistory(preVersion, configKey)
local currentVersion = redis.call("hget", configKey, versionField)
local nextVersion = currentVersion + 1;
addHistory(currentVersion, configKey, op)
local data = targetHistoryConfig["data"];
local createTime = redis.call('time')[1];

local result = redis.call("hmset", configKey, "configId", configId, "data", data, "hash", hash, "version", version, "createTime", createTime);
redis.call("publish", configKey, "rollback");
local result = redis.call("hmset", configKey, "configId", configId, "data", data, hashField, targetHash, versionField, nextVersion, "createTime", createTime);
redis.call("publish", configKey, op);
return result;
33 changes: 20 additions & 13 deletions cosky-config/src/main/resources/config_set.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,44 @@ local namespace = KEYS[1];
local configId = ARGV[1];
local data = ARGV[2];
local hash = ARGV[3];
local version = 1;
local op = 'set';
local nextVersion = 1;
local versionField = "version";
local hashField = "hash";
local configIdxKey = namespace .. ":cfg_idx";
local configHistoryIdxKey = namespace .. ":cfg_htr_idx:" .. configId;
local configKey = namespace .. ":cfg:" .. configId;
local preHash = redis.call("hget", configKey, hashField)
if (preHash ~= nil) and (preHash == hash) then
local currentHash = redis.call("hget", configKey, hashField);
if (currentHash ~= nil) and (currentHash == hash) then
return 0;
end

local function getConfigHistoryKey(version)
return namespace .. ":cfg_htr:" .. configId .. ":" .. tostring(version);
end

local function addHistory(preVersion, configKey)
local configHistoryKey = getConfigHistoryKey(preVersion);
redis.call("zadd", configHistoryIdxKey, preVersion, configHistoryKey);
local function addHistory(currentVersion, configKey, op)
local configHistoryKey = getConfigHistoryKey(currentVersion);
redis.call("zadd", configHistoryIdxKey, currentVersion, configHistoryKey);
redis.call("rename", configKey, configHistoryKey);
local opTime = redis.call('time')[1];
return redis.call("hmset", configHistoryKey, "op", "set", "opTime", opTime);
return redis.call("hmset", configHistoryKey, 'op', op, "opTime", opTime);
end

redis.call("sadd", configIdxKey, configKey)
local preVersion = redis.call("hget", configKey, versionField)
if preVersion then
version = preVersion + 1;
addHistory(preVersion, configKey);

local currentVersion = redis.call("hget", configKey, versionField)
if currentVersion then
nextVersion = currentVersion + 1;
addHistory(currentVersion, configKey, op);
else
local lastHistoryVersion = redis.call('zrevrange', configHistoryIdxKey, 0, 0, 'WITHSCORES')
if #lastHistoryVersion > 0 then
nextVersion = lastHistoryVersion[2] + 1;
end
end

local createTime = redis.call('time')[1];
local result = redis.call("hmset", configKey, "configId", configId, "data", data, "hash", hash, "version", version, "createTime", createTime);
redis.call("publish", configKey, "set");
local result = redis.call("hmset", configKey, "configId", configId, "data", data, hashField, hash, versionField, nextVersion, "createTime", createTime);
redis.call("publish", configKey, op);
return result;
7 changes: 6 additions & 1 deletion cosky-mirror/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ application {
applicationDefaultJvmArgs = listOf(
"-Xms512M",
"-Xmx512M",
"-XX:MaxMetaspaceSize=128M",
"-XX:MaxDirectMemorySize=256M",
"-Xss1m",
"-server",
"-XX:+UseG1GC",
"-Xlog:gc*:file=logs/${applicationName}-gc.log:time,tags:filecount=10,filesize=100M",
"-Xlog:gc*:file=logs/${applicationName}-gc.log:time,tags:filecount=10,filesize=32M",
"-XX:+HeapDumpOnOutOfMemoryError",
"-XX:HeapDumpPath=data",
"-Dcom.sun.management.jmxremote",
"-Dcom.sun.management.jmxremote.authenticate=false",
"-Dcom.sun.management.jmxremote.ssl=false",
Expand Down
7 changes: 6 additions & 1 deletion cosky-rest-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ application {
applicationDefaultJvmArgs = listOf(
"-Xms512M",
"-Xmx512M",
"-XX:MaxMetaspaceSize=128M",
"-XX:MaxDirectMemorySize=256M",
"-Xss1m",
"-server",
"-XX:+UseG1GC",
"-Xlog:gc*:file=logs/${applicationName}-gc.log:time,tags:filecount=10,filesize=100M",
"-Xlog:gc*:file=logs/${applicationName}-gc.log:time,tags:filecount=10,filesize=32M",
"-XX:+HeapDumpOnOutOfMemoryError",
"-XX:HeapDumpPath=data",
"-Dcom.sun.management.jmxremote",
"-Dcom.sun.management.jmxremote.authenticate=false",
"-Dcom.sun.management.jmxremote.ssl=false",
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group=me.ahoo.cosky
version=1.1.2
version=1.1.3

description=CoSky On Redis (Service Discovery and Configuration Service)
website=https://github.com/Ahoo-Wang/cosky
Expand Down
Loading

0 comments on commit 67ca974

Please sign in to comment.