Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

LeaderData.clients has leaking possibility #154

Open
@xirc

Description

Situation

  1. A leader received a Replicate message from an entity and will be replicating an entry of the message for the entity.
    • The leader register this replication (ClientContext with LogEntryIndex) into LeaderData.clients.
  2. The leader becomes a follower for some reason before it completes the replication.
    • There is another leader at this point.
  3. The new leader completes the replication.
  4. The old leader (a follower now) sends Replica to the entity.
    • The entry (ClientContext with LogEntryIndex) of LeaderData.clients is not removed.

Related source code

  • case FollowedLeaderCommit(leaderMember, leaderCommit) =>
    currentData
    .detectLeaderMember(leaderMember)
    .followLeaderCommit(leaderCommit)
    .applyCommittedLogEntries { logEntries =>
    logEntries.foreach { logEntry =>
    applyToReplicationActor(logEntry)
    }
    }
    case Committed(logEntryIndex) =>
    currentData
    .commit(logEntryIndex)
    .handleCommittedLogEntriesAndClients { entries =>
    entries.foreach {
    case (logEntry, Some(client)) =>
    if (log.isDebugEnabled)
    log.debug("=== [Leader] committed {} and will notify it to {} ===", logEntry, client)
    client.ref.tell(
    ReplicationSucceeded(logEntry.event.event, logEntry.index, client.instanceId),
    client.originSender.getOrElse(ActorRef.noSender),
    )
    case (logEntry, None) =>
    // 復旧中の commit or リーダー昇格時に未コミットのログがあった場合の commit
    applyToReplicationActor(logEntry)
    }
    }
  • def handleCommittedLogEntriesAndClients(handler: Seq[(LogEntry, Option[ClientContext])] => Unit): RaftMemberData = {
    val applicableLogEntries = selectApplicableLogEntries
    handler(applicableLogEntries.map(e => (e, clients.get(e.index))))
    updateVolatileState(lastApplied = applicableLogEntries.lastOption.map(_.index).getOrElse(lastApplied))
    .updateLeaderVolatileState(clients = clients -- applicableLogEntries.map(_.index)) // 通知したクライアントは削除してメモリを節約
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /