• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

apache / iotdb / #9905

23 Aug 2023 06:20AM UTC coverage: 47.785% (-0.1%) from 47.922%
#9905

push

travis_ci

web-flow
[To rel/1.2][Metric] Fix flush point statistics (#10934)

23 of 23 new or added lines in 1 file covered. (100.0%)

79851 of 167106 relevant lines covered (47.78%)

0.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.59
/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/consensus/SchemaRegionConsensusImpl.java
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one
3
 * or more contributor license agreements.  See the NOTICE file
4
 * distributed with this work for additional information
5
 * regarding copyright ownership.  The ASF licenses this file
6
 * to you under the Apache License, Version 2.0 (the
7
 * "License"); you may not use this file except in compliance
8
 * with the License.  You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing,
13
 * software distributed under the License is distributed on an
14
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
 * KIND, either express or implied.  See the License for the
16
 * specific language governing permissions and limitations
17
 * under the License.
18
 */
19

20
package org.apache.iotdb.db.consensus;
21

22
import org.apache.iotdb.common.rpc.thrift.TConsensusGroupType;
23
import org.apache.iotdb.common.rpc.thrift.TEndPoint;
24
import org.apache.iotdb.commons.consensus.SchemaRegionId;
25
import org.apache.iotdb.consensus.ConsensusFactory;
26
import org.apache.iotdb.consensus.IConsensus;
27
import org.apache.iotdb.consensus.config.ConsensusConfig;
28
import org.apache.iotdb.consensus.config.RatisConfig;
29
import org.apache.iotdb.db.conf.IoTDBConfig;
30
import org.apache.iotdb.db.conf.IoTDBDescriptor;
31
import org.apache.iotdb.db.consensus.statemachine.schemaregion.SchemaRegionStateMachine;
32
import org.apache.iotdb.db.schemaengine.SchemaEngine;
33

34
import org.apache.ratis.util.SizeInBytes;
35
import org.apache.ratis.util.TimeDuration;
36

37
import java.util.concurrent.TimeUnit;
38

39
/**
40
 * We can use SchemaRegionConsensusImpl.getInstance() to obtain a consensus layer reference for
41
 * schemaRegion's reading and writing
42
 */
43
public class SchemaRegionConsensusImpl {
44

45
  private SchemaRegionConsensusImpl() {
46
    // do nothing
47
  }
48

49
  public static IConsensus getInstance() {
50
    return SchemaRegionConsensusImplHolder.INSTANCE;
1✔
51
  }
52

53
  private static class SchemaRegionConsensusImplHolder {
54

55
    private static final IoTDBConfig CONF = IoTDBDescriptor.getInstance().getConfig();
1✔
56
    private static final IConsensus INSTANCE =
1✔
57
        ConsensusFactory.getConsensusImpl(
1✔
58
                CONF.getSchemaRegionConsensusProtocolClass(),
1✔
59
                ConsensusConfig.newBuilder()
1✔
60
                    .setThisNodeId(CONF.getDataNodeId())
1✔
61
                    .setThisNode(
1✔
62
                        new TEndPoint(
63
                            CONF.getInternalAddress(), CONF.getSchemaRegionConsensusPort()))
1✔
64
                    .setConsensusGroupType(TConsensusGroupType.SchemaRegion)
1✔
65
                    .setRatisConfig(
1✔
66
                        RatisConfig.newBuilder()
1✔
67
                            .setSnapshot(
1✔
68
                                RatisConfig.Snapshot.newBuilder()
1✔
69
                                    .setAutoTriggerThreshold(
1✔
70
                                        CONF.getSchemaRatisConsensusSnapshotTriggerThreshold())
1✔
71
                                    .build())
1✔
72
                            .setLog(
1✔
73
                                RatisConfig.Log.newBuilder()
1✔
74
                                    .setUnsafeFlushEnabled(
1✔
75
                                        CONF.isSchemaRatisConsensusLogUnsafeFlushEnable())
1✔
76
                                    .setSegmentSizeMax(
1✔
77
                                        SizeInBytes.valueOf(
1✔
78
                                            CONF.getSchemaRatisConsensusLogSegmentSizeMax()))
1✔
79
                                    .setPreserveNumsWhenPurge(
1✔
80
                                        CONF.getSchemaRatisConsensusPreserveWhenPurge())
1✔
81
                                    .build())
1✔
82
                            .setGrpc(
1✔
83
                                RatisConfig.Grpc.newBuilder()
1✔
84
                                    .setFlowControlWindow(
1✔
85
                                        SizeInBytes.valueOf(
1✔
86
                                            CONF.getSchemaRatisConsensusGrpcFlowControlWindow()))
1✔
87
                                    .build())
1✔
88
                            .setRpc(
1✔
89
                                RatisConfig.Rpc.newBuilder()
1✔
90
                                    .setTimeoutMin(
1✔
91
                                        TimeDuration.valueOf(
1✔
92
                                            CONF
93
                                                .getSchemaRatisConsensusLeaderElectionTimeoutMinMs(),
1✔
94
                                            TimeUnit.MILLISECONDS))
95
                                    .setTimeoutMax(
1✔
96
                                        TimeDuration.valueOf(
1✔
97
                                            CONF
98
                                                .getSchemaRatisConsensusLeaderElectionTimeoutMaxMs(),
1✔
99
                                            TimeUnit.MILLISECONDS))
100
                                    .setRequestTimeout(
1✔
101
                                        TimeDuration.valueOf(
1✔
102
                                            CONF.getSchemaRatisConsensusRequestTimeoutMs(),
1✔
103
                                            TimeUnit.MILLISECONDS))
104
                                    .setFirstElectionTimeoutMin(
1✔
105
                                        TimeDuration.valueOf(
1✔
106
                                            CONF.getRatisFirstElectionTimeoutMinMs(),
1✔
107
                                            TimeUnit.MILLISECONDS))
108
                                    .setFirstElectionTimeoutMax(
1✔
109
                                        TimeDuration.valueOf(
1✔
110
                                            CONF.getRatisFirstElectionTimeoutMaxMs(),
1✔
111
                                            TimeUnit.MILLISECONDS))
112
                                    .build())
1✔
113
                            .setClient(
1✔
114
                                RatisConfig.Client.newBuilder()
1✔
115
                                    .setClientRequestTimeoutMillis(
1✔
116
                                        CONF.getDataRatisConsensusRequestTimeoutMs())
1✔
117
                                    .setClientMaxRetryAttempt(
1✔
118
                                        CONF.getDataRatisConsensusMaxRetryAttempts())
1✔
119
                                    .setClientRetryInitialSleepTimeMs(
1✔
120
                                        CONF.getDataRatisConsensusInitialSleepTimeMs())
1✔
121
                                    .setClientRetryMaxSleepTimeMs(
1✔
122
                                        CONF.getDataRatisConsensusMaxSleepTimeMs())
1✔
123
                                    .setCoreClientNumForEachNode(CONF.getCoreClientNumForEachNode())
1✔
124
                                    .setMaxClientNumForEachNode(CONF.getMaxClientNumForEachNode())
1✔
125
                                    .build())
1✔
126
                            .setImpl(
1✔
127
                                RatisConfig.Impl.newBuilder()
1✔
128
                                    .setTriggerSnapshotFileSize(CONF.getSchemaRatisLogMax())
1✔
129
                                    .build())
1✔
130
                            .setLeaderLogAppender(
1✔
131
                                RatisConfig.LeaderLogAppender.newBuilder()
1✔
132
                                    .setBufferByteLimit(
1✔
133
                                        CONF.getSchemaRatisConsensusLogAppenderBufferSizeMax())
1✔
134
                                    .build())
1✔
135
                            .setRead(
1✔
136
                                RatisConfig.Read.newBuilder()
1✔
137
                                    // use thrift connection timeout to unify read timeout
138
                                    .setReadTimeout(
1✔
139
                                        TimeDuration.valueOf(
1✔
140
                                            CONF.getConnectionTimeoutInMS(), TimeUnit.MILLISECONDS))
1✔
141
                                    .build())
1✔
142
                            .build())
1✔
143
                    .setStorageDir(CONF.getSchemaRegionConsensusDir())
1✔
144
                    .build(),
1✔
145
                gid ->
146
                    new SchemaRegionStateMachine(
1✔
147
                        SchemaEngine.getInstance().getSchemaRegion((SchemaRegionId) gid)))
1✔
148
            .orElseThrow(
1✔
149
                () ->
150
                    new IllegalArgumentException(
×
151
                        String.format(
×
152
                            ConsensusFactory.CONSTRUCT_FAILED_MSG,
153
                            CONF.getSchemaRegionConsensusProtocolClass())));
×
154
  }
155
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc