mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-17 21:24:28 +00:00
make db replicated inherited from atomic
This commit is contained in:
parent
c0924b5911
commit
f103e24a09
@ -81,7 +81,7 @@ DatabaseReplicated::DatabaseReplicated(
|
||||
// : DatabaseOrdinary(name_, metadata_path_, "data/" + escapeForFileName(name_) + "/", "DatabaseReplicated (" + name_ + ")", context_)
|
||||
// TODO add constructor to Atomic and call it here with path and logger name specification
|
||||
// TODO ask why const and & are ommited in Atomic
|
||||
: DatabaseOrdinary(name_, metadata_path_, context_)
|
||||
: DatabaseAtomic(name_, metadata_path_, context_)
|
||||
, zookeeper_path(zookeeper_path_)
|
||||
, replica_name(replica_name_)
|
||||
{
|
||||
@ -122,8 +122,7 @@ void DatabaseReplicated::runMainThread() {
|
||||
|
||||
while (!stop_flag) {
|
||||
attachToThreadGroup();
|
||||
|
||||
sleepForSeconds(2);
|
||||
sleepForSeconds(1);// BURN CPU
|
||||
current_zookeeper = getZooKeeper();
|
||||
String last_n;
|
||||
if (!current_zookeeper->tryGet(zookeeper_path + "/last_entry", last_n, {}, NULL)) {
|
||||
@ -136,7 +135,6 @@ void DatabaseReplicated::runMainThread() {
|
||||
current_log_entry_n++;
|
||||
executeLog(current_log_entry_n);
|
||||
}
|
||||
// break; // debug purpose
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <Databases/DatabaseOrdinary.h>
|
||||
#include <Databases/DatabaseAtomic.h>
|
||||
#include <Common/randomSeed.h>
|
||||
#include <Common/ZooKeeper/ZooKeeper.h>
|
||||
|
||||
@ -14,7 +14,7 @@ namespace DB
|
||||
* that contain declaration of table represented by SQL ATTACH TABLE query
|
||||
* and operation log in zookeeper
|
||||
*/
|
||||
class DatabaseReplicated : public DatabaseOrdinary
|
||||
class DatabaseReplicated : public DatabaseAtomic
|
||||
{
|
||||
public:
|
||||
DatabaseReplicated(const String & name_, const String & metadata_path_, const String & zookeeper_path_, const String & replica_name_, Context & context);
|
||||
|
@ -98,7 +98,7 @@ void DatabaseWithOwnTablesBase::attachTableUnlocked(const String & table_name, c
|
||||
auto table_id = table->getStorageID();
|
||||
if (table_id.hasUUID())
|
||||
{
|
||||
assert(getDatabaseName() == DatabaseCatalog::TEMPORARY_DATABASE || getEngineName() == "Atomic");
|
||||
assert(getDatabaseName() == DatabaseCatalog::TEMPORARY_DATABASE || getEngineName() == "Atomic" || getEngineName() == "Replicated");
|
||||
DatabaseCatalog::instance().addUUIDMapping(table_id.uuid, shared_from_this(), table);
|
||||
}
|
||||
}
|
||||
|
@ -627,7 +627,7 @@ bool InterpreterCreateQuery::doCreateTable(ASTCreateQuery & create,
|
||||
if (need_add_to_database)
|
||||
{
|
||||
database = DatabaseCatalog::instance().getDatabase(create.database);
|
||||
if (database->getEngineName() == "Atomic") // || database->getEngineName() == "Replicated")
|
||||
if (database->getEngineName() == "Atomic" || (database->getEngineName() == "Replicated" && !context.from_replicated_log))
|
||||
{
|
||||
/// TODO implement ATTACH FROM 'path/to/data': generate UUID and move table data to store/
|
||||
if (create.attach && create.uuid == UUIDHelpers::Nil)
|
||||
@ -635,6 +635,11 @@ bool InterpreterCreateQuery::doCreateTable(ASTCreateQuery & create,
|
||||
if (!create.attach && create.uuid == UUIDHelpers::Nil)
|
||||
create.uuid = UUIDHelpers::generateV4();
|
||||
}
|
||||
else if (database->getEngineName() == "Replicated" && context.from_replicated_log) {
|
||||
if (create.uuid == UUIDHelpers::Nil)
|
||||
// change error to incorrect log or something
|
||||
throw Exception("Table UUID is not specified in the replicated log", ErrorCodes::INCORRECT_QUERY);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (create.uuid != UUIDHelpers::Nil)
|
||||
@ -703,16 +708,9 @@ bool InterpreterCreateQuery::doCreateTable(ASTCreateQuery & create,
|
||||
|
||||
|
||||
if (database->getEngineName() == "Replicated" && !context.from_replicated_log) {
|
||||
// propose
|
||||
// try to
|
||||
database->propose(query_ptr);
|
||||
database->createTable(context, table_name, res, query_ptr);
|
||||
// catch
|
||||
// throw and remove proposal
|
||||
// otherwise
|
||||
// proceed (commit to zk)
|
||||
} else
|
||||
database->createTable(context, table_name, res, query_ptr);
|
||||
}
|
||||
database->createTable(context, table_name, res, query_ptr);
|
||||
|
||||
/// We must call "startup" and "shutdown" while holding DDLGuard.
|
||||
/// Because otherwise method "shutdown" (from InterpreterDropQuery) can be called before startup
|
||||
|
@ -93,8 +93,8 @@ BlockIO InterpreterDropQuery::executeToTable(
|
||||
{
|
||||
context.checkAccess(table->isView() ? AccessType::DROP_VIEW : AccessType::DROP_TABLE, table_id);
|
||||
table->shutdown();
|
||||
TableExclusiveLockHolder table_lock;
|
||||
if (database->getEngineName() != "Atomic")
|
||||
TableStructureWriteLockHolder table_lock;
|
||||
if (database->getEngineName() != "Atomic" && database->getEngineName() != "Replicated")
|
||||
table_lock = table->lockExclusively(context.getCurrentQueryId(), context.getSettingsRef().lock_acquire_timeout);
|
||||
/// Drop table from memory, don't touch data and metadata
|
||||
if (database->getEngineName() == "Replicated" && !context.from_replicated_log) {
|
||||
@ -119,8 +119,13 @@ BlockIO InterpreterDropQuery::executeToTable(
|
||||
|
||||
table->shutdown();
|
||||
|
||||
<<<<<<< HEAD
|
||||
TableExclusiveLockHolder table_lock;
|
||||
if (database->getEngineName() != "Atomic")
|
||||
=======
|
||||
TableStructureWriteLockHolder table_lock;
|
||||
if (database->getEngineName() != "Atomic" && database->getEngineName() != "Replicated")
|
||||
>>>>>>> 921e85e9c9... make db replicated inherited from atomic
|
||||
table_lock = table->lockExclusively(context.getCurrentQueryId(), context.getSettingsRef().lock_acquire_timeout);
|
||||
|
||||
if (database->getEngineName() == "Replicated" && !context.from_replicated_log) {
|
||||
|
Loading…
Reference in New Issue
Block a user