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

apache / iotdb / #10032

08 Sep 2023 06:40AM UTC coverage: 47.635% (-0.003%) from 47.638%
#10032

push

travis_ci

web-flow
[To rel/1.2] Remove some copyright info (#11096)

80288 of 168549 relevant lines covered (47.63%)

0.48 hits per line

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

96.7
/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
                                    .setForceSyncNum(CONF.getSchemaRatisConsensusLogForceSyncNum())
1✔
77
                                    .setSegmentSizeMax(
1✔
78
                                        SizeInBytes.valueOf(
1✔
79
                                            CONF.getSchemaRatisConsensusLogSegmentSizeMax()))
1✔
80
                                    .setPreserveNumsWhenPurge(
1✔
81
                                        CONF.getSchemaRatisConsensusPreserveWhenPurge())
1✔
82
                                    .build())
1✔
83
                            .setGrpc(
1✔
84
                                RatisConfig.Grpc.newBuilder()
1✔
85
                                    .setFlowControlWindow(
1✔
86
                                        SizeInBytes.valueOf(
1✔
87
                                            CONF.getSchemaRatisConsensusGrpcFlowControlWindow()))
1✔
88
                                    .setLeaderOutstandingAppendsMax(
1✔
89
                                        CONF
90
                                            .getSchemaRatisConsensusGrpcLeaderOutstandingAppendsMax())
1✔
91
                                    .build())
1✔
92
                            .setRpc(
1✔
93
                                RatisConfig.Rpc.newBuilder()
1✔
94
                                    .setTimeoutMin(
1✔
95
                                        TimeDuration.valueOf(
1✔
96
                                            CONF
97
                                                .getSchemaRatisConsensusLeaderElectionTimeoutMinMs(),
1✔
98
                                            TimeUnit.MILLISECONDS))
99
                                    .setTimeoutMax(
1✔
100
                                        TimeDuration.valueOf(
1✔
101
                                            CONF
102
                                                .getSchemaRatisConsensusLeaderElectionTimeoutMaxMs(),
1✔
103
                                            TimeUnit.MILLISECONDS))
104
                                    .setRequestTimeout(
1✔
105
                                        TimeDuration.valueOf(
1✔
106
                                            CONF.getSchemaRatisConsensusRequestTimeoutMs(),
1✔
107
                                            TimeUnit.MILLISECONDS))
108
                                    .setFirstElectionTimeoutMin(
1✔
109
                                        TimeDuration.valueOf(
1✔
110
                                            CONF.getRatisFirstElectionTimeoutMinMs(),
1✔
111
                                            TimeUnit.MILLISECONDS))
112
                                    .setFirstElectionTimeoutMax(
1✔
113
                                        TimeDuration.valueOf(
1✔
114
                                            CONF.getRatisFirstElectionTimeoutMaxMs(),
1✔
115
                                            TimeUnit.MILLISECONDS))
116
                                    .build())
1✔
117
                            .setClient(
1✔
118
                                RatisConfig.Client.newBuilder()
1✔
119
                                    .setClientRequestTimeoutMillis(
1✔
120
                                        CONF.getDataRatisConsensusRequestTimeoutMs())
1✔
121
                                    .setClientMaxRetryAttempt(
1✔
122
                                        CONF.getDataRatisConsensusMaxRetryAttempts())
1✔
123
                                    .setClientRetryInitialSleepTimeMs(
1✔
124
                                        CONF.getDataRatisConsensusInitialSleepTimeMs())
1✔
125
                                    .setClientRetryMaxSleepTimeMs(
1✔
126
                                        CONF.getDataRatisConsensusMaxSleepTimeMs())
1✔
127
                                    .setCoreClientNumForEachNode(CONF.getCoreClientNumForEachNode())
1✔
128
                                    .setMaxClientNumForEachNode(CONF.getMaxClientNumForEachNode())
1✔
129
                                    .build())
1✔
130
                            .setImpl(
1✔
131
                                RatisConfig.Impl.newBuilder()
1✔
132
                                    .setTriggerSnapshotFileSize(CONF.getSchemaRatisLogMax())
1✔
133
                                    .build())
1✔
134
                            .setLeaderLogAppender(
1✔
135
                                RatisConfig.LeaderLogAppender.newBuilder()
1✔
136
                                    .setBufferByteLimit(
1✔
137
                                        CONF.getSchemaRatisConsensusLogAppenderBufferSizeMax())
1✔
138
                                    .build())
1✔
139
                            .setRead(
1✔
140
                                RatisConfig.Read.newBuilder()
1✔
141
                                    // use thrift connection timeout to unify read timeout
142
                                    .setReadTimeout(
1✔
143
                                        TimeDuration.valueOf(
1✔
144
                                            CONF.getConnectionTimeoutInMS(), TimeUnit.MILLISECONDS))
1✔
145
                                    .build())
1✔
146
                            .build())
1✔
147
                    .setStorageDir(CONF.getSchemaRegionConsensusDir())
1✔
148
                    .build(),
1✔
149
                gid ->
150
                    new SchemaRegionStateMachine(
1✔
151
                        SchemaEngine.getInstance().getSchemaRegion((SchemaRegionId) gid)))
1✔
152
            .orElseThrow(
1✔
153
                () ->
154
                    new IllegalArgumentException(
×
155
                        String.format(
×
156
                            ConsensusFactory.CONSTRUCT_FAILED_MSG,
157
                            CONF.getSchemaRegionConsensusProtocolClass())));
×
158
  }
159
}
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