Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
Lev Berman committed Jan 4, 2025
1 parent 5346b1b commit 94e4013
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
17 changes: 14 additions & 3 deletions apps/arweave/src/ar_chunk_storage.erl
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,8 @@ handle_cast(do_prepare_replica_2_9, State) ->
_ ->
SectorSize = ar_replica_2_9:get_sector_size(),
RangeStart2 = get_chunk_bucket_start(RangeStart + 1),
RepackSectorShift = (RepackCursor - RangeStart2) rem SectorSize,
RepackCursor2 = get_chunk_bucket_start(RepackCursor + 1),
RepackSectorShift = (RepackCursor2 - RangeStart2) rem SectorSize,
SectorShift = (PaddedEndOffset - RangeStart2) rem SectorSize,
case SectorShift > RepackSectorShift of
true ->
Expand Down Expand Up @@ -471,6 +472,13 @@ handle_cast(do_prepare_replica_2_9, State) ->
complete ->
{noreply, State#state{ is_prepared = true }};
waiting_for_repack ->
?LOG_INFO([{event, waiting_for_repacking},
{store_id, StoreID},
{padded_end_offset, PaddedEndOffset},
{repack_cursor, RepackCursor},
{cursor, Start},
{range_start, RangeStart},
{range_end, RangeEnd}]),
ar_util:cast_after(10000, self(), do_prepare_replica_2_9),
{noreply, State};
is_recorded ->
Expand Down Expand Up @@ -956,8 +964,11 @@ store_entropy(
case ar_storage_module:get_strict(
PaddedEndOffset, {replica_2_9, RewardAddr}) of
not_found ->
?LOG_WARNING([
{event, failed_to_find_storage_module_for_2_9_entropy},
{padded_end_offset, PaddedEndOffset}]),
not_found;
{ok, StoreID, _StorageModule} ->
{ok, StoreID} ->
{ok, StoreID}
end,
case FindModule of
Expand Down Expand Up @@ -1487,7 +1498,7 @@ get_repack_interval_size() ->
shift_repack_cursor(Cursor, RangeStart, RangeEnd) ->
RepackIntervalSize = get_repack_interval_size(),
SectorSize = ar_replica_2_9:get_sector_size(),
Cursor2 = get_chunk_bucket_start(Cursor + SectorSize + 1),
Cursor2 = get_chunk_bucket_start(Cursor + SectorSize + ?DATA_CHUNK_SIZE),
case Cursor2 > get_chunk_bucket_start(RangeEnd) of
true ->
RangeStart2 = get_chunk_bucket_start(RangeStart + 1),
Expand Down
16 changes: 10 additions & 6 deletions apps/arweave/src/ar_storage_module.erl
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,16 @@ get(Offset, Packing) ->
get(Offset, Packing, Config#config.storage_modules, not_found).

%% @doc Return a configured storage module with the given Packing covering the given Offset.
%% Return not_found if none is found.
%% Return not_found if none is found. If a module is configured with in-place repacking,
%% pick the target packing (the one we are repacking to.)
get_strict(Offset, Packing) ->
{ok, Config} = application:get_env(arweave, config),
get_strict(Offset, Packing, Config#config.storage_modules).
RepackInPlaceModulesStoreIDs = [
{{BucketSize, Bucket, TargetPacking}, ar_storage_module:id(Module)}
|| {{BucketSize, Bucket, _Packing} = Module, TargetPacking} <- Config#config.repack_in_place_storage_modules],
ModuleStoreIDs = [ar_storage_module:id(Module)
|| Module <- Config#config.storage_modules],
get_strict(Offset, Packing, ModuleStoreIDs ++ RepackInPlaceModulesStoreIDs).

%% @doc Return the list of all configured storage modules covering the given Offset.
get_all(Offset) ->
Expand Down Expand Up @@ -302,24 +308,22 @@ get(Offset, Packing, [{BucketSize, Bucket, Packing2} | StorageModules], StorageM
get(_Offset, _Packing, [], StorageModule) ->
StorageModule.

get_strict(Offset, Packing, [{BucketSize, Bucket, Packing2} | StorageModules]) ->
get_strict(Offset, Packing, [{{BucketSize, Bucket, Packing2}, StoreID} | StorageModules]) ->
case Offset =< BucketSize * Bucket
orelse Offset > BucketSize * (Bucket + 1) + get_overlap(Packing2) of
true ->
get_strict(Offset, Packing, StorageModules);
false ->
case Packing == Packing2 of
true ->
StoreID = ar_storage_module:id({BucketSize, Bucket, Packing}),
{ok, StoreID, {BucketSize, Bucket, Packing}};
{ok, StoreID};
false ->
get_strict(Offset, Packing, StorageModules)
end
end;
get_strict(_Offset, _Packing, []) ->
not_found.


get_overlap({replica_2_9, _Addr}) ->
?REPLICA_2_9_OVERLAP;
get_overlap(_Packing) ->
Expand Down

0 comments on commit 94e4013

Please sign in to comment.