Pinot

编译

#!/bin/bash
set -e
set -x
if [[ -d output ]]
then
    rm -rf output/*
fi
mvn install package -DskipTests -Dlicense.skip=true -Pbin-dist
mkdir -p output
cp -r pinot-distribution/target/apache-pinot-incubating-0.1.0-SNAPSHOT-bin/* output
chmod +x output/bin/*.sh

Segment 生成

一个segment的每列可能会有下面几个文件:

  1. .sv.unsorted.fwd single value 字典列&不排序列的正排
  2. .sv.sorted.fwd single value 字典列&排序列的正排
  3. .sv.raw.fwd single value 非字典列的正排
  4. .mv.fwd
  5. .bitmap.inv
  6. .bloom

SegmentIndexCreationDriverImpl

      // Initialize the index creation using the per-column statistics information
      indexCreator.init(config, segmentIndexCreationInfo, indexCreationInfoMap, dataSchema, tempIndexDir);

      // Build the index
      recordReader.rewind();
      LOGGER.info("Start building IndexCreator!");
      GenericRow readRow = null;
      while (recordReader.hasNext()) {
        long start = System.currentTimeMillis();
        readRow = GenericRow.createOrReuseRow(readRow);
        GenericRow transformedRow = _recordTransformer.transform(recordReader.next(readRow));
        long stop = System.currentTimeMillis();
        totalRecordReadTime += (stop - start);
        if (transformedRow != null) {
          indexCreator.indexRow(transformedRow);
          long stop1 = System.currentTimeMillis();
          totalIndexTime += (stop1 - stop);
        }
      }

Segment 读取
SegmentPreProcessor


Segment 加载

controller:

=> PinotSegmentUploadRestletResource.uploadSegment
=> ZKOperation.completeSegmentOperations
=> 
1. 如果是new segment,调用 processNewSegment
2. 如果是已经存在的,调用 processExistingSegment
processExistingSegment会判断新的crc和旧的是否一致,最后调用
PinotHelixResourceManager.refreshSegment
=> PinotHelixResourceManager.refreshSegment
1. set segment zk metadata
2. sendSegmentRefreshMessage
会发送一个Helix SegmentRefreshMessage消息给Server,Server收到之后从相应的controller上拉segment

server 这边

=> 在HelixServerStarter中,注册了一个message handler
_helixManager.getMessagingService().registerMessageHandlerFactory(Message.MessageType.USER_DEFINE_MSG.toString(), messageHandlerFactory);
=> 这个message handler会根据message类型创建不同的handler
public MessageHandler createHandler(Message message, NotificationContext context) {
    String msgSubType = message.getMsgSubType();
    switch (msgSubType) {
      case SegmentRefreshMessage.REFRESH_SEGMENT_MSG_SUB_TYPE:
        return new SegmentRefreshMessageHandler(new SegmentRefreshMessage(message), _metrics, context);
      case SegmentReloadMessage.RELOAD_SEGMENT_MSG_SUB_TYPE:
        return new SegmentReloadMessageHandler(new SegmentReloadMessage(message), _metrics, context);
      default:
        throw new UnsupportedOperationException("Unsupported user defined message sub type: " + msgSubType);
    }
}

=> 我们重点看下SegmentRefreshMessageHandler
    @Override
    public HelixTaskResult handleMessage()
        throws InterruptedException {
      HelixTaskResult result = new HelixTaskResult();
      try {
        acquireSema(_segmentName, LOGGER);
        // The number of retry times depends on the retry count in SegmentOperations.
        _fetcherAndLoader.addOrReplaceOfflineSegment(_tableNameWithType, _segmentName);
        result.setSuccess(true);
      } catch (Exception e) {
        _metrics.addMeteredTableValue(_tableNameWithType, ServerMeter.REFRESH_FAILURES, 1);
        Utils.rethrowException(e);
      } finally {
        releaseSema();
      }
      return result;
    }
他会调用_fetcherAndLoader.addOrReplaceOfflineSegment(_tableNameWithType, _segmentName); 如果 addOrReplaceOfflineSegment失败,handleMessage会跑出异常,猜测Helix捕获到异常的话会重新发送message或者给其他server发送message。

Server

启动

=> StartServerCommand.execute
=> HelixServerStarter
1. waitForAllSegmentsLoaded
2. 初始化ServerInstance

ServerInstance 里面注册了Netty的handler,ScheduledRequestHandler。

每个server进程有一个HelixInstanceDataManager

=> HelixInstanceDataManager.addOfflineSegment
=> ImmutableSegmentLoader.load(indexDir, indexLoadingConfig, schema) 负责把segment从文件加载到内存

你可能感兴趣的:(Pinot)