@@ -48,16 +48,16 @@ start(_) -> error(s3_profile_not_enabled).
4848-define (DEFAULT_REGION , <<" us-east-1" >>).
4949-define (DEFAULT_ENDPOINT , <<" https://s3.amazonaws.com" >>).
5050-define (DEFAULT_FORCE_PATH_STYLE , <<" false" >>).
51- -define (MAX_REDIRECTS , 100 ). % Only resolve 1000 links to data
52- -define (LINK_MARKER , <<" link:" >>).
53- % % Namespace for storing link objects separately to avoid file collisions
54- -define (CREATE_GROUP_KEY , <<" make_group" >>).
55-
51+ -define (MAX_REDIRECTS , 100 ).
5652-define (DEFAULT_RETRY_DELAY , 1000 ). % Wait for 1 second before retry.
5753-define (DEFAULT_RETRY_MODE , exp_backoff ).
5854-define (DEFAULT_RETRIES , 5 ). % Retries for 5 times until it returns.
5955-define (DEFAULT_MAX_RETRY_DELAY , 300000 ). % Max 5 minutes waiting to retry.
60-
56+ -define (LINK_MARKER , <<" link:" >>).
57+ % Key that symbolizes a group, since in S3 directories doesn't exist.
58+ -define (CREATE_GROUP_KEY , <<" make_group" >>).
59+ % Split the first key into at 2, one with 4 byte size, and the other
60+ % with the remaining
6161-define (SHARD_CUT , 4 ).
6262
6363% % @doc Initialize the S3 store connection.
@@ -87,7 +87,7 @@ start(Opts) ->
8787 s3_bucket_after_host = false ,
8888 s3_bucket_access_method = ForcePathStyle ,
8989 aws_region = Region ,
90- % Use `gun_pool` to define a connection pool.
90+ % Use `gun_pool` to define a connection pool. Default is `httpc`
9191 http_client = fun gun_request /6
9292 },
9393 ok ?= test_bucket_access (Bucket , Config ),
@@ -222,7 +222,7 @@ write(Opts, Key, Value, AttemptsRemaining) ->
222222 }
223223 ),
224224 try erlcloud_s3 :put_object (BucketStr , ShardedKeyStr , Value , [], Config ) of
225- L when is_list (L ) -> ok
225+ Response when is_list (Response ) -> ok
226226 catch
227227 Class :Reason ->
228228 ? event (error ,
@@ -350,6 +350,15 @@ read_direct(Opts, Key) ->
350350 not_found
351351 end .
352352
353+ % % @doc Shardk the first key (excluding `data`) into 2 parts defined
354+ % % by ?SHARD_CUT:
355+ % % - String with ?SHARD_CUT length
356+ % % - String with the reamining length
357+ % %
358+ % % NOTE: Keys with byte size of 4 or less aren't supported (excepted `data`).
359+ % %
360+ % % > shard_key(<<"UDgFxz7qUcB_TijjDfhUpXD3UGXpw8Xq6OrpoDiv3Y0">>).
361+ % % <<"UDgF/xz7qUcB_TijjDfhUpXD3UGXpw8Xq6OrpoDiv3Y0">>
353362-spec shard_key (binary ()) -> binary ().
354363shard_key (<<" data/" , DataKey /binary >>) ->
355364 ShardedKey = shard_key (DataKey ),
@@ -459,8 +468,7 @@ is_link(Value) ->
459468 end .
460469
461470% % @doc Create a group (virtual directory).
462- % % In S3, directories don't really exist, so this is a no-op.
463- % % Groups are detected by listing operations.
471+ % % In S3, directories don't really exist. We create a file to represent them.
464472-spec make_group (opts (), key ()) -> ok .
465473make_group (Opts , Path ) ->
466474 GroupKey = create_make_group_key (Path ),
@@ -594,7 +602,8 @@ head_exists(Opts, Key) when is_binary(Key) ->
594602 ShardedKeyStr = hb_util :list (ShardedKey ),
595603 ? event (store_s3 , {head_exists , {key , Key }}),
596604 try
597- is_list (erlcloud_s3 :head_object (BucketStr , ShardedKeyStr , [], Config ))
605+ Response = erlcloud_s3 :head_object (BucketStr , ShardedKeyStr , [], Config ),
606+ is_list (Response )
598607 catch
599608 _ :_ -> false
600609 end .
0 commit comments