-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add leader replica host to config * Add leader client * Add leader consensus handler * Handle not adding duplicate datanodes * Implement leader sync task * Add leader replica support to client_go * Add leader replica support to client_py * Increase leader health check timeout * Fix debug level logs log-level
- Loading branch information
Showing
14 changed files
with
270 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package tasks | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/sirupsen/logrus" | ||
|
||
"github.com/kysre/TurtleMQ/leader/internal/models" | ||
) | ||
|
||
type LeaderSyncer struct { | ||
logger *logrus.Logger | ||
handler *models.LeaderConsensusHandler | ||
directory *models.DataNodeDirectory | ||
period int | ||
} | ||
|
||
func NewLeaderSyncer( | ||
logger *logrus.Logger, | ||
handler *models.LeaderConsensusHandler, | ||
directory *models.DataNodeDirectory, | ||
period int, | ||
) *LeaderSyncer { | ||
return &LeaderSyncer{ | ||
logger: logger, | ||
handler: handler, | ||
directory: directory, | ||
period: period, | ||
} | ||
} | ||
|
||
func (ls *LeaderSyncer) RunLeaderSync() { | ||
ls.logger.Debug("Running leader sync") | ||
tickerPeriod := time.Duration(ls.period) * time.Second | ||
ticker := time.NewTicker(tickerPeriod) | ||
for { | ||
select { | ||
case <-ticker.C: | ||
if ls.handler.IsReplicaAvailable() { | ||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) | ||
ls.handler.AddDataNodesToReplica(ctx, ls.directory.DataNodes) | ||
cancel() | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.