本文整理汇总了Golang中gostore/log.Debug函数的典型用法代码示例。如果您正苦于以下问题:Golang Debug函数的具体用法?Golang Debug怎么用?Golang Debug使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Debug函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: addSegment
func (c *segmentCollection) addSegment(newseg *segment) {
// add at the end
for _, seg := range c.end {
if seg.positionEnd <= newseg.positionStart && newseg.tokens.IsOverlapsing(seg.tokens) {
log.Debug("Added segment %s overlapse %s at end. Marking overlapsed as not writable!", newseg, seg)
seg.writable = false
seg.nextSegments = append(seg.nextSegments, newseg)
newseg.prevSegments = append(newseg.prevSegments, seg)
}
}
c.end = append(c.end, newseg)
c.cleanup(true)
// add at beggining
for _, seg := range c.beginning {
if newseg.positionEnd <= seg.positionStart && newseg.tokens.IsOverlapsing(seg.tokens) {
log.Debug("Added segment %s overlapse %s at beginning.", newseg, seg)
seg.prevSegments = append(seg.prevSegments, newseg)
newseg.nextSegments = append(newseg.nextSegments, seg)
}
}
c.beginning = append(c.beginning, newseg)
c.cleanup(false)
}
示例2: getWritableSegment
func (m *segmentManager) getWritableSegment(token Token) *segment {
if !m.tokens.IsWithin(token) {
log.Fatal("Got a token not within range: got %d, range from %d to %d", token, m.tokens.from, m.tokens.to)
}
seg := m.timeline.getEndSegment(token)
// no writable segment found, create one
if seg == nil || !seg.writable {
if seg == nil {
log.Debug("Couldn't find a segment for token %d", token)
} else {
log.Debug("Segment for token %d is not writable", token)
}
// find the right chunk for this token
chunkLength := int(math.Ceil(float64(m.tokens.Length()) / SEG_CHUNKING))
found := false
chunk := m.tokens
for !found {
to := int(chunk.from) + chunkLength
if to > int(m.tokens.to) { // prevent overflow
to = int(m.tokens.to)
}
chunk = TokenRange{chunk.from, Token(to)}
if chunk.IsWithin(token) {
found = true
} else {
chunk = TokenRange{chunk.to + 1, m.tokens.to}
}
}
pos := uint64(0)
if seg != nil {
pos = seg.positionEnd // TODO: THIS IS NOT GOOD! IT SHOULD TAKE THE BIGGEST END POSITION OF ALL OVERRIDEN SEGMENTS
}
log.Info("Creating a new segment for tokens %d to %d @ %d", chunk.from, chunk.to, pos)
seg = createSegment(m.dataDir, chunk.from, chunk.to, pos)
m.timeline.addSegment(seg)
// find an id, assign it to the segment
for m.segments[m.nextSegId] != nil {
m.nextSegId++
}
seg.id = m.nextSegId
m.segments[seg.id] = seg
m.nextSegId++
}
return seg
}
示例3: head
func (api *api) head(resp *rest.ResponseWriter, req *rest.Request, path *Path) {
log.Debug("FSS API: Received a head request for path %s\n", path)
header, err := api.fss.HeaderJSON(path, nil)
resp.Write(header)
log.Debug("API: Fs Header data returned\n")
if err != nil {
log.Error("API: Fs header returned an error: %s\n", err)
resp.ReturnError(err.String())
}
}
示例4: get
func (api *api) get(resp *rest.ResponseWriter, req *rest.Request, path *Path) {
log.Debug("FSS API: Received a read request for path %s\n", path)
// TODO: Handle offset
// TODO: Handle version
// TODO: Handle size
_, err := api.fss.Read(path, 0, -1, 0, resp, nil)
log.Debug("API: Fs Read data returned\n")
if err != nil && err != os.EOF {
log.Error("API: Fs Read returned an error for %s: %s\n", path, err)
resp.ReturnError(err.String())
}
}
示例5: RemoteDeleteReplica
func (fss *FsService) RemoteDeleteReplica(message *comm.Message) {
// read payload
str, _ := message.Message.ReadString()
path := NewPath(str) // path
version, _ := message.Message.ReadInt64() // version
log.Debug("%d FSS: Received sync delete replica for path '%s' version '%d'\n", fss.cluster.MyNode.Id, path, version)
// Get the header
localheader := fss.headers.GetFileHeader(path)
// Delete the file localy
file := OpenFile(fss, localheader, version)
file.Delete()
// Delete in the header
localheader.header.Exists = false
localheader.header.ClearChildren()
localheader.header.Size = 0
localheader.Save()
// todo: add to garbage collector
// Send an acknowledgement
msg := fss.comm.NewMsgMessage(fss.serviceId)
fss.comm.RespondSource(message, msg)
}
示例6: RemoteExists
func (fss *FsService) RemoteExists(message *comm.Message) {
// Read payload
pathString, _ := message.Message.ReadString()
path := NewPath(pathString) // path
forceLocal, _ := message.Message.ReadBool() // force local
log.Debug("%d: FSS: Received new exists message for path %s\n", fss.cluster.MyNode.Id, path)
result := fss.ring.Resolve(path.String())
// get header, check if it exists or handed off
localheader := fss.headers.GetFileHeader(path)
// if file exists locally or its been handed off
if localheader.header.Exists {
response := fss.comm.NewMsgMessage(fss.serviceId)
response.Message.WriteBool(true)
fss.comm.RespondSource(message, response)
} else {
// if I'm the master or we force local
if result.IsFirst(fss.cluster.MyNode) || forceLocal {
response := fss.comm.NewMsgMessage(fss.serviceId)
response.Message.WriteBool(false)
fss.comm.RespondSource(message, response)
} else {
fss.comm.RedirectFirst(result, message)
}
}
}
示例7: RemoteReplicaVersion
func (fss *FsService) RemoteReplicaVersion(message *comm.Message) {
// Read payload
str, _ := message.Message.ReadString() // path
path := NewPath(str)
version, _ := message.Message.ReadInt64() // current version
nextversion, _ := message.Message.ReadInt64() // next version
size, _ := message.Message.ReadInt64() // size
mimetype, _ := message.Message.ReadString() // mimetype
log.Debug("%d FSS: Received sync version replica for path '%s'\n", fss.cluster.MyNode.Id, path)
// Get the header
localheader := fss.headers.GetFileHeader(path)
// Update the header
localheader.header.Path = path.String()
localheader.header.Name = path.BaseName()
localheader.header.Exists = true
localheader.header.Version = version
localheader.header.NextVersion = nextversion
localheader.header.MimeType = mimetype
localheader.header.Size = size
localheader.Save()
// enqueue replication for background download
fss.replicationEnqueue(path)
// Send an acknowledgement
req := fss.comm.NewMsgMessage(fss.serviceId)
fss.comm.RespondSource(message, req)
}
示例8: Boot
func (cs *ClusterService) Boot() {
myNode := cs.cluster.MyNode
log.Debug("%d: Booting cluster service", myNode.Id)
cs.loadCluster()
// Contact master or listen for incoming requests if I'm master
masters := cs.cluster.Rings.GetRing(cs.masterRing).ResolveToken(master_token)
if masters.IsFirst(myNode) {
// TODO: We should contact secondary master first!
myNode.Status = cluster.Status_Online
cs.state = state_online
myNode.Adhoc = false
} else {
myNode.Status = cluster.Status_Offline
cs.state = state_offline
// switch to adhoc, we are not yet in the cluster
myNode.Adhoc = true
// contact master
cs.ContactMaster()
}
}
示例9: RemoteContactMaster
func (cs *ClusterService) RemoteContactMaster(msg *comm.Message) {
myNode := cs.cluster.MyNode
log.Debug("%d: Got a ContactMaster request: %s", myNode.Id, msg)
if cs.state == state_online {
masters := cs.cluster.Rings.GetRing(cs.masterRing).ResolveToken(master_token)
// make sure I'm the master, and online
if myNode.Status == cluster.Status_Online && masters.IsFirst(myNode) {
node := cluster.NewEmptyNode()
err := node.Unserialize(msg.Message)
if err != nil {
cs.comm.RespondError(msg, os.NewError("Couldn't unmarshal node data"))
log.Error("Couldn't unmarshal node data: %s", err)
return
}
node.Status = cluster.Status_Online
cs.cluster.MergeNode(node, true)
// TODO: Send the cluster back to the node
resp := cs.comm.NewMsgMessage(cs.serviceId)
cs.comm.RespondSource(msg, resp)
//log.Fatal("BLABLA", node.Id)
// TODO: LOCK SO THAT WE DON'T MAKE IT ONLINE TWICE
// TODO: Accept the node
// TODO: Check its rings
// TODO: Broadcast the change
} else {
cs.comm.RedirectFirst(masters, msg)
}
}
}
示例10: RemoteHeader
func (fss *FsService) RemoteHeader(message *comm.Message) {
// read payload
str, _ := message.Message.ReadString()
path := NewPath(str)
log.Debug("FSS: Received new need header message for path %s\n", path)
result := fss.ring.Resolve(path.String())
// TODO: When versioning will be added, should not be that way since we may have it, but not of the right version
if result.InOnlineNodes(fss.cluster.MyNode) {
// If file exists localy or I'm the master
localheader := fss.headers.GetFileHeader(path)
if localheader.header.Exists || result.IsFirst(fss.cluster.MyNode) {
// respond data
response := fss.comm.NewDataMessage(fss.serviceId)
localheader := fss.headers.GetFileHeader(path)
header := localheader.header.ToJSON()
response.DataSize = int64(len(header))
response.Data = bytes.NewBuffer(header)
fss.comm.RespondSource(message, response)
} else {
fss.comm.RedirectFirst(result, message)
}
} else {
fss.comm.RedirectOne(result, message)
}
}
示例11: post
func (api *api) post(resp *rest.ResponseWriter, req *rest.Request, path *Path) {
log.Debug("FSS API: Received a write request for %d bytes\n", req.ContentLength)
mimetype := "application/octet-stream"
mtar, ok := req.Params["type"]
if ok {
mimetype = mtar[0]
}
err := api.fss.Write(path, req.ContentLength, mimetype, req.Body, nil)
if err != nil {
log.Error("API: Fs Write returned an error: %s\n", err)
resp.ReturnError(err.String())
}
log.Debug("API: Fs Write returned\n")
}
示例12: cleanup
//
// Removes all not writable segments that aren't covering any part of the range anymore
//
func (c *segmentCollection) cleanup(end bool) {
newSegs := make([]*segment, 0)
var toClean []*segment
if end {
toClean = c.end
} else {
toClean = c.beginning
}
for o := 0; o < len(toClean); o++ {
oSeg := toClean[o]
// if the segment is not writable OR we are cleaning the beginning
if !oSeg.writable || !end {
covRange := oSeg.tokens
useless := false
// iterate on all segments, remove ranges covered from other segments from covRange
for i := 0; i < len(toClean) && !useless; i++ {
iSeg := toClean[i]
// it's not the segment we are iterating on the outter loop + it's after or before (depending if we clean the end or beginning)
if (i != o) && ((end && iSeg.positionStart >= oSeg.positionEnd) || (!end && iSeg.positionEnd <= oSeg.positionStart)) {
if iSeg.tokens.IsWithin(covRange.from) {
covRange = TokenRange{iSeg.tokens.to, covRange.to}
}
if iSeg.tokens.IsWithin(covRange.to) {
covRange = TokenRange{covRange.from, iSeg.tokens.from}
}
}
// as soon as the coverage range is <= 0, we know that this range is useless
if covRange.Length() <= 0 {
useless = true
log.Debug("Segment %s now useless at end=%v. Removing it.", oSeg, end)
}
}
// only add the segment to the new array if it isn't useless
if !useless {
newSegs = append(newSegs, oSeg)
}
} else if end {
// if its a writable segment, add it
newSegs = append(newSegs, oSeg)
}
}
if end {
c.end = newSegs
} else {
c.beginning = newSegs
}
}
示例13: start
func (s *Server) start() {
var err os.Error
log.Debug("ServiceServer: starting listening tcp socket on %s\n", s.tcpaddr)
s.tcpsock, err = net.ListenTCP("tcp", s.tcpaddr)
if err != nil {
log.Fatal("Couldn't create TCP server listener: %s\n", err)
}
go s.acceptTCP()
log.Debug("ServiceServer: starting listening udp socket on %s\n", s.udpaddr)
s.udpsock, err = net.ListenUDP("udp", s.udpaddr)
if err != nil {
log.Fatal("Couldn't create UDP server listener: %s\n", err)
}
go s.acceptUDP()
}
示例14: NewServer
// Returns an API Server
func NewServer(handler Handler, adr string) *Server {
server := new(Server)
server.handler = handler
server.servmux = http.NewServeMux()
con, err := net.Listen("tcp", adr)
if err != nil {
log.Error("API: Couldn't create listener socket: %s\n", err)
}
// Add handling function at root, delegating everything to the handler
server.servmux.HandleFunc("/", func(httpresp http.ResponseWriter, httpreq *http.Request) {
log.Debug("API: Connection on url %s\n", httpreq.URL)
resp := &ResponseWriter{httpresp}
var req *Request
if req = NewRequest(resp, httpreq); req == nil {
log.Error("API: Couldn't create request object")
return
}
handler.Handle(resp, req)
// TODO: Remove that! Shouldn't be here!!
// Read the rest, so we don't cause Broken Pipe on the other end if we don't read to the end
ioutil.ReadAll(req.Body)
})
// Start serving the API on another thread
go func() {
log.Debug("API: Starting API server on adr %s\n", adr)
err = http.Serve(con, server.servmux)
con.Close()
if err != nil {
log.Fatal("API: Serve error: ", err.String())
}
}()
return server
}
示例15: RemoteChildrenList
func (fss *FsService) RemoteChildrenList(message *comm.Message) {
str, _ := message.Message.ReadString()
forceLocal, _ := message.Message.ReadBool()
path := NewPath(str)
log.Debug("FSS: Received message to list child for %s\n", path)
result := fss.ring.Resolve(path.String())
// I'm one of the nodes
if result.InOnlineNodes(fss.cluster.MyNode) {
localheader := fss.headers.GetFileHeader(path)
// we have the header locally
if localheader.header.Exists {
children := localheader.header.Children
// Create the message to send back
var count uint16 = uint16(len(children))
response := fss.comm.NewMsgMessage(fss.serviceId)
// Write child count
response.Message.WriteUint16(count) // children count
for _, child := range children {
response.Message.WriteString(child.Name) // name
response.Message.WriteString(child.MimeType) // type
response.Message.WriteInt64(child.Size) // size
}
fss.comm.RespondSource(message, response)
} else { // we don't have the header, we redirect to the appropriate node
// if i'm the master or forced local
if result.IsFirst(fss.cluster.MyNode) || forceLocal {
fss.comm.RespondError(message, ErrorFileNotFound)
} else {
fss.comm.RedirectFirst(result, message)
}
}
} else { // I'm not one of the nodes
// if its was forced local
if forceLocal {
fss.comm.RespondError(message, ErrorFileNotFound)
} else {
fss.comm.RedirectOne(result, message)
}
}
}