1
1
package tech .ydb .yoj .repository .ydb ;
2
2
3
3
import com .google .common .net .HostAndPort ;
4
+ import lombok .AccessLevel ;
5
+ import lombok .AllArgsConstructor ;
4
6
import lombok .Builder ;
5
7
import lombok .NonNull ;
6
8
import lombok .Value ;
@@ -26,6 +28,7 @@ public static YdbConfig createForTesting(String host, int port, String tablespac
26
28
database ,
27
29
null ,
28
30
HostAndPort .fromParts (host , port ),
31
+ null ,
29
32
SESSION_CREATE_TIMEOUT_DEFAULT ,
30
33
SESSION_CREATE_RETRY_COUNT_DEFAULT ,
31
34
SESSION_KEEP_ALIVE_TIME_DEFAULT ,
@@ -61,6 +64,9 @@ public static YdbConfig createForTesting(String host, int port, String tablespac
61
64
@ With
62
65
HostAndPort hostAndPort ;
63
66
67
+ @ With
68
+ BalancingConfig balancingConfig ;
69
+
64
70
@ With
65
71
Duration sessionCreationTimeout ;
66
72
@ With
@@ -136,4 +142,40 @@ public Duration getTcpKeepaliveTimeout() {
136
142
public boolean isUseSingleChannelTransport () {
137
143
return Optional .ofNullable (useSingleChannelTransport ).orElse (false );
138
144
}
145
+
146
+ @ Value
147
+ @ AllArgsConstructor (access = AccessLevel .PRIVATE )
148
+ public static class BalancingConfig {
149
+ Policy policy ;
150
+ String preferableLocation ;
151
+
152
+ /**
153
+ * Use all available cluster nodes regardless datacenter locality
154
+ */
155
+ static BalancingConfig useAllNodes () {
156
+ return new BalancingConfig (Policy .USE_ALL_NODES , null );
157
+ }
158
+
159
+ /**
160
+ * Use preferable location (data center)
161
+ *
162
+ * @param preferableLocation a name of location
163
+ */
164
+ static BalancingConfig usePreferableLocation (@ NonNull String preferableLocation ) {
165
+ return new BalancingConfig (Policy .USE_PREFERABLE_LOCATION , preferableLocation );
166
+ }
167
+
168
+ /**
169
+ * Detecting of local DC by the latency measuring
170
+ */
171
+ static BalancingConfig detectLocalDc () {
172
+ return new BalancingConfig (Policy .DETECT_LOCAL_DC , null );
173
+ }
174
+
175
+ public enum Policy {
176
+ USE_ALL_NODES ,
177
+ USE_PREFERABLE_LOCATION ,
178
+ DETECT_LOCAL_DC ,
179
+ }
180
+ }
139
181
}
0 commit comments