-
Notifications
You must be signed in to change notification settings - Fork 839
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
SEARCH-300 (BTS-789) remove database directory for arangosearch #18420
Conversation
and a lot of refactoring
} | ||
return true; | ||
}); | ||
stale = static_cast<size_t>(end - it); |
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.
NIT
stale = static_cast<size_t>(end - it); | |
stale = static_cast<size_t>(std::distance(it, 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.
I completely disagree, if distance will do for each, I want instead of this code will be written ++stale in cycle above
// TODO(MBkkt) Why shouldn't we remove database data | ||
// if exists database with same name? |
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.
Because this thread executes the deletion at some point after the user issued a db._dropDatabase()
call.
Consider the following situation:
- user executes
db._dropDatabase("foo");
- user executes
db._createDatabase("foo");
- DatabaseManagerThread now finds the deleted database "foo". Shall it remove its application directory now? We cannot be sure about it, because it may be the new database's application directory.
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.
I understand, but we use id for new databases in path for v8 stuff (query register still use name :()
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.
We unfortunately use the database name for the Foxx app directories.
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.
Not always, please check following code
/// @brief return either the name of the database to be used as a folder name,
/// or its id if its name contains special characters and is not fully supported
/// in every OS
[[nodiscard]] static std::string_view getDatabaseDirName(std::string_view name,
std::string_view id) {
bool const isOldStyleName = DatabaseNameValidator::isAllowedName(
/*allowSystem=*/true, /*extendedNames=*/false, name);
return (isOldStyleName || id.empty()) ? name : id;
}
// compare-exchange failed. try again! | ||
expected = _refCount.load(std::memory_order_relaxed); | ||
} | ||
} while (!_refCount.compare_exchange_weak(v, v + 2, std::memory_order_acquire, |
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.
Why is the memory order acquire
here and not release
?
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.
Because we probably want to synchronize with markAsDropped (if don't want should be relaxed), and our +2 not needed for synchronization code.
You can look on intrusive_ptr as an a good example of this pattern
https://www.boost.org/doc/libs/1_81_0/libs/atomic/doc/html/atomic/usage_examples.html#boost_atomic.usage_examples.example_reference_counters
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.
For -2 we need release because we want to synchronize with isDangling
} | ||
|
||
void TRI_vocbase_t::forceUse() { _refCount += 2; } | ||
void TRI_vocbase_t::forceUse() noexcept { | ||
_refCount.fetch_add(2, std::memory_order_relaxed); |
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.
Should it be memory order release
here?
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.
Not
auto const v = _refCount.load(std::memory_order_acquire); | ||
TRI_ASSERT((v & 1) == 0 || !isSystem()); | ||
return v == 1; |
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.
I think this could be a behavior change and may be unsafe.
It someone manages to set the drop bit on the system database, this function will now return true
, but previously it always returned false
. It could have unintended side-effects for example in the DatabaseManagerThread, which will remove the database then if this function here returns true.
ofc it would be useful to not allow to set the drop bit for the system database in the first place, but this function here previously provided some extra security.
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.
No, please see assert in markAsDropped.
System database is never isDropped, so it's never isDangling
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.
I guess ASSERT than should be our choice. As system database should never have delete bit set.
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.
LGTM in general. See comments and this PR needs tests
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.
LGTM
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.
LGTM
Scope & Purpose
SEARCH-300 remove database directory for arangosearch
and a lot of refactoring
Checklist
Related Information
(Please reference tickets / specification / other PRs etc)