mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 08:40:50 +00:00
Allow manual compaction of rocksdb via OPTIMIZE query
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
This commit is contained in:
parent
7d4c97e8f3
commit
09c1e76982
@ -47,6 +47,7 @@ namespace ErrorCodes
|
||||
extern const int LOGICAL_ERROR;
|
||||
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
|
||||
extern const int ROCKSDB_ERROR;
|
||||
extern const int NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
using FieldVectorPtr = std::shared_ptr<FieldVector>;
|
||||
@ -310,6 +311,36 @@ void StorageEmbeddedRocksDB::drop()
|
||||
rocksdb_ptr = nullptr;
|
||||
}
|
||||
|
||||
bool StorageEmbeddedRocksDB::optimize(
|
||||
const ASTPtr & /*query*/,
|
||||
const StorageMetadataPtr & /*metadata_snapshot*/,
|
||||
const ASTPtr & partition,
|
||||
bool final,
|
||||
bool deduplicate,
|
||||
const Names & /* deduplicate_by_columns */,
|
||||
bool cleanup,
|
||||
ContextPtr /*context*/)
|
||||
{
|
||||
if (partition)
|
||||
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Partition cannot be specified when optimizing table of type EmbeddedRocksDB");
|
||||
|
||||
if (final)
|
||||
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "FINAL cannot be specified when optimizing table of type EmbeddedRocksDB");
|
||||
|
||||
if (deduplicate)
|
||||
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "DEDUPLICATE cannot be specified when optimizing table of type EmbeddedRocksDB");
|
||||
|
||||
if (cleanup)
|
||||
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "CLEANUP cannot be specified when optimizing table of type EmbeddedRocksDB");
|
||||
|
||||
std::shared_lock lock(rocksdb_ptr_mx);
|
||||
rocksdb::CompactRangeOptions compact_options;
|
||||
auto status = rocksdb_ptr->CompactRange(compact_options, nullptr, nullptr);
|
||||
if (!status.ok())
|
||||
throw Exception(ErrorCodes::ROCKSDB_ERROR, "Compaction failed: {}", status.ToString());
|
||||
return true;
|
||||
}
|
||||
|
||||
void StorageEmbeddedRocksDB::initDB()
|
||||
{
|
||||
rocksdb::Status status;
|
||||
|
@ -55,6 +55,16 @@ public:
|
||||
void mutate(const MutationCommands &, ContextPtr) override;
|
||||
void drop() override;
|
||||
|
||||
bool optimize(
|
||||
const ASTPtr & query,
|
||||
const StorageMetadataPtr & metadata_snapshot,
|
||||
const ASTPtr & partition,
|
||||
bool final,
|
||||
bool deduplicate,
|
||||
const Names & deduplicate_by_columns,
|
||||
bool cleanup,
|
||||
ContextPtr context) override;
|
||||
|
||||
bool supportsParallelInsert() const override { return true; }
|
||||
bool supportsIndexForIn() const override { return true; }
|
||||
bool mayBenefitFromIndexForIn(
|
||||
|
5
tests/queries/0_stateless/02910_rocksdb_optimize.sql
Normal file
5
tests/queries/0_stateless/02910_rocksdb_optimize.sql
Normal file
@ -0,0 +1,5 @@
|
||||
-- Tags: use-rocksdb
|
||||
|
||||
CREATE TABLE dict (key UInt64, value String) ENGINE = EmbeddedRocksDB PRIMARY KEY key;
|
||||
INSERT INTO dict SELECT number, toString(number) FROM numbers(1e3);
|
||||
OPTIMIZE TABLE dict;
|
Loading…
Reference in New Issue
Block a user