本文整理匯總了Golang中github.com/getwe/goose/log.Error函數的典型用法代碼示例。如果您正苦於以下問題:Golang Error函數的具體用法?Golang Error怎麽用?Golang Error使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Error函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Read
// 讀取數據,外部需要準備好夠存放的desBuf
func (this *BigFile) Read(i BigFileIndex, desBuf []byte) error {
if i.FileNo >= this.bigfileStat.FileCnt {
return log.Error("BigFile.Read FileNo[%d] Error", i.FileNo)
}
if i.Length > uint32(len(desBuf)) {
return log.Error("BigFile.Read BigFileIndex.Length[%d] > len(desBuf)[%d]",
i.Length, uint32(len(desBuf)))
}
var f *os.File
if i.FileNo == this.bigfileStat.FileCnt-1 {
f = this.readwriteFile
} else {
f = this.readOnlyFile[i.FileNo]
}
n, err := f.ReadAt(desBuf[:i.Length], int64(i.Offset))
if err == io.EOF {
if uint32(n) == i.Length {
// 剛剛好讀完
return nil
}
}
if uint32(n) != i.Length {
return log.Error("Read Length Error offset[%d] destBuf len[%d],ReadAt len[%d]",
i.Offset, i.Length, n)
}
if err != nil {
return log.Error("ReadAt file", err.Error())
}
return nil
}
示例2: Append
// 追加數據,返回追加數據的存儲信息.不可並發進行寫操作.
func (this *BigFile) Append(buf []byte) (*BigFileIndex, error) {
f, err := this.getRwFile()
if err != nil {
return nil, err
}
i := BigFileIndex{}
i.FileNo = this.bigfileStat.FileCnt - 1
i.Length = uint32(len(buf))
off, err := this.readwriteFile.Seek(0, 1)
i.Offset = uint32(off)
if i.Offset != this.bigfileStat.LastFileOffset {
return nil, log.Error("BigFile.Append getOffset[%d] LastFileOffset[%d]",
i.Offset, this.bigfileStat.LastFileOffset)
}
n, err := f.Write(buf)
if err != nil {
return nil, log.Error("BigFile.Append write fail : %s", err.Error())
}
if uint32(n) != i.Length {
// 寫成功,但是寫入長度跟期望對不上
// 回滾文件指針
this.readwriteFile.Seek(int64(i.Offset), 0)
return nil, log.Error("BigFile.Append write succ bug length error : %s",
err.Error())
}
// 更新狀態文件
this.bigfileStat.LastFileOffset = i.Offset + i.Length
this.saveStatFile()
return &i, nil
}
示例3: searchModeRun
// 檢索模式運行
func (this *Goose) searchModeRun() {
log.Debug("run in search mode")
if this.searchSty == nil {
log.Error("Please set search strategy,see Goose.SetSearchStrategy()")
return
}
if this.indexSty == nil {
log.Warn("can't build index real time witout Index Strategy")
}
gooseSearch := NewGooseSearch()
err := gooseSearch.Init(this.confPath, this.indexSty, this.searchSty)
if err != nil {
log.Error(err)
return
}
log.Debug("goose search init succ")
err = gooseSearch.Run()
if err != nil {
log.Error(err)
return
}
}
示例4: ReadData
// 讀取Data數據,可以並發.
func (this *DataManager) ReadData(inId InIdType, buf *Data) error {
if inId < 1 || inId > this.dataStatus.MaxInId {
return log.Error("inId [%d] illegal MaxInId[%d]", inId, this.dataStatus.MaxInId)
}
// 讀一級索引
bigFileI, err := this.readData0(inId)
if err != nil {
return err
}
if bigFileI.Length == 0 {
return log.Error("Read data0 inId[%d],fileNo[%d],length[%d],offset[%d]",
inId, bigFileI.FileNo, bigFileI.Length, bigFileI.Offset)
}
// 讀二級索引
if bigFileI.Length > uint32(buf.Len()) {
*buf = NewData(int(bigFileI.Length))
}
err = this.data1.Read(bigFileI, *buf)
if err != nil {
return err
}
return nil
}
示例5: Open
// 打開已存在的大文件,如果不存在,直接返回錯誤
func (this *BigFile) Open(path string, name string) error {
// 是打開已有數據文件狀態
this.fileModel = bigFileModelOpen
this.filePath = path
this.fileName = name
this.statFileFullPath = filepath.Join(this.filePath,
fmt.Sprintf("%s%s", this.fileName, statFileSuffix))
// 解析獲取文件信息
err := this.parseStatFile()
if err != nil {
return log.Warn(err)
}
// 檢驗狀態文件
if this.bigfileStat.SuggestFileSize == 0 {
return log.Error("BigFile.Open stat file error")
}
// 除了最後一個文件,其它以隻讀方式打開
readOnlyFileCnt := uint8(0)
if this.bigfileStat.FileCnt > 0 {
readOnlyFileCnt = this.bigfileStat.FileCnt - 1
}
this.readOnlyFile = make([]*os.File, readOnlyFileCnt)
for i := 0; uint8(i) < readOnlyFileCnt; i++ {
f, err := this.openRoFile(uint8(i))
if err != nil {
return err
}
this.readOnlyFile[i] = f
// 校驗這些隻讀文件的大小,他們肯定是大於等於配置才對
// TODO
}
// 最後一個文件已讀寫方式打開
if this.bigfileStat.FileCnt > 0 {
err = this.openRwFile(this.bigfileStat.FileCnt - 1)
if err != nil {
return err
}
// 設置文件指針
this.readwriteFile.Seek(int64(this.bigfileStat.LastFileOffset), 0)
// 最後一個文件的文件指針應該就是文件大小
sz, _ := FileSize(this.readwriteFile)
if sz != int64(this.bigfileStat.LastFileOffset) {
return log.Error("BigFile.Open", "FileStatInfo Error LastFileOffset:[%d] != FileSize:[%d]",
this.bigfileStat.LastFileOffset, sz)
}
} else {
this.readwriteFile = nil
}
return nil
}
示例6: AllocID
// 根據唯一外部ID,分配內部ID,可並發內部有鎖控製按順序分配
func (this *DBSearcher) AllocID(outID OutIdType) (InIdType, error) {
if this.varIndex == nil {
return 0, log.Error("No Var Index")
}
if this.idMgr == nil {
return 0, log.Error("no id manager")
}
return this.idMgr.AllocID(outID)
}
示例7: WriteValue
// 寫入Value數據,可並發寫入.
func (this *DBSearcher) WriteValue(InID InIdType, v Value) error {
if this.varIndex == nil {
return log.Error("No Var Index")
}
if this.valueMgr == nil {
return log.Error("no value manager")
}
return this.valueMgr.WriteValue(InID, v)
}
示例8: WriteData
// 寫入Data數據,可並發調用.
func (this *DBSearcher) WriteData(InID InIdType, d Data) error {
if this.varIndex == nil {
return log.Error("No Var Index")
}
if this.dataMgr == nil {
return log.Error("no data manager")
}
// dataMgr內部鎖控製,並發寫順序寫入
return this.dataMgr.Append(InID, d)
}
示例9: Init
// 創建全新的磁盤索引,初始化後隻允許進行索引寫入.
// maxFileSz 索引大文件單個文件的最大大小.
// MaxTermCnt 是預期要寫入的term的總數量.
func (this *DiskIndex) Init(path string, name string, maxFileSz uint32, MaxTermCnt int64) error {
this.lock.Lock()
defer this.lock.Unlock()
if this.indexStatus != DiskIndexInit {
return log.Error("index status error")
}
if len(path) == 0 || len(name) == 0 {
return log.Error("path[%s] name[%s] error")
}
this.filePath = path
this.fileName = name
this.StatusFilePath = filepath.Join(this.filePath,
fmt.Sprintf("%s.index.stat", this.fileName))
// 磁盤狀態文件需要設置的兩個步驟:(1)指示要寫入的結構;(2)設置寫入路徑
this.SelfStatus = &this.diskStatus
this.diskStatus.MaxTermCount = MaxTermCnt
// 初始化三級索引
this.index3 = &BigFile{}
ind3name := fmt.Sprintf("%s.index3", this.fileName)
err := this.index3.Init(this.filePath, ind3name, maxFileSz)
if err != nil {
return log.Error(err)
}
// 打開二級索引
ind2name := filepath.Join(this.filePath, fmt.Sprintf("%s.index2", this.fileName))
// 打開新文件,創建|截斷|隻寫
this.index2, err = os.OpenFile(ind2name, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
if err != nil {
return log.Error(err)
}
// 計算預期一級索引大小
index1Sz := this.diskStatus.MaxTermCount * int64(binary.Size(TermSign(0)))
// 打開一級索引
this.index1 = new(MmapFile)
ind1name := fmt.Sprintf("%s.index1", this.fileName)
err = this.index1.OpenFile(this.filePath, ind1name, uint32(index1Sz))
if err != nil {
return log.Error("mmap open[%s] size[%d] fail : %s", ind1name, index1Sz, err)
}
this.indexStatus = DiskIndexWriteOnly
return this.SaveJsonFile()
}
示例10: runIndexServer
func (this *GooseSearch) runIndexServer(listenPort int, requestBufSize int) error {
if 0 == listenPort || 0 == requestBufSize {
return log.Error("arg error istenPort[%d] requestBufSize[%d]",
listenPort, requestBufSize)
}
if this.varIndexer == nil {
return nil
}
listener, err := net.Listen("tcp", fmt.Sprintf("localhost:%d", listenPort))
if err != nil {
log.Error("runIndexServer listen fail : %s", err.Error())
return err
}
// 簡單一個協程完成接受請求和完成處理.索引更新不要求高並發性.
go func() {
reqbuf := make([]byte, requestBufSize)
for {
var reqlen int
conn, err := listener.Accept()
if err != nil {
log.Warn("IndexServer accept fail : %s", err.Error())
goto LabelError
}
// receive data
reqlen, err = conn.Read(reqbuf)
if err != nil {
log.Warn("IndexSearcher read fail : %s", err.Error())
goto LabelError
}
// index
err = this.varIndexer.BuildIndex(NewBufferIterOnce(reqbuf[:reqlen]))
if err != nil {
log.Warn("IndexSearcher BuildIndex fail : %s", err.Error())
goto LabelError
}
LabelError:
conn.Close()
}
}()
return nil
}
示例11: ReadNum
// 讀取offset開始的destSz個字節作為數字返回
func (this *MmapFile) ReadNum(offset uint32, destSz uint32) (uint64, error) {
if destSz == 0 {
return 0, log.Error("Mmapfile.ReadNum not a basic num")
}
if int64(offset)+int64(destSz) > int64(len(this.fileMmap)) {
return 0, log.Error("Mmapfile.ReadNum over length limit")
}
buf := this.fileMmap[offset : offset+uint32(destSz)]
order := binary.BigEndian
switch destSz {
case 1:
return uint64(buf[0]), nil
case 2:
return uint64(order.Uint16(buf)), nil
case 4:
return uint64(order.Uint32(buf)), nil
case 8:
return uint64(order.Uint64(buf)), nil
default:
return 0, log.Error("MmapFile.ReadNum Wrong Type")
}
return 0, nil
/*
switch v := n.(type) {
case *int8:
*v = int8(buf[0])
case *uint8:
*v = buf[0]
case *int16:
*v = int16(order.Uint16(buf))
case *uint16:
*v = uint16(order.Uint16(buf))
case *int32:
*v = int32(order.Uint32(buf))
case *uint32:
*v = uint32(order.Uint32(buf))
case *int64:
*v = int64(order.Uint64(buf))
case *uint64:
*v = uint64(order.Uint64(buf))
default:
return NewGooseError("MmapFile.ReadNum","Wrong Type","")
}
return nil
*/
}
示例12: WriteIndex
// 寫入索引,不可並發寫入
func (this *DBBuilder) WriteIndex(InID InIdType, termlist []TermInDoc) error {
if this.transformMgr == nil {
return log.Error("no transform manager")
}
return this.transformMgr.WriteIndex(InID, termlist)
}
示例13: WriteValue
// 寫入Value數據,可並發寫入
func (this *DBBuilder) WriteValue(InID InIdType, v Value) error {
if this.valueMgr == nil {
return log.Error("no value manager")
}
return this.valueMgr.WriteValue(InID, v)
}
示例14: parseDoc
func (this *StaticIndexer) parseDoc() {
// context
context := NewStyContext()
// 一直從chan中獲取doc,直到這個chan被close
for doc := range this.parseDocChan {
var err error
// parse
parseRes := &docParsed{}
parseRes.outId, parseRes.termList, parseRes.value, parseRes.data,
err = this.strategy.ParseDoc(doc, context)
if err != nil {
log.Error(err)
parseRes = nil
}
// 打印策略日誌
context.Log.PrintAllInfo()
// toWriteDbQueue是待寫入db的隊列.
// 阻塞等待隊列有空餘位置然後寫入隊列.
this.writeDbQueue <- parseRes
}
log.Info("Finish parseDoc , goroutine exit.")
}
示例15: ReadBytes
// read bytes (reference)
func (this *MmapFile) ReadBytes(offset uint32, length uint32) ([]byte, error) {
if uint64(offset+length) > uint64(len(this.fileMmap)) {
return nil, log.Error("Mmapfile.ReadBytes over length limit")
}
return this.fileMmap[offset : offset+length], nil
}