2424from urllib .parse import parse_qs
2525
2626from .backends import NbdBackend , create_backend
27- from .concurrency import ConcurrencyManager
2827from .config import TransferRegistry
2928from .constants import CHUNK_SIZE , MAX_PARALLEL_READS , MAX_PARALLEL_WRITES , MAX_PATCH_JSON_SIZE
3029from .util import is_fallback_dirty_response , json_bytes , now_s
@@ -38,14 +37,13 @@ class Handler(BaseHTTPRequestHandler):
3837 All backend I/O is delegated to ImageBackend implementations via the
3938 create_backend() factory.
4039
41- Class-level attributes _concurrency and _registry are injected
40+ Class-level attribute _registry is injected
4241 by the server at startup (see server.py / make_handler()).
4342 """
4443
4544 server_version = "cloudstack-image-server/1.0"
4645 server_protocol = "HTTP/1.1"
4746
48- _concurrency : ConcurrencyManager
4947 _registry : TransferRegistry
5048
5149 _CONTENT_RANGE_RE = re .compile (r"^bytes\s+(\d+)-(\d+)/(?:\*|\d+)$" )
@@ -493,10 +491,6 @@ def do_PATCH(self) -> None:
493491 def _handle_get_image (
494492 self , image_id : str , cfg : Dict [str , Any ], range_header : Optional [str ]
495493 ) -> None :
496- if not self ._concurrency .acquire_read (image_id ):
497- self ._send_error_json (HTTPStatus .SERVICE_UNAVAILABLE , "too many parallel reads" )
498- return
499-
500494 start = now_s ()
501495 bytes_sent = 0
502496 try :
@@ -564,7 +558,6 @@ def _handle_get_image(
564558 except Exception :
565559 pass
566560 finally :
567- self ._concurrency .release_read (image_id )
568561 dur = now_s () - start
569562 logging .info (
570563 "GET end image_id=%s bytes=%d duration_s=%.3f" , image_id , bytes_sent , dur
@@ -573,10 +566,6 @@ def _handle_get_image(
573566 def _handle_put_image (
574567 self , image_id : str , cfg : Dict [str , Any ], content_length : int , flush : bool
575568 ) -> None :
576- if not self ._concurrency .acquire_write (image_id ):
577- self ._send_error_json (HTTPStatus .SERVICE_UNAVAILABLE , "too many parallel writes" )
578- return
579-
580569 start = now_s ()
581570 bytes_written = 0
582571 try :
@@ -596,7 +585,6 @@ def _handle_put_image(
596585 logging .error ("PUT error image_id=%s err=%r" , image_id , e )
597586 self ._send_error_json (HTTPStatus .INTERNAL_SERVER_ERROR , "backend error" )
598587 finally :
599- self ._concurrency .release_write (image_id )
600588 dur = now_s () - start
601589 logging .info (
602590 "PUT end image_id=%s bytes=%d duration_s=%.3f" , image_id , bytes_written , dur
@@ -610,10 +598,6 @@ def _handle_put_range(
610598 content_length : int ,
611599 flush : bool ,
612600 ) -> None :
613- if not self ._concurrency .acquire_write (image_id ):
614- self ._send_error_json (HTTPStatus .SERVICE_UNAVAILABLE , "too many parallel writes" )
615- return
616-
617601 start = now_s ()
618602 bytes_written = 0
619603 try :
@@ -650,7 +634,6 @@ def _handle_put_range(
650634 logging .error ("PUT range error image_id=%s err=%r" , image_id , e )
651635 self ._send_error_json (HTTPStatus .INTERNAL_SERVER_ERROR , "backend error" )
652636 finally :
653- self ._concurrency .release_write (image_id )
654637 dur = now_s () - start
655638 logging .info (
656639 "PUT range end image_id=%s bytes=%d duration_s=%.3f flush=%s" ,
@@ -725,10 +708,6 @@ def _handle_patch_zero(
725708 size : int ,
726709 flush : bool ,
727710 ) -> None :
728- if not self ._concurrency .acquire_write (image_id ):
729- self ._send_error_json (HTTPStatus .SERVICE_UNAVAILABLE , "too many parallel writes" )
730- return
731-
732711 start = now_s ()
733712 try :
734713 logging .info (
@@ -749,7 +728,6 @@ def _handle_patch_zero(
749728 logging .error ("PATCH zero error image_id=%s err=%r" , image_id , e )
750729 self ._send_error_json (HTTPStatus .INTERNAL_SERVER_ERROR , "backend error" )
751730 finally :
752- self ._concurrency .release_write (image_id )
753731 dur = now_s () - start
754732 logging .info ("PATCH zero end image_id=%s duration_s=%.3f" , image_id , dur )
755733
@@ -760,10 +738,6 @@ def _handle_patch_range(
760738 range_header : str ,
761739 content_length : int ,
762740 ) -> None :
763- if not self ._concurrency .acquire_write (image_id ):
764- self ._send_error_json (HTTPStatus .SERVICE_UNAVAILABLE , "too many parallel writes" )
765- return
766-
767741 start = now_s ()
768742 bytes_written = 0
769743 try :
@@ -807,7 +781,6 @@ def _handle_patch_range(
807781 logging .error ("PATCH range error image_id=%s err=%r" , image_id , e )
808782 self ._send_error_json (HTTPStatus .INTERNAL_SERVER_ERROR , "backend error" )
809783 finally :
810- self ._concurrency .release_write (image_id )
811784 dur = now_s () - start
812785 logging .info (
813786 "PATCH range end image_id=%s bytes=%d duration_s=%.3f" ,
0 commit comments