aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Storages/MergeTree/MergeTreeDataPartUUID.cpp
blob: 3c3a6ecee7f7e9a3621d7f466e8b1cf23e24045f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <vector>
#include <Storages/MergeTree/MergeTreeDataPartUUID.h>


namespace DB
{

std::vector<UUID> PartUUIDs::add(const std::vector<UUID> & new_uuids)
{
    std::lock_guard lock(mutex);
    std::vector<UUID> intersection;

    /// First check any presence of uuids in a uuids, return duplicates back if any
    for (const auto & uuid : new_uuids)
    {
        if (uuids.find(uuid) != uuids.end())
            intersection.emplace_back(uuid);
    }

    if (intersection.empty())
    {
        for (const auto & uuid : new_uuids)
            uuids.emplace(uuid);
    }
    return intersection;
}

std::vector<UUID> PartUUIDs::get() const
{
    std::lock_guard lock(mutex);
    return std::vector<UUID>(uuids.begin(), uuids.end());
}

bool PartUUIDs::has(const UUID & uuid) const
{
    std::lock_guard lock(mutex);
    return uuids.find(uuid) != uuids.end();
}

}