-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add multi sentinel support #11
Conversation
Changes Unknown when pulling fe6db9c on tovbinm:mt/multi_sentinel into * on etaty:master*. |
@@ -177,7 +176,7 @@ abstract class SentinelMonitored(system: ActorSystem) { | |||
def withMasterAddr[T](initFunction: (String, Int) => T): T = { | |||
import scala.concurrent.duration._ | |||
|
|||
val f = sentinelClient.getMasterAddr(master) map { | |||
val f = sentinelClients.head.getMasterAddr(master) map { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be stupid to ask the first Sentinel, then if it fails, try the second.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, right! We can do something like:
val f = sentinelClients.map(_.getMasterAddr(master))
val ff = Future.find(f) { case Some(x) => true case _ => false }
.map {
case Some(Some((ip: String, port: Int))) => initFunction(ip, port)
case _ => throw new Exception(s"No such master '$master'")
}
Await.result(ff, 15 seconds)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think firstCompletedOf
doesn't work if the first reply from Redis says "no master"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I came to the same conclusion ;)
Really great :) I don't really know about the use cases of Sentinel. |
Usually you run one sentinel process on each machine. For instance, if we have three Redis instances: one master and two slaves; then we'll have three sentinel processes, one per machine. Sentinels are not likely to die, except when the whole machine is down. |
Oh, do you mean detecting new sentinels automatically? i.e. subscribing to "+sentinel " and "-dup-sentinel " ? |
Yes, detecting new sentinels and starting a connection to it. |
Then it probably should be done internally in SentinelClient. |
…, instead of just the first one
Yes SentinelClient fire a callback, and the MonitoredClient can act on it (starting a new SentinelClient for example) |
Changes Unknown when pulling 731948a on tovbinm:mt/multi_sentinel into * on etaty:master*. |
…nd update it when sentinel processes go up and down, by subcribing to '+sentinel' and '+sdown'
@etaty , added sentinels auto discovery |
Changes Unknown when pulling 5cdd8b4 on tovbinm:mt/multi_sentinel into * on etaty:master*. |
looks good, i will merge it during the weekend. |
Great! Looking forward hearing from you. |
…g the write phase as well
def onNewSentinel(masterName: String, sentinelip: String, sentinelport: Int) = { | ||
val k = makeSentinelClientKey(sentinelip, sentinelport) | ||
if (master == masterName && !sentinelClients.contains(k)) { | ||
synchronized { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe sentinelClients.synchronized
will be better (sync only on the Map instance, instead of SentinelMonitored)
(it's just a protection for the future)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or use SynchronizedMap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer sentinelClients.synchronized
, since using SynchronizedMap will not prevent from double addition/removal from the map. For this purpose we have the if (!sentinelClients.contains(k))
statement inside the synchronized section.
Can you tell me if it's ready to be merged ? |
Not yet. I'll ping you. ;) -Matthew
|
@etaty what else should be done for this one? |
Merging :) |
Awesome! |
thanks :) I will release version 1.3 during the week |
No description provided.