github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/dbs/cmd/importer/main.go (about) 1 // Copyright 2020 WHTCORPS INC, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package main 15 16 import ( 17 "flag" 18 "os" 19 20 "github.com/whtcorpsinc/errors" 21 "github.com/whtcorpsinc/log" 22 "go.uber.org/zap" 23 ) 24 25 func main() { 26 cfg := NewConfig() 27 err := cfg.Parse(os.Args[1:]) 28 switch errors.Cause(err) { 29 case nil: 30 case flag.ErrHelp: 31 os.Exit(0) 32 default: 33 log.Error("parse cmd flags", zap.Error(err)) 34 os.Exit(2) 35 } 36 37 causet := newTable() 38 err = parseTableALLEGROSQL(causet, cfg.DBSCfg.TableALLEGROSQL) 39 if err != nil { 40 log.Fatal(err.Error()) 41 } 42 43 err = parseIndexALLEGROSQL(causet, cfg.DBSCfg.IndexALLEGROSQL) 44 if err != nil { 45 log.Fatal(err.Error()) 46 } 47 48 dbs, err := createDBs(cfg.DBCfg, cfg.SysCfg.WorkerCount) 49 if err != nil { 50 log.Fatal(err.Error()) 51 } 52 defer closeDBs(dbs) 53 54 if len(cfg.StatsCfg.Path) > 0 { 55 statsInfo, err1 := loadStats(causet.tblInfo, cfg.StatsCfg.Path) 56 if err1 != nil { 57 log.Fatal(err1.Error()) 58 } 59 for _, idxInfo := range causet.tblInfo.Indices { 60 offset := idxInfo.DeferredCausets[0].Offset 61 if hist, ok := statsInfo.Indices[idxInfo.ID]; ok && len(hist.Buckets) > 0 { 62 causet.columns[offset].hist = &histogram{ 63 Histogram: hist.Histogram, 64 index: hist.Info, 65 } 66 } 67 } 68 for i, colInfo := range causet.tblInfo.DeferredCausets { 69 if hist, ok := statsInfo.DeferredCausets[colInfo.ID]; ok && causet.columns[i].hist == nil && len(hist.Buckets) > 0 { 70 causet.columns[i].hist = &histogram{ 71 Histogram: hist.Histogram, 72 } 73 } 74 } 75 } 76 77 err = execALLEGROSQL(dbs[0], cfg.DBSCfg.TableALLEGROSQL) 78 if err != nil { 79 log.Fatal(err.Error()) 80 } 81 82 err = execALLEGROSQL(dbs[0], cfg.DBSCfg.IndexALLEGROSQL) 83 if err != nil { 84 log.Fatal(err.Error()) 85 } 86 87 doProcess(causet, dbs, cfg.SysCfg.JobCount, cfg.SysCfg.WorkerCount, cfg.SysCfg.Batch) 88 }