本文整理匯總了Golang中cluster.Shard.Id方法的典型用法代碼示例。如果您正苦於以下問題:Golang Shard.Id方法的具體用法?Golang Shard.Id怎麽用?Golang Shard.Id使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cluster.Shard
的用法示例。
在下文中一共展示了Shard.Id方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: CommitSeriesData
func (self *CoordinatorImpl) CommitSeriesData(db string, series *protocol.Series) error {
lastPointIndex := 0
now := common.CurrentTime()
var shardToWrite cluster.Shard
for _, point := range series.Points {
if point.Timestamp == nil {
point.Timestamp = &now
}
}
lastTime := int64(math.MinInt64)
if len(series.Points) > 0 && *series.Points[0].Timestamp == lastTime {
// just a hack to make sure lastTime will never equal the first
// point's timestamp
lastTime = 0
}
// sort the points by timestamp
series.SortPointsTimeDescending()
for i, point := range series.Points {
if *point.Timestamp != lastTime {
shard, err := self.clusterConfiguration.GetShardToWriteToBySeriesAndTime(db, *series.Name, *point.Timestamp)
if err != nil {
return err
}
if shardToWrite == nil {
shardToWrite = shard
} else if shardToWrite.Id() != shard.Id() {
newIndex := i
newSeries := &protocol.Series{Name: series.Name, Fields: series.Fields, Points: series.Points[lastPointIndex:newIndex]}
if err := self.write(db, newSeries, shardToWrite); err != nil {
return err
}
lastPointIndex = newIndex
shardToWrite = shard
}
lastTime = *point.Timestamp
}
}
series.Points = series.Points[lastPointIndex:]
if len(series.Points) > 0 {
if shardToWrite == nil {
shardToWrite, _ = self.clusterConfiguration.GetShardToWriteToBySeriesAndTime(db, *series.Name, *series.Points[0].Timestamp)
}
err := self.write(db, series, shardToWrite)
if err != nil {
log.Error("COORD error writing: ", err)
return err
}
return err
}
return nil
}
示例2: CommitSeriesData
func (self *CoordinatorImpl) CommitSeriesData(db string, series *protocol.Series) error {
lastTime := int64(0)
lastPointIndex := 0
now := common.CurrentTime()
var shardToWrite cluster.Shard
for i, point := range series.Points {
if point.Timestamp == nil {
point.Timestamp = &now
}
if *point.Timestamp != lastTime {
shard, err := self.clusterConfiguration.GetShardToWriteToBySeriesAndTime(db, *series.Name, *point.Timestamp)
if err != nil {
return err
}
if shardToWrite == nil {
shardToWrite = shard
} else if shardToWrite.Id() != shard.Id() {
newIndex := i + 1
newSeries := &protocol.Series{Name: series.Name, Fields: series.Fields, Points: series.Points[lastPointIndex:newIndex]}
self.write(db, newSeries, shardToWrite)
lastPointIndex = newIndex
shardToWrite = shard
}
lastTime = *point.Timestamp
}
}
series.Points = series.Points[lastPointIndex:]
if len(series.Points) > 0 {
if shardToWrite == nil {
shardToWrite, _ = self.clusterConfiguration.GetShardToWriteToBySeriesAndTime(db, *series.Name, *series.Points[0].Timestamp)
}
err := self.write(db, series, shardToWrite)
if err != nil {
log.Error("COORD error writing: ", err)
}
return err
}
return nil
}