Skip to content

Fix cleanup_index_files in smoosh so we can enable it by default #4239

@nickva

Description

@nickva

cleanup_index_files is currently disabled by default:

cleanup_index_files(DbName, _Shard) ->
case config:get("smoosh", "cleanup_index_files", "false") of
"true" ->
fabric:cleanup_index_files(DbName);
_ ->
ok
end.

When enabled it can misbehave, especially in cases when there are lot of concurrent view compactions. As implemented currently cleanup_index_files spawns a simple, unmonitored process on each shard compaction start

spawn(fun() -> cleanup_index_files(DbName, Shard) end),
Ref = erlang:monitor(process, Pid),
Pid ! {'$gen_call', {self(), Ref}, compact},
State#state{starting = [{Ref, {Shard, GroupId}} | State#state.starting]};
:

During cleanup it performs a cluster-wide fabric call to fetch all design docs and then does wildcard view index folder search for stale files. Since this happens at the cluster database level we end performing the exact same cleanup action for the same fabric db Q times. With the fetching all ddocs and the wildcard directory search this operation can quickly overwhelm the cluster, falling behind while creating these unbounded processes, often doing redundant work.

At the same time, it would be nice to have the ability to cleanup stale view index files so they don't keep piling up and being able to default this setting to true.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions