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

apache / iotdb / #10020

07 Sep 2023 06:24AM UTC coverage: 47.718% (+0.001%) from 47.717%
#10020

push

travis_ci

web-flow
fix readonly because of disk full (#11060)

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

80265 of 168206 relevant lines covered (47.72%)

0.48 hits per line

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

37.04
/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/rescon/disk/FolderManager.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
package org.apache.iotdb.db.storageengine.rescon.disk;
20

21
import org.apache.iotdb.commons.cluster.NodeStatus;
22
import org.apache.iotdb.commons.conf.CommonDescriptor;
23
import org.apache.iotdb.db.exception.DiskSpaceInsufficientException;
24
import org.apache.iotdb.db.storageengine.rescon.disk.strategy.DirectoryStrategy;
25
import org.apache.iotdb.db.storageengine.rescon.disk.strategy.DirectoryStrategyType;
26
import org.apache.iotdb.db.storageengine.rescon.disk.strategy.MaxDiskUsableSpaceFirstStrategy;
27
import org.apache.iotdb.db.storageengine.rescon.disk.strategy.MinFolderOccupiedSpaceFirstStrategy;
28
import org.apache.iotdb.db.storageengine.rescon.disk.strategy.RandomOnDiskUsableSpaceStrategy;
29
import org.apache.iotdb.db.storageengine.rescon.disk.strategy.SequenceStrategy;
30

31
import org.slf4j.Logger;
32
import org.slf4j.LoggerFactory;
33

34
import java.util.List;
35

36
public class FolderManager {
37
  private static final Logger logger = LoggerFactory.getLogger(FolderManager.class);
1✔
38

39
  private final List<String> folders;
40
  private final DirectoryStrategy selectStrategy;
41

42
  public FolderManager(List<String> folders, DirectoryStrategyType type)
43
      throws DiskSpaceInsufficientException {
1✔
44
    this.folders = folders;
1✔
45
    switch (type) {
1✔
46
      case SEQUENCE_STRATEGY:
47
        this.selectStrategy = new SequenceStrategy();
1✔
48
        break;
1✔
49
      case MAX_DISK_USABLE_SPACE_FIRST_STRATEGY:
50
        this.selectStrategy = new MaxDiskUsableSpaceFirstStrategy();
×
51
        break;
×
52
      case MIN_FOLDER_OCCUPIED_SPACE_FIRST_STRATEGY:
53
        this.selectStrategy = new MinFolderOccupiedSpaceFirstStrategy();
×
54
        break;
×
55
      case RANDOM_ON_DISK_USABLE_SPACE_STRATEGY:
56
        this.selectStrategy = new RandomOnDiskUsableSpaceStrategy();
×
57
        break;
×
58
      default:
59
        throw new RuntimeException();
×
60
    }
61
    try {
62
      this.selectStrategy.setFolders(folders);
1✔
63
    } catch (DiskSpaceInsufficientException e) {
×
64
      logger.error("All folders are full, change system mode to read-only.", e);
×
65
      CommonDescriptor.getInstance().getConfig().setNodeStatus(NodeStatus.ReadOnly);
×
66
      CommonDescriptor.getInstance().getConfig().setStatusReason(NodeStatus.DISK_FULL);
×
67
      throw e;
×
68
    }
1✔
69
  }
1✔
70

71
  public String getNextFolder() throws DiskSpaceInsufficientException {
72
    try {
73
      return folders.get(selectStrategy.nextFolderIndex());
1✔
74
    } catch (DiskSpaceInsufficientException e) {
×
75
      logger.error("All folders are full, change system mode to read-only.", e);
×
76
      CommonDescriptor.getInstance().getConfig().setNodeStatus(NodeStatus.ReadOnly);
×
77
      CommonDescriptor.getInstance().getConfig().setStatusReason(NodeStatus.DISK_FULL);
×
78
      throw e;
×
79
    }
80
  }
81
}
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