mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-14 02:12:21 +00:00
rm old files from nonexistant dir since the rebase
This commit is contained in:
parent
0d392bbb34
commit
1cb96bf176
@ -1,215 +0,0 @@
|
|||||||
#include <iomanip>
|
|
||||||
|
|
||||||
#include <Core/Settings.h>
|
|
||||||
#include <Databases/DatabaseOnDisk.h>
|
|
||||||
#include <Databases/DatabaseReplicated.h>
|
|
||||||
#include <Databases/DatabasesCommon.h>
|
|
||||||
#include <IO/ReadBufferFromFile.h>
|
|
||||||
#include <IO/ReadHelpers.h>
|
|
||||||
#include <IO/WriteBufferFromFile.h>
|
|
||||||
#include <IO/WriteHelpers.h>
|
|
||||||
#include <Interpreters/Context.h>
|
|
||||||
#include <Interpreters/InterpreterCreateQuery.h>
|
|
||||||
#include <Parsers/ASTCreateQuery.h>
|
|
||||||
#include <Parsers/ASTSetQuery.h>
|
|
||||||
#include <Parsers/ParserCreateQuery.h>
|
|
||||||
#include <Parsers/formatAST.h>
|
|
||||||
#include <Parsers/parseQuery.h>
|
|
||||||
#include <Storages/StorageFactory.h>
|
|
||||||
#include <TableFunctions/TableFunctionFactory.h>
|
|
||||||
|
|
||||||
#include <Parsers/queryToString.h>
|
|
||||||
|
|
||||||
#include <Poco/DirectoryIterator.h>
|
|
||||||
#include <Poco/Event.h>
|
|
||||||
#include <Common/Stopwatch.h>
|
|
||||||
#include <Common/ThreadPool.h>
|
|
||||||
#include <Common/escapeForFileName.h>
|
|
||||||
#include <Common/quoteString.h>
|
|
||||||
#include <Common/typeid_cast.h>
|
|
||||||
#include <common/logger_useful.h>
|
|
||||||
|
|
||||||
#include <Common/ZooKeeper/KeeperException.h>
|
|
||||||
#include <Common/ZooKeeper/Types.h>
|
|
||||||
#include <Common/ZooKeeper/ZooKeeper.h>
|
|
||||||
|
|
||||||
#include <ext/scope_guard.h>
|
|
||||||
|
|
||||||
namespace DB
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
namespace ErrorCodes
|
|
||||||
{
|
|
||||||
extern const int NO_ZOOKEEPER;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DatabaseReplicated::setZooKeeper(zkutil::ZooKeeperPtr zookeeper)
|
|
||||||
{
|
|
||||||
std::lock_guard lock(current_zookeeper_mutex);
|
|
||||||
current_zookeeper = zookeeper;
|
|
||||||
}
|
|
||||||
|
|
||||||
zkutil::ZooKeeperPtr DatabaseReplicated::tryGetZooKeeper() const
|
|
||||||
{
|
|
||||||
std::lock_guard lock(current_zookeeper_mutex);
|
|
||||||
return current_zookeeper;
|
|
||||||
}
|
|
||||||
|
|
||||||
zkutil::ZooKeeperPtr DatabaseReplicated::getZooKeeper() const
|
|
||||||
{
|
|
||||||
auto res = tryGetZooKeeper();
|
|
||||||
if (!res)
|
|
||||||
throw Exception("Cannot get ZooKeeper", ErrorCodes::NO_ZOOKEEPER);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DatabaseReplicated::DatabaseReplicated(
|
|
||||||
const String & name_,
|
|
||||||
const String & metadata_path_,
|
|
||||||
const String & zookeeper_path_,
|
|
||||||
const String & replica_name_,
|
|
||||||
const Context & context_)
|
|
||||||
: DatabaseOrdinary(name_, metadata_path_, context_)
|
|
||||||
, zookeeper_path(zookeeper_path_)
|
|
||||||
, replica_name(replica_name_)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (!zookeeper_path.empty() && zookeeper_path.back() == '/')
|
|
||||||
zookeeper_path.resize(zookeeper_path.size() - 1);
|
|
||||||
/// If zookeeper chroot prefix is used, path should start with '/', because chroot concatenates without it.
|
|
||||||
if (!zookeeper_path.empty() && zookeeper_path.front() != '/')
|
|
||||||
zookeeper_path = "/" + zookeeper_path;
|
|
||||||
replica_path = zookeeper_path + "/replicas/" + replica_name;
|
|
||||||
|
|
||||||
if (context_.hasZooKeeper()) {
|
|
||||||
current_zookeeper = context_.getZooKeeper();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!current_zookeeper)
|
|
||||||
{
|
|
||||||
// TODO wtf is attach
|
|
||||||
// if (!attach)
|
|
||||||
throw Exception("Can't create replicated table without ZooKeeper", ErrorCodes::NO_ZOOKEEPER);
|
|
||||||
|
|
||||||
/// Do not activate the replica. It will be readonly.
|
|
||||||
// TODO is it relevant for engines?
|
|
||||||
// LOG_ERROR(log, "No ZooKeeper: database will be in readonly mode.");
|
|
||||||
// TODO is_readonly = true;
|
|
||||||
// return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// can the zk path exist and no metadata on disk be available at the same moment? if so, in such a case, the db instance must be restored.
|
|
||||||
|
|
||||||
current_zookeeper->createIfNotExists(zookeeper_path, String());
|
|
||||||
current_zookeeper->createIfNotExists(replica_path, String());
|
|
||||||
// TODO what to do?
|
|
||||||
// TODO createDatabaseIfNotExists ?
|
|
||||||
// TODO check database structure ?
|
|
||||||
}
|
|
||||||
|
|
||||||
void DatabaseReplicated::createTable(
|
|
||||||
const Context & context,
|
|
||||||
const String & table_name,
|
|
||||||
const StoragePtr & table,
|
|
||||||
const ASTPtr & query)
|
|
||||||
{
|
|
||||||
// try
|
|
||||||
DatabaseOnDisk::createTable(context, table_name, table, query);
|
|
||||||
|
|
||||||
// replicated stuff
|
|
||||||
String statement = getObjectDefinitionFromCreateQuery(query);
|
|
||||||
auto zookeeper = getZooKeeper();
|
|
||||||
// TODO в чем прикол именно так создавать зиноды?
|
|
||||||
Coordination::Requests ops;
|
|
||||||
ops.emplace_back(zkutil::makeCreateRequest(zookeeper_path, "",
|
|
||||||
zkutil::CreateMode::Persistent));
|
|
||||||
ops.emplace_back(zkutil::makeCreateRequest(zookeeper_path + "/metadata", metadata,
|
|
||||||
zkutil::CreateMode::Persistent));
|
|
||||||
// ops.emplace_back(zkutil::makeCreateRequest(zookeeper_path + "/columns", getColumns().toString(),
|
|
||||||
// zkutil::CreateMode::Persistent));
|
|
||||||
ops.emplace_back(zkutil::makeCreateRequest(zookeeper_path + "/log", "",
|
|
||||||
zkutil::CreateMode::Persistent));
|
|
||||||
// ops.emplace_back(zkutil::makeCreateRequest(zookeeper_path + "/blocks", "",
|
|
||||||
// zkutil::CreateMode::Persistent));
|
|
||||||
// ops.emplace_back(zkutil::makeCreateRequest(zookeeper_path + "/block_numbers", "",
|
|
||||||
// zkutil::CreateMode::Persistent));
|
|
||||||
// ops.emplace_back(zkutil::makeCreateRequest(zookeeper_path + "/nonincrement_block_numbers", "",
|
|
||||||
// zkutil::CreateMode::Persistent)); /// /nonincrement_block_numbers dir is unused, but is created nonetheless for backwards compatibility.
|
|
||||||
// TODO do we need a leader here? (probably yes) what is it gonna do?
|
|
||||||
ops.emplace_back(zkutil::makeCreateRequest(zookeeper_path + "/leader_election", "",
|
|
||||||
zkutil::CreateMode::Persistent));
|
|
||||||
ops.emplace_back(zkutil::makeCreateRequest(zookeeper_path + "/temp", "",
|
|
||||||
zkutil::CreateMode::Persistent));
|
|
||||||
ops.emplace_back(zkutil::makeCreateRequest(zookeeper_path + "/replicas", "",
|
|
||||||
zkutil::CreateMode::Persistent));
|
|
||||||
|
|
||||||
Coordination::Responses responses;
|
|
||||||
auto code = zookeeper->tryMulti(ops, responses);
|
|
||||||
if (code && code != Coordination::ZNODEEXISTS)
|
|
||||||
throw Coordination::Exception(code);
|
|
||||||
|
|
||||||
// ...
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DatabaseReplicated::renameTable(
|
|
||||||
const Context & context,
|
|
||||||
const String & table_name,
|
|
||||||
IDatabase & to_database,
|
|
||||||
const String & to_table_name,
|
|
||||||
TableStructureWriteLockHolder & lock)
|
|
||||||
{
|
|
||||||
// try
|
|
||||||
DatabaseOnDisk::renameTable(context, table_name, to_database, to_table_name, lock);
|
|
||||||
// replicated stuff
|
|
||||||
String statement = getObjectDefinitionFromCreateQuery(query);
|
|
||||||
// this one is fairly more complex
|
|
||||||
}
|
|
||||||
|
|
||||||
void DatabaseReplicated::removeTable(
|
|
||||||
const Context & context,
|
|
||||||
const String & table_name)
|
|
||||||
{
|
|
||||||
// try
|
|
||||||
DatabaseOnDisk::removeTable(context, table_name);
|
|
||||||
// replicated stuff
|
|
||||||
String statement = getObjectDefinitionFromCreateQuery(query);
|
|
||||||
// ...
|
|
||||||
}
|
|
||||||
|
|
||||||
void DatabaseReplicated::drop(const Context & context)
|
|
||||||
{
|
|
||||||
DatabaseOnDisk::drop(context);
|
|
||||||
// replicated stuff
|
|
||||||
String statement = getObjectDefinitionFromCreateQuery(query);
|
|
||||||
// should it be possible to recover after a drop.
|
|
||||||
// if not, we can just delete all the zookeeper nodes starting from
|
|
||||||
// zookeeper path. does it work recursively? hope so...
|
|
||||||
}
|
|
||||||
|
|
||||||
void DatabaseOrdinary::loadStoredObjects(
|
|
||||||
Context & context,
|
|
||||||
bool has_force_restore_data_flag)
|
|
||||||
{
|
|
||||||
syncReplicaState(context);
|
|
||||||
updateMetadata(context);
|
|
||||||
|
|
||||||
DatabaseOrdinary::loadStoredObjects(context, has_force_restore_data_flag);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// sync replica's zookeeper metadata
|
|
||||||
void syncReplicaState(Context & context) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// get the up to date metadata from zookeeper to local metadata dir
|
|
||||||
// for replicated (only?) tables
|
|
||||||
void updateMetadata(Context & context) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,61 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <Databases/DatabaseOrdinary.h>
|
|
||||||
#include <Common/randomSeed.h>
|
|
||||||
#include <Common/ZooKeeper/ZooKeeper.h>
|
|
||||||
|
|
||||||
namespace DB
|
|
||||||
{
|
|
||||||
/** Replicated database engine.
|
|
||||||
* It stores tables list using list of .sql files,
|
|
||||||
* that contain declaration of table represented by SQL ATTACH TABLE query
|
|
||||||
* and operation log in zookeeper
|
|
||||||
*/
|
|
||||||
class DatabaseReplicated : public DatabaseOrdinary
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
DatabaseReplicated(const String & name_, const String & metadata_path_, const String & zookeeper_path_, const String & replica_name_, const Context & context);
|
|
||||||
|
|
||||||
String getEngineName() const override { return "Replicated"; }
|
|
||||||
|
|
||||||
void createTable(
|
|
||||||
const Context & context,
|
|
||||||
const String & table_name,
|
|
||||||
const StoragePtr & table,
|
|
||||||
const ASTPtr & query) override;
|
|
||||||
|
|
||||||
void removeTable(
|
|
||||||
const Context & context,
|
|
||||||
const String & table_name) override;
|
|
||||||
|
|
||||||
void renameTable(
|
|
||||||
const Context & context,
|
|
||||||
const String & table_name,
|
|
||||||
IDatabase & to_database,
|
|
||||||
const String & to_table_name,
|
|
||||||
TableStructureWriteLockHolder & lock) override;
|
|
||||||
|
|
||||||
void drop(const Context & context) override;
|
|
||||||
|
|
||||||
void loadStoredObjects(
|
|
||||||
Context & context,
|
|
||||||
bool has_force_restore_data_flag) override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
String zookeeper_path;
|
|
||||||
String replica_name;
|
|
||||||
String replica_path;
|
|
||||||
|
|
||||||
zkutil::ZooKeeperPtr current_zookeeper; /// Use only the methods below.
|
|
||||||
mutable std::mutex current_zookeeper_mutex; /// To recreate the session in the background thread.
|
|
||||||
|
|
||||||
zkutil::ZooKeeperPtr tryGetZooKeeper() const;
|
|
||||||
zkutil::ZooKeeperPtr getZooKeeper() const;
|
|
||||||
void setZooKeeper(zkutil::ZooKeeperPtr zookeeper);
|
|
||||||
|
|
||||||
void syncReplicaState(Context & context);
|
|
||||||
|
|
||||||
void updateMetadata(Context & context);
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user