-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[deprecated]86318 move geo index directories and files when database is deleted #3
base: master
Are you sure you want to change the base?
Conversation
6e96337
to
36b31c7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks mostly good. I'm questioning the path generation in hastings_util:rename_dir/3 and the hastings_vacuum:cleanup/3 could use some refactoring for simplification.
src/hastings_util.erl
Outdated
|
||
|
||
rename_dir(RootDelDir, Original, DbName) -> | ||
GeoIdxDirList = lists:subtract( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic looks wrong to me. The first thing that comes to mind is if there are repeated directory names. I think we usually do this relative offset using a binary:longest_common_prefix or something.
src/hastings_vacuum.erl
Outdated
]). | ||
|
||
|
||
-record(st, { | ||
queue = queue:new(), | ||
cleaner | ||
qSelectiveClean = queue:new(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Big nope to hungarian notation and camel case. Call these selective_clean and full_clean.
src/hastings_vacuum.erl
Outdated
true -> | ||
ActiveSigs = [] | ||
end, | ||
cleanup(DbName, ActiveSigs, Options). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than have cleanup do the switching logic between the kind of deletions to perform it'd probably be better to have that logic here. Something like:
Context = couch_util:get_value(context, Options, compaction),
DoRecovery = config:get_boolean("couchdb", "enable_database_recovery", false),
case {Context, DoRecovery} of
{delete, true} ->
move_all_indexes(DbName);
{delete, false} ->
delete_all_indexes(DbName);
_ ->
delete_inactive_indexes(DbName, get_active_sigs())
end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactored with your suggestion
4373362
to
b138b7b
Compare
@davisp Thanks a lot for your review. I have addressed your comments and also added eunit test. Would you please review when you get time? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor nit on the path processing, +1 once that's addressed.
src/hastings_util.erl
Outdated
PrefLen = binary:longest_common_prefix( | ||
[list_to_binary(RootDir), Original] | ||
), | ||
% skip directory separator, such as "/" or "\" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't the directory separator be part of the longest common prefix? If not I'd still rather see this as an assertion, something along the lines of:
case Original of
<<"/", Rest/binary>> -> Rest;
<<"\", Rest/binary>> -> Rest;
_ -> Other
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Under current situation, the RootDir
doesn't contain the last directory separator, for example:
RootDir = /srv/geo_index
Original = <<"/srv/geo_index/shards/00000000-06666665/user1/db1.1480
073506/20b5ad91cc1334a53700c5da3e835d91">>
I want to remove the "/" in front of shards
.
Thanks for your suggestion, I already added assertion to adapt to more situations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
8d00a79
to
15c0b6b
Compare
Bugzid: 86318
Overview
Before change, the geo index directories and files were not deleted when database was deleted. This will cause orphan geo index files and directories. In detail, when database was deleted, the
gen_server:cast(?MODULE, {cleanup, DbName})
was called inhttps://github.com/cloudant-labs/hastings/blob/master/src/hastings_vacuum.erl#L99. Later,
{ok, JsonDDocs} = get_ddocs(DbName)
inclean_db/1
was called. Because database was deleted,{'DOWN', Ref, _, _, {error, database_does_not_exist}}
message was sent in https://github.com/cloudant-labs/hastings/blob/master/src/hastings_vacuum.erl#L149. Finally,cleanup(DbName, ActiveSigs)
was not called in https://github.com/cloudant-labs/hastings/blob/master/src/hastings_vacuum.erl#L127.This PR is aimed to address above issue and take action against geo index when database is deleted.
The direct approach is to delete geo index files and directoires when database is deleted, i.e. https://github.com/cloudant-labs/hastings/pull/3/files#diff-7ac6be6388d90e131766d8c5824cb226R259
The second approach is to move geo index to directory like
/srv/geo/./.recovery/<dbname.ts>/shard/60000000-7fffffff/<dbname.ts>/e66df316792ab411705e2741bba44371
when the corresponding database was deleted and "enable_database_recovery" configuration item is set to true. This allows geo index files to be re-used if database is recovered.https://github.com/cloudant-labs/hastings/pull/3/files#diff-7ac6be6388d90e131766d8c5824cb226R259
Testing recommendations
GitHub issue number
This PR will be the number
Related Pull Requests
N/A
Checklist