예제 #1
0
파일: server.go 프로젝트: yuya008/godis
func InitServer(godis *Godis, ser *goconf.Section) {
	if v, err := ser.String("host"); err == nil {
		godis.Host = v
	}
	if v, err := ser.String("port"); err == nil {
		godis.Port = v
	}
	if v, err := ser.Int("max_dbs"); err == nil {
		godis.Dbs = make([]db.DB, v)
	}
	for i := 0; i < len(godis.Dbs); i++ {
		db.InitDB(uint16(i), &godis.Dbs[i])
	}
	if v, err := ser.Int("max_client"); err == nil {
		godis.MaxClientsN = uint64(v)
	}
	if v, err := ser.Int("cmd_args_num"); err == nil {
		godis.Cmdargsnum = int(v)
	}
	if v, err := ser.Int("cmd_arg_size"); err == nil {
		godis.Cmdargsize = uint64(v)
	}
	if v, err := ser.Int("ts_trylock_timeout"); err == nil {
		godis.Tstimeout = time.Millisecond * time.Duration(v)
	}
	if _, err := ser.String("datadir"); err == nil {
		godis.Dl, err = store.NewDataLog(ser)
		if err != nil {
			log.Panicln(err)
		}
		godis.Dl.LoadDiskData(godis.Dbs)
		godis.Dl.StartDataWriteThread()
		godis.Tl, err = store.NewTsLog(ser)
		if err != nil {
			log.Panicln(err)
		}
		godis.Tl.Load(godis.Dbs)
	} else {
		log.Panicln("Please configure dataDir!")
	}
}
예제 #2
0
파일: tslog.go 프로젝트: yuya008/godis
func NewTsLog(sec *goconf.Section) (*TsLog, error) {
	var (
		dir         string
		dataFileMax int = DefaultTsLogFileMaxSize
		metaFileMax int = DefaultTsLogMetaFileMaxSize
	)
	if v, err := sec.String("ts_data_dir"); err == nil {
		dir = v
	} else {
		if v, err := sec.String("datadir"); err == nil {
			dir = fmt.Sprintf("%s/%s", v, "ts")
		} else {
			log.Panicln("Please configure dataDir!")
		}
	}
	if v, err := sec.Int("ts_log_max_size"); err == nil {
		dataFileMax = int(v)
	}
	if v, err := sec.Int("ts_metalog_max_size"); err == nil {
		metaFileMax = int(v)
	}
	fileinfo, err := os.Stat(dir)
	if err != nil {
		return nil, err
	}
	if !fileinfo.IsDir() {
		return nil, Err_ts_log_dir_not_dir
	}
	tslog := &TsLog{
		dir:             dir,
		dataFileMaxSize: dataFileMax,
		metaFileMaxSize: metaFileMax,
	}
	tslog.scanTsLogFile()
	return tslog, nil
}
예제 #3
0
파일: datalog.go 프로젝트: yuya008/godis
func NewDataLog(sec *goconf.Section) (*DataLog, error) {
	var (
		datadir         string
		dataFileMaxSize uint64        = DefaultDataFileMaxSize
		dataWQSize      int           = DefaultWriteQSize
		dataSync        time.Duration = DefaultWriteSync
	)
	if v, err := sec.String("datadir"); err == nil {
		datadir = v
	}
	if v, err := sec.Int("data_file_max_size"); err == nil {
		dataFileMaxSize = uint64(v)
	}
	if v, err := sec.Int("data_write_queue_size"); err == nil {
		dataWQSize = int(v)
	}
	if v, err := sec.Int("data_write_sync_interval"); err == nil {
		dataSync = time.Millisecond * time.Duration(v)
	}

	fileinfo, err := os.Stat(datadir)
	if err != nil {
		return nil, err
	}
	if !fileinfo.IsDir() {
		return nil, Err_datadir_not_dir
	}
	dl := &DataLog{
		Datadir:          datadir,
		DataFileMaxSize:  dataFileMaxSize,
		logWriteQ:        make(chan *dataRecord, dataWQSize),
		dataSyncInterval: dataSync,
	}
	err = dl.scanLogFile()
	if err != nil {
		return nil, err
	}
	return dl, nil
}