GitHub user Susmit07 edited a comment on the discussion: Distributed lock on
file within pekko cluster
> that keeps track of which files are locked
Persistance storage is a issue currently in our project, as in-memory map can
be risky if pod gets restarted
``
def apply(): Behavior[Command] = Behaviors.setup { context =>
val lockedFiles = mutable.Map.empty[String, String] // Map filePath -> node
holding the lock
Behaviors.receiveMessage {
case RequestLock(filePath, replyTo) =>
if (lockedFiles.contains(filePath)) {
replyTo ! LockResponse(success = false) // Lock not available
} else {
lockedFiles.put(filePath, context.self.path.name) // Lock acquired
replyTo ! LockResponse(success = true)
}
Behaviors.same
case ReleaseLock(filePath, replyTo) =>
lockedFiles.remove(filePath)
replyTo ! LockResponse(success = true)
Behaviors.same
}
}
``
Your suggestion I liked tbh
GitHub link:
https://github.com/apache/pekko-connectors/discussions/826#discussioncomment-10744066
----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]