Skip to content

Commit 77b8919

Browse files
committed
Fix Keeper ephemeral count
1 parent 9581562 commit 77b8919

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
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

0 commit comments

Comments
 (0)