Skip to content

Commit 7fd4486

Browse files
committed
2.4.6
1 parent bd57720 commit 7fd4486

7 files changed

Lines changed: 228 additions & 326 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ You can use **Apache Maven** or **Gradle**/**Grails** to download the SDK.
2424
<dependency>
2525
<groupId>com.tencent.tcvectordb</groupId>
2626
<artifactId>vectordatabase-sdk-java</artifactId>
27-
<version>2.4.5</version>
27+
<version>2.4.6</version>
2828
</dependency>
2929
```
3030

3131
- Gradle/Grails
3232

3333
```gradle
34-
compile 'com.tencent.tcvectordb:vectordatabase-sdk-java:2.4.5'
34+
compile 'com.tencent.tcvectordb:vectordatabase-sdk-java:2.4.6'
3535
```
3636

3737
### Examples

tcvectordb/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ You can use **Apache Maven** or **Gradle**/**Grails** to download the SDK.
2424
<dependency>
2525
<groupId>com.tencent.tcvectordb</groupId>
2626
<artifactId>vectordatabase-sdk-java</artifactId>
27-
<version>2.4.5</version>
27+
<version>2.4.6</version>
2828
</dependency>
2929
```
3030

3131
- Gradle/Grails
3232

3333
```gradle
34-
compile 'com.tencent.tcvectordb:vectordatabase-sdk-java:2.4.5'
34+
compile 'com.tencent.tcvectordb:vectordatabase-sdk-java:2.4.6'
3535
```
3636

3737
### Examples

tcvectordb/pom.xml

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,37 @@
44

55
<groupId>com.tencent.tcvectordb</groupId>
66
<artifactId>vectordatabase-sdk-java</artifactId>
7-
<version>2.4.5</version>
7+
<version>2.4.6</version>
88
<packaging>jar</packaging>
99

1010
<name>vectordatabase-sdk-java</name>
1111

12+
<description>
13+
tencent vectordatabase java sdk.
14+
</description>
15+
<url>https://cloud.tencent.com/product/vdb</url>
16+
<licenses>
17+
<license>
18+
<name>The Apache License, Version 2.0</name>
19+
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
20+
</license>
21+
</licenses>
22+
<developers>
23+
<developer>
24+
<id>tcvectordb</id>
25+
<name>yihaoan</name>
26+
<email>yihaoan@tencent.com</email>
27+
</developer>
28+
</developers>
29+
<scm>
30+
<connection>scm:git:https://github.com/Tencent/vectordatabase-sdk-java.git
31+
</connection>
32+
<developerConnection>
33+
scm:git:https://github.com/Tencent/vectordatabase-sdk-java.git
34+
</developerConnection>
35+
<url>https://github.com/Tencent/vectordatabase-sdk-java</url>
36+
</scm>
37+
1238
<properties>
1339
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1440
<okhttp.version>4.9.2</okhttp.version>
@@ -104,11 +130,6 @@
104130
<artifactId>tcvdb-text</artifactId>
105131
<version>1.0.2</version>
106132
</dependency>
107-
<dependency>
108-
<groupId>org.apache.commons</groupId>
109-
<artifactId>commons-pool2</artifactId>
110-
<version>2.12.0</version>
111-
</dependency>
112133
</dependencies>
113134
<build>
114135
<plugins>
@@ -122,14 +143,14 @@
122143
</configuration>
123144
</plugin>
124145
<plugin>
125-
<groupId>org.sonatype.plugins</groupId>
126-
<artifactId>nexus-staging-maven-plugin</artifactId>
127-
<version>1.6.13</version>
146+
<groupId>org.sonatype.central</groupId>
147+
<artifactId>central-publishing-maven-plugin</artifactId>
148+
<version>0.8.0</version>
128149
<extensions>true</extensions>
129150
<configuration>
130-
<serverId>ossrh</serverId>
131-
<nexusUrl>https://oss.sonatype.org</nexusUrl>
132-
<autoReleaseAfterClose>true</autoReleaseAfterClose>
151+
<publishingServerId>ossrh</publishingServerId>
152+
<autoPublish>true</autoPublish>
153+
<waitUntil>published</waitUntil>
133154
</configuration>
134155
</plugin>
135156
<plugin>
@@ -145,6 +166,28 @@
145166
</execution>
146167
</executions>
147168
</plugin>
169+
<plugin>
170+
<groupId>org.apache.maven.plugins</groupId>
171+
<artifactId>maven-javadoc-plugin</artifactId>
172+
<version>3.2.0</version>
173+
<executions>
174+
<execution>
175+
<id>attach-javadoc</id>
176+
<phase>verify</phase>
177+
<goals>
178+
<!--生成javadoc的jar -->
179+
<goal>jar</goal>
180+
<!--生成javadoc的html -->
181+
<goal>javadoc</goal>
182+
</goals>
183+
<configuration>
184+
<!--不显示javadoc警告-->
185+
<additionalOptions>-Xdoclint:none</additionalOptions>
186+
<additionalJOption>-Xdoclint:none</additionalJOption>
187+
</configuration>
188+
</execution>
189+
</executions>
190+
</plugin>
148191
<plugin>
149192
<groupId>org.apache.maven.plugins</groupId>
150193
<artifactId>maven-gpg-plugin</artifactId>

tcvectordb/src/main/java/com/tencent/tcvectordb/examples/CommonService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ private static ConnectParam initConnectParam() {
5353
.withUsername("root")
5454
.withKey(vdbKey)
5555
.withTimeout(30)
56+
.withMaxIdleConnections(10)
5657
.build();
5758
}
5859

tcvectordb/src/main/java/com/tencent/tcvectordb/model/param/database/ConnectParam.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class ConnectParam {
4242
* max idle connection count, unit is second
4343
*/
4444
private final int maxIdleConnections;
45+
private final int connectionPoolSize;
4546
/**
4647
* keep alive duration, unit is second
4748
*/
@@ -55,6 +56,7 @@ private ConnectParam(Builder builder) {
5556
this.connectTimeout = builder.connectTimeout;
5657
this.maxIdleConnections = builder.maxIdleConnections;
5758
this.keepAliveDuration = builder.keepAliveDuration;
59+
this.connectionPoolSize = builder.connectionPoolSize;
5860
}
5961

6062
public String getUrl() {
@@ -73,6 +75,10 @@ public int getTimeout() {
7375
return timeout;
7476
}
7577

78+
public int getConnectionPoolSize() {
79+
return connectionPoolSize;
80+
}
81+
7682
public long getConnectTimeout() {
7783
return connectTimeout;
7884
}
@@ -106,6 +112,8 @@ public static class Builder {
106112
* max idle connection count, unit is second
107113
*/
108114
private int maxIdleConnections = 10;
115+
116+
private int connectionPoolSize = 1;
109117
/**
110118
* keep alive duration, unit is second
111119
*/
@@ -158,6 +166,7 @@ public Builder withConnectTimeout(int connectTimeout) {
158166
public Builder withMaxIdleConnections(int maxIdleConnections) {
159167
if (maxIdleConnections > 0) {
160168
this.maxIdleConnections = maxIdleConnections;
169+
this.connectionPoolSize = maxIdleConnections;
161170
}
162171
return this;
163172
}

tcvectordb/src/main/java/com/tencent/tcvectordb/rpc/pool/ChannelPool.java

Lines changed: 23 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,30 @@
44
import com.tencent.tcvectordb.model.param.database.ConnectParam;
55
import com.tencent.tcvectordb.rpc.Interceptor.AuthorityInterceptor;
66
import io.grpc.ManagedChannel;
7-
import io.grpc.ManagedChannelBuilder;
87
import io.grpc.okhttp.OkHttpChannelBuilder;
9-
import org.apache.commons.pool2.BasePooledObjectFactory;
10-
import org.apache.commons.pool2.PooledObject;
11-
import org.apache.commons.pool2.impl.DefaultPooledObject;
12-
import org.apache.commons.pool2.impl.GenericObjectPool;
13-
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
148

159
import java.net.MalformedURLException;
1610
import java.net.URL;
17-
import java.time.Duration;
18-
import java.util.concurrent.TimeUnit;
11+
import java.util.ArrayList;
12+
import java.util.List;
13+
import java.util.concurrent.atomic.AtomicLong;
1914

2015
public class ChannelPool {
21-
private final GenericObjectPool<ManagedChannel> pool;
16+
private List<ManagedChannel> pool;
17+
private AtomicLong channelSelectorCounter = new AtomicLong(0);
2218

2319
public ChannelPool(ConnectParam param, int maxReceiveMessageSize, String authorization) {
24-
GenericObjectPoolConfig<ManagedChannel> config = new GenericObjectPoolConfig<>();
25-
config.setMaxTotal(param.getMaxIdleConnections()); // 最大连接数
26-
config.setMaxIdle(param.getMaxIdleConnections()); // 最大空闲连接
27-
config.setMaxWait(Duration.ofSeconds(param.getConnectTimeout()));
2820

29-
this.pool = new GenericObjectPool<>(new ChannelFactory(getAddress(param.getUrl()), maxReceiveMessageSize, authorization), config);
21+
this.pool = new ArrayList<>();
3022

31-
for (int i = 0; i < pool.getMaxIdle(); i++) {
23+
for (int i = 0; i < (param.getConnectionPoolSize()); i++) {
3224
try {
33-
pool.addObject(); // 添加一个初始对象到池中,直到达到maxIdle设置的数量
25+
pool.add(OkHttpChannelBuilder.forTarget(getAddress(param.getUrl())).
26+
intercept(new AuthorityInterceptor(authorization)).
27+
flowControlWindow(maxReceiveMessageSize).
28+
maxInboundMessageSize(maxReceiveMessageSize).
29+
enableRetry().
30+
usePlaintext().build());
3431
} catch (Exception e) {
3532
throw new VectorDBException("create channel pool error", e);
3633
}
@@ -53,63 +50,26 @@ private String getAddress(String url){
5350

5451
public ManagedChannel getChannel() {
5552
try {
56-
// printPoolStats();
57-
return pool.borrowObject();
53+
long count = channelSelectorCounter.incrementAndGet();
54+
if (count < 0) {
55+
count = 0;
56+
channelSelectorCounter.set(0);
57+
}
58+
Long index = count % pool.size();
59+
return pool.get(index.intValue());
5860
} catch (Exception e) {
5961
throw new RuntimeException(e);
6062
}
6163
}
6264

63-
public void returnChannel(ManagedChannel channel) {
64-
pool.returnObject(channel);
65-
}
66-
6765
/**
6866
* 关闭连接池,会关闭池中所有 ManagedChannel
6967
*/
7068
public void close() {
7169
if (pool != null) {
72-
pool.close();
73-
}
74-
}
75-
76-
public void printPoolStats() {
77-
System.out.println("Active: " + pool.getNumActive());
78-
System.out.println("Idle: " + pool.getNumIdle());
79-
System.out.println("Total created: " + pool.getCreatedCount());
80-
System.out.println("Total borrowed: " + pool.getBorrowedCount());
81-
System.out.println("Total returned: " + pool.getReturnedCount());
82-
}
83-
84-
private static class ChannelFactory extends BasePooledObjectFactory<ManagedChannel> {
85-
private final String url;
86-
private final int maxReceiveMessageSize;
87-
private final String authorization;
88-
89-
public ChannelFactory(String url, int maxReceiveMessageSize, String authorization) {
90-
this.url = url;
91-
this.maxReceiveMessageSize = maxReceiveMessageSize;
92-
this.authorization = authorization;
93-
}
94-
95-
@Override
96-
public ManagedChannel create() {
97-
return OkHttpChannelBuilder.forTarget(url).
98-
intercept(new AuthorityInterceptor(this.authorization)).
99-
flowControlWindow(maxReceiveMessageSize).
100-
maxInboundMessageSize(maxReceiveMessageSize).
101-
enableRetry().
102-
usePlaintext().build();
103-
}
104-
105-
@Override
106-
public PooledObject<ManagedChannel> wrap(ManagedChannel channel) {
107-
return new DefaultPooledObject<>(channel);
108-
}
109-
110-
@Override
111-
public void destroyObject(PooledObject<ManagedChannel> p) {
112-
p.getObject().shutdown();
70+
for (ManagedChannel channel : pool) {
71+
channel.shutdown();
72+
}
11373
}
11474
}
11575
}

0 commit comments

Comments
 (0)