Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/leo_gateway/include/leo_http.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@
cache_max_content_len = 0 :: pos_integer(), %% cache max content length (byte)
cachable_content_type = [] :: list(), %% cachable content types
cachable_path_pattern = [] :: list(), %% cachable path patterns
has_disk_cache = false :: boolean(), %% Has Disk Cache?
%% for large-object
max_chunked_objs = 0 :: pos_integer(), %% max chunked objects
max_len_of_obj = 0 :: pos_integer(), %% max length a object (byte)
Expand Down Expand Up @@ -535,6 +536,7 @@
range_header :: string(), %% range header
custom_metadata = <<>> :: binary(),
has_inner_cache = false :: boolean(), %% has inner-cache?
has_disk_cache = false :: boolean(), %% has disk cache?
is_cached = false :: boolean(), %% is cached?
is_dir = false :: boolean(), %% is directory?
is_multi_delete = false :: boolean(), %% is multi delete request?
Expand Down
7 changes: 7 additions & 0 deletions apps/leo_gateway/src/leo_gateway_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,12 @@ get_options() ->
end
end, [], List)
end,
HasDiskCache = case CacheDiscCapacity of
DCSize when DCSize > 0 ->
true;
_ ->
false
end,

%% Retrieve large-object-related properties:
LargeObjectProp = ?env_large_object_properties(),
Expand Down Expand Up @@ -660,6 +666,7 @@ get_options() ->
cache_max_content_len = CacheMaxContentLen,
cachable_content_type = CachableContentTypes1,
cachable_path_pattern = CachablePathPatterns1,
has_disk_cache = HasDiskCache,
max_chunked_objs = MaxChunkedObjs,
max_len_of_obj = MaxObjLen,
chunked_obj_len = ChunkedObjLen,
Expand Down
8 changes: 6 additions & 2 deletions apps/leo_gateway/src/leo_gateway_http_commons.erl
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ do_health_check([#member{node = Node}|Rest]) ->
get_object(Req, Key, #req_params{bucket_name = BucketName,
custom_header_settings = CustomHeaderSettings,
has_inner_cache = HasInnerCache,
has_disk_cache = HasDiskCache,
sending_chunked_obj_len = SendChunkLen,
begin_time = BeginTime}) ->
IMSSec = case cowboy_req:parse_header(?HTTP_HEAD_IF_MODIFIED_SINCE, Req) of
Expand Down Expand Up @@ -380,7 +381,8 @@ get_object(Req, Key, #req_params{bucket_name = BucketName,
{ok, Pid} = leo_large_object_get_handler:start_link(
{Key, #transport_record{transport = Transport,
socket = Socket,
sending_chunked_obj_len = SendChunkLen}}),
sending_chunked_obj_len = SendChunkLen},
HasDiskCache}),
try
Ret = leo_large_object_get_handler:get(
Pid, TotalChunkedObjs, Req, Meta),
Expand All @@ -403,6 +405,7 @@ get_object(Req, Key, #req_params{bucket_name = BucketName,
get_object_with_cache(Req, Key, CacheObj, #req_params{bucket_name = BucketName,
custom_header_settings = CustomHeaderSettings,
sending_chunked_obj_len = SendChunkLen,
has_disk_cache = HasDiskCache,
begin_time = BeginTime}) ->
IMSSec = case cowboy_req:parse_header(?HTTP_HEAD_IF_MODIFIED_SINCE, Req) of
{ok, undefined,_} ->
Expand Down Expand Up @@ -566,7 +569,8 @@ get_object_with_cache(Req, Key, CacheObj, #req_params{bucket_name = BucketName,
{ok, Pid} = leo_large_object_get_handler:start_link(
{Key, #transport_record{transport = Transport,
socket = Socket,
sending_chunked_obj_len = SendChunkLen}}),
sending_chunked_obj_len = SendChunkLen},
HasDiskCache}),
try
Ret = leo_large_object_get_handler:get(
Pid, TotalChunkedObjs, Req, Meta),
Expand Down
1 change: 1 addition & 0 deletions apps/leo_gateway/src/leo_gateway_rest_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ handle_1(Req, [{NumOfMinLayers, NumOfMaxLayers}, HasInnerCache, _CustomHeaderSet
min_layers = NumOfMinLayers,
max_layers = NumOfMaxLayers,
has_inner_cache = HasInnerCache,
has_disk_cache = Props#http_options.has_disk_cache,
is_cached = true,
max_chunked_objs = Props#http_options.max_chunked_objs,
max_len_of_obj = Props#http_options.max_len_of_obj,
Expand Down
1 change: 1 addition & 0 deletions apps/leo_gateway/src/leo_gateway_s3_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,7 @@ handle_1(Req, [{NumOfMinLayers, NumOfMaxLayers},
max_layers = NumOfMaxLayers,
qs_prefix = Prefix,
has_inner_cache = HasInnerCache,
has_disk_cache = Props#http_options.has_disk_cache,
is_cached = true,
is_dir = IsDir,
is_acl = IsACL,
Expand Down
20 changes: 16 additions & 4 deletions apps/leo_gateway/src/leo_large_object_get_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
-record(state, {
key = <<>> :: binary(),
transport_rec :: #transport_record{},
is_disc_cache_active :: boolean(),
iterator :: leo_large_object_commons:iterator()
}).

Expand All @@ -74,8 +75,8 @@
%%====================================================================
-spec(start_link(Args) ->
ok | {error, any()} when Args::tuple()).
start_link({Key, TransportRec}) ->
gen_server:start_link(?MODULE, [Key, TransportRec], []).
start_link({Key, TransportRec, IsDiskCacheActive}) ->
gen_server:start_link(?MODULE, [Key, TransportRec, IsDiskCacheActive], []).


%% @doc Stop this server
Expand All @@ -102,14 +103,25 @@ get(Pid, TotalOfChunkedObjs, Req, Meta) ->
%%====================================================================
%% GEN_SERVER CALLBACKS
%%====================================================================
init([Key, TransportRec]) ->
init([Key, TransportRec, IsDiskCacheActive]) ->
State = #state{key = Key,
transport_rec = TransportRec},
transport_rec = TransportRec,
is_disc_cache_active = IsDiskCacheActive},
{ok, State}.

handle_call(stop, _From, State) ->
{stop, normal, ok, State};

handle_call({get, TotalOfChunkedObjs, Req, Meta}, _From,
#state{key = Key, transport_rec = TransportRec, is_disc_cache_active = false} = State) ->
Reply = handle_loop(TotalOfChunkedObjs,
#req_info{key = Key,
chunk_key = Key,
request = Req,
metadata = Meta,
transport_rec = TransportRec}),
{reply, Reply, State};

handle_call({get, TotalOfChunkedObjs, Req, Meta}, _From,
#state{key = Key, transport_rec = TransportRec} = State) ->
Reply = case leo_tran_serializable_cntnr:run(
Expand Down