func (dl *TsLog) PutAMeta( status uint8, id uint64, list ds.List, ) *RecordPosition { if list.Len() == 0 { return nil } buffer := bytes.NewBuffer(nil) err := binary.Write(buffer, binary.BigEndian, &status) if err != nil { return nil } err = binary.Write(buffer, binary.BigEndian, &id) if err != nil { return nil } var tn uint16 = uint16(list.Len()) err = binary.Write(buffer, binary.BigEndian, &tn) if err != nil { return nil } log.Println("PutAMeta()", dl.metaFile) isswitchfile := dl.testFileSize(dl.metaFile, int64(dl.metaFileMaxSize)) var wfilen uint16 = uint16(dl.metaFileMaxN) if isswitchfile { wfilen++ } for e := list.GetFirstNode(); e != nil; e = e.Next { if v, ok := e.Value.(*RecordPosition); ok { log.Println(v) err := binary.Write(buffer, binary.BigEndian, &v.FileNo) if err != nil { return nil } err = binary.Write(buffer, binary.BigEndian, &v.Offset) if err != nil { return nil } } } dl.mutex1.Lock() defer dl.mutex1.Unlock() if isswitchfile { dl.switchMetaFile() } log.Println("PutAMeta()", isswitchfile) offset, err := dl.metaFile.Seek(0, os.SEEK_CUR) if err != nil { return nil } _, err = dl.metaFile.Write(buffer.Bytes()) if err != nil { log.Println("PutAMeta()", err) } return &RecordPosition{ FileNo: uint16(dl.metaFileMaxN), Offset: offset, } }
func reply(c *Client, msg string, result ds.List) { defer c.W.Flush() var resultN int32 if result == nil { resultN = -1 } if msg == success { resultN = 0 if result != nil { resultN = int32(result.Len()) } } else { c.CmdError = true } err := binary.Write(c.W, binary.BigEndian, &resultN) if err != nil { log.Println("reply()", err) return } if len(msg) == 0 { log.Println("reply()", "msg len == 0") return } var msgLen uint8 = uint8(len(msg)) err = binary.Write(c.W, binary.BigEndian, &msgLen) if err != nil { log.Println("reply()", err) return } c.W.WriteString(msg) if result == nil || resultN == 0 { return } var objlen uint64 var obj *ds.Object var ok bool for e := result.GetFirstNode(); e != nil; e = e.Next { if obj, ok = e.Value.(*ds.Object); !ok { continue } objlen = uint64(len(obj.GetBuffer())) if objlen == 0 { continue } err = binary.Write(c.W, binary.BigEndian, &objlen) if err != nil { log.Println("reply()", err) return } _, err = c.W.Write(obj.GetBuffer()) if err != nil { log.Println("reply()", err) return } } }
func printTsrArray(tsrList ds.List) { var tsr *TsRecord var ok bool log.Println("----------------") for e := tsrList.GetFirstNode(); e != nil; e = e.Next { if tsr, ok = e.Value.(*TsRecord); !ok { continue } log.Println(tsr) } log.Println("----------------") }
func (ts *Ts) subTsrListBySavePoint(savepoint int) ds.List { var i int = 0 var tsr *TsRecord var ok bool var l ds.List = ts.tsrList for e := l.GetFirstNode(); e != nil; e = e.Next { if tsr, ok = e.Value.(*TsRecord); !ok { continue } if tsr.Op == SavePoint && savepoint == tsr.SavePointId { break } i++ } if list := l.SubList(i, l.Len()); list != nil { for e := list.GetFirstNode(); e != nil; e = e.Next { l.Remove(e.Value) } return list } return l }