View Javadoc
1   /*
2    * Copyright 2021 TiKV Project Authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   */
17  
18  package org.tikv.common.meta;
19  
20  import com.fasterxml.jackson.annotation.JsonCreator;
21  import com.fasterxml.jackson.annotation.JsonProperty;
22  import java.io.Serializable;
23  
24  public class TiFlashReplicaInfo implements Serializable {
25    private final long count;
26    private final String[] locationLabels;
27    private final boolean available;
28    private final long[] availablePartitionIDs;
29  
30    @JsonCreator
31    public TiFlashReplicaInfo(
32        @JsonProperty("Count") long count,
33        @JsonProperty("LocationLabels") String[] locationLabels,
34        @JsonProperty("Available") boolean available,
35        @JsonProperty("AvailablePartitionIDs") long[] availablePartitionIDs) {
36      this.count = count;
37      this.locationLabels = locationLabels;
38      this.available = available;
39      this.availablePartitionIDs = availablePartitionIDs;
40    }
41  
42    public boolean isPartitionAvailable(long pid) {
43      for (long id : availablePartitionIDs) {
44        if (id == pid) {
45          return true;
46        }
47      }
48      return false;
49    }
50  
51    public long getCount() {
52      return count;
53    }
54  
55    public String[] getLocationLabels() {
56      return locationLabels;
57    }
58  
59    public boolean isAvailable() {
60      return available;
61    }
62  
63    public long[] getAvailablePartitionIDs() {
64      return availablePartitionIDs;
65    }
66  }