func reportChunkserverInfo(key string, chunkserver *metadata.Chunkserver, oldChunkserver *metadata.Chunkserver) error { if oldChunkserver.Status == INIT_STATUS { err := mdDriver.UpdateChunkserverInfo(chunkserver, INIT_STATUS, RW_STATUS) if err != nil { return err } chunkserver.Status = RW_STATUS } if RW_STATUS == oldChunkserver.Status { err := mdDriver.UpdateChunkserverInfo(chunkserver, RW_STATUS, RW_STATUS) if err != nil { return err } chunkserver.Status = RW_STATUS } if RO_STATUS == oldChunkserver.Status { err := mdDriver.UpdateChunkserverInfo(chunkserver, RO_STATUS, RW_STATUS) if err != nil { return err } log.Infof("[reportChunkserverInfo] update RO_STATUS to RW_STATUS chunkserver: %v", key) chunkserver.Status = RW_STATUS } chunkserver.UpdateTime = time.Now() lock.Lock() _, ok := serverInfo[key] if !ok { lock.Unlock() return fmt.Errorf("do not exist: %v", chunkserver) } serverInfo[key] = chunkserver lock.Unlock() return nil }
func AddChunkserver(chunkserver *metadata.Chunkserver) error { chunkserver.Status = INIT_STATUS chunkserver.TotalFreeSpace = 0 chunkserver.MaxFreeSpace = 0 chunkserver.PendingWrites = 0 chunkserver.WritingCount = 0 chunkserver.DataDir = "" chunkserver.ReadingCount = 0 chunkserver.TotalChunks = 0 chunkserver.ConnectionsCount = 0 err := mdDriver.AddChunkserver(chunkserver) if err != nil { return err } lock.Lock() defer lock.Unlock() key := fmt.Sprintf("%d:%s:%d", chunkserver.GroupId, chunkserver.Ip, chunkserver.Port) chunkserver.UpdateTime = time.Now() serverInfo[key] = chunkserver return nil }