當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Shard.SyncWrite方法代碼示例

本文整理匯總了Golang中cluster.Shard.SyncWrite方法的典型用法代碼示例。如果您正苦於以下問題:Golang Shard.SyncWrite方法的具體用法?Golang Shard.SyncWrite怎麽用?Golang Shard.SyncWrite使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cluster.Shard的用法示例。


在下文中一共展示了Shard.SyncWrite方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: write

func (self *CoordinatorImpl) write(db string, series []*protocol.Series, shard cluster.Shard, sync bool) error {
	request := &protocol.Request{Type: &write, Database: &db, MultiSeries: series}
	// break the request if it's too big
	if request.Size() >= MAX_REQUEST_SIZE {
		if l := len(series); l > 1 {
			// create two requests with half the serie
			if err := self.write(db, series[:l/2], shard, sync); err != nil {
				return err
			}
			return self.write(db, series[l/2:], shard, sync)
		}

		// otherwise, split the points of the only series
		s := series[0]
		l := len(s.Points)
		s1 := &protocol.Series{Name: s.Name, Fields: s.Fields, Points: s.Points[:l/2]}
		if err := self.write(db, []*protocol.Series{s1}, shard, sync); err != nil {
			return err
		}
		s2 := &protocol.Series{Name: s.Name, Fields: s.Fields, Points: s.Points[l/2:]}
		return self.write(db, []*protocol.Series{s2}, shard, sync)
	}
	if sync {
		return shard.SyncWrite(request)
	}
	return shard.Write(request)
}
開發者ID:hanshenu,項目名稱:influxdb,代碼行數:27,代碼來源:coordinator.go

示例2: write

func (self *CoordinatorImpl) write(db string, series []*protocol.Series, shard cluster.Shard, sync bool) error {
	request := &protocol.Request{Type: &write, Database: &db, MultiSeries: series}
	if sync {
		return shard.SyncWrite(request)
	}
	return shard.Write(request)
}
開發者ID:qz267,項目名稱:influxdb,代碼行數:7,代碼來源:coordinator.go

示例3: writeWithoutAssigningId

func (self *CoordinatorImpl) writeWithoutAssigningId(db string, series []*protocol.Series, shard cluster.Shard, sync bool) error {
	request := &protocol.Request{Type: &write, Database: &db, MultiSeries: series}
	// break the request if it's too big
	if request.Size() >= MAX_REQUEST_SIZE {
		if l := len(series); l > 1 {
			// create two requests with half the serie
			if err := self.writeWithoutAssigningId(db, series[:l/2], shard, sync); err != nil {
				return err
			}
			return self.writeWithoutAssigningId(db, series[l/2:], shard, sync)
		}

		// otherwise, split the points of the only series
		s := series[0]
		l := len(s.Points)
		s1 := &protocol.Series{Name: s.Name, FieldIds: s.FieldIds, Points: s.Points[:l/2]}
		if err := self.writeWithoutAssigningId(db, []*protocol.Series{s1}, shard, sync); err != nil {
			return err
		}
		s2 := &protocol.Series{Name: s.Name, FieldIds: s.FieldIds, Points: s.Points[l/2:]}
		return self.writeWithoutAssigningId(db, []*protocol.Series{s2}, shard, sync)
	}

	// if we received a synchronous write, then this is coming from the
	// continuous queries which have the sequence numbers assigned
	if sync {
		return shard.SyncWrite(request, false)
	}

	// If the shard isn't replicated do a syncrhonous write
	if shard.ReplicationFactor() <= 1 {
		// assign sequenceNumber and write synchronously
		return shard.SyncWrite(request, true)
	}
	return shard.Write(request)
}
開發者ID:jhermann,項目名稱:influxdb,代碼行數:36,代碼來源:coordinator.go


注:本文中的cluster.Shard.SyncWrite方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。