github.com/matrixorigin/matrixone@v1.2.0/pkg/cnservice/distributed_tae.go (about)

     1  // Copyright 2021 - 2022 Matrix Origin
     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  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package cnservice
    16  
    17  import (
    18  	"context"
    19  
    20  	"github.com/matrixorigin/matrixone/pkg/common/mpool"
    21  	"github.com/matrixorigin/matrixone/pkg/common/runtime"
    22  	"github.com/matrixorigin/matrixone/pkg/config"
    23  	"github.com/matrixorigin/matrixone/pkg/defines"
    24  	"github.com/matrixorigin/matrixone/pkg/fileservice"
    25  	"github.com/matrixorigin/matrixone/pkg/sql/colexec"
    26  	"github.com/matrixorigin/matrixone/pkg/util/status"
    27  	"github.com/matrixorigin/matrixone/pkg/vm/engine/disttae"
    28  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/blockio"
    29  )
    30  
    31  func (s *service) initDistributedTAE(
    32  	ctx context.Context,
    33  	pu *config.ParameterUnit,
    34  ) error {
    35  
    36  	// txn client
    37  	client, err := s.getTxnClient()
    38  	if err != nil {
    39  		return err
    40  	}
    41  	pu.TxnClient = client
    42  
    43  	// hakeeper
    44  	hakeeper, err := s.getHAKeeperClient()
    45  	if err != nil {
    46  		return err
    47  	}
    48  
    49  	// use s3 as main fs
    50  	fs, err := fileservice.Get[fileservice.FileService](s.fileService, defines.SharedFileServiceName)
    51  	if err != nil {
    52  		return err
    53  	}
    54  	colexec.NewServer(hakeeper)
    55  
    56  	// start I/O pipeline
    57  	blockio.Start()
    58  
    59  	// engine
    60  	distributeTaeMp, err := mpool.NewMPool("distributed_tae", 0, mpool.NoFixed)
    61  	if err != nil {
    62  		return err
    63  	}
    64  	s.storeEngine = disttae.New(
    65  		ctx,
    66  		distributeTaeMp,
    67  		fs,
    68  		client,
    69  		hakeeper,
    70  		s.gossipNode.StatsKeyRouter(),
    71  		s.cfg.LogtailUpdateStatsThreshold,
    72  	)
    73  	pu.StorageEngine = s.storeEngine
    74  
    75  	// set up log tail client to subscribe table and receive table log.
    76  	cnEngine := pu.StorageEngine.(*disttae.Engine)
    77  	err = cnEngine.InitLogTailPushModel(ctx, s.timestampWaiter)
    78  	if err != nil {
    79  		return err
    80  	}
    81  
    82  	ss, ok := runtime.ProcessLevelRuntime().GetGlobalVariables(runtime.StatusServer)
    83  	if ok {
    84  		statusServer := ss.(*status.Server)
    85  		statusServer.SetTxnClient(s.cfg.UUID, client)
    86  		statusServer.SetLogTailClient(s.cfg.UUID, cnEngine.PushClient())
    87  	}
    88  
    89  	// internal sql executor.
    90  	internalExecutorMp, err := mpool.NewMPool("internal_executor", 0, mpool.NoFixed)
    91  	if err != nil {
    92  		return err
    93  	}
    94  	s.initInternalSQlExecutor(internalExecutorMp)
    95  	return nil
    96  }