예제 #1
0
  /**
   * This function displays the first 5KB of a file if it is in ASCII format.
   *
   * @param path The path of the file to display
   * @param request The HttpServletRequest object
   * @throws FileDoesNotExistException
   * @throws IOException
   * @throws InvalidPathException
   * @throws TException
   */
  private void displayFile(String path, HttpServletRequest request)
      throws FileDoesNotExistException, InvalidPathException, IOException {
    TachyonClient tachyonClient = TachyonClient.getClient(mMasterInfo.getMasterAddress());
    TachyonFile tFile = tachyonClient.getFile(path);
    if (tFile == null) {
      throw new FileDoesNotExistException(path);
    }

    InStream is = tFile.getInStream(OpType.READ_NO_CACHE);
    int len = Math.min(5 * Constants.KB, (int) tFile.getSize());
    byte[] data = new byte[len];
    is.read(data, 0, len);
    String fileData = CommonUtils.convertByteArrayToString(data);
    if (fileData == null) {
      fileData = "The requested file is not completely encoded in ascii";
    }
    is.close();

    try {
      tachyonClient.close();
    } catch (TException e) {
      LOG.error(e.getMessage());
    }
    request.setAttribute("fileData", fileData);
    return;
  }
예제 #2
0
  public static void writeParition()
      throws IOException, TableDoesNotExistException, InvalidPathException,
          FileAlreadyExistException, TException {
    RawTable rawTable = sTachyonClient.getRawTable(sTablePath);

    LOG.info("Writing data...");
    for (int column = 0; column < COLS; column++) {
      RawColumn rawColumn = rawTable.getRawColumn(column);
      if (!rawColumn.createPartition(0)) {
        CommonUtils.runtimeException(
            "Failed to create partition in table " + sTablePath + " under column " + column);
      }

      ByteBuffer buf = ByteBuffer.allocate(80);
      buf.order(ByteOrder.nativeOrder());
      for (int k = 0; k < 20; k++) {
        buf.putInt(k);
      }
      buf.flip();
      CommonUtils.printByteBuffer(LOG, buf);
      buf.flip();

      TachyonFile tFile = rawColumn.getPartition(0);
      OutStream os = tFile.createOutStream(sWriteType);
      os.write(buf);
      os.close();
    }
  }
예제 #3
0
 public static void createRawTable() throws InvalidPathException {
   long startTimeMs = CommonUtils.getCurrentMs();
   ByteBuffer data = ByteBuffer.allocate(12);
   data.putInt(-1);
   data.putInt(-2);
   data.putInt(-3);
   data.flip();
   mId = sTachyonClient.createRawTable(sTablePath, 3, data);
   CommonUtils.printTimeTakenMs(startTimeMs, LOG, "createRawTable with id " + mId);
 }
예제 #4
0
 public static void main(String[] args)
     throws IOException, TableDoesNotExistException, OutOfMemoryForPinFileException,
         InvalidPathException, FileAlreadyExistException, TException {
   if (args.length != 3) {
     System.out.println(
         "java -cp target/tachyon-"
             + Version.VERSION
             + "-jar-with-dependencies.jar "
             + "tachyon.examples.BasicRawTableOperations <TachyonMasterAddress> <FilePath>");
     System.exit(-1);
   }
   sTachyonClient = TachyonClient.getClient(args[0]);
   sTablePath = args[1];
   sWriteType = OpType.getOpType(args[2]);
   createRawTable();
   writeParition();
   readPartition();
 }
예제 #5
0
  public static void readPartition()
      throws IOException, TableDoesNotExistException, InvalidPathException, TException {
    LOG.info("Reading data...");
    RawTable rawTable = sTachyonClient.getRawTable(mId);
    ByteBuffer metadata = rawTable.getMetadata();
    LOG.info("Metadata: ");
    LOG.info(metadata.getInt() + " ");
    LOG.info(metadata.getInt() + " ");
    LOG.info(metadata.getInt() + " ");

    for (int column = 0; column < COLS; column++) {
      RawColumn rawColumn = rawTable.getRawColumn(column);
      TachyonFile tFile = rawColumn.getPartition(0);

      ByteBuffer buf = tFile.readByteBuffer();
      if (buf == null) {
        tFile.recacheData();
      }
      CommonUtils.printByteBuffer(LOG, tFile.readByteBuffer());
      tFile.releaseFileLock();
    }
  }