Exemple #1
0
  synchronized List<StorageLocation> addStorageLocations(
      DataNode datanode,
      NamespaceInfo nsInfo,
      Collection<StorageLocation> dataDirs,
      StartupOption startOpt)
      throws IOException {

    final String bpid = nsInfo.getBlockPoolID();
    List<StorageLocation> successVolumes = Lists.newArrayList();

    for (StorageLocation dataDir : dataDirs) {
      File root = dataDir.getFile();
      if (!containsStorageDir(root)) {
        try {
          StorageDirectory sd = loadStorageDirectory(datanode, nsInfo, root, startOpt);
          addStorageDir(sd);
        } catch (IOException e) {
          LOG.warn(e);
          continue;
        }
      } else {
        LOG.info("Storage directory " + dataDir + " has already been used.");
      }
      List<File> bpDataDirs = new ArrayList<File>();
      bpDataDirs.add(BlockPoolSliceStorage.getBpRoot(bpid, new File(root, STORAGE_DIR_CURRENT)));

      try {
        makeBlockPoolDataDir(bpDataDirs, null);
        BlockPoolSliceStorage bpStorage = this.bpStorageMap.get(bpid);
        if (bpStorage == null) {
          bpStorage =
              new BlockPoolSliceStorage(
                  nsInfo.getNamespaceID(), bpid, nsInfo.getCTime(), nsInfo.getClusterID());
        }
        bpStorage.recoverTransitionRead(datanode, nsInfo, bpDataDirs, startOpt);
        addBlockPoolStorage(bpid, bpStorage);
      } catch (IOException e) {
        LOG.warn("Failed to add storage for block pool: " + bpid + " : " + e.getMessage());
        continue;
      }
      successVolumes.add(dataDir);
    }

    return successVolumes;
  }
  public void updateStorageLocation(StorageLocation sl, Connection c) throws SQLException {
    PreparedStatement stmt = null;
    String password = m_encryptionManager.encryptPassword(sl.getPassword());
    try {
      stmt =
          c.prepareStatement(
              "update storage_location "
                  + "set server_name = ?, storage_directory = ?, "
                  + "mapped_storage_directory = ?, read_only = ?, accessible_remotely = ?, min_free_percent = ?, "
                  + "percent_free = ?, local_only_percent = ?, username = ?, password = ?, domain = ?, management_server = ? where id = ?");

      stmt.setString(1, sl.getServer());
      stmt.setString(2, sl.getStorageDirectory());
      stmt.setString(3, sl.getMappedStorageDirectory());
      stmt.setBoolean(4, sl.isReadOnly());
      stmt.setBoolean(5, sl.isAccessibleRemotely());
      stmt.setInt(6, sl.getMinFreePercent());
      stmt.setInt(7, sl.getPercentFree());
      stmt.setInt(8, sl.getLocalOnlyPercent());
      stmt.setString(9, sl.getUserName());
      stmt.setString(10, password);
      stmt.setString(11, sl.getDomain());
      stmt.setString(12, sl.getManagementServer());
      stmt.setInt(13, sl.getStorageLocationId());

      if (stmt.executeUpdate() != 1) {
        throw new SQLException(
            "Unable to update storage location record with id=" + sl.getStorageLocationId());
      }
      m_storageLocationCache.flush(sl.getStorageLocationId());

      if (m_partitionManager instanceof IPartitionManagerCacheControl) {
        IPartitionManagerCacheControl pmcc = (IPartitionManagerCacheControl) m_partitionManager;
        pmcc.RefreshByStorageLocationId(sl.getStorageLocationId());
      }
    } finally {
      if (stmt != null) stmt.close();
    }
  }
  public StorageLocation initializeStorageLocation(StorageLocation locToPersist, Connection c)
      throws SQLException {
    PreparedStatement updateStmt = null;
    Statement schemaStmt = null;

    if (locToPersist == null) {
      throw new SQLException("Null StorageLocation");
    }
    String password = m_encryptionManager.encryptPassword(locToPersist.getPassword());

    try {
      // insert partition storage location record
      updateStmt =
          c.prepareStatement(
              "insert into storage_location (id, server_name, "
                  + "storage_directory, mapped_storage_directory, min_free_percent, "
                  + "local_only_percent, local_bias_multiplier, storage_type, username, password, domain, management_server) "
                  + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
      updateStmt.setInt(1, locToPersist.getStorageLocationId());
      updateStmt.setString(2, locToPersist.getServer());
      updateStmt.setString(3, locToPersist.getStorageDirectory());
      updateStmt.setString(4, locToPersist.getMappedStorageDirectory());
      updateStmt.setInt(5, PartitionManager.DEFAULT_MIN_FREE_PERCENT);
      updateStmt.setInt(6, PartitionManager.DEFAULT_LOCAL_ONLY_PERCENT);
      updateStmt.setInt(7, DEFAULT_LOCAL_BIAS_MULTIPLIER);
      updateStmt.setString(8, locToPersist.getStorageType());
      updateStmt.setString(9, locToPersist.getUserName());
      updateStmt.setString(10, password);
      updateStmt.setString(11, locToPersist.getDomain());
      updateStmt.setString(12, locToPersist.getManagementServer());
      if (updateStmt.executeUpdate() != 1) {
        throw new SQLException(
            "Unable to insert StorageLocation record with id="
                + locToPersist.getStorageLocationId()
                + ", server="
                + locToPersist.getServer());
      }
      updateStmt.close();
      updateStmt = null;

      m_storageLocationIdsCache.flush();

      // Instead of creating a new partition and have defaults defined in the DB and in code, just
      // pull the newly created partition from the DB and
      // rely on the DB defaults
      return getStorageLocationInternal(locToPersist.getStorageLocationId(), c);
    } catch (SQLException e) {
      throw e;
    } finally {
      if (updateStmt != null) updateStmt.close();
      if (schemaStmt != null) schemaStmt.close();
    }
  }