Skip to content

Commit

Permalink
Disallow copy and move (#4578)
Browse files Browse the repository at this point in the history
ref #4411
  • Loading branch information
ZHANGWENTAI authored May 7, 2022
1 parent ad24c10 commit 7ffb943
Show file tree
Hide file tree
Showing 50 changed files with 228 additions and 142 deletions.
4 changes: 2 additions & 2 deletions dbms/src/Common/ActionBlocker.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#pragma once
#include <Common/nocopyable.h>

#include <atomic>

Expand Down Expand Up @@ -60,8 +61,7 @@ class ActionBlocker
return *this;
}

LockHolder(const LockHolder & other) = delete;
LockHolder & operator=(const LockHolder & other) = delete;
DISALLOW_COPY(LockHolder);

~LockHolder()
{
Expand Down
4 changes: 3 additions & 1 deletion dbms/src/Common/COWPtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#pragma once

#include <Common/nocopyable.h>

#include <boost/smart_ptr/intrusive_ptr.hpp>
#include <boost/smart_ptr/intrusive_ref_counter.hpp>
#include <initializer_list>
Expand Down Expand Up @@ -121,7 +123,7 @@ class COWPtr : public boost::intrusive_ref_counter<Derived>

public:
/// Copy: not possible.
mutable_ptr(const mutable_ptr &) = delete;
DISALLOW_COPY(mutable_ptr);

/// Move: ok.
mutable_ptr(mutable_ptr &&) = default;
Expand Down
6 changes: 2 additions & 4 deletions dbms/src/Common/CPUAffinityManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#pragma once

#include <Common/nocopyable.h>
#include <common/defines.h>

#include <string>
Expand Down Expand Up @@ -126,9 +127,6 @@ class CPUAffinityManager
CPUAffinityManager();
// Disable copy and move
public:
CPUAffinityManager(const CPUAffinityManager &) = delete;
CPUAffinityManager & operator=(const CPUAffinityManager &) = delete;
CPUAffinityManager(CPUAffinityManager &&) = delete;
CPUAffinityManager & operator=(CPUAffinityManager &&) = delete;
DISALLOW_COPY_AND_MOVE(CPUAffinityManager);
};
} // namespace DB
4 changes: 2 additions & 2 deletions dbms/src/Common/CompactArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#pragma once

#include <Common/nocopyable.h>
#include <Core/Defines.h>
#include <IO/ReadBuffer.h>
#include <IO/ReadHelpers.h>
Expand Down Expand Up @@ -105,8 +106,7 @@ class CompactArray<BucketIndex, content_width, bucket_count>::Reader final
{
}

Reader(const Reader &) = delete;
Reader & operator=(const Reader &) = delete;
DISALLOW_COPY(Reader);

bool next()
{
Expand Down
3 changes: 2 additions & 1 deletion dbms/src/Common/DNSCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#pragma once
#include <Common/nocopyable.h>
#include <Poco/Net/IPAddress.h>
#include <Poco/Net/SocketAddress.h>

Expand All @@ -27,7 +28,7 @@ namespace DB
class DNSCache : public ext::Singleton<DNSCache>
{
public:
DNSCache(const DNSCache &) = delete;
DISALLOW_COPY(DNSCache);

/// Accepts host names like 'example.com' or '127.0.0.1' or '::1' and resolve its IP
Poco::Net::IPAddress resolveHost(const std::string & host);
Expand Down
6 changes: 4 additions & 2 deletions dbms/src/Common/ExecutableTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#pragma once

#include <Common/nocopyable.h>

#include <memory>

namespace DB
Expand All @@ -24,8 +26,8 @@ class IExecutableTask
IExecutableTask() = default;

virtual ~IExecutableTask() = default;
IExecutableTask(const IExecutableTask & rhs) = delete;
IExecutableTask & operator=(const IExecutableTask & rhs) = delete;

DISALLOW_COPY(IExecutableTask);
IExecutableTask(IExecutableTask && other) = default;
IExecutableTask & operator=(IExecutableTask && other) = default;

Expand Down
4 changes: 2 additions & 2 deletions dbms/src/Common/HashTable/FixedHashTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#pragma once

#include <Common/HashTable/HashTable.h>
#include <Common/nocopyable.h>

namespace DB
{
Expand Down Expand Up @@ -258,8 +259,7 @@ class FixedHashTable : private boost::noncopyable
: in(in_)
{}

Reader(const Reader &) = delete;
Reader & operator=(const Reader &) = delete;
DISALLOW_COPY(Reader);

bool next()
{
Expand Down
5 changes: 3 additions & 2 deletions dbms/src/Common/HashTable/HashTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <Common/Exception.h>
#include <Common/HashTable/HashTableAllocator.h>
#include <Common/HashTable/HashTableKeyHolder.h>
#include <Common/nocopyable.h>
#include <Core/Defines.h>
#include <Core/Types.h>
#include <IO/ReadBuffer.h>
Expand All @@ -32,6 +33,7 @@
#include <new>
#include <utility>


#ifdef DBMS_HASH_MAP_DEBUG_RESIZES
#include <Common/Stopwatch.h>

Expand Down Expand Up @@ -770,8 +772,7 @@ class HashTable : private boost::noncopyable
{
}

Reader(const Reader &) = delete;
Reader & operator=(const Reader &) = delete;
DISALLOW_COPY(Reader);

bool next()
{
Expand Down
5 changes: 2 additions & 3 deletions dbms/src/Common/HashTable/SmallTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#pragma once

#include <Common/HashTable/HashMap.h>

#include <Common/nocopyable.h>

namespace DB
{
Expand Down Expand Up @@ -95,8 +95,7 @@ class SmallTable : private boost::noncopyable
{
}

Reader(const Reader &) = delete;
Reader & operator=(const Reader &) = delete;
DISALLOW_COPY(Reader);

bool next()
{
Expand Down
5 changes: 2 additions & 3 deletions dbms/src/Common/RWLock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <Common/ProfileEvents.h>
#include <Common/RWLock.h>
#include <Common/Stopwatch.h>

#include <Common/nocopyable.h>

namespace ProfileEvents
{
Expand Down Expand Up @@ -59,8 +59,7 @@ class RWLock::LockHolderImpl
GroupsContainer::iterator it_group;

public:
LockHolderImpl(const LockHolderImpl & other) = delete;
LockHolderImpl & operator=(const LockHolderImpl & other) = delete;
DISALLOW_COPY(LockHolderImpl);

/// Implicit memory allocation for query_id is done here
LockHolderImpl(const String & query_id_, Type type)
Expand Down
8 changes: 3 additions & 5 deletions dbms/src/Common/TiFlashMetrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#pragma once

#include <Common/TiFlashBuildInfo.h>
#include <Common/nocopyable.h>
#include <prometheus/counter.h>
#include <prometheus/exposer.h>
#include <prometheus/gateway.h>
Expand All @@ -24,6 +25,7 @@

#include <ext/scope_guard.h>


// to make GCC 11 happy
#include <cassert>

Expand Down Expand Up @@ -341,11 +343,7 @@ class TiFlashMetrics
}
APPLY_FOR_METRICS(MAKE_METRIC_MEMBER_M, MAKE_METRIC_MEMBER_F)

TiFlashMetrics(const TiFlashMetrics &) = delete;
TiFlashMetrics & operator=(const TiFlashMetrics &) = delete;

TiFlashMetrics(TiFlashMetrics &&) = delete;
TiFlashMetrics & operator=(TiFlashMetrics &&) = delete;
DISALLOW_COPY_AND_MOVE(TiFlashMetrics);

friend class MetricsPrometheus;
};
Expand Down
27 changes: 27 additions & 0 deletions dbms/src/Common/nocopyable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2022 PingCAP, Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#define DISALLOW_COPY(ClassName) \
ClassName(const ClassName &) = delete; \
ClassName & operator=(const ClassName &) = delete

#define DISALLOW_MOVE(ClassName) \
ClassName(ClassName &&) = delete; \
ClassName & operator=(ClassName &&) = delete

#define DISALLOW_COPY_AND_MOVE(ClassName) \
DISALLOW_COPY(ClassName); \
DISALLOW_MOVE(ClassName)
7 changes: 5 additions & 2 deletions dbms/src/Common/tests/gtest_mpmc_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#include <Common/MPMCQueue.h>
#include <Common/nocopyable.h>
#include <TestUtils/TiFlashTestBasic.h>

#include <chrono>
Expand Down Expand Up @@ -465,13 +466,15 @@ class MPMCQueueTest : public ::testing::Test
struct ThrowInjectable
{
ThrowInjectable() = default;
ThrowInjectable(const ThrowInjectable &) = delete;

DISALLOW_COPY(ThrowInjectable);

ThrowInjectable(ThrowInjectable && rhs)
{
throwOrMove(std::move(rhs));
}

ThrowInjectable & operator=(const ThrowInjectable &) = delete;

ThrowInjectable & operator=(ThrowInjectable && rhs)
{
if (this != &rhs)
Expand Down
23 changes: 12 additions & 11 deletions dbms/src/DataStreams/SummingSortedBlockInputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@

#pragma once

#include <Core/Row.h>
#include <AggregateFunctions/AggregateFunctionFactory.h>
#include <AggregateFunctions/IAggregateFunction.h>
#include <Common/nocopyable.h>
#include <Core/ColumnNumbers.h>
#include <Core/Row.h>
#include <DataStreams/MergingSortedBlockInputStream.h>
#include <AggregateFunctions/IAggregateFunction.h>
#include <AggregateFunctions/AggregateFunctionFactory.h>


namespace DB
{

namespace ErrorCodes
{
extern const int LOGICAL_ERROR;
extern const int LOGICAL_ERROR;
}


Expand Down Expand Up @@ -121,7 +122,7 @@ class SummingSortedBlockInputStream : public MergingSortedBlockInputStream

AggregateDescription() = default;
AggregateDescription(AggregateDescription &&) = default;
AggregateDescription(const AggregateDescription &) = delete;
DISALLOW_COPY(AggregateDescription);
};

/// Stores numbers of key-columns and value-columns.
Expand All @@ -134,14 +135,14 @@ class SummingSortedBlockInputStream : public MergingSortedBlockInputStream
std::vector<AggregateDescription> columns_to_aggregate;
std::vector<MapDescription> maps_to_sum;

RowRef current_key; /// The current primary key.
RowRef next_key; /// The primary key of the next row.
RowRef current_key; /// The current primary key.
RowRef next_key; /// The primary key of the next row.

Row current_row;
bool current_row_is_zero = true; /// Are all summed columns zero (or empty)? It is updated incrementally.
bool current_row_is_zero = true; /// Are all summed columns zero (or empty)? It is updated incrementally.

bool output_is_non_empty = false; /// Have we given out at least one row as a result.
size_t merged_rows = 0; /// Number of rows merged into current result block
bool output_is_non_empty = false; /// Have we given out at least one row as a result.
size_t merged_rows = 0; /// Number of rows merged into current result block

/** We support two different cursors - with Collation and without.
* Templates are used instead of polymorphic SortCursor and calls to virtual functions.
Expand All @@ -159,4 +160,4 @@ class SummingSortedBlockInputStream : public MergingSortedBlockInputStream
void addRow(SortCursor & cursor);
};

}
} // namespace DB
5 changes: 3 additions & 2 deletions dbms/src/Debug/MockSSTReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@

#pragma once

#include <Common/nocopyable.h>
#include <Storages/Transaction/ProxyFFI.h>

#include <map>


namespace DB
{

Expand All @@ -35,8 +37,7 @@ struct MockSSTReader
using Key = std::pair<std::string, ColumnFamilyType>;
struct Data : std::vector<std::pair<std::string, std::string>>
{
Data(const Data &) = delete;
Data & operator=(const Data &) = delete;
DISALLOW_COPY(Data);
Data(Data &&) = default;
Data & operator=(Data &&) = default;
Data() = default;
Expand Down
Loading

0 comments on commit 7ffb943

Please sign in to comment.