param_table.go 6.9 KB
Newer Older
X
XuanYang-cn 已提交
1 2 3 4 5 6
package datanode

import (
	"os"
	"path"
	"strconv"
7
	"sync"
X
XuanYang-cn 已提交
8

X
XuanYang-cn 已提交
9
	"github.com/zilliztech/milvus-distributed/internal/log"
X
XuanYang-cn 已提交
10 11 12 13 14 15 16 17 18 19
	"github.com/zilliztech/milvus-distributed/internal/util/paramtable"
)

type ParamTable struct {
	// === PRIVATE Configs ===
	dataNodeIDList []UniqueID

	paramtable.BaseTable

	// === DataNode Internal Components Configs ===
X
XuanYang-cn 已提交
20
	NodeID                  UniqueID
21 22
	IP                      string
	Port                    int
X
XuanYang-cn 已提交
23 24 25 26 27
	FlowGraphMaxQueueLength int32
	FlowGraphMaxParallelism int32
	FlushInsertBufferSize   int32
	FlushDdBufferSize       int32
	InsertBinlogRootPath    string
28
	DdlBinlogRootPath       string
X
XuanYang-cn 已提交
29
	Log                     log.Config
X
XuanYang-cn 已提交
30 31 32 33 34 35

	// === DataNode External Components Configs ===
	// --- Pulsar ---
	PulsarAddress string

	// - insert channel -
X
XuanYang-cn 已提交
36
	InsertChannelNames []string
X
XuanYang-cn 已提交
37 38

	// - dd channel -
X
XuanYang-cn 已提交
39
	DDChannelNames []string
X
XuanYang-cn 已提交
40 41

	// - seg statistics channel -
X
XuanYang-cn 已提交
42
	SegmentStatisticsChannelName string
X
XuanYang-cn 已提交
43 44

	// - timetick channel -
X
XuanYang-cn 已提交
45
	TimeTickChannelName string
X
XuanYang-cn 已提交
46

X
XuanYang-cn 已提交
47
	// - complete flush channel -
X
XuanYang-cn 已提交
48
	CompleteFlushChannelName string
X
XuanYang-cn 已提交
49

X
XuanYang-cn 已提交
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
	// - channel subname -
	MsgChannelSubName string

	// --- ETCD ---
	EtcdAddress         string
	MetaRootPath        string
	SegFlushMetaSubPath string
	DDLFlushMetaSubPath string

	// --- MinIO ---
	MinioAddress         string
	MinioAccessKeyID     string
	MinioSecretAccessKey string
	MinioUseSSL          bool
	MinioBucketName      string
}

var Params ParamTable
68
var once sync.Once
X
XuanYang-cn 已提交
69 70

func (p *ParamTable) Init() {
71 72 73 74 75 76
	once.Do(func() {
		p.BaseTable.Init()
		err := p.LoadYaml("advanced/data_node.yaml")
		if err != nil {
			panic(err)
		}
X
XuanYang-cn 已提交
77

78 79 80 81 82 83 84
		// === DataNode Internal Components Configs ===
		p.initNodeID()
		p.initFlowGraphMaxQueueLength()
		p.initFlowGraphMaxParallelism()
		p.initFlushInsertBufferSize()
		p.initFlushDdBufferSize()
		p.initInsertBinlogRootPath()
85
		p.initDdlBinlogRootPath()
X
XuanYang-cn 已提交
86
		p.initLogCfg()
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113

		// === DataNode External Components Configs ===
		// --- Pulsar ---
		p.initPulsarAddress()

		// - insert channel -
		p.initInsertChannelNames()

		// - dd channel -
		p.initDDChannelNames()

		// - channel subname -
		p.initMsgChannelSubName()

		// --- ETCD ---
		p.initEtcdAddress()
		p.initMetaRootPath()
		p.initSegFlushMetaSubPath()
		p.initDDLFlushMetaSubPath()

		// --- MinIO ---
		p.initMinioAddress()
		p.initMinioAccessKeyID()
		p.initMinioSecretAccessKey()
		p.initMinioUseSSL()
		p.initMinioBucketName()
	})
X
XuanYang-cn 已提交
114 115 116
}

// ==== DataNode internal components configs ====
X
XuanYang-cn 已提交
117
func (p *ParamTable) initNodeID() {
X
XuanYang-cn 已提交
118 119 120 121 122 123 124 125 126 127 128 129 130 131
	p.dataNodeIDList = p.DataNodeIDList()
	dataNodeIDStr := os.Getenv("DATA_NODE_ID")
	if dataNodeIDStr == "" {
		if len(p.dataNodeIDList) <= 0 {
			dataNodeIDStr = "0"
		} else {
			dataNodeIDStr = strconv.Itoa(int(p.dataNodeIDList[0]))
		}
	}
	err := p.Save("_dataNodeID", dataNodeIDStr)
	if err != nil {
		panic(err)
	}

X
XuanYang-cn 已提交
132 133 134
	p.NodeID = p.ParseInt64("_dataNodeID")
}

X
XuanYang-cn 已提交
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
// ---- flowgraph configs ----
func (p *ParamTable) initFlowGraphMaxQueueLength() {
	p.FlowGraphMaxQueueLength = p.ParseInt32("dataNode.dataSync.flowGraph.maxQueueLength")
}

func (p *ParamTable) initFlowGraphMaxParallelism() {
	p.FlowGraphMaxParallelism = p.ParseInt32("dataNode.dataSync.flowGraph.maxParallelism")
}

// ---- flush configs ----
func (p *ParamTable) initFlushInsertBufferSize() {
	p.FlushInsertBufferSize = p.ParseInt32("datanode.flush.insertBufSize")
}

func (p *ParamTable) initFlushDdBufferSize() {
	p.FlushDdBufferSize = p.ParseInt32("datanode.flush.ddBufSize")
}

func (p *ParamTable) initInsertBinlogRootPath() {
	// GOOSE TODO: rootPath change to  TenentID
	rootPath, err := p.Load("etcd.rootPath")
	if err != nil {
		panic(err)
	}
	p.InsertBinlogRootPath = path.Join(rootPath, "insert_log")
}

162
func (p *ParamTable) initDdlBinlogRootPath() {
X
XuanYang-cn 已提交
163 164 165 166 167
	// GOOSE TODO: rootPath change to  TenentID
	rootPath, err := p.Load("etcd.rootPath")
	if err != nil {
		panic(err)
	}
168
	p.DdlBinlogRootPath = path.Join(rootPath, "data_definition_log")
X
XuanYang-cn 已提交
169 170 171 172 173 174 175 176 177 178 179 180 181
}

// ---- Pulsar ----
func (p *ParamTable) initPulsarAddress() {
	url, err := p.Load("_PulsarAddress")
	if err != nil {
		panic(err)
	}
	p.PulsarAddress = url
}

// - insert channel -
func (p *ParamTable) initInsertChannelNames() {
X
XuanYang-cn 已提交
182
	p.InsertChannelNames = make([]string, 0)
X
XuanYang-cn 已提交
183 184 185
}

func (p *ParamTable) initDDChannelNames() {
X
XuanYang-cn 已提交
186
	p.DDChannelNames = make([]string, 0)
X
XuanYang-cn 已提交
187 188 189 190 191 192
}

// - msg channel subname -
func (p *ParamTable) initMsgChannelSubName() {
	name, err := p.Load("msgChannel.subNamePrefix.dataNodeSubNamePrefix")
	if err != nil {
X
XuanYang-cn 已提交
193
		panic(err)
X
XuanYang-cn 已提交
194
	}
X
XuanYang-cn 已提交
195
	p.MsgChannelSubName = name + "-" + strconv.FormatInt(p.NodeID, 10)
X
XuanYang-cn 已提交
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
}

// --- ETCD ---
func (p *ParamTable) initEtcdAddress() {
	addr, err := p.Load("_EtcdAddress")
	if err != nil {
		panic(err)
	}
	p.EtcdAddress = addr
}

func (p *ParamTable) initMetaRootPath() {
	rootPath, err := p.Load("etcd.rootPath")
	if err != nil {
		panic(err)
	}
	subPath, err := p.Load("etcd.metaSubPath")
	if err != nil {
		panic(err)
	}
	p.MetaRootPath = path.Join(rootPath, subPath)
}

func (p *ParamTable) initSegFlushMetaSubPath() {
	subPath, err := p.Load("etcd.segFlushMetaSubPath")
	if err != nil {
		panic(err)
	}
	p.SegFlushMetaSubPath = subPath
}

func (p *ParamTable) initDDLFlushMetaSubPath() {
	subPath, err := p.Load("etcd.ddlFlushMetaSubPath")
	if err != nil {
		panic(err)
	}
	p.DDLFlushMetaSubPath = subPath
}

func (p *ParamTable) initMinioAddress() {
	endpoint, err := p.Load("_MinioAddress")
	if err != nil {
		panic(err)
	}
	p.MinioAddress = endpoint
}

func (p *ParamTable) initMinioAccessKeyID() {
	keyID, err := p.Load("minio.accessKeyID")
	if err != nil {
		panic(err)
	}
	p.MinioAccessKeyID = keyID
}

func (p *ParamTable) initMinioSecretAccessKey() {
	key, err := p.Load("minio.secretAccessKey")
	if err != nil {
		panic(err)
	}
	p.MinioSecretAccessKey = key
}

func (p *ParamTable) initMinioUseSSL() {
	usessl, err := p.Load("minio.useSSL")
	if err != nil {
		panic(err)
	}
	p.MinioUseSSL, _ = strconv.ParseBool(usessl)
}

func (p *ParamTable) initMinioBucketName() {
	bucketName, err := p.Load("minio.bucketName")
	if err != nil {
		panic(err)
	}
	p.MinioBucketName = bucketName
}

func (p *ParamTable) sliceIndex() int {
X
XuanYang-cn 已提交
276 277
	dataNodeID := p.NodeID
	dataNodeIDList := p.dataNodeIDList
X
XuanYang-cn 已提交
278 279 280 281 282 283 284
	for i := 0; i < len(dataNodeIDList); i++ {
		if dataNodeID == dataNodeIDList[i] {
			return i
		}
	}
	return -1
}
X
XuanYang-cn 已提交
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313

func (p *ParamTable) initLogCfg() {
	p.Log = log.Config{}
	format, err := p.Load("log.format")
	if err != nil {
		panic(err)
	}
	p.Log.Format = format
	level, err := p.Load("log.level")
	if err != nil {
		panic(err)
	}
	p.Log.Level = level
	devStr, err := p.Load("log.dev")
	if err != nil {
		panic(err)
	}
	dev, err := strconv.ParseBool(devStr)
	if err != nil {
		panic(err)
	}
	p.Log.Development = dev
	p.Log.File.MaxSize = p.ParseInt("log.file.maxSize")
	p.Log.File.MaxBackups = p.ParseInt("log.file.maxBackups")
	p.Log.File.MaxDays = p.ParseInt("log.file.maxAge")
	rootPath, err := p.Load("log.file.rootPath")
	if err != nil {
		panic(err)
	}
S
sunby 已提交
314 315 316 317 318
	if len(rootPath) != 0 {
		p.Log.File.Filename = path.Join(rootPath, "datanode-"+strconv.FormatInt(p.NodeID, 10)+".log")
	} else {
		p.Log.File.Filename = ""
	}
X
XuanYang-cn 已提交
319
}