<commit_before>/*
 * Licensed to the University of California, Berkeley under one or more contributor license
 * agreements. See the NOTICE file distributed with this work for additional information regarding
 * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance with the License. You may obtain a
 * copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */

package tachyon.client.next.block;

import java.io.Closeable;
import java.io.IOException;

import tachyon.client.next.ClientOptions;
import tachyon.master.MasterClient;
import tachyon.thrift.BlockInfo;
import tachyon.thrift.FileBlockInfo;

/**
 * Tachyon Block Store client. This is an internal client for all block level operations in Tachyon.
 * An instance of this class can be obtained via {@link TachyonBS#get}. This class is thread safe.
 */
public class TachyonBS implements Closeable {

  public static TachyonBS sCachedClient = null;

  public static synchronized TachyonBS get() {
    if (sCachedClient != null) {
      return sCachedClient;
    }
    sCachedClient = new TachyonBS();
    return sCachedClient;
  }

  private final BSContext mContext;

  public TachyonBS() {
    mContext = BSContext.INSTANCE;
  }

  public void close() {

  }

  /**
   * Deletes a block from Tachyon space and under storage space.
   *
   * @param blockId the blockId of the block to delete
   */
  // TODO: Evaluate if this is necessary for now, or if file level delete is sufficient
  public void delete(long blockId) {
    MasterClient masterClient = mContext.acquireMasterClient();
    try {
      // TODO: Implement delete RPC
    } finally {
      mContext.releaseMasterClient(masterClient);
    }
  }

  /**
   * Frees a block from Tachyon space by removing it from all the workers which currently own a
   * copy of the block. This does not remove the block from under storage.
   *
   * @param blockId the blockId of the block to free
   */
  // TODO: Evaluate if this is necessary for now, or if file level free is sufficient
  public void free(long blockId) {
    // TODO: Implement free RPC
  }

  /**
   * Gets the block info of a block, if it exists.
   *
   * @param blockId the blockId to obtain information about
   * @return a FileBlockInfo containing the metadata of the block
   * @throws IOException if the block does not exist
   */
  public FileBlockInfo getInfo(long blockId) throws IOException {
    MasterClient masterClient = mContext.acquireMasterClient();
    try {
      return masterClient.user_getClientBlockInfo(blockId);
    } finally {
      mContext.releaseMasterClient(masterClient);
    }
  }

  /**
   * Gets a stream to read the data of a block. The stream can be backed by Tachyon storage or
   * the under storage system.
   *
   * @param blockId the block to read from
   * @param options the custom options when reading the block
   * @return a BlockInStream which can be used to read the data in a streaming fashion
   * @throws IOException if the block does not exist
   */
  public BlockInStream getInStream(long blockId, ClientOptions options) throws IOException {
    MasterClient masterClient = mContext.acquireMasterClient();
    try {
      // TODO: Fix this RPC
      BlockInfo blockInfo = masterClient.user_getClientBlockInfo(blockId);
      return new ClientBlockInStream(blockInfo, options);
    } finally {
      mContext.releaseMasterClient(masterClient);
    }
  }

  /**
   * Gets a stream to write data to a block. The stream can only be backed by Tachyon storage.
   *
   * @param blockId the block to write
   * @param options the custom options when writing the block
   * @return a BlockOutStream which can be used to write data to the block in a streaming fashion
   * @throws IOException if the block cannot be written
   */
  public BlockOutStream getOutStream(long blockId, ClientOptions options) throws IOException {
    // No specified location to read from
    if (null == options.getLocation()) {
      // Local client, attempt to do direct write to local storage
      if (mContext.hasLocalWorker()) {
        return new LocalBlockOutStream(blockId, options);
      }
      // Client is not local or the data is not available on the local worker, use remote stream
      return new RemoteBlockOutStream(blockId, options);
    }
    // TODO: Handle the case when a location is specified
    return null;
  }

  // TODO: Evaluate if this is necessary for now, or if file level promote is sufficient
  public boolean promote(long blockId) {
    // TODO: Implement me
    return false;
  }
}<commit_msg>Remove unnecessary methods in TachyonBS.<commit_after>/*
 * Licensed to the University of California, Berkeley under one or more contributor license
 * agreements. See the NOTICE file distributed with this work for additional information regarding
 * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance with the License. You may obtain a
 * copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */

package tachyon.client.next.block;

import java.io.Closeable;
import java.io.IOException;

import tachyon.client.next.ClientOptions;
import tachyon.master.MasterClient;
import tachyon.thrift.BlockInfo;
import tachyon.thrift.FileBlockInfo;

/**
 * Tachyon Block Store client. This is an internal client for all block level operations in Tachyon.
 * An instance of this class can be obtained via {@link TachyonBS#get}. This class is thread safe.
 */
public class TachyonBS implements Closeable {

  public static TachyonBS sCachedClient = null;

  public static synchronized TachyonBS get() {
    if (sCachedClient != null) {
      return sCachedClient;
    }
    sCachedClient = new TachyonBS();
    return sCachedClient;
  }

  private final BSContext mContext;

  public TachyonBS() {
    mContext = BSContext.INSTANCE;
  }

  public void close() {

  }

  /**
   * Gets the block info of a block, if it exists.
   *
   * @param blockId the blockId to obtain information about
   * @return a FileBlockInfo containing the metadata of the block
   * @throws IOException if the block does not exist
   */
  public FileBlockInfo getInfo(long blockId) throws IOException {
    MasterClient masterClient = mContext.acquireMasterClient();
    try {
      return masterClient.user_getClientBlockInfo(blockId);
    } finally {
      mContext.releaseMasterClient(masterClient);
    }
  }

  /**
   * Gets a stream to read the data of a block. The stream can be backed by Tachyon storage or
   * the under storage system.
   *
   * @param blockId the block to read from
   * @param options the custom options when reading the block
   * @return a BlockInStream which can be used to read the data in a streaming fashion
   * @throws IOException if the block does not exist
   */
  public BlockInStream getInStream(long blockId, ClientOptions options) throws IOException {
    MasterClient masterClient = mContext.acquireMasterClient();
    try {
      // TODO: Fix this RPC
      BlockInfo blockInfo = masterClient.user_getClientBlockInfo(blockId);
      return new ClientBlockInStream(blockInfo, options);
    } finally {
      mContext.releaseMasterClient(masterClient);
    }
  }

  /**
   * Gets a stream to write data to a block. The stream can only be backed by Tachyon storage.
   *
   * @param blockId the block to write
   * @param options the custom options when writing the block
   * @return a BlockOutStream which can be used to write data to the block in a streaming fashion
   * @throws IOException if the block cannot be written
   */
  public BlockOutStream getOutStream(long blockId, ClientOptions options) throws IOException {
    // No specified location to read from
    if (null == options.getLocation()) {
      // Local client, attempt to do direct write to local storage
      if (mContext.hasLocalWorker()) {
        return new LocalBlockOutStream(blockId, options);
      }
      // Client is not local or the data is not available on the local worker, use remote stream
      return new RemoteBlockOutStream(blockId, options);
    }
    // TODO: Handle the case when a location is specified
    return null;
  }
}
{'fraction_non_alphanumeric': 0.06544561090015635, 'fraction_numerical': 0.0008934554389099843, 'mean_word_length': 3.383259911894273, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2144927', 'n_tokens_mistral': 2391, 'n_tokens_neox': 2341, 'n_words': 1048}