Skip to content

Commit

Permalink
support force drop big stream (#823)
Browse files Browse the repository at this point in the history
  • Loading branch information
yokofly authored Aug 19, 2024
1 parent 8488d6e commit eca386e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/Core/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,7 @@ static constexpr UInt64 operator""_GiB(unsigned long long value)
M(String, replay_time_column, "_tp_append_time", "user specified replay time column, default column is _tp_append_time", 0) \
M(UInt64, max_events, 0, "Total events to generate for random stream", 0) \
M(Float, eps, -1., "control the random stream eps in query time, defalut value is -1, if it is 0 means no limit.", 0) \
M(Bool, force_drop_big_stream, false, "When enabled, the query can directly force drop big stream greater than configured `max_[stream/partition]_size_to_drop`", 0) \
// End of GLOBAL_SETTINGS

#define CONFIGURABLE_GLOBAL_SETTINGS(M) \
Expand Down
10 changes: 7 additions & 3 deletions src/Interpreters/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2803,8 +2803,10 @@ const StorageS3Settings & Context::getStorageS3Settings() const

void Context::checkCanBeDropped(const String & database, const String & table, const size_t & size, const size_t & max_size_to_drop) const
{
if (!max_size_to_drop || size <= max_size_to_drop)
/// proton: starts. add setting `force_drop_big_stream`
if (!max_size_to_drop || size <= max_size_to_drop || getSettingsRef().force_drop_big_stream)
return;
/// proton: ends.

fs::path force_file(getFlagsPath() + "force_drop_table");
bool force_file_exists = fs::exists(force_file);
Expand All @@ -2827,11 +2829,13 @@ void Context::checkCanBeDropped(const String & database, const String & table, c
String max_size_to_drop_str = formatReadableSizeWithDecimalSuffix(max_size_to_drop);
throw Exception(ErrorCodes::STREAM_SIZE_EXCEEDS_MAX_DROP_SIZE_LIMIT,
"Stream or Partition in {}.{} was not dropped.\nReason:\n"
"1. Size ({}) is greater than max_[table/partition]_size_to_drop ({})\n"
"1. Size ({}) is greater than max_[stream/partition]_size_to_drop ({})\n"
"2. File '{}' intended to force DROP {}\n"
"3. Setting 'force_drop_big_stream' is not set\n"
"How to fix this:\n"
"1. Either increase (or set to zero) max_[stream/partition]_size_to_drop in server config\n"
"2. Either create forcing file {} and make sure that proton has write permission for it.\n"
"2. Either create forcing file {} and make sure that timeplus DBMS has write permission for it.\n"
"3. Either add setting 'force_drop_big_stream=true'\n"
"Example:\nsudo touch '{}' && sudo chmod 666 '{}'",
backQuoteIfNeed(database), backQuoteIfNeed(table),
size_str, max_size_to_drop_str,
Expand Down
4 changes: 2 additions & 2 deletions src/Storages/StorageMergeTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,10 @@ StorageMergeTree::write(const ASTPtr & /*query*/, const StorageMetadataPtr & met
void StorageMergeTree::checkTableCanBeDropped(ContextPtr context_) const
{
IStorage::checkTableCanBeDropped(context_);
/// proton: ends.

auto table_id = getStorageID();
getContext()->checkTableCanBeDropped(table_id.database_name, table_id.table_name, getTotalActiveSizeInBytes());
context_->checkTableCanBeDropped(table_id.database_name, table_id.table_name, getTotalActiveSizeInBytes());
/// proton: ends.
}

void StorageMergeTree::drop()
Expand Down
Empty file.
5 changes: 5 additions & 0 deletions tests/queries_ported/0_stateless/99006_force_drop.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE STREAM 99006_v(id int);

INSERT INTO 99006_v(id) values(3);

DROP STREAM 99006_v settings force_drop_big_stream = true;

0 comments on commit eca386e

Please sign in to comment.