95
95
import org .apache .accumulo .core .rpc .SslConnectionParams ;
96
96
import org .apache .accumulo .core .security .Authorizations ;
97
97
import org .apache .accumulo .core .securityImpl .thrift .TCredentials ;
98
- import org .apache .accumulo .core .singletons .SingletonManager ;
99
- import org .apache .accumulo .core .singletons .SingletonReservation ;
100
98
import org .apache .accumulo .core .spi .common .ServiceEnvironment ;
101
99
import org .apache .accumulo .core .spi .scan .ScanServerInfo ;
102
100
import org .apache .accumulo .core .spi .scan .ScanServerSelector ;
@@ -137,6 +135,7 @@ public class ClientContext implements AccumuloClient {
137
135
private ConditionalWriterConfig conditionalWriterConfig ;
138
136
private final AccumuloConfiguration accumuloConf ;
139
137
private final Configuration hadoopConf ;
138
+ private final HashMap <TableId ,ClientTabletCache > tabletCaches = new HashMap <>();
140
139
141
140
// These fields are very frequently accessed (each time a connection is created) and expensive to
142
141
// compute, so cache them.
@@ -156,7 +155,6 @@ public class ClientContext implements AccumuloClient {
156
155
private final TableOperationsImpl tableops ;
157
156
private final NamespaceOperations namespaceops ;
158
157
private InstanceOperations instanceops = null ;
159
- private final SingletonReservation singletonReservation ;
160
158
private final ThreadPools clientThreadPools ;
161
159
private ThreadPoolExecutor cleanupThreadPool ;
162
160
private ThreadPoolExecutor scannerReadaheadPool ;
@@ -223,27 +221,24 @@ public String getGroup() {
223
221
}
224
222
225
223
/**
226
- * Create a client context with the provided configuration. Legacy client code must provide a
227
- * no-op SingletonReservation to preserve behavior prior to 2.x. Clients since 2.x should call
228
- * Accumulo.newClient() builder, which will create a client reservation in
229
- * {@link ClientBuilderImpl#buildClient}
224
+ * Create a client context with the provided configuration. Clients should call
225
+ * Accumulo.newClient() builder
230
226
*/
231
- public ClientContext (SingletonReservation reservation , ClientInfo info ,
232
- AccumuloConfiguration serverConf , UncaughtExceptionHandler ueh ) {
227
+ public ClientContext (ClientInfo info , AccumuloConfiguration serverConf ,
228
+ UncaughtExceptionHandler ueh ) {
233
229
this .info = info ;
234
230
this .hadoopConf = info .getHadoopConf ();
235
231
236
232
this .zooSession = memoize (() -> {
237
- var zk = info
238
- .getZooKeeperSupplier (getClass ().getSimpleName () + "(" + info .getPrincipal () + ")" , "" )
239
- .get ();
233
+ var zk =
234
+ info .getZooKeeperSupplier (getClass ().getSimpleName () + "(" + info .getPrincipal () + ")" ,
235
+ ZooUtil . getRoot ( getInstanceID ())) .get ();
240
236
zooKeeperOpened .set (true );
241
237
return zk ;
242
238
});
243
239
244
240
this .zooCache = memoize (() -> {
245
- var zc = new ZooCache (getZooSession (),
246
- createPersistentWatcherPaths (ZooUtil .getRoot (getInstanceID ())));
241
+ var zc = new ZooCache (getZooSession (), createPersistentWatcherPaths ());
247
242
zooCacheCreated .set (true );
248
243
return zc ;
249
244
});
@@ -255,11 +250,9 @@ public ClientContext(SingletonReservation reservation, ClientInfo info,
255
250
() -> SaslConnectionParams .from (getConfiguration (), getCredentials ().getToken ()), 100 ,
256
251
MILLISECONDS );
257
252
scanServerSelectorSupplier = memoize (this ::createScanServerSelector );
258
- this .singletonReservation = Objects .requireNonNull (reservation );
259
253
this .tableops = new TableOperationsImpl (this );
260
254
this .namespaceops = new NamespaceOperationsImpl (this , tableops );
261
- this .serverPaths =
262
- Suppliers .memoize (() -> new ServiceLockPaths (this .getZooKeeperRoot (), this .getZooCache ()));
255
+ this .serverPaths = Suppliers .memoize (() -> new ServiceLockPaths (this .getZooCache ()));
263
256
if (ueh == Threads .UEH ) {
264
257
clientThreadPools = ThreadPools .getServerThreadPools ();
265
258
} else {
@@ -504,10 +497,6 @@ public InstanceId getInstanceID() {
504
497
return info .getInstanceId ();
505
498
}
506
499
507
- public String getZooKeeperRoot () {
508
- return ZooUtil .getRoot (getInstanceID ());
509
- }
510
-
511
500
/**
512
501
* Returns the instance name given at system initialization time.
513
502
*
@@ -813,7 +802,6 @@ public synchronized void close() {
813
802
if (cleanupThreadPool != null ) {
814
803
cleanupThreadPool .shutdown (); // wait for shutdown tasks to execute
815
804
}
816
- singletonReservation .close ();
817
805
}
818
806
}
819
807
@@ -846,16 +834,10 @@ public T build() {
846
834
}
847
835
848
836
public static AccumuloClient buildClient (ClientBuilderImpl <AccumuloClient > cbi ) {
849
- SingletonReservation reservation = SingletonManager .getClientReservation ();
850
- try {
851
- // ClientContext closes reservation unless a RuntimeException is thrown
852
- ClientInfo info = cbi .getClientInfo ();
853
- var config = ClientConfConverter .toAccumuloConf (info .getClientProperties ());
854
- return new ClientContext (reservation , info , config , cbi .getUncaughtExceptionHandler ());
855
- } catch (RuntimeException e ) {
856
- reservation .close ();
857
- throw e ;
858
- }
837
+ // ClientContext closes reservation unless a RuntimeException is thrown
838
+ ClientInfo info = cbi .getClientInfo ();
839
+ var config = ClientConfConverter .toAccumuloConf (info .getClientProperties ());
840
+ return new ClientContext (info , config , cbi .getUncaughtExceptionHandler ());
859
841
}
860
842
861
843
public static Properties buildProps (ClientBuilderImpl <Properties > cbi ) {
@@ -1090,10 +1072,9 @@ public synchronized ZookeeperLockChecker getTServerLockChecker() {
1090
1072
// so, it can't rely on being able to continue to use the same client's ZooCache,
1091
1073
// because that client could be closed, and its ZooSession also closed
1092
1074
// this needs to be fixed; TODO https://github.com/apache/accumulo/issues/2301
1093
- var zk = info .getZooKeeperSupplier (ZookeeperLockChecker .class .getSimpleName (), "" ).get ();
1094
- String zkRoot = getZooKeeperRoot ();
1095
- this .zkLockChecker =
1096
- new ZookeeperLockChecker (new ZooCache (zk , Set .of (zkRoot + Constants .ZTSERVERS )), zkRoot );
1075
+ var zk = info .getZooKeeperSupplier (ZookeeperLockChecker .class .getSimpleName (),
1076
+ ZooUtil .getRoot (getInstanceID ())).get ();
1077
+ this .zkLockChecker = new ZookeeperLockChecker (new ZooCache (zk , Set .of (Constants .ZTSERVERS )));
1097
1078
}
1098
1079
return this .zkLockChecker ;
1099
1080
}
@@ -1107,13 +1088,18 @@ public NamespaceMapping getNamespaces() {
1107
1088
return namespaces ;
1108
1089
}
1109
1090
1110
- private static Set <String > createPersistentWatcherPaths (String zkRoot ) {
1091
+ public HashMap <TableId ,ClientTabletCache > tabletCaches () {
1092
+ ensureOpen ();
1093
+ return tabletCaches ;
1094
+ }
1095
+
1096
+ private static Set <String > createPersistentWatcherPaths () {
1111
1097
Set <String > pathsToWatch = new HashSet <>();
1112
1098
for (String path : Set .of (Constants .ZCOMPACTORS , Constants .ZDEADTSERVERS , Constants .ZGC_LOCK ,
1113
1099
Constants .ZMANAGER_LOCK , Constants .ZMINI_LOCK , Constants .ZMONITOR_LOCK ,
1114
1100
Constants .ZNAMESPACES , Constants .ZRECOVERY , Constants .ZSSERVERS , Constants .ZTABLES ,
1115
1101
Constants .ZTSERVERS , Constants .ZUSERS , RootTable .ZROOT_TABLET , Constants .ZTEST_LOCK )) {
1116
- pathsToWatch .add (zkRoot + path );
1102
+ pathsToWatch .add (path );
1117
1103
}
1118
1104
return pathsToWatch ;
1119
1105
}
0 commit comments