Skip to content

Commit 1e97926

Browse files
authored
Merge pull request ClickHouse#78799 from ClickHouse/debug-keeper-ephemeral
Fix Keeper ephemeral count
2 parents 633f6d4 + 94dd8ec commit 1e97926

File tree

5 files changed

+14
-9
lines changed

5 files changed

+14
-9
lines changed

src/Coordination/KeeperSnapshotManager.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,10 @@ void KeeperStorageSnapshot<Storage>::deserialize(SnapshotDeserializationResult<S
443443
node.getChildren().reserve(node.stats.numChildren());
444444

445445
if (ephemeral_owner != 0)
446+
{
446447
storage.committed_ephemerals[node.stats.ephemeralOwner()].insert(std::string{path});
448+
++storage.committed_ephemeral_nodes;
449+
}
447450

448451
if (recalculate_digest)
449452
storage.nodes_digest += node.getDigest(path);

src/Coordination/KeeperStorage.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,14 @@ void unregisterEphemeralPath(KeeperStorageBase::Ephemerals & ephemerals, int64_t
122122
if (ephemerals_it == ephemerals.end())
123123
{
124124
if (throw_if_missing)
125-
throw Exception(ErrorCodes::LOGICAL_ERROR, "Session {} is missing ephemeral path {}", session_id, path);
125+
throw Exception(ErrorCodes::LOGICAL_ERROR, "Session {} is expected to have ephemeral paths but no path is registered", session_id);
126126

127127
return;
128128
}
129129

130-
ephemerals_it->second.erase(path);
130+
if (auto erased = ephemerals_it->second.erase(path); !erased && throw_if_missing)
131+
throw Exception(ErrorCodes::LOGICAL_ERROR, "Session {} is missing ephemeral path {}", session_id, path);
132+
131133
if (ephemerals_it->second.empty())
132134
ephemerals.erase(ephemerals_it);
133135
}
@@ -255,14 +257,9 @@ void NodeStats::copyStats(const Coordination::Stat & stat)
255257
aversion = stat.aversion;
256258

257259
if (stat.ephemeralOwner == 0)
258-
{
259-
is_ephemeral_and_ctime.is_ephemeral = false;
260260
setNumChildren(stat.numChildren);
261-
}
262261
else
263-
{
264262
setEphemeralOwner(stat.ephemeralOwner);
265-
}
266263
}
267264

268265
void KeeperRocksNodeInfo::copyStats(const Coordination::Stat & stat)
@@ -1356,6 +1353,7 @@ bool KeeperStorage<Container>::removeNode(const std::string & path, int32_t vers
13561353

13571354
if (prev_node.stats.ephemeralOwner() != 0)
13581355
{
1356+
chassert(committed_ephemeral_nodes != 0);
13591357
--committed_ephemeral_nodes;
13601358
std::lock_guard lock(ephemeral_mutex);
13611359
unregisterEphemeralPath(committed_ephemerals, prev_node.stats.ephemeralOwner(), path, /*throw_if_missing=*/true);

src/Coordination/KeeperStorage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ struct NodeStats
6060

6161
void setEphemeralOwner(int64_t ephemeral_owner)
6262
{
63-
is_ephemeral_and_ctime.is_ephemeral = ephemeral_owner != 0;
63+
is_ephemeral_and_ctime.is_ephemeral = true;
6464
ephemeral_or_children_data.ephemeral_owner = ephemeral_owner;
6565
}
6666

src/Coordination/ZooKeeperDataReader.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,10 @@ int64_t deserializeStorageData(Storage & storage, ReadBuffer & in, LoggerPtr log
137137
storage.container.insertOrReplace(path, node);
138138

139139
if (ephemeral_owner != 0)
140+
{
140141
storage.committed_ephemerals[ephemeral_owner].insert(path);
142+
++storage.committed_ephemeral_nodes;
143+
}
141144

142145
storage.acl_map.addUsage(node.acl_id);
143146
}

src/Coordination/tests/gtest_coordination_common.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ void addNode(Storage & storage, const std::string & path, const std::string & da
113113
using Node = typename Storage::Node;
114114
Node node{};
115115
node.setData(data);
116-
node.stats.setEphemeralOwner(ephemeral_owner);
116+
if (ephemeral_owner)
117+
node.stats.setEphemeralOwner(ephemeral_owner);
117118
storage.container.insertOrReplace(path, node);
118119
auto child_it = storage.container.find(path);
119120
auto child_path = DB::getBaseNodeName(child_it->key);

0 commit comments

Comments
 (0)