@@ -252,6 +252,15 @@ protected void serviceStart() throws Exception {
252
252
initLocalDirAllocator ();
253
253
}
254
254
255
+ /**
256
+ * Check the service is running.
257
+ * @throws IllegalStateException if not in STARTED.
258
+ */
259
+ protected void checkRunning () throws IllegalStateException {
260
+ Preconditions .checkState (isInState (STATE .STARTED ),
261
+ "Store is in state %s" , getServiceState ());
262
+ }
263
+
255
264
/**
256
265
* Return the store path capabilities.
257
266
* If the object stream factory is non-null, hands off the
@@ -262,6 +271,7 @@ protected void serviceStart() throws Exception {
262
271
*/
263
272
@ Override
264
273
public boolean hasPathCapability (final Path path , final String capability ) {
274
+ checkRunning ();
265
275
switch (toLowerCase (capability )) {
266
276
case StreamCapabilities .IOSTATISTICS :
267
277
return true ;
@@ -278,6 +288,7 @@ public boolean hasPathCapability(final Path path, final String capability) {
278
288
*/
279
289
@ Override
280
290
public boolean inputStreamHasCapability (final String capability ) {
291
+ checkRunning ();
281
292
if (objectInputStreamFactory != null ) {
282
293
return objectInputStreamFactory .hasCapability (capability );
283
294
}
@@ -298,26 +309,29 @@ private void initLocalDirAllocator() {
298
309
/** Acquire write capacity for rate limiting {@inheritDoc}. */
299
310
@ Override
300
311
public Duration acquireWriteCapacity (final int capacity ) {
312
+ checkRunning ();
301
313
return writeRateLimiter .acquire (capacity );
302
314
}
303
315
304
316
/** Acquire read capacity for rate limiting {@inheritDoc}. */
305
317
@ Override
306
318
public Duration acquireReadCapacity (final int capacity ) {
319
+ checkRunning ();
307
320
return readRateLimiter .acquire (capacity );
308
-
309
321
}
310
322
311
323
/**
312
324
* Create a new store context.
313
325
* @return a new store context.
314
326
*/
315
327
private StoreContext createStoreContext () {
328
+ checkRunning ();
316
329
return storeContextFactory .createStoreContext ();
317
330
}
318
331
319
332
@ Override
320
333
public StoreContext getStoreContext () {
334
+ checkRunning ();
321
335
return storeContext ;
322
336
}
323
337
@@ -327,41 +341,49 @@ public StoreContext getStoreContext() {
327
341
* @throws UncheckedIOException on any failure to create the client.
328
342
*/
329
343
private S3Client getS3Client () throws UncheckedIOException {
344
+ checkRunning ();
330
345
return clientManager .getOrCreateS3ClientUnchecked ();
331
346
}
332
347
333
348
@ Override
334
349
public S3TransferManager getOrCreateTransferManager () throws IOException {
350
+ checkRunning ();
335
351
return clientManager .getOrCreateTransferManager ();
336
352
}
337
353
338
354
@ Override
339
355
public S3Client getOrCreateS3Client () throws IOException {
356
+ checkRunning ();
340
357
return clientManager .getOrCreateS3Client ();
341
358
}
342
359
343
360
@ Override
344
361
public S3AsyncClient getOrCreateAsyncClient () throws IOException {
362
+ checkRunning ();
345
363
return clientManager .getOrCreateAsyncClient ();
346
364
}
347
365
348
366
@ Override
349
367
public S3Client getOrCreateS3ClientUnchecked () throws UncheckedIOException {
368
+ checkRunning ();
350
369
return clientManager .getOrCreateS3ClientUnchecked ();
351
370
}
352
371
353
372
@ Override
354
373
public S3Client getOrCreateAsyncS3ClientUnchecked () throws UncheckedIOException {
374
+ checkRunning ();
355
375
return clientManager .getOrCreateAsyncS3ClientUnchecked ();
356
376
}
357
377
358
378
@ Override
359
379
public S3Client getOrCreateUnencryptedS3Client () throws IOException {
380
+ checkRunning ();
360
381
return clientManager .getOrCreateUnencryptedS3Client ();
361
382
}
362
383
363
384
@ Override
364
385
public DurationTrackerFactory getDurationTrackerFactory () {
386
+ checkRunning ();
365
387
return durationTrackerFactory ;
366
388
}
367
389
@@ -380,6 +402,7 @@ private S3AStorageStatistics getStorageStatistics() {
380
402
381
403
@ Override
382
404
public RequestFactory getRequestFactory () {
405
+ checkRunning ();
383
406
return requestFactory ;
384
407
}
385
408
@@ -389,6 +412,7 @@ public RequestFactory getRequestFactory() {
389
412
*/
390
413
@ Override
391
414
public ClientManager clientManager () {
415
+ checkRunning ();
392
416
return clientManager ;
393
417
}
394
418
@@ -507,6 +531,7 @@ private void incrementBytesWritten(final long bytes) {
507
531
*/
508
532
@ Override
509
533
public void incrementPutStartStatistics (long bytes ) {
534
+ checkRunning ();
510
535
LOG .debug ("PUT start {} bytes" , bytes );
511
536
incrementWriteOperations ();
512
537
incrementGauge (OBJECT_PUT_REQUESTS_ACTIVE , 1 );
@@ -599,6 +624,7 @@ public Map.Entry<Duration, DeleteObjectsResponse> deleteObjects(
599
624
final DeleteObjectsRequest deleteRequest )
600
625
throws SdkException {
601
626
627
+ checkRunning ();
602
628
DeleteObjectsResponse response ;
603
629
BulkDeleteRetryHandler retryHandler = new BulkDeleteRetryHandler (createStoreContext ());
604
630
@@ -671,6 +697,7 @@ public HeadObjectResponse headObject(String key,
671
697
Invoker changeInvoker ,
672
698
S3AFileSystemOperations fsHandler ,
673
699
String operation ) throws IOException {
700
+ checkRunning ();
674
701
HeadObjectResponse response = getStoreContext ().getInvoker ()
675
702
.retryUntranslated ("HEAD " + key , true ,
676
703
() -> {
@@ -729,6 +756,7 @@ public HeadObjectResponse headObject(String key,
729
756
public ResponseInputStream <GetObjectResponse > getRangedS3Object (String key ,
730
757
long start ,
731
758
long end ) throws IOException {
759
+ checkRunning ();
732
760
final GetObjectRequest request = getRequestFactory ().newGetObjectRequestBuilder (key )
733
761
.range (S3AUtils .formatRange (start , end ))
734
762
.build ();
@@ -757,7 +785,7 @@ public ResponseInputStream<GetObjectResponse> getRangedS3Object(String key,
757
785
public Map .Entry <Duration , Optional <DeleteObjectResponse >> deleteObject (
758
786
final DeleteObjectRequest request )
759
787
throws SdkException {
760
-
788
+ checkRunning ();
761
789
String key = request .key ();
762
790
blockRootDelete (key );
763
791
DurationInfo d = new DurationInfo (LOG , false , "deleting %s" , key );
@@ -810,6 +838,7 @@ public UploadPartResponse uploadPart(
810
838
final RequestBody body ,
811
839
@ Nullable final DurationTrackerFactory trackerFactory )
812
840
throws AwsServiceException , UncheckedIOException {
841
+ checkRunning ();
813
842
long len = request .contentLength ();
814
843
incrementPutStartStatistics (len );
815
844
try {
@@ -852,6 +881,7 @@ public UploadInfo putObject(
852
881
PutObjectRequest putObjectRequest ,
853
882
File file ,
854
883
ProgressableProgressListener listener ) throws IOException {
884
+ checkRunning ();
855
885
long len = getPutRequestLength (putObjectRequest );
856
886
LOG .debug ("PUT {} bytes to {} via transfer manager " , len , putObjectRequest .key ());
857
887
incrementPutStartStatistics (len );
@@ -882,6 +912,7 @@ public UploadInfo putObject(
882
912
@ Retries .OnceTranslated
883
913
public CompletedFileUpload waitForUploadCompletion (String key , UploadInfo uploadInfo )
884
914
throws IOException {
915
+ checkRunning ();
885
916
FileUpload upload = uploadInfo .getFileUpload ();
886
917
try {
887
918
CompletedFileUpload result = upload .completionFuture ().join ();
@@ -931,6 +962,7 @@ public LocalDirAllocator getDirectoryAllocator() {
931
962
public File createTemporaryFileForWriting (String pathStr ,
932
963
long size ,
933
964
Configuration conf ) throws IOException {
965
+ checkRunning ();
934
966
requireNonNull (directoryAllocator , "directory allocator not initialized" );
935
967
Path path = directoryAllocator .getLocalPathForWrite (pathStr ,
936
968
size , conf );
0 commit comments