5454import org .apache .accumulo .core .fate .zookeeper .ZooReservation ;
5555import org .apache .accumulo .core .metadata .schema .Ample ;
5656import org .apache .accumulo .core .metadata .schema .TabletMetadata ;
57- import org .apache .accumulo .manager .Manager ;
5857import org .apache .accumulo .server .ServerContext ;
5958import org .apache .hadoop .fs .FileSystem ;
6059import org .apache .hadoop .fs .Path ;
@@ -140,13 +139,14 @@ public static LockRange widen(Ample ample, TableId tableId, LockRange range, Tab
140139
141140 }
142141
143- public static long reserveTable (Manager env , TableId tableId , FateId fateId , LockType lockType ,
144- boolean tableMustExist , TableOperation op ) throws Exception {
145- return reserveTable (env , tableId , fateId , lockType , tableMustExist , op , LockRange .infinite ());
142+ public static long reserveTable (ServerContext ctx , TableId tableId , FateId fateId ,
143+ LockType lockType , boolean tableMustExist , TableOperation op ) throws Exception {
144+ return reserveTable (ctx , tableId , fateId , lockType , tableMustExist , op , LockRange .infinite ());
146145 }
147146
148- public static long reserveTable (Manager env , TableId tableId , FateId fateId , LockType lockType ,
149- boolean tableMustExist , TableOperation op , final LockRange range ) throws Exception {
147+ public static long reserveTable (ServerContext ctx , TableId tableId , FateId fateId ,
148+ LockType lockType , boolean tableMustExist , TableOperation op , final LockRange range )
149+ throws Exception {
150150 final LockRange widenedRange ;
151151
152152 boolean shouldWiden = lockType == LockType .WRITE || op == TableOperation .COMPACT ;
@@ -174,13 +174,13 @@ public static long reserveTable(Manager env, TableId tableId, FateId fateId, Loc
174174 *
175175 * Widening is done for compactions because those operations widen their range.
176176 */
177- widenedRange = widen (env . getContext () .getAmple (), tableId , range , op , tableMustExist );
177+ widenedRange = widen (ctx .getAmple (), tableId , range , op , tableMustExist );
178178 log .debug ("{} widened write lock range from {} to {}" , fateId , range , widenedRange );
179179 } else {
180180 widenedRange = range ;
181181 }
182182
183- var lock = getLock (env . getContext () , tableId , fateId , lockType , widenedRange );
183+ var lock = getLock (ctx , tableId , fateId , lockType , widenedRange );
184184 if (shouldWiden && !widenedRange .equals (lock .getRange ())) {
185185 // It is possible the range changed since the lock entry was created. Pre existing locks are
186186 // found using the fate id and could have a different range.
@@ -201,7 +201,7 @@ public static long reserveTable(Manager env, TableId tableId, FateId fateId, Loc
201201 // it means the table splits changed so release the lock and try again later. The table
202202 // splits in this range can not change once the lock is acquired, so this recheck is done
203203 // after getting the lock.
204- var widenedRange2 = widen (env . getContext () .getAmple (), tableId , range , op , tableMustExist );
204+ var widenedRange2 = widen (ctx .getAmple (), tableId , range , op , tableMustExist );
205205 if (!widenedRange .equals (widenedRange2 )) {
206206 lock .unlock ();
207207 log .info (
@@ -212,7 +212,7 @@ public static long reserveTable(Manager env, TableId tableId, FateId fateId, Loc
212212 }
213213
214214 if (tableMustExist ) {
215- ZooReaderWriter zk = env . getContext () .getZooSession ().asReaderWriter ();
215+ ZooReaderWriter zk = ctx .getZooSession ().asReaderWriter ();
216216 if (!zk .exists (Constants .ZTABLES + "/" + tableId )) {
217217 throw new AcceptableThriftTableOperationException (tableId .canonical (), "" , op ,
218218 TableOperationExceptionType .NOTFOUND , "Table does not exist" );
@@ -232,23 +232,23 @@ public static long reserveTable(Manager env, TableId tableId, FateId fateId, Loc
232232 }
233233 }
234234
235- public static void unreserveTable (Manager env , TableId tableId , FateId fateId ,
235+ public static void unreserveTable (ServerContext ctx , TableId tableId , FateId fateId ,
236236 LockType lockType ) {
237- getLock (env . getContext () , tableId , fateId , lockType , LockRange .infinite ()).unlock ();
237+ getLock (ctx , tableId , fateId , lockType , LockRange .infinite ()).unlock ();
238238 log .info ("table {} {} unlocked for {}" , tableId , fateId , lockType );
239239 }
240240
241- public static void unreserveNamespace (Manager env , NamespaceId namespaceId , FateId fateId ,
241+ public static void unreserveNamespace (ServerContext ctx , NamespaceId namespaceId , FateId fateId ,
242242 LockType lockType ) {
243- getLock (env . getContext () , namespaceId , fateId , lockType , LockRange .infinite ()).unlock ();
243+ getLock (ctx , namespaceId , fateId , lockType , LockRange .infinite ()).unlock ();
244244 log .info ("namespace {} {} unlocked for {}" , namespaceId , fateId , lockType );
245245 }
246246
247- public static long reserveNamespace (Manager env , NamespaceId namespaceId , FateId fateId ,
247+ public static long reserveNamespace (ServerContext ctx , NamespaceId namespaceId , FateId fateId ,
248248 LockType lockType , boolean mustExist , TableOperation op ) throws Exception {
249- if (getLock (env . getContext () , namespaceId , fateId , lockType , LockRange .infinite ()).tryLock ()) {
249+ if (getLock (ctx , namespaceId , fateId , lockType , LockRange .infinite ()).tryLock ()) {
250250 if (mustExist ) {
251- ZooReaderWriter zk = env . getContext () .getZooSession ().asReaderWriter ();
251+ ZooReaderWriter zk = ctx .getZooSession ().asReaderWriter ();
252252 if (!zk .exists (Constants .ZNAMESPACES + "/" + namespaceId )) {
253253 throw new AcceptableThriftTableOperationException (namespaceId .canonical (), "" , op ,
254254 TableOperationExceptionType .NAMESPACE_NOTFOUND , "Namespace does not exist" );
@@ -261,10 +261,10 @@ public static long reserveNamespace(Manager env, NamespaceId namespaceId, FateId
261261 }
262262 }
263263
264- public static long reserveHdfsDirectory (Manager env , String directory , FateId fateId )
264+ public static long reserveHdfsDirectory (ServerContext ctx , String directory , FateId fateId )
265265 throws KeeperException , InterruptedException {
266266
267- ZooReaderWriter zk = env . getContext () .getZooSession ().asReaderWriter ();
267+ ZooReaderWriter zk = ctx .getZooSession ().asReaderWriter ();
268268
269269 if (ZooReservation .attempt (zk , Constants .ZHDFS_RESERVATIONS + "/"
270270 + Base64 .getEncoder ().encodeToString (directory .getBytes (UTF_8 )), fateId , "" )) {
@@ -276,12 +276,10 @@ public static long reserveHdfsDirectory(Manager env, String directory, FateId fa
276276 }
277277 }
278278
279- public static void unreserveHdfsDirectory (Manager env , String directory , FateId fateId )
279+ public static void unreserveHdfsDirectory (ServerContext ctx , String directory , FateId fateId )
280280 throws KeeperException , InterruptedException {
281- ZooReservation .release (env .getContext ().getZooSession ().asReaderWriter (),
282- Constants .ZHDFS_RESERVATIONS + "/"
283- + Base64 .getEncoder ().encodeToString (directory .getBytes (UTF_8 )),
284- fateId );
281+ ZooReservation .release (ctx .getZooSession ().asReaderWriter (), Constants .ZHDFS_RESERVATIONS + "/"
282+ + Base64 .getEncoder ().encodeToString (directory .getBytes (UTF_8 )), fateId );
285283 log .trace ("{} unreserved bulk dir {}" , fateId , directory );
286284 }
287285
@@ -308,9 +306,9 @@ private static DistributedLock getLock(ServerContext context, AbstractId<?> id,
308306 return lock ;
309307 }
310308
311- public static DistributedLock getReadLock (Manager env , AbstractId <?> id , FateId fateId ,
309+ public static DistributedLock getReadLock (ServerContext ctx , AbstractId <?> id , FateId fateId ,
312310 LockRange range ) {
313- return Utils .getLock (env . getContext () , id , fateId , LockType .READ , range );
311+ return Utils .getLock (ctx , id , fateId , LockType .READ , range );
314312 }
315313
316314 /**
@@ -320,9 +318,9 @@ public static DistributedLock getReadLock(Manager env, AbstractId<?> id, FateId
320318 *
321319 * @param path the fully-qualified path
322320 */
323- public static SortedSet <Text > getSortedSetFromFile (Manager manager , Path path , boolean encoded )
321+ public static SortedSet <Text > getSortedSetFromFile (ServerContext ctx , Path path , boolean encoded )
324322 throws IOException {
325- FileSystem fs = path .getFileSystem (manager . getContext () .getHadoopConf ());
323+ FileSystem fs = path .getFileSystem (ctx .getHadoopConf ());
326324 var data = new TreeSet <Text >();
327325 try (var file = new java .util .Scanner (fs .open (path ), UTF_8 )) {
328326 while (file .hasNextLine ()) {
0 commit comments