<commit_before>package tachyon.master;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.thrift.TException;

import tachyon.TachyonURI;
import tachyon.UnderFileSystem;
import tachyon.conf.CommonConf;
import tachyon.thrift.BlockInfoException;
import tachyon.thrift.ClientBlockInfo;
import tachyon.thrift.ClientDependencyInfo;
import tachyon.thrift.ClientFileInfo;
import tachyon.thrift.ClientRawTableInfo;
import tachyon.thrift.ClientWorkerInfo;
import tachyon.thrift.Command;
import tachyon.thrift.DependencyDoesNotExistException;
import tachyon.thrift.FileAlreadyExistException;
import tachyon.thrift.FileDoesNotExistException;
import tachyon.thrift.InvalidPathException;
import tachyon.thrift.MasterService;
import tachyon.thrift.NetAddress;
import tachyon.thrift.NoWorkerException;
import tachyon.thrift.SuspectedFileSizeException;
import tachyon.thrift.TableColumnException;
import tachyon.thrift.TableDoesNotExistException;
import tachyon.thrift.TachyonException;
import tachyon.util.CommonUtils;

/**
 * The Master server program.
 * 
 * It maintains the state of each worker. It never keeps the state of any user.
 */
public class MasterServiceHandler implements MasterService.Iface {
  private final MasterInfo mMasterInfo;

  public MasterServiceHandler(MasterInfo masterInfo) {
    mMasterInfo = masterInfo;
  }

  @Override
  public boolean addCheckpoint(long workerId, int fileId, long fileSizeBytes, String checkpointPath)
      throws FileDoesNotExistException, SuspectedFileSizeException, BlockInfoException, TException {
    try {
      return mMasterInfo.addCheckpoint(
          workerId, fileId, fileSizeBytes, new TachyonURI(checkpointPath));
    } catch (FileNotFoundException e) {
      throw new FileDoesNotExistException(e.getMessage());
    }
  }

  @Override
  public ClientFileInfo getFileStatus(int fileId, String path) throws InvalidPathException,
      TException {
    if (fileId != -1) {
      return mMasterInfo.getClientFileInfo(fileId);

    }

    return mMasterInfo.getClientFileInfo(new TachyonURI(path));
  }

  @Override
  public List<ClientWorkerInfo> getWorkersInfo() throws TException {
    return mMasterInfo.getWorkersInfo();
  }

  @Override
  public List<ClientFileInfo> liststatus(String path) throws InvalidPathException,
      FileDoesNotExistException, TException {
    return mMasterInfo.getFilesInfo(new TachyonURI(path));
  }

  @Override
  public void user_completeFile(int fileId) throws FileDoesNotExistException, TException {
    mMasterInfo.completeFile(fileId);
  }

  @Override
  public int user_createDependency(List<String> parents, List<String> children,
      String commandPrefix, List<ByteBuffer> data, String comment, String framework,
      String frameworkVersion, int dependencyType, long childrenBlockSizeByte)
      throws InvalidPathException, FileDoesNotExistException, FileAlreadyExistException,
      BlockInfoException, TachyonException, TException {
    try {
      List<TachyonURI> childrenUris = new ArrayList<TachyonURI>(children.size());
      for (int k = 0; k < children.size(); k ++) {
        mMasterInfo.createFile(new TachyonURI(children.get(k)), childrenBlockSizeByte);
        childrenUris.add(k, new TachyonURI(children.get(k)));
      }
      List<TachyonURI> parentUris = new ArrayList<TachyonURI>(parents.size());
      for (int k = 0; k < parents.size(); k ++) {
        parentUris.add(k, new TachyonURI(parents.get(k)));
      }
      return mMasterInfo.createDependency(parentUris, childrenUris, commandPrefix, data, comment,
          framework, frameworkVersion, DependencyType.getDependencyType(dependencyType));
    } catch (IOException e) {
      throw new FileDoesNotExistException(e.getMessage());
    }
  }

  @Override
  public int user_createFile(String path, String ufsPath, long blockSizeByte, boolean recursive)
      throws FileAlreadyExistException, InvalidPathException, BlockInfoException,
      SuspectedFileSizeException, TachyonException, TException {
    if (!ufsPath.isEmpty()) {
      UnderFileSystem underfs = UnderFileSystem.get(ufsPath);
      try {
        long ufsBlockSizeByte = underfs.getBlockSizeByte(ufsPath);
        long fileSizeByte = underfs.getFileSize(ufsPath);
        int fileId = mMasterInfo.createFile(new TachyonURI(path), ufsBlockSizeByte, recursive);
        if (fileId != -1 &&
            mMasterInfo.addCheckpoint(-1, fileId, fileSizeByte, new TachyonURI(ufsPath))) {
          return fileId;
        }
      } catch (IOException e) {
        throw new TachyonException(e.getMessage());
      }
    }

    return mMasterInfo.createFile(new TachyonURI(path), blockSizeByte, recursive);
  }

  @Override
  public long user_createNewBlock(int fileId) throws FileDoesNotExistException, TException {
    return mMasterInfo.createNewBlock(fileId);
  }

  @Override
  public int user_createRawTable(String path, int columns, ByteBuffer metadata)
      throws FileAlreadyExistException, InvalidPathException, TableColumnException,
      TachyonException, TException {
    return mMasterInfo.createRawTable(new TachyonURI(path), columns,
        CommonUtils.generateNewByteBufferFromThriftRPCResults(metadata));
  }

  @Override
  public boolean user_delete(int fileId, String path, boolean recursive) throws TachyonException,
      TException {<commit_msg>minor tweak<commit_after>package tachyon.master;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.thrift.TException;

import tachyon.TachyonURI;
import tachyon.UnderFileSystem;
import tachyon.conf.CommonConf;
import tachyon.thrift.BlockInfoException;
import tachyon.thrift.ClientBlockInfo;
import tachyon.thrift.ClientDependencyInfo;
import tachyon.thrift.ClientFileInfo;
import tachyon.thrift.ClientRawTableInfo;
import tachyon.thrift.ClientWorkerInfo;
import tachyon.thrift.Command;
import tachyon.thrift.DependencyDoesNotExistException;
import tachyon.thrift.FileAlreadyExistException;
import tachyon.thrift.FileDoesNotExistException;
import tachyon.thrift.InvalidPathException;
import tachyon.thrift.MasterService;
import tachyon.thrift.NetAddress;
import tachyon.thrift.NoWorkerException;
import tachyon.thrift.SuspectedFileSizeException;
import tachyon.thrift.TableColumnException;
import tachyon.thrift.TableDoesNotExistException;
import tachyon.thrift.TachyonException;
import tachyon.util.CommonUtils;

/**
 * The Master server program.
 * 
 * It maintains the state of each worker. It never keeps the state of any user.
 */
public class MasterServiceHandler implements MasterService.Iface {
  private final MasterInfo mMasterInfo;

  public MasterServiceHandler(MasterInfo masterInfo) {
    mMasterInfo = masterInfo;
  }

  @Override
  public boolean addCheckpoint(long workerId, int fileId, long fileSizeBytes, String checkpointPath)
      throws FileDoesNotExistException, SuspectedFileSizeException, BlockInfoException, TException {
    try {
      return mMasterInfo.addCheckpoint(workerId, fileId, fileSizeBytes, new TachyonURI(
          checkpointPath));
    } catch (FileNotFoundException e) {
      throw new FileDoesNotExistException(e.getMessage());
    }
  }

  @Override
  public ClientFileInfo getFileStatus(int fileId, String path) throws InvalidPathException,
      TException {
    if (fileId != -1) {
      return mMasterInfo.getClientFileInfo(fileId);

    }

    return mMasterInfo.getClientFileInfo(new TachyonURI(path));
  }

  @Override
  public List<ClientWorkerInfo> getWorkersInfo() throws TException {
    return mMasterInfo.getWorkersInfo();
  }

  @Override
  public List<ClientFileInfo> liststatus(String path) throws InvalidPathException,
      FileDoesNotExistException, TException {
    return mMasterInfo.getFilesInfo(new TachyonURI(path));
  }

  @Override
  public void user_completeFile(int fileId) throws FileDoesNotExistException, TException {
    mMasterInfo.completeFile(fileId);
  }

  @Override
  public int user_createDependency(List<String> parents, List<String> children,
      String commandPrefix, List<ByteBuffer> data, String comment, String framework,
      String frameworkVersion, int dependencyType, long childrenBlockSizeByte)
      throws InvalidPathException, FileDoesNotExistException, FileAlreadyExistException,
      BlockInfoException, TachyonException, TException {
    try {
      List<TachyonURI> childrenUris = new ArrayList<TachyonURI>(children.size());
      for (int k = 0; k < children.size(); k ++) {
        mMasterInfo.createFile(new TachyonURI(children.get(k)), childrenBlockSizeByte);
        childrenUris.add(new TachyonURI(children.get(k)));
      }
      List<TachyonURI> parentUris = new ArrayList<TachyonURI>(parents.size());
      for (int k = 0; k < parents.size(); k ++) {
        parentUris.add(new TachyonURI(parents.get(k)));
      }
      return mMasterInfo.createDependency(parentUris, childrenUris, commandPrefix, data, comment,
          framework, frameworkVersion, DependencyType.getDependencyType(dependencyType));
    } catch (IOException e) {
      throw new FileDoesNotExistException(e.getMessage());
    }
  }

  @Override
  public int user_createFile(String path, String ufsPath, long blockSizeByte, boolean recursive)
      throws FileAlreadyExistException, InvalidPathException, BlockInfoException,
      SuspectedFileSizeException, TachyonException, TException {
    if (!ufsPath.isEmpty()) {
      UnderFileSystem underfs = UnderFileSystem.get(ufsPath);
      try {
        long ufsBlockSizeByte = underfs.getBlockSizeByte(ufsPath);
        long fileSizeByte = underfs.getFileSize(ufsPath);
        int fileId = mMasterInfo.createFile(new TachyonURI(path), ufsBlockSizeByte, recursive);
        if (fileId != -1
            && mMasterInfo.addCheckpoint(-1, fileId, fileSizeByte, new TachyonURI(ufsPath))) {
          return fileId;
        }
      } catch (IOException e) {
        throw new TachyonException(e.getMessage());
      }
    }

    return mMasterInfo.createFile(new TachyonURI(path), blockSizeByte, recursive);
  }

  @Override
  public long user_createNewBlock(int fileId) throws FileDoesNotExistException, TException {
    return mMasterInfo.createNewBlock(fileId);
  }

  @Override
  public int user_createRawTable(String path, int columns, ByteBuffer metadata)
      throws FileAlreadyExistException, InvalidPathException, TableColumnException,
      TachyonException, TException {
    return mMasterInfo.createRawTable(new TachyonURI(path), columns,
        CommonUtils.generateNewByteBufferFromThriftRPCResults(metadata));
  }

  @Override
  public boolean user_delete(int fileId, String path, boolean recursive) throws TachyonException,
      TException {
{'fraction_non_alphanumeric': 0.08357611070648216, 'fraction_numerical': 0.0009104151493080845, 'mean_word_length': 4.739289446185998, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5998133', 'n_tokens_mistral': 3278, 'n_tokens_neox': 3175, 'n_words': 695}