mirror of
https://github.com/cubefs/cubefs.git
synced 2026-08-02 02:00:56 +00:00
Refactor: if not config warnLogDir,then donnot write umplog to disk
Signed-off-by: awzhgw <guowl18702995996@gmail.com>
This commit is contained in:
parent
4a3ba7403f
commit
6a9dbc369b
@ -39,17 +39,15 @@ type DataPartitionRepairTask struct {
|
||||
ExtentsToBeRepaired []*storage.ExtentInfo
|
||||
LeaderTinyDeleteRecordFileSize int64
|
||||
LeaderAddr string
|
||||
LeaderTinyExtentRealSize map[uint64]int64
|
||||
}
|
||||
|
||||
func NewDataPartitionRepairTask(extentFiles []*storage.ExtentInfo, leaderTinyExtentRealSize map[uint64]int64, tinyDeleteRecordFileSize int64, source, leaderAddr string) (task *DataPartitionRepairTask) {
|
||||
func NewDataPartitionRepairTask(extentFiles []*storage.ExtentInfo, tinyDeleteRecordFileSize int64, source, leaderAddr string) (task *DataPartitionRepairTask) {
|
||||
task = &DataPartitionRepairTask{
|
||||
extents: make(map[uint64]*storage.ExtentInfo),
|
||||
ExtentsToBeCreated: make([]*storage.ExtentInfo, 0),
|
||||
ExtentsToBeRepaired: make([]*storage.ExtentInfo, 0),
|
||||
LeaderTinyDeleteRecordFileSize: tinyDeleteRecordFileSize,
|
||||
LeaderAddr: leaderAddr,
|
||||
LeaderTinyExtentRealSize: leaderTinyExtentRealSize,
|
||||
}
|
||||
for _, extentFile := range extentFiles {
|
||||
extentFile.Source = source
|
||||
@ -119,9 +117,6 @@ func (dp *DataPartition) repair(extentType uint8) {
|
||||
// every time we need to figureAnnotatef out which extents need to be repaired and which ones do not.
|
||||
dp.sendAllTinyExtentsToC(extentType, availableTinyExtents, brokenTinyExtents)
|
||||
|
||||
for extentId, extentSize := range repairTasks[0].LeaderTinyExtentRealSize {
|
||||
dp.extentStore.UpdateTinyExtentRealSize(extentId, uint64(extentSize))
|
||||
}
|
||||
// error check
|
||||
if dp.extentStore.AvailableTinyExtentCnt()+dp.extentStore.BrokenTinyExtentCnt() > storage.TinyExtentCount {
|
||||
log.LogWarnf("action[repair] partition(%v) GoodTinyExtents(%v) "+
|
||||
@ -136,13 +131,13 @@ func (dp *DataPartition) repair(extentType uint8) {
|
||||
|
||||
func (dp *DataPartition) buildDataPartitionRepairTask(repairTasks []*DataPartitionRepairTask, extentType uint8, tinyExtents []uint64) (err error) {
|
||||
// get the local extent info
|
||||
extents, leaderTinyExtentRealSize, leaderTinyDeleteRecordFileSize, err := dp.getLocalExtentInfo(extentType, tinyExtents)
|
||||
extents, leaderTinyDeleteRecordFileSize, err := dp.getLocalExtentInfo(extentType, tinyExtents)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// new repair task for the leader
|
||||
repairTasks[0] = NewDataPartitionRepairTask(extents, leaderTinyExtentRealSize, leaderTinyDeleteRecordFileSize, dp.replicas[0], dp.replicas[0])
|
||||
repairTasks[0] = NewDataPartitionRepairTask(extents, leaderTinyDeleteRecordFileSize, dp.replicas[0], dp.replicas[0])
|
||||
repairTasks[0].addr = dp.replicas[0]
|
||||
|
||||
// new repair tasks for the followers
|
||||
@ -152,14 +147,14 @@ func (dp *DataPartition) buildDataPartitionRepairTask(repairTasks []*DataPartiti
|
||||
log.LogErrorf("buildDataPartitionRepairTask partitionID(%v) on (%v) err(%v)", dp.partitionID, dp.replicas[index], err)
|
||||
continue
|
||||
}
|
||||
repairTasks[index] = NewDataPartitionRepairTask(extents, leaderTinyExtentRealSize, leaderTinyDeleteRecordFileSize, dp.replicas[index], dp.replicas[0])
|
||||
repairTasks[index] = NewDataPartitionRepairTask(extents, leaderTinyDeleteRecordFileSize, dp.replicas[index], dp.replicas[0])
|
||||
repairTasks[index].addr = dp.replicas[index]
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (dp *DataPartition) getLocalExtentInfo(extentType uint8, tinyExtents []uint64) (extents []*storage.ExtentInfo, leaderTinyExtentRealSize map[uint64]int64, leaderTinyDeleteRecordFileSize int64, err error) {
|
||||
func (dp *DataPartition) getLocalExtentInfo(extentType uint8, tinyExtents []uint64) (extents []*storage.ExtentInfo, leaderTinyDeleteRecordFileSize int64, err error) {
|
||||
localExtents := make([]*storage.ExtentInfo, 0)
|
||||
extents = make([]*storage.ExtentInfo, 0)
|
||||
|
||||
@ -181,7 +176,6 @@ func (dp *DataPartition) getLocalExtentInfo(extentType uint8, tinyExtents []uint
|
||||
if err = json.Unmarshal(data, &extents); err != nil {
|
||||
err = errors.Trace(err, "getLocalExtentInfo extent DataPartition(%v) GetAllWaterMark", dp.partitionID)
|
||||
}
|
||||
leaderTinyExtentRealSize = dp.extentStore.GetTinyExtentsRealSize(tinyExtents)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@ -121,10 +121,7 @@ func CreateDataPartition(dpCfg *dataPartitionCfg, disk *Disk, request *proto.Cre
|
||||
if dp, err = newDataPartition(dpCfg, disk); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
go dp.StartRaftLoggingSchedule()
|
||||
dp.ForceLoadHeader()
|
||||
|
||||
if request.CreateType == proto.NormalCreateDataPartition {
|
||||
err = dp.StartRaft()
|
||||
} else {
|
||||
@ -135,6 +132,7 @@ func CreateDataPartition(dpCfg *dataPartitionCfg, disk *Disk, request *proto.Cre
|
||||
}
|
||||
|
||||
// persist file metadata
|
||||
go dp.StartRaftLoggingSchedule()
|
||||
err = dp.PersistMetadata(request.CreateType)
|
||||
disk.AddSize(uint64(dp.Size()))
|
||||
return
|
||||
@ -278,6 +276,9 @@ func (dp *DataPartition) ReloadSnapshot() {
|
||||
return
|
||||
}
|
||||
dp.snapshotMutex.Lock()
|
||||
for _, f := range dp.snapshot {
|
||||
storage.PutSnapShotFileToPool(f)
|
||||
}
|
||||
dp.snapshot = files
|
||||
dp.snapshotMutex.Unlock()
|
||||
}
|
||||
@ -656,9 +657,6 @@ func (dp *DataPartition) DoExtentStoreRepair(repairTask *DataPartitionRepairTask
|
||||
}
|
||||
wg.Wait()
|
||||
dp.doStreamFixTinyDeleteRecord(repairTask, time.Now().Unix()-dp.FullSyncTinyDeleteTime > MaxFullSyncTinyDeleteTime)
|
||||
for extentID, tinyExtentRealSize := range repairTask.LeaderTinyExtentRealSize {
|
||||
dp.extentStore.UpdateTinyExtentRealSize(extentID, uint64(tinyExtentRealSize))
|
||||
}
|
||||
}
|
||||
|
||||
func (dp *DataPartition) doStreamFixTinyDeleteRecord(repairTask *DataPartitionRepairTask, isFullSync bool) {
|
||||
|
||||
@ -159,7 +159,6 @@ func (s *DataNode) getPartitionAPI(w http.ResponseWriter, r *http.Request) {
|
||||
FileCount int `json:"fileCount"`
|
||||
Replicas []string `json:"replicas"`
|
||||
TinyDeleteRecordSize int64 `json:"tinyDeleteRecordSize"`
|
||||
TinyExtentRealSize map[uint64]int64 `json:"tinyExtentRealSize"`
|
||||
RaftStatus *raft.Status `json: "raftStatus"`
|
||||
}{
|
||||
VolName: partition.volumeID,
|
||||
@ -172,7 +171,6 @@ func (s *DataNode) getPartitionAPI(w http.ResponseWriter, r *http.Request) {
|
||||
FileCount: len(files),
|
||||
Replicas: partition.Replicas(),
|
||||
TinyDeleteRecordSize: tinyDeleteRecordSize,
|
||||
TinyExtentRealSize: partition.extentStore.GetAllTinyExtentsRealSize(),
|
||||
RaftStatus: partition.raftPartition.Status(),
|
||||
}
|
||||
s.buildSuccessResp(w, result)
|
||||
|
||||
@ -283,13 +283,13 @@ func (manager *SpaceManager) CreatePartition(request *proto.CreateDataPartitionR
|
||||
|
||||
// DeletePartition deletes a partition based on the partition id.
|
||||
func (manager *SpaceManager) DeletePartition(dpID uint64) {
|
||||
manager.partitionMutex.Lock()
|
||||
defer manager.partitionMutex.Unlock()
|
||||
dp := manager.partitions[dpID]
|
||||
dp := manager.Partition(dpID)
|
||||
if dp == nil {
|
||||
return
|
||||
}
|
||||
manager.partitionMutex.Lock()
|
||||
delete(manager.partitions, dpID)
|
||||
manager.partitionMutex.Unlock()
|
||||
dp.Stop()
|
||||
dp.Disk().DetachDataPartition(dp)
|
||||
os.RemoveAll(dp.Path())
|
||||
|
||||
@ -4,7 +4,6 @@
|
||||
"volName": "ltptest",
|
||||
"owner": "ltptest",
|
||||
"logDir": "/cfs/log",
|
||||
"warnLogDir":"/cfs/log",
|
||||
"logLevel": "info",
|
||||
"consulAddr": "http://192.168.0.100:8500",
|
||||
"exporterPort": 9500,
|
||||
|
||||
@ -8,7 +8,6 @@
|
||||
"exporterPort": 9500,
|
||||
"rack": "rack-01",
|
||||
"logDir": "/cfs/log",
|
||||
"warnLogDir":"/cfs/log",
|
||||
"logLevel": "info",
|
||||
"disks": [
|
||||
"/cfs/disk:10737418240"
|
||||
|
||||
@ -12,6 +12,5 @@
|
||||
"logLevel": "info",
|
||||
"logDir": "/cfs/log",
|
||||
"walDir": "/cfs/data/wal",
|
||||
"warnLogDir":"/cfs/log",
|
||||
"storeDir": "/cfs/data/store"
|
||||
}
|
||||
|
||||
@ -12,6 +12,5 @@
|
||||
"logLevel": "info",
|
||||
"logDir": "/cfs/log",
|
||||
"walDir": "/cfs/data/wal",
|
||||
"warnLogDir":"/cfs/log",
|
||||
"storeDir": "/cfs/data/store"
|
||||
}
|
||||
|
||||
@ -12,6 +12,5 @@
|
||||
"logLevel": "info",
|
||||
"logDir": "/cfs/log",
|
||||
"walDir": "/cfs/data/wal",
|
||||
"warnLogDir":"/cfs/log",
|
||||
"storeDir": "/cfs/data/store"
|
||||
}
|
||||
|
||||
@ -8,7 +8,6 @@
|
||||
"exporterPort": 9500,
|
||||
"logLevel": "info",
|
||||
"logDir": "/cfs/log",
|
||||
"warnLogDir":"/cfs/log",
|
||||
"totalMem":"6442450944",
|
||||
"metadataDir": "/cfs/data/meta",
|
||||
"raftDir": "/cfs/data/raft",
|
||||
|
||||
@ -109,7 +109,7 @@ wait_proc_done() {
|
||||
logfile=$2
|
||||
logfile2=${logfile}-2
|
||||
logfile3=${logfile}-3
|
||||
maxtime=${3:-29000}
|
||||
maxtime=${3:-3000}
|
||||
checktime=${4:-60}
|
||||
retfile=${5:-"/tmp/ltpret"}
|
||||
timeout=1
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
rm -rf /cfs/disk/* /cfs/log/*
|
||||
mkdir -p /cfs/bin /cfs/log /cfs/disk
|
||||
|
||||
sleep 10
|
||||
echo "start datanode"
|
||||
/cfs/bin/cfs-server -c /cfs/conf/datanode.json
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
rm -rf /cfs/data* /cfs/log/*
|
||||
mkdir -p /cfs/log /cfs/data/wal /cfs/data/store /cfs/bin
|
||||
|
||||
echo "start master"
|
||||
/cfs/bin/cfs-server -c /cfs/conf/master.json
|
||||
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
rm -rf /cfs/data/* /cfs/log/*
|
||||
mkdir -p /cfs/bin /cfs/log /cfs/data/meta /cfs/data/raft
|
||||
|
||||
echo "start metanode"
|
||||
/cfs/bin/cfs-server -c /cfs/conf/metanode.json
|
||||
|
||||
|
||||
@ -63,7 +63,6 @@ type Extent struct {
|
||||
extentID uint64
|
||||
modifyTime int64
|
||||
dataSize int64
|
||||
realSize int64
|
||||
hasClose int32
|
||||
header []byte
|
||||
sync.Mutex
|
||||
@ -413,33 +412,3 @@ func (e *Extent) tinyExtentAvaliOffset(offset int64) (newOffset, newEnd int64, e
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (e *Extent) tinyExtentUpdateRealSize(leaderFileSize int64) {
|
||||
if !IsTinyExtent(e.extentID) {
|
||||
return
|
||||
}
|
||||
if e.dataSize < leaderFileSize {
|
||||
atomic.StoreInt64(&e.realSize, 0)
|
||||
return
|
||||
}
|
||||
atomic.StoreInt64(&e.realSize, 0)
|
||||
var (
|
||||
offset, realSize int64
|
||||
)
|
||||
for {
|
||||
newOffset, err := e.file.Seek(int64(offset), SEEK_DATA)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
newEnd, err := e.file.Seek(int64(newOffset), SEEK_HOLE)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
if newOffset >= leaderFileSize || newEnd >= leaderFileSize {
|
||||
break
|
||||
}
|
||||
realSize = realSize + (newEnd - newOffset)
|
||||
offset = newEnd
|
||||
}
|
||||
atomic.StoreInt64(&e.realSize, realSize)
|
||||
}
|
||||
|
||||
@ -54,8 +54,20 @@ const (
|
||||
|
||||
var (
|
||||
RegexpExtentFile, _ = regexp.Compile("^(\\d)+$")
|
||||
SnapShotFilePool = &sync.Pool{New: func() interface{} {
|
||||
return new(proto.File)
|
||||
}}
|
||||
)
|
||||
|
||||
func GetSnapShotFileFromPool() (f *proto.File) {
|
||||
f = SnapShotFilePool.Get().(*proto.File)
|
||||
return
|
||||
}
|
||||
|
||||
func PutSnapShotFileToPool(f *proto.File) {
|
||||
SnapShotFilePool.Put(f)
|
||||
}
|
||||
|
||||
type ExtentFilter func(info *ExtentInfo) bool
|
||||
|
||||
// Filters
|
||||
@ -182,7 +194,7 @@ func (s *ExtentStore) SnapShot() (files []*proto.File, err error) {
|
||||
|
||||
files = make([]*proto.File, 0, len(normalExtentSnapshot))
|
||||
for _, ei := range normalExtentSnapshot {
|
||||
file := new(proto.File)
|
||||
file := GetSnapShotFileFromPool()
|
||||
file.Name = strconv.FormatUint(ei.FileID, 10)
|
||||
file.Size = uint32(ei.Size)
|
||||
file.Modified = ei.ModifyTime
|
||||
@ -191,7 +203,7 @@ func (s *ExtentStore) SnapShot() (files []*proto.File, err error) {
|
||||
}
|
||||
tinyExtentSnapshot = s.getTinyExtentInfo()
|
||||
for _, ei := range tinyExtentSnapshot {
|
||||
file := new(proto.File)
|
||||
file := GetSnapShotFileFromPool()
|
||||
file.Name = strconv.FormatUint(ei.FileID, 10)
|
||||
file.Size = uint32(ei.Size)
|
||||
file.Modified = ei.ModifyTime
|
||||
@ -459,31 +471,6 @@ func (s *ExtentStore) GetAllWatermarks(filter ExtentFilter) (extents []*ExtentIn
|
||||
return
|
||||
}
|
||||
|
||||
func (s *ExtentStore) GetTinyExtentsRealSize(extentIDs []uint64) (tinyExtentRealSize map[uint64]int64) {
|
||||
tinyExtentRealSize = make(map[uint64]int64, 0)
|
||||
for _, extentID := range extentIDs {
|
||||
e, err := s.extentWithHeaderByExtentID(extentID)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
tinyExtentRealSize[extentID] = atomic.LoadInt64(&e.realSize)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *ExtentStore) GetAllTinyExtentsRealSize() (tinyExtentRealSize map[uint64]int64) {
|
||||
tinyExtentRealSize = make(map[uint64]int64, 0)
|
||||
var extentID uint64
|
||||
for extentID = TinyExtentStartID; extentID < TinyExtentCount+TinyExtentStartID; extentID++ {
|
||||
e, err := s.extentWithHeaderByExtentID(extentID)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
tinyExtentRealSize[extentID] = atomic.LoadInt64(&e.realSize)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *ExtentStore) getTinyExtentInfo() (extents []*ExtentInfo) {
|
||||
extents = make([]*ExtentInfo, 0)
|
||||
s.eiMutex.RLock()
|
||||
@ -843,7 +830,7 @@ func (s *ExtentStore) AutoComputeExtentCrc() {
|
||||
}
|
||||
ei.UpdateExtentInfo(e, extentCrc)
|
||||
}
|
||||
time.Sleep(time.Millisecond * 50)
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
}
|
||||
|
||||
}
|
||||
@ -921,19 +908,3 @@ func (s *ExtentStore) TinyExtentAvaliOffset(extentID uint64, offset int64) (newO
|
||||
return
|
||||
}
|
||||
|
||||
func (s *ExtentStore) UpdateTinyExtentRealSize(extentID uint64, leaderSize uint64) {
|
||||
var (
|
||||
e *Extent
|
||||
err error
|
||||
)
|
||||
if !IsTinyExtent(extentID) {
|
||||
return
|
||||
}
|
||||
s.eiMutex.RLock()
|
||||
ei := s.extentInfoMap[extentID]
|
||||
s.eiMutex.RUnlock()
|
||||
if e, err = s.extentWithHeader(ei); err != nil {
|
||||
return
|
||||
}
|
||||
e.tinyExtentUpdateRealSize(int64(leaderSize))
|
||||
}
|
||||
|
||||
@ -16,6 +16,7 @@ package exporter
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/chubaofs/chubaofs/util/log"
|
||||
"github.com/chubaofs/chubaofs/util/ump"
|
||||
"sync"
|
||||
)
|
||||
@ -41,12 +42,14 @@ type Alarm struct {
|
||||
}
|
||||
|
||||
func Warning(detail string) (a *Alarm) {
|
||||
ump.Alarm(fmt.Sprintf("%v_%v_warning", clustername, modulename), detail)
|
||||
if !enabled {
|
||||
key := fmt.Sprintf("%v_%v_warning", clustername, modulename)
|
||||
ump.Alarm(key, detail)
|
||||
log.LogCriticalf(key, detail)
|
||||
if !enabledPrometheus {
|
||||
return
|
||||
}
|
||||
a = AlarmPool.Get().(*Alarm)
|
||||
a.name = metricsName(fmt.Sprintf("%s_%s_alarm", clustername, modulename))
|
||||
a.name = metricsName(key)
|
||||
a.Add(1)
|
||||
return
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ type Counter struct {
|
||||
}
|
||||
|
||||
func NewCounter(name string) (c *Counter) {
|
||||
if !enabled {
|
||||
if !enabledPrometheus {
|
||||
return
|
||||
}
|
||||
c = CounterPool.Get().(*Counter)
|
||||
@ -53,7 +53,7 @@ func NewCounter(name string) (c *Counter) {
|
||||
}
|
||||
|
||||
func (c *Counter) Add(val int64) {
|
||||
if !enabled {
|
||||
if !enabledPrometheus {
|
||||
return
|
||||
}
|
||||
c.val = val
|
||||
@ -68,7 +68,7 @@ func (c *Counter) publish() {
|
||||
}
|
||||
|
||||
func (c *Counter) AddWithLabels(val int64, labels map[string]string) {
|
||||
if !enabled {
|
||||
if !enabledPrometheus {
|
||||
return
|
||||
}
|
||||
c.labels = labels
|
||||
|
||||
@ -35,11 +35,11 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
namespace string
|
||||
clustername string
|
||||
modulename string
|
||||
enabled = false
|
||||
replacer = strings.NewReplacer("-", "_", ".", "_", " ", "_", ",", "_")
|
||||
namespace string
|
||||
clustername string
|
||||
modulename string
|
||||
enabledPrometheus = false
|
||||
replacer = strings.NewReplacer("-", "_", ".", "_", " ", "_", ",", "_")
|
||||
)
|
||||
|
||||
func metricsName(name string) string {
|
||||
@ -55,7 +55,7 @@ func Init(cluster string, role string, cfg *config.Config) {
|
||||
log.LogInfof("exporter port not set")
|
||||
return
|
||||
}
|
||||
enabled = true
|
||||
enabledPrometheus = true
|
||||
http.Handle(PromHandlerPattern, promhttp.HandlerFor(prometheus.DefaultGatherer, promhttp.HandlerOpts{
|
||||
Timeout: 5 * time.Second,
|
||||
}))
|
||||
@ -82,7 +82,7 @@ func Init(cluster string, role string, cfg *config.Config) {
|
||||
}
|
||||
|
||||
func collect() {
|
||||
if !enabled {
|
||||
if !enabledPrometheus {
|
||||
return
|
||||
}
|
||||
go collectCounter()
|
||||
|
||||
@ -49,7 +49,7 @@ type Gauge struct {
|
||||
}
|
||||
|
||||
func NewGauge(name string) (g *Gauge) {
|
||||
if !enabled {
|
||||
if !enabledPrometheus {
|
||||
return
|
||||
}
|
||||
g = GaugePool.Get().(*Gauge)
|
||||
@ -85,7 +85,7 @@ func (c *Gauge) Metric() prometheus.Gauge {
|
||||
}
|
||||
|
||||
func (g *Gauge) Set(val int64) {
|
||||
if !enabled {
|
||||
if !enabledPrometheus {
|
||||
return
|
||||
}
|
||||
g.val = val
|
||||
@ -100,7 +100,7 @@ func (c *Gauge) publish() {
|
||||
}
|
||||
|
||||
func (g *Gauge) SetWithLabels(val int64, labels map[string]string) {
|
||||
if !enabled {
|
||||
if !enabledPrometheus {
|
||||
return
|
||||
}
|
||||
g.labels = labels
|
||||
|
||||
@ -51,7 +51,7 @@ type TimePointCount struct {
|
||||
}
|
||||
|
||||
func NewTP(name string) (tp *TimePoint) {
|
||||
if !enabled {
|
||||
if !enabledPrometheus {
|
||||
return
|
||||
}
|
||||
tp = TPPool.Get().(*TimePoint)
|
||||
@ -61,7 +61,7 @@ func NewTP(name string) (tp *TimePoint) {
|
||||
}
|
||||
|
||||
func (tp *TimePoint) Set() {
|
||||
if !enabled {
|
||||
if !enabledPrometheus {
|
||||
return
|
||||
}
|
||||
val := time.Since(tp.startTime).Nanoseconds()
|
||||
|
||||
@ -34,13 +34,14 @@ import (
|
||||
type Level uint8
|
||||
|
||||
const (
|
||||
DebugLevel Level = 1
|
||||
InfoLevel = DebugLevel<<1 + 1
|
||||
WarnLevel = InfoLevel<<1 + 1
|
||||
ErrorLevel = WarnLevel<<1 + 1
|
||||
FatalLevel = ErrorLevel<<1 + 1
|
||||
ReadLevel = InfoLevel
|
||||
UpdateLevel = InfoLevel
|
||||
DebugLevel Level = 1
|
||||
InfoLevel = DebugLevel<<1 + 1
|
||||
WarnLevel = InfoLevel<<1 + 1
|
||||
ErrorLevel = WarnLevel<<1 + 1
|
||||
FatalLevel = ErrorLevel<<1 + 1
|
||||
CriticalLevel = FatalLevel << +1
|
||||
ReadLevel = InfoLevel
|
||||
UpdateLevel = InfoLevel
|
||||
)
|
||||
|
||||
const (
|
||||
@ -60,6 +61,7 @@ var levelPrefixes = []string{
|
||||
"[FATAL]",
|
||||
"[READ ]",
|
||||
"[WRITE]",
|
||||
"[Critical]",
|
||||
}
|
||||
|
||||
type RolledFile []os.FileInfo
|
||||
@ -230,6 +232,7 @@ type Log struct {
|
||||
infoLogger *LogObject
|
||||
readLogger *LogObject
|
||||
updateLogger *LogObject
|
||||
criticalLogger *LogObject
|
||||
level Level
|
||||
msgC chan string
|
||||
rotate *LogRotate
|
||||
@ -237,12 +240,13 @@ type Log struct {
|
||||
}
|
||||
|
||||
var (
|
||||
ErrLogFileName = "_error.log"
|
||||
WarnLogFileName = "_warn.log"
|
||||
InfoLogFileName = "_info.log"
|
||||
DebugLogFileName = "_debug.log"
|
||||
ReadLogFileName = "_read.log"
|
||||
UpdateLogFileName = "_write.log"
|
||||
ErrLogFileName = "_error.log"
|
||||
WarnLogFileName = "_warn.log"
|
||||
InfoLogFileName = "_info.log"
|
||||
DebugLogFileName = "_debug.log"
|
||||
ReadLogFileName = "_read.log"
|
||||
UpdateLogFileName = "_write.log"
|
||||
CriticalLogFileName = "_critical.log"
|
||||
)
|
||||
|
||||
var gLog *Log = nil
|
||||
@ -297,8 +301,8 @@ func (l *Log) initLog(logDir, module string, level Level) error {
|
||||
return
|
||||
}
|
||||
var err error
|
||||
logHandles := [...]**LogObject{&l.debugLogger, &l.infoLogger, &l.warnLogger, &l.errorLogger, &l.readLogger, &l.updateLogger}
|
||||
logNames := [...]string{DebugLogFileName, InfoLogFileName, WarnLogFileName, ErrLogFileName, ReadLogFileName, UpdateLogFileName}
|
||||
logHandles := [...]**LogObject{&l.debugLogger, &l.infoLogger, &l.warnLogger, &l.errorLogger, &l.readLogger, &l.updateLogger, &l.criticalLogger}
|
||||
logNames := [...]string{DebugLogFileName, InfoLogFileName, WarnLogFileName, ErrLogFileName, ReadLogFileName, UpdateLogFileName, CriticalLogFileName}
|
||||
for i := range logHandles {
|
||||
if *logHandles[i], err = newLog(logNames[i]); err != nil {
|
||||
return err
|
||||
@ -334,6 +338,7 @@ func (l *Log) Flush() {
|
||||
l.errorLogger,
|
||||
l.readLogger,
|
||||
l.updateLogger,
|
||||
l.criticalLogger,
|
||||
}
|
||||
for _, logger := range loggers {
|
||||
if logger != nil {
|
||||
@ -451,9 +456,6 @@ func LogFatal(v ...interface{}) {
|
||||
if gLog == nil {
|
||||
return
|
||||
}
|
||||
if FatalLevel&gLog.level != gLog.level {
|
||||
return
|
||||
}
|
||||
s := fmt.Sprintln(v...)
|
||||
s = gLog.SetPrefix(s, levelPrefixes[4])
|
||||
gLog.errorLogger.Output(2, s)
|
||||
@ -465,15 +467,32 @@ func LogFatalf(format string, v ...interface{}) {
|
||||
if gLog == nil {
|
||||
return
|
||||
}
|
||||
if FatalLevel&gLog.level != gLog.level {
|
||||
return
|
||||
}
|
||||
s := fmt.Sprintf(format, v...)
|
||||
s = gLog.SetPrefix(s, levelPrefixes[4])
|
||||
gLog.errorLogger.Output(2, s)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// LogFatal logs the fatal errors.
|
||||
func LogCritical(v ...interface{}) {
|
||||
if gLog == nil {
|
||||
return
|
||||
}
|
||||
s := fmt.Sprintln(v...)
|
||||
s = gLog.SetPrefix(s, levelPrefixes[4])
|
||||
gLog.criticalLogger.Output(2, s)
|
||||
}
|
||||
|
||||
// LogFatalf logs the fatal errors with specified format.
|
||||
func LogCriticalf(format string, v ...interface{}) {
|
||||
if gLog == nil {
|
||||
return
|
||||
}
|
||||
s := fmt.Sprintf(format, v...)
|
||||
s = gLog.SetPrefix(s, levelPrefixes[4])
|
||||
gLog.criticalLogger.Output(2, s)
|
||||
}
|
||||
|
||||
// LogRead
|
||||
func LogRead(v ...interface{}) {
|
||||
if gLog == nil {
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
package ump
|
||||
|
||||
import (
|
||||
"os"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"sync"
|
||||
@ -54,12 +55,20 @@ var (
|
||||
FunctionTpPool = &sync.Pool{New: func() interface{} {
|
||||
return new(FunctionTp)
|
||||
}}
|
||||
enableUmp = true
|
||||
)
|
||||
|
||||
func InitUmp(module, dataDir string) (err error) {
|
||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||
if err := initLogName(module, dataDir); err != nil {
|
||||
return err
|
||||
if _, err = os.Stat(dataDir); err != nil {
|
||||
enableUmp = false
|
||||
err=nil
|
||||
return
|
||||
}
|
||||
if err = initLogName(module, dataDir); err != nil {
|
||||
enableUmp = false
|
||||
err=nil
|
||||
return
|
||||
}
|
||||
|
||||
backGroudWrite()
|
||||
@ -67,6 +76,9 @@ func InitUmp(module, dataDir string) (err error) {
|
||||
}
|
||||
|
||||
func BeforeTP(key string) (o *TpObject) {
|
||||
if !enableUmp {
|
||||
return
|
||||
}
|
||||
o = TpObjectPool.Get().(*TpObject)
|
||||
o.StartTime = time.Now()
|
||||
tp := FunctionTpPool.Get().(*FunctionTp)
|
||||
@ -80,6 +92,9 @@ func BeforeTP(key string) (o *TpObject) {
|
||||
}
|
||||
|
||||
func AfterTP(o *TpObject, err error) {
|
||||
if !enableUmp {
|
||||
return
|
||||
}
|
||||
tp := o.UmpType.(*FunctionTp)
|
||||
tp.ElapsedTime = strconv.FormatInt((int64)(time.Since(o.StartTime)/1e6), 10)
|
||||
TpObjectPool.Put(o)
|
||||
@ -96,6 +111,9 @@ func AfterTP(o *TpObject, err error) {
|
||||
}
|
||||
|
||||
func Alive(key string) {
|
||||
if !enableUmp {
|
||||
return
|
||||
}
|
||||
alive := SystemAlivePool.Get().(*SystemAlive)
|
||||
alive.HostName = HostName
|
||||
alive.Key = key
|
||||
@ -108,6 +126,9 @@ func Alive(key string) {
|
||||
}
|
||||
|
||||
func Alarm(key, detail string) {
|
||||
if !enableUmp {
|
||||
return
|
||||
}
|
||||
alarm := AlarmPool.Get().(*BusinessAlarm)
|
||||
alarm.Time = time.Now().Format(LogTimeForMat)
|
||||
alarm.Key = key
|
||||
|
||||
24
vendor/github.com/tiglabs/raft/.gitignore
generated
vendored
24
vendor/github.com/tiglabs/raft/.gitignore
generated
vendored
@ -1,24 +0,0 @@
|
||||
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
||||
*.o
|
||||
*.a
|
||||
*.so
|
||||
|
||||
# Folders
|
||||
_obj
|
||||
_test
|
||||
|
||||
# Architecture specific extensions/prefixes
|
||||
*.[568vq]
|
||||
[568vq].out
|
||||
|
||||
*.cgo1.go
|
||||
*.cgo2.c
|
||||
_cgo_defun.c
|
||||
_cgo_gotypes.go
|
||||
_cgo_export.*
|
||||
|
||||
_testmain.go
|
||||
|
||||
*.exe
|
||||
*.test
|
||||
*.prof
|
||||
Loading…
Reference in New Issue
Block a user