Skip to content

Commit ee3c9fa

Browse files
lavrukovAlexander Lavrukov
andauthored
Remove AutoClosable from YdbSchemaOperations (#172)
Now YdbSchemaOperations is just a thin wrapper, and all API clients are managed by the owning YdbRepository. Co-authored-by: Alexander Lavrukov <lavrukov@yandex-team.ru>
1 parent 20876b8 commit ee3c9fa

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/YdbRepository.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
import tech.ydb.core.grpc.GrpcTransportBuilder;
1616
import tech.ydb.core.impl.SingleChannelTransport;
1717
import tech.ydb.core.impl.auth.GrpcAuthRpc;
18+
import tech.ydb.scheme.SchemeClient;
1819
import tech.ydb.table.SessionPoolStats;
1920
import tech.ydb.table.TableClient;
21+
import tech.ydb.topic.TopicClient;
2022
import tech.ydb.yoj.repository.db.Entity;
2123
import tech.ydb.yoj.repository.db.EntitySchema;
2224
import tech.ydb.yoj.repository.db.Repository;
@@ -355,18 +357,26 @@ public record Settings(
355357

356358
private static final class SessionClient implements AutoCloseable {
357359
private final TableClient tableClient;
360+
private final SchemeClient schemeClient;
361+
private final TopicClient topicClient;
362+
358363
private final SessionManager sessionManager;
359364
private final YdbSchemaOperations schemaOperations;
360365

361366
private SessionClient(YdbConfig config, Settings repositorySettings, GrpcTransport transport) {
362367
this.tableClient = createClient(config, repositorySettings, transport);
368+
this.schemeClient = SchemeClient.newClient(transport).build();
369+
this.topicClient = TopicClient.newClient(transport).build();
370+
363371
this.sessionManager = new YdbSessionManager(tableClient, config.getSessionCreationTimeout());
364-
this.schemaOperations = new YdbSchemaOperations(config.getTablespace(), this.sessionManager, transport);
372+
this.schemaOperations = new YdbSchemaOperations(
373+
config.getTablespace(), sessionManager, schemeClient, topicClient
374+
);
365375
}
366376

367377
@Override
368378
public void close() {
369-
Exceptions.closeAll(tableClient, schemaOperations);
379+
Exceptions.closeAll(tableClient, schemeClient, topicClient);
370380
}
371381
}
372382

repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/client/YdbSchemaOperations.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import org.slf4j.LoggerFactory;
1111
import tech.ydb.core.Result;
1212
import tech.ydb.core.Status;
13-
import tech.ydb.core.grpc.GrpcTransport;
1413
import tech.ydb.proto.ValueProtos;
1514
import tech.ydb.scheme.SchemeClient;
1615
import tech.ydb.scheme.description.DescribePathResult;
@@ -42,7 +41,6 @@
4241
import tech.ydb.yoj.repository.ydb.exception.YdbSchemaPathNotFoundException;
4342
import tech.ydb.yoj.repository.ydb.yql.YqlPrimitiveType;
4443
import tech.ydb.yoj.repository.ydb.yql.YqlType;
45-
import tech.ydb.yoj.util.lang.Exceptions;
4644

4745
import java.util.ArrayList;
4846
import java.util.List;
@@ -58,21 +56,26 @@
5856
import static lombok.AccessLevel.PRIVATE;
5957
import static tech.ydb.core.StatusCode.SCHEME_ERROR;
6058

61-
@Getter
6259
@InternalApi
63-
public final class YdbSchemaOperations implements AutoCloseable {
60+
public final class YdbSchemaOperations {
6461
private static final Logger log = LoggerFactory.getLogger(YdbSchemaOperations.class);
6562

63+
@Getter
64+
private String tablespace;
6665
private final SessionManager sessionManager;
6766
private final SchemeClient schemeClient;
6867
private final TopicClient topicClient;
69-
private String tablespace;
7068

71-
public YdbSchemaOperations(String tablespace, @NonNull SessionManager sessionManager, GrpcTransport transport) {
69+
public YdbSchemaOperations(
70+
String tablespace,
71+
SessionManager sessionManager,
72+
SchemeClient schemeClient,
73+
TopicClient topicClient
74+
) {
7275
this.tablespace = YdbPaths.canonicalTablespace(tablespace);
7376
this.sessionManager = sessionManager;
74-
this.schemeClient = SchemeClient.newClient(transport).build();
75-
this.topicClient = TopicClient.newClient(transport).build();
77+
this.schemeClient = schemeClient;
78+
this.topicClient = topicClient;
7679
}
7780

7881
public void setTablespace(String tablespace) {
@@ -476,11 +479,6 @@ public boolean hasPath(String path) {
476479
throw new YdbRepositoryException("Can't describe table '" + path + "': " + result);
477480
}
478481

479-
@Override
480-
public void close() {
481-
Exceptions.closeAll(topicClient, schemeClient);
482-
}
483-
484482
@Value
485483
private static class DirectoryEntity {
486484
EntryType type;

0 commit comments

Comments
 (0)