Skip to content

DatabaseAtomic#7512

Merged
tavplubix merged 101 commits intomasterfrom
database_atomic
Apr 24, 2020
Merged

DatabaseAtomic#7512
tavplubix merged 101 commits intomasterfrom
database_atomic

Conversation

@tavplubix
Copy link
Copy Markdown
Member

@tavplubix tavplubix commented Oct 28, 2019

I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en

For changelog. Remove if this is non-significant change.

Category (leave one):

  • New Feature

Short description (up to few sentences):
Added experimental database engine Atomic. It supports non-blocking DROP and RENAME TABLE queries and atomic EXCHANGE TABLES t1 AND t2 query
#6787

@stavrolia stavrolia added the pr-feature Pull request with new product feature label Oct 28, 2019
databases.emplace(unescapeForFileName(it.name()), it.path().toString());
}

if (!default_database_name.empty() && !databases.count(default_database_name))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, add comment.


static void renameat2(const std::string & old_path, const std::string & new_path, int flags)
{
if (old_path.empty() || new_path.empty())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, use more detailed exception message.
Like Cannot rename old_path to new_path because one of them is empty or Cannot rename old_path to new_path because one of them is absolute.

@@ -0,0 +1,122 @@
#include <Common/rename.h>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think file name is too general.
At least better to use renameDirectory.h or something.

return;

if (errno == EEXIST)
throwFromErrnoWithPath("Cannot RENAME_NOREPLACE " + old_path + " to " + new_path, new_path, ErrorCodes::ATOMIC_RENAME_FAIL);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot rename old_path to new_path because path is already exists.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, add the comment to throwFromErrnoWithPath declaration in Exception.h

if (errno == EEXIST)
throwFromErrnoWithPath("Cannot RENAME_NOREPLACE " + old_path + " to " + new_path, new_path, ErrorCodes::ATOMIC_RENAME_FAIL);
if (errno == ENOENT)
throwFromErrno("Paths cannot be exchanged because " + old_path + " or " + new_path + " does not exist", ErrorCodes::ATOMIC_RENAME_FAIL);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good comment.
But why we don't use throwFromErrnoWithPath now?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of RENAME_EXCHANGE we cannot choose one of them. However, throwFromErrnoWithPath is useful only to add information about available space and inodes to exception message

/// Do not use [[noreturn]] to avoid warnings like "code will never be executed" in other places
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmissing-noreturn"
static void renameExchangeFallback(const std::string &, const std::string &)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this function?
maybe throw exception right into renameExchange

Copy link
Copy Markdown
Member Author

@tavplubix tavplubix Apr 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need it to suppress warnings like declaration missing '[[noreturn]]' and code will never be executed in MacOS build only for this exception and this function.


void loadStoredObjects(Context & context, bool has_force_restore_data_flag) override;

void assertCanBeDetached(bool cleenup);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment is needed.



DatabaseAtomic::DatabaseAtomic(String name_, String metadata_path_, Context & context_)
: DatabaseOrdinary(name_, metadata_path_, "store/", "DatabaseAtomic (" + name_ + ")", context_)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::move for name_ and metadata_path_

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name_ cannot be moved because it's also used in other argument

@tavplubix tavplubix removed the pr-improvement Pull request with some product improvements label Apr 23, 2020
@azat
Copy link
Copy Markdown
Member

azat commented May 17, 2020

@tavplubix
Copy link
Copy Markdown
Member Author

It's SIGABRT caused by std::terminate() call when ALTER tries to rewrite metadata after database was dropped.
#10968

@azat azat mentioned this pull request May 17, 2020
@winter7
Copy link
Copy Markdown

winter7 commented Jun 2, 2020

Can we "alter" a database to Atomic engine?

@tavplubix
Copy link
Copy Markdown
Member Author

Can we "alter" a database to Atomic engine?

As for now it can be done only manually by modifying metadata files and moving data of tables. Also it's possible to RENAME TABLE db_ordinary.table_name TO db_atomic.table_name. But notice that Atomic engine is experimetal and backward compatibility may be broken in future versions. Ability to alter a database from Ordinary to Atomic engine will be probably added later.

@winter7
Copy link
Copy Markdown

winter7 commented Jun 9, 2020

Thanks! I think I will wait for the official ALTER release and keep an eye on this engine.

@tavplubix tavplubix restored the database_atomic branch September 24, 2020 23:07
@tavplubix tavplubix deleted the database_atomic branch September 26, 2020 23:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-feature Pull request with new product feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants