component_param_test.go 11.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions and limitations under the License.

package paramtable

import (
15
	"math"
16 17
	"os"
	"path"
18
	"testing"
19
	"time"
20

21
	"github.com/stretchr/testify/assert"
22 23
)

24 25 26 27 28 29
func shouldPanic(t *testing.T, name string, f func()) {
	defer func() { recover() }()
	f()
	t.Errorf("%s should have panicked", name)
}

30 31 32
func TestComponentParam(t *testing.T) {
	var CParams ComponentParam
	CParams.Init()
33

34
	t.Run("test commonConfig", func(t *testing.T) {
35
		Params := CParams.CommonCfg
36 37 38 39 40 41 42 43

		assert.NotEqual(t, Params.DefaultPartitionName, "")
		t.Logf("default partition name = %s", Params.DefaultPartitionName)

		assert.NotEqual(t, Params.DefaultIndexName, "")
		t.Logf("default index name = %s", Params.DefaultIndexName)

		assert.Equal(t, Params.RetentionDuration, int64(DefaultRetentionDuration))
44
		t.Logf("default retention duration = %d", Params.RetentionDuration)
45

X
Xiaofan 已提交
46 47 48 49 50 51 52 53
		assert.Equal(t, int64(Params.EntityExpirationTTL), int64(-1))
		t.Logf("default entity expiration = %d", Params.EntityExpirationTTL)

		// test the case coommo
		Params.Base.Save("common.entityExpiration", "50")
		Params.initEntityExpiration()
		assert.Equal(t, int64(Params.EntityExpirationTTL.Seconds()), int64(DefaultRetentionDuration))

54 55
		assert.NotEqual(t, Params.SimdType, "")
		t.Logf("knowhere simd type = %s", Params.SimdType)
56

57 58 59
		assert.Equal(t, Params.IndexSliceSize, int64(DefaultIndexSliceSize))
		t.Logf("knowhere index slice size = %d", Params.IndexSliceSize)

60 61 62
		assert.Equal(t, Params.GracefulTime, int64(DefaultGracefulTime))
		t.Logf("default grafeful time = %d", Params.GracefulTime)

63 64 65 66
		// -- proxy --
		assert.Equal(t, Params.ProxySubName, "by-dev-proxy")
		t.Logf("ProxySubName: %s", Params.ProxySubName)

67 68 69 70 71 72 73 74 75 76 77 78
		// -- rootcoord --
		assert.Equal(t, Params.RootCoordTimeTick, "by-dev-rootcoord-timetick")
		t.Logf("rootcoord timetick channel = %s", Params.RootCoordTimeTick)

		assert.Equal(t, Params.RootCoordStatistics, "by-dev-rootcoord-statistics")
		t.Logf("rootcoord statistics channel = %s", Params.RootCoordStatistics)

		assert.Equal(t, Params.RootCoordDml, "by-dev-rootcoord-dml")
		t.Logf("rootcoord dml channel = %s", Params.RootCoordDml)

		assert.Equal(t, Params.RootCoordDelta, "by-dev-rootcoord-delta")
		t.Logf("rootcoord delta channel = %s", Params.RootCoordDelta)
79

80 81
		assert.Equal(t, Params.RootCoordSubName, "by-dev-rootCoord")
		t.Logf("rootcoord subname = %s", Params.RootCoordSubName)
82

83 84 85
		// -- querycoord --
		assert.Equal(t, Params.QueryCoordSearch, "by-dev-search")
		t.Logf("querycoord search channel = %s", Params.QueryCoordSearch)
86

87 88
		assert.Equal(t, Params.QueryCoordSearchResult, "by-dev-searchResult")
		t.Logf("querycoord search result channel = %s", Params.QueryCoordSearchResult)
89

90 91
		assert.Equal(t, Params.QueryCoordTimeTick, "by-dev-queryTimeTick")
		t.Logf("querycoord timetick channel = %s", Params.QueryCoordTimeTick)
92

93 94 95 96
		// -- querynode --
		assert.Equal(t, Params.QueryNodeStats, "by-dev-query-node-stats")
		t.Logf("querynode stats channel = %s", Params.QueryNodeStats)

97 98 99
		assert.Equal(t, Params.QueryNodeSubName, "by-dev-queryNode")
		t.Logf("querynode subname = %s", Params.QueryNodeSubName)

100 101 102 103 104 105 106 107 108
		// -- datacoord --
		assert.Equal(t, Params.DataCoordTimeTick, "by-dev-datacoord-timetick-channel")
		t.Logf("datacoord timetick channel = %s", Params.DataCoordTimeTick)

		assert.Equal(t, Params.DataCoordSegmentInfo, "by-dev-segment-info-channel")
		t.Logf("datacoord segment info channel = %s", Params.DataCoordSegmentInfo)

		assert.Equal(t, Params.DataCoordSubName, "by-dev-dataCoord")
		t.Logf("datacoord subname = %s", Params.DataCoordSubName)
109 110 111

		assert.Equal(t, Params.DataNodeSubName, "by-dev-dataNode")
		t.Logf("datanode subname = %s", Params.DataNodeSubName)
112 113 114
	})

	t.Run("test rootCoordConfig", func(t *testing.T) {
115
		Params := CParams.RootCoordCfg
116 117 118 119 120

		assert.NotEqual(t, Params.MaxPartitionNum, 0)
		t.Logf("master MaxPartitionNum = %d", Params.MaxPartitionNum)
		assert.NotEqual(t, Params.MinSegmentSizeToEnableIndex, 0)
		t.Logf("master MinSegmentSizeToEnableIndex = %d", Params.MinSegmentSizeToEnableIndex)
121 122 123 124 125 126 127 128
		assert.NotEqual(t, Params.ImportTaskExpiration, 0)
		t.Logf("master ImportTaskExpiration = %f", Params.ImportTaskExpiration)
		assert.NotEqual(t, Params.ImportTaskRetention, 0)
		t.Logf("master ImportTaskRetention = %f", Params.ImportTaskRetention)
		assert.NotEqual(t, Params.ImportIndexCheckInterval, 0)
		t.Logf("master ImportIndexCheckInterval = %f", Params.ImportIndexCheckInterval)
		assert.NotEqual(t, Params.ImportIndexWaitLimit, 0)
		t.Logf("master ImportIndexWaitLimit = %f", Params.ImportIndexWaitLimit)
129 130 131 132 133 134 135 136

		Params.CreatedTime = time.Now()
		Params.UpdatedTime = time.Now()
		t.Logf("created time: %v", Params.CreatedTime)
		t.Logf("updated time: %v", Params.UpdatedTime)
	})

	t.Run("test proxyConfig", func(t *testing.T) {
137
		Params := CParams.ProxyCfg
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154

		t.Logf("TimeTickInterval: %v", Params.TimeTickInterval)

		t.Logf("MsgStreamTimeTickBufSize: %d", Params.MsgStreamTimeTickBufSize)

		t.Logf("MaxNameLength: %d", Params.MaxNameLength)

		t.Logf("MaxFieldNum: %d", Params.MaxFieldNum)

		t.Logf("MaxShardNum: %d", Params.MaxShardNum)

		t.Logf("MaxDimension: %d", Params.MaxDimension)

		t.Logf("MaxTaskNum: %d", Params.MaxTaskNum)
	})

	t.Run("test proxyConfig panic", func(t *testing.T) {
155
		Params := CParams.ProxyCfg
156 157

		shouldPanic(t, "proxy.timeTickInterval", func() {
158
			Params.Base.Save("proxy.timeTickInterval", "")
159 160 161 162
			Params.initTimeTickInterval()
		})

		shouldPanic(t, "proxy.msgStream.timeTick.bufSize", func() {
163
			Params.Base.Save("proxy.msgStream.timeTick.bufSize", "abc")
164 165 166 167
			Params.initMsgStreamTimeTickBufSize()
		})

		shouldPanic(t, "proxy.maxNameLength", func() {
168
			Params.Base.Save("proxy.maxNameLength", "abc")
169 170 171
			Params.initMaxNameLength()
		})

172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
		shouldPanic(t, "proxy.maxUsernameLength", func() {
			Params.Base.Save("proxy.maxUsernameLength", "abc")
			Params.initMaxUsernameLength()
		})

		shouldPanic(t, "proxy.minPasswordLength", func() {
			Params.Base.Save("proxy.minPasswordLength", "abc")
			Params.initMinPasswordLength()
		})

		shouldPanic(t, "proxy.maxPasswordLength", func() {
			Params.Base.Save("proxy.maxPasswordLength", "abc")
			Params.initMaxPasswordLength()
		})

187
		shouldPanic(t, "proxy.maxFieldNum", func() {
188
			Params.Base.Save("proxy.maxFieldNum", "abc")
189 190 191 192
			Params.initMaxFieldNum()
		})

		shouldPanic(t, "proxy.maxShardNum", func() {
193
			Params.Base.Save("proxy.maxShardNum", "abc")
194 195 196 197
			Params.initMaxShardNum()
		})

		shouldPanic(t, "proxy.maxDimension", func() {
198
			Params.Base.Save("proxy.maxDimension", "-asdf")
199 200 201 202
			Params.initMaxDimension()
		})

		shouldPanic(t, "proxy.maxTaskNum", func() {
203
			Params.Base.Save("proxy.maxTaskNum", "-asdf")
204 205 206 207 208
			Params.initMaxTaskNum()
		})
	})

	t.Run("test queryCoordConfig", func(t *testing.T) {
209
		//Params := CParams.QueryCoordCfg
210 211 212
	})

	t.Run("test queryNodeConfig", func(t *testing.T) {
213
		Params := CParams.QueryNodeCfg
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233

		cacheSize := Params.CacheSize
		assert.Equal(t, int64(32), cacheSize)
		err := os.Setenv("CACHE_SIZE", "2")
		assert.NoError(t, err)
		Params.initCacheSize()
		assert.Equal(t, int64(2), Params.CacheSize)
		err = os.Setenv("CACHE_SIZE", "32")
		assert.NoError(t, err)
		Params.initCacheSize()
		assert.Equal(t, int64(32), Params.CacheSize)

		interval := Params.StatsPublishInterval
		assert.Equal(t, 1000, interval)

		length := Params.FlowGraphMaxQueueLength
		assert.Equal(t, int32(1024), length)

		maxParallelism := Params.FlowGraphMaxParallelism
		assert.Equal(t, int32(1024), maxParallelism)
234 235 236 237 238 239 240 241 242 243 244

		// test query side config
		chunkRows := Params.ChunkRows
		assert.Equal(t, int64(32768), chunkRows)

		nlist := Params.SmallIndexNlist
		assert.Equal(t, int64(256), nlist)

		nprobe := Params.SmallIndexNProbe
		assert.Equal(t, int64(16), nprobe)

245 246 247
		assert.Equal(t, true, Params.GroupEnabled)
		assert.Equal(t, int32(10240), Params.MaxReceiveChanSize)
		assert.Equal(t, int32(10240), Params.MaxUnsolvedQueueSize)
248
		assert.Equal(t, int32(math.MaxInt32), Params.MaxReadConcurrency)
249 250
		assert.Equal(t, int64(1000), Params.MaxGroupNQ)
		assert.Equal(t, 10.0, Params.TopKMergeRatio)
251
		assert.Equal(t, 10.0, Params.CPURatio)
252

253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
		// test small indexNlist/NProbe default
		Params.Base.Remove("queryNode.segcore.smallIndex.nlist")
		Params.Base.Remove("queryNode.segcore.smallIndex.nprobe")
		Params.Base.Save("queryNode.segcore.chunkRows", "8192")
		Params.initSmallIndexParams()
		chunkRows = Params.ChunkRows
		assert.Equal(t, int64(8192), chunkRows)

		nlist = Params.SmallIndexNlist
		assert.Equal(t, int64(128), nlist)

		nprobe = Params.SmallIndexNProbe
		assert.Equal(t, int64(8), nprobe)

		Params.Base.Remove("queryNode.segcore.smallIndex.nlist")
		Params.Base.Remove("queryNode.segcore.smallIndex.nprobe")
		Params.Base.Save("queryNode.segcore.chunkRows", "64")
		Params.initSmallIndexParams()
		chunkRows = Params.ChunkRows
		assert.Equal(t, int64(1024), chunkRows)

		nlist = Params.SmallIndexNlist
		assert.Equal(t, int64(64), nlist)

		nprobe = Params.SmallIndexNProbe
		assert.Equal(t, int64(4), nprobe)
279 280 281
	})

	t.Run("test dataCoordConfig", func(t *testing.T) {
282 283
		Params := CParams.DataCoordCfg
		assert.Equal(t, 24*60*60*time.Second, Params.SegmentMaxLifetime)
284 285 286
	})

	t.Run("test dataNodeConfig", func(t *testing.T) {
287
		Params := CParams.DataNodeCfg
288

X
Xiaofan 已提交
289
		Params.SetNodeID(2)
290

X
Xiaofan 已提交
291
		id := Params.GetNodeID()
292
		t.Logf("NodeID: %d", id)
293 294

		alias := Params.Alias
295
		t.Logf("Alias: %s", alias)
296 297

		length := Params.FlowGraphMaxQueueLength
298
		t.Logf("flowGraphMaxQueueLength: %d", length)
299 300

		maxParallelism := Params.FlowGraphMaxParallelism
301
		t.Logf("flowGraphMaxParallelism: %d", maxParallelism)
302 303

		size := Params.FlushInsertBufferSize
304
		t.Logf("FlushInsertBufferSize: %d", size)
305 306

		path1 := Params.InsertBinlogRootPath
307
		t.Logf("InsertBinlogRootPath: %s", path1)
308 309

		Params.CreatedTime = time.Now()
310
		t.Logf("CreatedTime: %v", Params.CreatedTime)
311 312

		Params.UpdatedTime = time.Now()
313
		t.Logf("UpdatedTime: %v", Params.UpdatedTime)
314 315 316 317 318 319 320

		assert.Equal(t, path.Join("files", "insert_log"), Params.InsertBinlogRootPath)

		assert.Equal(t, path.Join("files", "stats_log"), Params.StatsBinlogRootPath)
	})

	t.Run("test indexCoordConfig", func(t *testing.T) {
321
		Params := CParams.IndexCoordCfg
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336

		t.Logf("Address: %v", Params.Address)

		t.Logf("Port: %v", Params.Port)

		Params.CreatedTime = time.Now()
		t.Logf("CreatedTime: %v", Params.CreatedTime)

		Params.UpdatedTime = time.Now()
		t.Logf("UpdatedTime: %v", Params.UpdatedTime)

		t.Logf("IndexStorageRootPath: %v", Params.IndexStorageRootPath)
	})

	t.Run("test indexNodeConfig", func(t *testing.T) {
337
		Params := CParams.IndexNodeCfg
338 339 340 341 342 343 344

		t.Logf("IP: %v", Params.IP)

		t.Logf("Address: %v", Params.Address)

		t.Logf("Port: %v", Params.Port)

X
Xiaofan 已提交
345
		t.Logf("NodeID: %v", Params.GetNodeID())
346 347 348 349 350 351 352 353 354 355 356 357

		t.Logf("Alias: %v", Params.Alias)

		Params.CreatedTime = time.Now()
		t.Logf("CreatedTime: %v", Params.CreatedTime)

		Params.UpdatedTime = time.Now()
		t.Logf("UpdatedTime: %v", Params.UpdatedTime)

		t.Logf("IndexStorageRootPath: %v", Params.IndexStorageRootPath)
	})
}